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 68 of file guild.h.

Member Typedef Documentation

◆ GuildMap

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

Definition at line 214 of file guild.h.

◆ MemberList

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

Definition at line 208 of file guild.h.

Constructor & Destructor Documentation

◆ ~Guild()

Guild::~Guild ( )

Definition at line 106 of file guild.cpp.

References clearMembers().

107 {
108  clearMembers();
109 }
void clearMembers()
Definition: guild.h:154

◆ Guild()

Guild::Guild ( const int16_t  id)
explicitprivate

Constructor with guild id passed to it.

Definition at line 94 of file guild.cpp.

References guilds.

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

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 111 of file guild.cpp.

References getMember(), and mMembers.

Referenced by GuildManager::process(), EAthena::GuildRecv::processGuildMemberList(), and GuildManager::updateList().

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

◆ addMember() [2/2]

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

Adds member to the list.

Definition at line 126 of file guild.cpp.

References getMember(), and mMembers.

127 {
128  GuildMember *m = getMember(name);
129  if (m != nullptr)
130  return m;
131 
132  m = new GuildMember(this, name);
133 
134  mMembers.push_back(m);
135 
136  return m;
137 }
GuildMember * getMember(const BeingId id) const
Definition: guild.cpp:139
MemberList mMembers
Definition: guild.h:222

◆ addPos()

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

Definition at line 368 of file guild.cpp.

References mPositions.

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

369 {
370  mPositions[id] = name;
371 }
PositionsMap mPositions
Definition: guild.h:223

◆ clearGuilds()

void Guild::clearGuilds ( )
static

Definition at line 397 of file guild.cpp.

References guilds.

Referenced by Client::stateSwitchLogin1().

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

◆ clearMembers()

void Guild::clearMembers ( )
inline

◆ getAvatarAt()

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

Implements AvatarListModel.

Definition at line 291 of file guild.cpp.

References mMembers.

292 {
293  return mMembers[index];
294 }
MemberList mMembers
Definition: guild.h:222

◆ getEmblemId()

int Guild::getEmblemId ( ) const
inline

Definition at line 197 of file guild.h.

198  { return mEmblemId; }
int mEmblemId
Definition: guild.h:225

◆ getGuild()

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

Definition at line 373 of file guild.cpp.

References 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().

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

◆ getId()

int16_t Guild::getId ( ) const
inline

◆ 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 170 of file guild.h.

References A_WARN_UNUSED, GuildMember::getGuild(), and GuildMember::getPos().

171  { return mCanInviteUsers; }
bool mCanInviteUsers
Definition: guild.h:227

◆ getMember() [1/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 139 of file guild.cpp.

References mMembers.

Referenced by addMember(), LocalPlayer::checkNewName(), GuildManager::process(), EAthena::GuildRecv::processGuildMemberLogin(), EAthena::GuildRecv::processGuildMemberPosChange(), EAthena::GuildRecv::processGuildUpdateCoords(), WhoIsOnline::setNeutralColor(), PopupMenu::showPlayerPopup(), PopupMenu::showPopup(), Actions::splitWhisper(), and ChatWindow::updateOnline().

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

◆ getMember() [2/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 153 of file guild.cpp.

References mMembers.

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

◆ 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 189 of file guild.cpp.

References mMembers.

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

◆ 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 172 of file guild.cpp.

References mMembers.

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

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

◆ getMembers()

const MemberList* Guild::getMembers ( ) const
inline

Definition at line 210 of file guild.h.

Referenced by SocialGuildTab2::buildCounter(), and SocialGuildTab::buildCounter().

211  { return &mMembers; }
MemberList mMembers
Definition: guild.h:222

◆ getName()

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

Get the name of the guild.

Returns
returns name of the guild

Definition at line 127 of file guild.h.

References Avatar::mName.

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

128  { return mName; }
std::string mName
Definition: guild.h:224

◆ getNames()

void Guild::getNames ( StringVect names) const

Definition at line 354 of file guild.cpp.

References mMembers.

Referenced by GuildTab::getAutoCompleteList(), and GuildManager::getNames().

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

◆ getNumberOfElements()

int Guild::getNumberOfElements ( )
inlinevirtual

Get size of members list.

Returns
Returns the number of members in the guild.

Implements ListModel.

Definition at line 161 of file guild.h.

References A_WARN_UNUSED, and CAST_S32.

162  { return CAST_S32(mMembers.size()); }
MemberList mMembers
Definition: guild.h:222
#define CAST_S32
Definition: cast.h:29

◆ getPos()

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

Definition at line 384 of file guild.cpp.

References mPositions.

Referenced by GuildMember::getAdditionString().

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

◆ getPositions()

const PositionsMap& Guild::getPositions ( ) const
inline

Definition at line 191 of file guild.h.

Referenced by PopupMenu::showChangePos().

192  { return mPositions; }
PositionsMap mPositions
Definition: guild.h:223

◆ getServerGuild()

bool Guild::getServerGuild ( ) const
inline

◆ isMember() [1/3]

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

Definition at line 303 of file guild.cpp.

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

Referenced by WhoIsOnline::setNeutralColor().

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

◆ isMember() [2/3]

bool Guild::isMember ( const BeingId  id) const

Definition at line 326 of file guild.cpp.

References mMembers.

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

◆ isMember() [3/3]

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

Definition at line 340 of file guild.cpp.

References mMembers.

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

◆ removeFromMembers()

void Guild::removeFromMembers ( )

Definition at line 272 of file guild.cpp.

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

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

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

◆ removeMember() [1/3]

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

Removes a member from the guild.

Definition at line 203 of file guild.cpp.

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

Referenced by Being::clearGuilds(), GuildManager::process(), EAthena::GuildRecv::processGuildExpulsionContinue(), EAthena::GuildRecv::processGuildLeave(), and EAthena::GuildRecv::processGuildLeave2().

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

◆ removeMember() [2/3]

void Guild::removeMember ( const BeingId  id)

Removes a member from the guild by account id.

Definition at line 226 of file guild.cpp.

References mMembers.

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

◆ removeMember() [3/3]

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

Removes a member from the guild.

Definition at line 249 of file guild.cpp.

References mMembers.

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

◆ setEmblemId()

void Guild::setEmblemId ( const int  id)
inline

Definition at line 194 of file guild.h.

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

195  { mEmblemId = id; }
int mEmblemId
Definition: guild.h:225

◆ setName()

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

Set the guild's name.

Definition at line 78 of file guild.h.

References A_WARN_UNUSED, and Avatar::mName.

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

79  { mName = name; }
std::string mName
Definition: guild.h:224

◆ setRights()

void Guild::setRights ( const int16_t  rights)

Definition at line 296 of file guild.cpp.

References mCanInviteUsers.

297 {
298  // to invite, rights must be greater than 0
299  if (rights > 0)
300  mCanInviteUsers = true;
301 }
bool mCanInviteUsers
Definition: guild.h:227

◆ setServerGuild()

void Guild::setServerGuild ( const bool  b)
inline

Definition at line 202 of file guild.h.

Referenced by GuildManager::createGuild(), and GuildManager::updateList().

203  { mServerGuild = b; }
bool mServerGuild
Definition: guild.h:228

◆ sort()

void Guild::sort ( )

Definition at line 392 of file guild.cpp.

References guildSorter, and mMembers.

Referenced by GuildManager::process(), EAthena::GuildRecv::processGuildMemberList(), and GuildManager::updateList().

393 {
394  std::sort(mMembers.begin(), mMembers.end(), guildSorter);
395 }
MemberList mMembers
Definition: guild.h:222
static class SortGuildFunctor guildSorter

Field Documentation

◆ guilds

Guild::GuildMap Guild::guilds
staticprivate

Definition at line 215 of file guild.h.

Referenced by clearGuilds(), GuildMember::getAdditionString(), getGuild(), and Guild().

◆ mCanInviteUsers

bool Guild::mCanInviteUsers
private

Definition at line 227 of file guild.h.

Referenced by setRights().

◆ mEmblemId

int Guild::mEmblemId
private

Definition at line 225 of file guild.h.

◆ mId

int16_t Guild::mId
private

Definition at line 226 of file guild.h.

Referenced by removeFromMembers().

◆ mMembers

MemberList Guild::mMembers
private

◆ mName

std::string Guild::mName
private

Definition at line 224 of file guild.h.

◆ mPositions

PositionsMap Guild::mPositions
private

Definition at line 223 of file guild.h.

Referenced by addPos(), and getPos().

◆ mServerGuild

bool Guild::mServerGuild
private

Definition at line 228 of file guild.h.


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