ManaPlus
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
Guild Class Reference

#include <guild.h>

Inheritance diagram for Guild:
AvatarListModel ListModel

Public Types

typedef std::vector< GuildMember * > MemberList
 

Public Member Functions

 ~Guild ()
 
void setName (const std::string &name)
 
GuildMemberaddMember (const BeingId accountId, const int charId, const std::string &name)
 
GuildMemberaddMember (const std::string &name)
 
GuildMembergetMember (const BeingId id) const
 
GuildMembergetMember (const BeingId accountId, const int charId) const
 
GuildMembergetMemberByCharId (const int charId) const
 
GuildMembergetMember (const std::string &name) const
 
const std::string & getName () const
 
int16_t getId () const
 
void removeMember (const GuildMember *const member)
 
void removeMember (const BeingId id)
 
void removeMember (const std::string &name)
 
void removeFromMembers ()
 
void clearMembers ()
 
int getNumberOfElements ()
 
AvatargetAvatarAt (const int index)
 
bool getInviteRights () const
 
void setRights (const int16_t rights)
 
bool isMember (const GuildMember *const member) const
 
bool isMember (const BeingId id) const
 
bool isMember (const std::string &name) const
 
void getNames (StringVect &names) const
 
void addPos (const int id, const std::string &name)
 
void sort ()
 
std::string getPos (const int id) const
 
const PositionsMapgetPositions () const
 
void setEmblemId (const int id)
 
int getEmblemId () const
 
void setServerGuild (const bool b)
 
bool getServerGuild () const
 
const MemberListgetMembers () const
 
- Public Member Functions inherited from AvatarListModel
 AvatarListModel ()
 
std::string getElementAt (int i)
 
- Public Member Functions inherited from ListModel
 ListModel ()
 
virtual ~ListModel ()
 

Static Public Member Functions

static GuildgetGuild (const int16_t id)
 
static void clearGuilds ()
 

Private Types

typedef std::map< int, Guild * > GuildMap
 

Private Member Functions

 Guild (const int16_t id)
 

Private Attributes

MemberList mMembers
 
PositionsMap mPositions
 
std::string mName
 
int mEmblemId
 
int16_t mId
 
bool mCanInviteUsers
 
bool mServerGuild
 

Static Private Attributes

static GuildMap guilds
 

Detailed Description

Definition at line 69 of file guild.h.

Member Typedef Documentation

◆ GuildMap

typedef std::map<int, Guild*> Guild::GuildMap
private

Definition at line 215 of file guild.h.

◆ MemberList

typedef std::vector<GuildMember*> Guild::MemberList

Definition at line 209 of file guild.h.

Constructor & Destructor Documentation

◆ ~Guild()

Guild::~Guild ( )

Definition at line 107 of file guild.cpp.

108 {
109  clearMembers();
110 }
void clearMembers()
Definition: guild.h:155

References clearMembers().

◆ Guild()

Guild::Guild ( const int16_t  id)
explicitprivate

Constructor with guild id passed to it.

Definition at line 95 of file guild.cpp.

95  :
96  mMembers(),
97  mPositions(),
98  mName(),
99  mEmblemId(0),
100  mId(id),
101  mCanInviteUsers(false),
102  mServerGuild(true)
103 {
104  guilds[id] = this;
105 }
int mEmblemId
Definition: guild.h:226
bool mCanInviteUsers
Definition: guild.h:228
MemberList mMembers
Definition: guild.h:223
PositionsMap mPositions
Definition: guild.h:224
static GuildMap guilds
Definition: guild.h:216
bool mServerGuild
Definition: guild.h:229
int16_t mId
Definition: guild.h:227
std::string mName
Definition: guild.h:225

References guilds.

Referenced by getGuild().

Member Function Documentation

◆ addMember() [1/2]

GuildMember * Guild::addMember ( const BeingId  accountId,
const int  charId,
const std::string &  name 
)

Adds member to the list.

Definition at line 112 of file guild.cpp.

115 {
116  GuildMember *m = getMember(accountId, charId);
117  if (m != nullptr)
118  return m;
119 
120  m = new GuildMember(this, accountId, charId, name);
121 
122  mMembers.push_back(m);
123 
124  return m;
125 }
GuildMember * getMember(const BeingId id) const
Definition: guild.cpp:140

References getMember(), and mMembers.

Referenced by EAthena::GuildRecv::processGuildMemberList().

◆ addMember() [2/2]

GuildMember * Guild::addMember ( const std::string &  name)

Adds member to the list.

Definition at line 127 of file guild.cpp.

128 {
129  GuildMember *m = getMember(name);
130  if (m != nullptr)
131  return m;
132 
133  m = new GuildMember(this, name);
134 
135  mMembers.push_back(m);
136 
137  return m;
138 }

References getMember(), and mMembers.

◆ addPos()

void Guild::addPos ( const int  id,
const std::string &  name 
)

Definition at line 369 of file guild.cpp.

370 {
371  mPositions[id] = name;
372 }

References mPositions.

Referenced by EAthena::GuildRecv::processGuildPosNameList().

◆ clearGuilds()

void Guild::clearGuilds ( )
static

Definition at line 398 of file guild.cpp.

399 {
400  GuildMap::iterator it = guilds.begin();
401  while (it != guilds.end())
402  {
403  delete (*it).second;
404  ++ it;
405  }
406  guilds.clear();
407 }

References guilds.

◆ clearMembers()

void Guild::clearMembers ( )
inline

◆ getAvatarAt()

Avatar * Guild::getAvatarAt ( const int  index)
virtual

Implements AvatarListModel.

Definition at line 292 of file guild.cpp.

293 {
294  return mMembers[index];
295 }

References mMembers.

◆ getEmblemId()

int Guild::getEmblemId ( ) const
inline

Definition at line 198 of file guild.h.

199  { return mEmblemId; }

◆ getGuild()

Guild * Guild::getGuild ( const int16_t  id)
static

Definition at line 374 of file guild.cpp.

375 {
376  const GuildMap::const_iterator it = guilds.find(id);
377  if (it != guilds.end())
378  return it->second;
379 
380  Guild *const guild = new Guild(id);
381  guilds[id] = guild;
382  return guild;
383 }
Definition: guild.h:70
Guild(const int16_t id)
Definition: guild.cpp:95
uint32_t guild

References Guild(), guild, and guilds.

Referenced by GuildManager::clear(), GuildManager::createGuild(), EAthena::GuildRecv::processGuildBasicInfo(), EAthena::GuildRecv::processGuildPositionInfo(), TmwAthena::BeingRecv::processPlayerMove(), TmwAthena::BeingRecv::processPlayerUpdate1(), TmwAthena::BeingRecv::processPlayerUpdate2(), GuildManager::reload(), WhoIsOnline::setNeutralColor(), and GuildManager::updateList().

◆ getId()

int16_t Guild::getId ( ) const
inline

Get the id of the guild.

Returns
Returns the id of the guild

Definition at line 135 of file guild.h.

136  { return mId; }

References Avatar::mId.

Referenced by SocialGuildTab::action(), EAthena::GuildRecv::processGuildLeave(), EAthena::GuildRecv::processGuildLeave2(), WhoIsOnline::setNeutralColor(), PopupMenu::showChatPopup(), and PopupMenu::showPopup().

◆ getInviteRights()

bool Guild::getInviteRights ( ) const
inline

Get whether user can invite users to this guild.

Returns
Returns true if user can invite users

Definition at line 171 of file guild.h.

172  { return mCanInviteUsers; }

◆ getMember() [1/3]

GuildMember * Guild::getMember ( const BeingId  accountId,
const int  charId 
) const

Find a member by account ID and char ID.

Returns
the member with the given ID, or NULL if they don't exist.

Definition at line 154 of file guild.cpp.

156 {
157  MemberList::const_iterator itr = mMembers.begin();
158  const MemberList::const_iterator itr_end = mMembers.end();
159  while (itr != itr_end)
160  {
161  if ((*itr) != nullptr &&
162  (*itr)->mId == accountId &&
163  (*itr)->mCharId == charId)
164  {
165  return (*itr);
166  }
167  ++itr;
168  }
169 
170  return nullptr;
171 }

References mMembers.

◆ getMember() [2/3]

GuildMember * Guild::getMember ( const BeingId  id) const

Find a member by ID.

Returns
the member with the given ID, or NULL if they don't exist.

Definition at line 140 of file guild.cpp.

141 {
142  MemberList::const_iterator itr = mMembers.begin();
143  const MemberList::const_iterator itr_end = mMembers.end();
144  while (itr != itr_end)
145  {
146  if (((*itr) != nullptr) && (*itr)->mId == id)
147  return (*itr);
148  ++itr;
149  }
150 
151  return nullptr;
152 }

References mMembers.

Referenced by addMember(), EAthena::GuildRecv::processGuildMemberLogin(), EAthena::GuildRecv::processGuildMemberPosChange(), EAthena::GuildRecv::processGuildUpdateCoords(), WhoIsOnline::setNeutralColor(), PopupMenu::showPlayerPopup(), and PopupMenu::showPopup().

◆ getMember() [3/3]

GuildMember * Guild::getMember ( const std::string &  name) const

Find a member by name.

Returns
the member with the given name, or NULL if they don't exist.

Definition at line 190 of file guild.cpp.

191 {
192  MemberList::const_iterator itr = mMembers.begin();
193  const MemberList::const_iterator itr_end = mMembers.end();
194  while (itr != itr_end)
195  {
196  if (((*itr) != nullptr) && (*itr)->getName() == name)
197  return (*itr);
198  ++itr;
199  }
200 
201  return nullptr;
202 }

References mMembers.

◆ getMemberByCharId()

GuildMember * Guild::getMemberByCharId ( const int  charId) const

Find a member by char ID.

Returns
the member with the given ID, or NULL if they don't exist.

Definition at line 173 of file guild.cpp.

174 {
175  MemberList::const_iterator itr = mMembers.begin();
176  const MemberList::const_iterator itr_end = mMembers.end();
177  while (itr != itr_end)
178  {
179  if ((*itr) != nullptr &&
180  (*itr)->mCharId == charId)
181  {
182  return (*itr);
183  }
184  ++itr;
185  }
186 
187  return nullptr;
188 }

References mMembers.

Referenced by EAthena::GuildRecv::processGuildExpulsion2(), and EAthena::GuildRecv::processGuildLeave2().

◆ getMembers()

const MemberList* Guild::getMembers ( ) const
inline

Definition at line 211 of file guild.h.

212  { return &mMembers; }

◆ getName()

const std::string& Guild::getName ( ) const
inline

Get the name of the guild.

Returns
returns name of the guild

Definition at line 128 of file guild.h.

129  { return mName; }

References Avatar::mName.

Referenced by SocialGuildTab::action(), SocialGuildTab::invite(), SocialGuildTab::leave(), EAthena::GuildRecv::processGuildMemberList(), and EAthena::GuildRecv::processGuildPositionInfo().

◆ getNames()

void Guild::getNames ( StringVect names) const

Definition at line 355 of file guild.cpp.

356 {
357  names.clear();
358  MemberList::const_iterator it = mMembers.begin();
359  const MemberList::const_iterator it_end = mMembers.end();
360 
361  while (it != it_end)
362  {
363  if (*it != nullptr)
364  names.push_back((*it)->getName());
365  ++it;
366  }
367 }

References mMembers.

Referenced by GuildTab::getAutoCompleteList().

◆ getNumberOfElements()

int Guild::getNumberOfElements ( )
inlinevirtual

Get size of members list.

Returns
Returns the number of members in the guild.

Implements ListModel.

Definition at line 162 of file guild.h.

163  { return CAST_S32(mMembers.size()); }
#define CAST_S32
Definition: cast.h:30

References CAST_S32.

◆ getPos()

std::string Guild::getPos ( const int  id) const

Definition at line 385 of file guild.cpp.

386 {
387  const PositionsMap::const_iterator it = mPositions.find(id);
388  if (it == mPositions.end())
389  return "";
390  return it->second;
391 }

References mPositions.

Referenced by GuildMember::getAdditionString().

◆ getPositions()

const PositionsMap& Guild::getPositions ( ) const
inline

Definition at line 192 of file guild.h.

193  { return mPositions; }

◆ getServerGuild()

bool Guild::getServerGuild ( ) const
inline

Definition at line 206 of file guild.h.

207  { return mServerGuild; }

Referenced by PopupMenu::showChatPopup(), PopupMenu::showPlayerPopup(), and PopupMenu::showPopup().

◆ isMember() [1/3]

bool Guild::isMember ( const BeingId  id) const

Definition at line 327 of file guild.cpp.

328 {
329  MemberList::const_iterator itr = mMembers.begin();
330  const MemberList::const_iterator itr_end = mMembers.end();
331  while (itr != itr_end)
332  {
333  if (((*itr) != nullptr) && (*itr)->mId == id)
334  return true;
335  ++itr;
336  }
337 
338  return false;
339 }

References mMembers.

◆ isMember() [2/3]

bool Guild::isMember ( const GuildMember *const  member) const

Definition at line 304 of file guild.cpp.

305 {
306  if (member == nullptr)
307  return false;
308 
309  if ((member->mGuild != nullptr) && member->mGuild != this)
310  return false;
311 
312  MemberList::const_iterator itr = mMembers.begin();
313  const MemberList::const_iterator itr_end = mMembers.end();
314  while (itr != itr_end)
315  {
316  if (((*itr) != nullptr) && (*itr)->mId == member->mId &&
317  (*itr)->getName() == member->getName())
318  {
319  return true;
320  }
321  ++itr;
322  }
323 
324  return false;
325 }
BeingId mId
Definition: avatar.h:187
std::string getName() const
Definition: avatar.h:53
Guild * mGuild
Definition: guild.h:65

References Avatar::getName(), GuildMember::mGuild, Avatar::mId, and mMembers.

Referenced by WhoIsOnline::setNeutralColor().

◆ isMember() [3/3]

bool Guild::isMember ( const std::string &  name) const

Definition at line 341 of file guild.cpp.

342 {
343  MemberList::const_iterator itr = mMembers.begin();
344  const MemberList::const_iterator itr_end = mMembers.end();
345  while (itr != itr_end)
346  {
347  if (((*itr) != nullptr) && (*itr)->getName() == name)
348  return true;
349  ++itr;
350  }
351 
352  return false;
353 }

References mMembers.

◆ removeFromMembers()

void Guild::removeFromMembers ( )

Definition at line 273 of file guild.cpp.

274 {
275  if (actorManager == nullptr)
276  return;
277 
278  MemberList::const_iterator itr = mMembers.begin();
279  const MemberList::const_iterator itr_end = mMembers.end();
280  while (itr != itr_end)
281  {
282  if (*itr != nullptr)
283  {
284  Being *const b = actorManager->findBeing((*itr)->getID());
285  if (b != nullptr)
286  b->removeGuild(mId);
287  }
288  ++itr;
289  }
290 }
ActorManager * actorManager
Being * findBeing(const BeingId id) const
Definition: being.h:96
void removeGuild(const int id)
Definition: being.cpp:1248

References actorManager, ActorManager::findBeing(), mId, mMembers, and Being::removeGuild().

Referenced by EAthena::GuildRecv::processGuildExpulsionContinue(), EAthena::GuildRecv::processGuildLeave(), and EAthena::GuildRecv::processGuildLeave2().

◆ removeMember() [1/3]

void Guild::removeMember ( const BeingId  id)

Removes a member from the guild by account id.

Definition at line 227 of file guild.cpp.

228 {
229  bool deleted = true;
230  while (deleted)
231  {
232  deleted = false;
233  MemberList::iterator itr = mMembers.begin();
234  const MemberList::iterator itr_end = mMembers.end();
235  while (itr != itr_end)
236  {
237  if (((*itr) != nullptr) && (*itr)->mId == id)
238  {
239  GuildMember *member = *itr;
240  mMembers.erase(itr);
241  delete member;
242  deleted = true;
243  break;
244  }
245  ++itr;
246  }
247  }
248 }

References mMembers.

◆ removeMember() [2/3]

void Guild::removeMember ( const GuildMember *const  member)

Removes a member from the guild.

Definition at line 204 of file guild.cpp.

205 {
206  if (member == nullptr)
207  return;
208  MemberList::iterator itr = mMembers.begin();
209  const MemberList::iterator itr_end = mMembers.end();
210  while (itr != itr_end)
211  {
212  if (*itr == nullptr)
213  continue;
214  if ((*itr)->mId == member->mId &&
215  (*itr)->mCharId == member->mCharId &&
216  (*itr)->getName() == member->getName())
217  {
218  GuildMember *m = *itr;
219  mMembers.erase(itr);
220  delete m;
221  return;
222  }
223  ++ itr;
224  }
225 }
int mCharId
Definition: avatar.h:188

References Avatar::getName(), Avatar::mCharId, Avatar::mId, and mMembers.

Referenced by EAthena::GuildRecv::processGuildExpulsionContinue(), EAthena::GuildRecv::processGuildLeave(), and EAthena::GuildRecv::processGuildLeave2().

◆ removeMember() [3/3]

void Guild::removeMember ( const std::string &  name)

Removes a member from the guild.

Definition at line 250 of file guild.cpp.

251 {
252  bool deleted = true;
253  while (deleted)
254  {
255  deleted = false;
256  MemberList::iterator itr = mMembers.begin();
257  const MemberList::iterator itr_end = mMembers.end();
258  while (itr != itr_end)
259  {
260  if (((*itr) != nullptr) && (*itr)->getName() == name)
261  {
262  GuildMember *member = *itr;
263  mMembers.erase(itr);
264  delete member;
265  deleted = true;
266  break;
267  }
268  ++itr;
269  }
270  }
271 }

References mMembers.

◆ setEmblemId()

void Guild::setEmblemId ( const int  id)
inline

◆ setName()

void Guild::setName ( const std::string &  name)
inline

Set the guild's name.

Definition at line 79 of file guild.h.

80  { mName = name; }

References Avatar::mName.

Referenced by EAthena::GuildRecv::processGuildBasicInfo(), and EAthena::GuildRecv::processGuildPositionInfo().

◆ setRights()

void Guild::setRights ( const int16_t  rights)

Definition at line 297 of file guild.cpp.

298 {
299  // to invite, rights must be greater than 0
300  if (rights > 0)
301  mCanInviteUsers = true;
302 }

References mCanInviteUsers.

◆ setServerGuild()

void Guild::setServerGuild ( const bool  b)
inline

Definition at line 203 of file guild.h.

204  { mServerGuild = b; }

◆ sort()

void Guild::sort ( )

Definition at line 393 of file guild.cpp.

394 {
395  std::sort(mMembers.begin(), mMembers.end(), guildSorter);
396 }
static class SortGuildFunctor guildSorter

References guildSorter, and mMembers.

Referenced by EAthena::GuildRecv::processGuildMemberList().

Field Documentation

◆ guilds

Guild::GuildMap Guild::guilds
staticprivate

Definition at line 216 of file guild.h.

Referenced by clearGuilds(), getGuild(), and Guild().

◆ mCanInviteUsers

bool Guild::mCanInviteUsers
private

Definition at line 228 of file guild.h.

Referenced by setRights().

◆ mEmblemId

int Guild::mEmblemId
private

Definition at line 226 of file guild.h.

◆ mId

int16_t Guild::mId
private

Definition at line 227 of file guild.h.

Referenced by removeFromMembers().

◆ mMembers

MemberList Guild::mMembers
private

◆ mName

std::string Guild::mName
private

Definition at line 225 of file guild.h.

◆ mPositions

PositionsMap Guild::mPositions
private

Definition at line 224 of file guild.h.

Referenced by addPos(), and getPos().

◆ mServerGuild

bool Guild::mServerGuild
private

Definition at line 229 of file guild.h.


The documentation for this class was generated from the following files: