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

◆ MemberList

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

Definition at line 201 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:147

◆ 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:217
bool mCanInviteUsers
Definition: guild.h:220
PositionsMap mPositions
Definition: guild.h:216
bool mServerGuild
Definition: guild.h:221
MemberList mMembers
Definition: guild.h:215
static GuildMap guilds
Definition: guild.h:208
int mEmblemId
Definition: guild.h:218
int16_t mId
Definition: guild.h:219

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:215

◆ 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:215

◆ addPos()

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

Definition at line 351 of file guild.cpp.

References mPositions.

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

352 {
353  mPositions[id] = name;
354 }
PositionsMap mPositions
Definition: guild.h:216

◆ clearGuilds()

void Guild::clearGuilds ( )
static

Definition at line 380 of file guild.cpp.

References guilds.

Referenced by Client::stateSwitchLogin1().

381 {
382  GuildMap::iterator it = guilds.begin();
383  while (it != guilds.end())
384  {
385  delete (*it).second;
386  ++ it;
387  }
388  guilds.clear();
389 }
static GuildMap guilds
Definition: guild.h:208

◆ clearMembers()

void Guild::clearMembers ( )
inline

◆ getAvatarAt()

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

Implements AvatarListModel.

Definition at line 274 of file guild.cpp.

References mMembers.

275 {
276  return mMembers[index];
277 }
MemberList mMembers
Definition: guild.h:215

◆ getEmblemId()

int Guild::getEmblemId ( ) const
inline

Definition at line 190 of file guild.h.

191  { return mEmblemId; }
int mEmblemId
Definition: guild.h:218

◆ getGuild()

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

Definition at line 356 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().

357 {
358  const GuildMap::const_iterator it = guilds.find(id);
359  if (it != guilds.end())
360  return it->second;
361 
362  Guild *const guild = new Guild(id);
363  guilds[id] = guild;
364  return guild;
365 }
static GuildMap guilds
Definition: guild.h:208
uint32_t guild
Definition: guild.h:68

◆ getId()

int16_t Guild::getId ( ) const
inline

Get the id of the guild.

Returns
Returns the id of the guild

Definition at line 127 of file guild.h.

References Avatar::mId.

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

128  { return mId; }
int16_t mId
Definition: guild.h:219

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

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

164  { return mCanInviteUsers; }
bool mCanInviteUsers
Definition: guild.h:220

◆ 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:215

◆ 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:215

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

References mMembers.

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) && (*itr)->getName() == name)
179  return (*itr);
180  ++itr;
181  }
182 
183  return nullptr;
184 }
MemberList mMembers
Definition: guild.h:215

◆ getMembers()

const MemberList* Guild::getMembers ( ) const
inline

Definition at line 203 of file guild.h.

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

204  { return &mMembers; }
MemberList mMembers
Definition: guild.h:215

◆ getName()

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

Get the name of the guild.

Returns
returns name of the guild

Definition at line 120 of file guild.h.

References Avatar::mName.

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

121  { return mName; }
std::string mName
Definition: guild.h:217

◆ getNames()

void Guild::getNames ( StringVect names) const

Definition at line 337 of file guild.cpp.

References mMembers.

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

338 {
339  names.clear();
340  MemberList::const_iterator it = mMembers.begin();
341  const MemberList::const_iterator it_end = mMembers.end();
342 
343  while (it != it_end)
344  {
345  if (*it != nullptr)
346  names.push_back((*it)->getName());
347  ++it;
348  }
349 }
MemberList mMembers
Definition: guild.h:215

◆ getNumberOfElements()

int Guild::getNumberOfElements ( )
inlinevirtual

Get size of members list.

Returns
Returns the number of members in the guild.

Implements ListModel.

Definition at line 154 of file guild.h.

References A_WARN_UNUSED, and CAST_S32.

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

◆ getPos()

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

Definition at line 367 of file guild.cpp.

References mPositions.

Referenced by GuildMember::getAdditionString().

368 {
369  const PositionsMap::const_iterator it = mPositions.find(id);
370  if (it == mPositions.end())
371  return "";
372  return it->second;
373 }
PositionsMap mPositions
Definition: guild.h:216

◆ getPositions()

const PositionsMap& Guild::getPositions ( ) const
inline

Definition at line 184 of file guild.h.

Referenced by PopupMenu::showChangePos().

185  { return mPositions; }
PositionsMap mPositions
Definition: guild.h:216

◆ getServerGuild()

bool Guild::getServerGuild ( ) const
inline

◆ isMember() [1/3]

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

Definition at line 286 of file guild.cpp.

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

Referenced by WhoIsOnline::setNeutralColor().

287 {
288  if (member == nullptr)
289  return false;
290 
291  if ((member->mGuild != nullptr) && member->mGuild != this)
292  return false;
293 
294  MemberList::const_iterator itr = mMembers.begin();
295  const MemberList::const_iterator itr_end = mMembers.end();
296  while (itr != itr_end)
297  {
298  if (((*itr) != nullptr) && (*itr)->mId == member->mId &&
299  (*itr)->getName() == member->getName())
300  {
301  return true;
302  }
303  ++itr;
304  }
305 
306  return false;
307 }
std::string getName() const
Definition: avatar.h:52
Guild * mGuild
Definition: guild.h:64
MemberList mMembers
Definition: guild.h:215
BeingId mId
Definition: avatar.h:186

◆ isMember() [2/3]

bool Guild::isMember ( const BeingId  id) const

Definition at line 309 of file guild.cpp.

References mMembers.

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 == id)
316  return true;
317  ++itr;
318  }
319 
320  return false;
321 }
MemberList mMembers
Definition: guild.h:215

◆ isMember() [3/3]

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

Definition at line 323 of file guild.cpp.

References mMembers.

324 {
325  MemberList::const_iterator itr = mMembers.begin();
326  const MemberList::const_iterator itr_end = mMembers.end();
327  while (itr != itr_end)
328  {
329  if (((*itr) != nullptr) && (*itr)->getName() == name)
330  return true;
331  ++itr;
332  }
333 
334  return false;
335 }
MemberList mMembers
Definition: guild.h:215

◆ removeFromMembers()

void Guild::removeFromMembers ( )

Definition at line 255 of file guild.cpp.

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

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

256 {
257  if (actorManager == nullptr)
258  return;
259 
260  MemberList::const_iterator itr = mMembers.begin();
261  const MemberList::const_iterator itr_end = mMembers.end();
262  while (itr != itr_end)
263  {
264  if (*itr != nullptr)
265  {
266  Being *const b = actorManager->findBeing((*itr)->getID());
267  if (b != nullptr)
268  b->removeGuild(mId);
269  }
270  ++itr;
271  }
272 }
MemberList mMembers
Definition: guild.h:215
Being * findBeing(const BeingId id) const
void removeGuild(const int id)
Definition: being.cpp:1209
Definition: being.h:93
ActorManager * actorManager
int16_t mId
Definition: guild.h:219

◆ removeMember() [1/3]

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

Removes a member from the guild.

Definition at line 186 of file guild.cpp.

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

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

187 {
188  if (member == nullptr)
189  return;
190  MemberList::iterator itr = mMembers.begin();
191  const MemberList::iterator itr_end = mMembers.end();
192  while (itr != itr_end)
193  {
194  if (*itr == nullptr)
195  continue;
196  if ((*itr)->mId == member->mId &&
197  (*itr)->mCharId == member->mCharId &&
198  (*itr)->getName() == member->getName())
199  {
200  GuildMember *m = *itr;
201  mMembers.erase(itr);
202  delete m;
203  return;
204  }
205  ++ itr;
206  }
207 }
std::string getName() const
Definition: avatar.h:52
int mCharId
Definition: avatar.h:187
MemberList mMembers
Definition: guild.h:215
BeingId mId
Definition: avatar.h:186

◆ removeMember() [2/3]

void Guild::removeMember ( const BeingId  id)

Removes a member from the guild.

Definition at line 209 of file guild.cpp.

References mMembers.

210 {
211  bool deleted = true;
212  while (deleted)
213  {
214  deleted = false;
215  MemberList::iterator itr = mMembers.begin();
216  const MemberList::iterator itr_end = mMembers.end();
217  while (itr != itr_end)
218  {
219  if (((*itr) != nullptr) && (*itr)->mId == id)
220  {
221  GuildMember *member = *itr;
222  mMembers.erase(itr);
223  delete member;
224  deleted = true;
225  break;
226  }
227  ++itr;
228  }
229  }
230 }
MemberList mMembers
Definition: guild.h:215

◆ removeMember() [3/3]

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

Removes a member from the guild.

Definition at line 232 of file guild.cpp.

References mMembers.

233 {
234  bool deleted = true;
235  while (deleted)
236  {
237  deleted = false;
238  MemberList::iterator itr = mMembers.begin();
239  const MemberList::iterator itr_end = mMembers.end();
240  while (itr != itr_end)
241  {
242  if (((*itr) != nullptr) && (*itr)->getName() == name)
243  {
244  GuildMember *member = *itr;
245  mMembers.erase(itr);
246  delete member;
247  deleted = true;
248  break;
249  }
250  ++itr;
251  }
252  }
253 }
MemberList mMembers
Definition: guild.h:215

◆ setEmblemId()

void Guild::setEmblemId ( const int  id)
inline

Definition at line 187 of file guild.h.

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

188  { mEmblemId = id; }
int mEmblemId
Definition: guild.h:218

◆ 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:217

◆ setRights()

void Guild::setRights ( const int16_t  rights)

Definition at line 279 of file guild.cpp.

References mCanInviteUsers.

280 {
281  // to invite, rights must be greater than 0
282  if (rights > 0)
283  mCanInviteUsers = true;
284 }
bool mCanInviteUsers
Definition: guild.h:220

◆ setServerGuild()

void Guild::setServerGuild ( const bool  b)
inline

Definition at line 195 of file guild.h.

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

196  { mServerGuild = b; }
bool mServerGuild
Definition: guild.h:221

◆ sort()

void Guild::sort ( )

Definition at line 375 of file guild.cpp.

References guildSorter, and mMembers.

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

376 {
377  std::sort(mMembers.begin(), mMembers.end(), guildSorter);
378 }
MemberList mMembers
Definition: guild.h:215
static class SortGuildFunctor guildSorter

Field Documentation

◆ guilds

Guild::GuildMap Guild::guilds
staticprivate

Definition at line 208 of file guild.h.

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

◆ mCanInviteUsers

bool Guild::mCanInviteUsers
private

Definition at line 220 of file guild.h.

Referenced by setRights().

◆ mEmblemId

int Guild::mEmblemId
private

Definition at line 218 of file guild.h.

◆ mId

int16_t Guild::mId
private

Definition at line 219 of file guild.h.

Referenced by removeFromMembers().

◆ mMembers

MemberList Guild::mMembers
private

◆ mName

std::string Guild::mName
private

Definition at line 217 of file guild.h.

◆ mPositions

PositionsMap Guild::mPositions
private

Definition at line 216 of file guild.h.

Referenced by addPos(), and getPos().

◆ mServerGuild

bool Guild::mServerGuild
private

Definition at line 221 of file guild.h.


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