ManaPlus
guild.h
Go to the documentation of this file.
1 /*
2  * The ManaPlus Client
3  * Copyright (C) 2004-2009 The Mana World Development Team
4  * Copyright (C) 2009-2010 The Mana Developers
5  * Copyright (C) 2011-2019 The ManaPlus Developers
6  * Copyright (C) 2019-2021 Andrei Karas
7  *
8  * This file is part of The ManaPlus Client.
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef GUILD_H
25 #define GUILD_H
26 
28 
29 #include "utils/cast.h"
30 #include "utils/dtor.h"
31 #include "utils/stringvector.h"
32 
33 #include <map>
34 
35 class Guild;
36 
37 typedef std::map<unsigned, std::string> PositionsMap;
38 
39 class GuildMember final : public Avatar
40 {
41  public:
43 
45  { return mGuild; }
46 
48  { return mPos; }
49 
50  void setPos(const int pos)
51  { mPos = pos; }
52 
53  std::string getAdditionString() const override final A_WARN_UNUSED;
54 
55  protected:
56  friend class Guild;
57 
58  GuildMember(Guild *const guild,
59  const BeingId accountId,
60  const int charId,
61  const std::string &name);
62 
63  GuildMember(Guild *const guild, const std::string &name);
64 
66  int mPos;
67 };
68 
69 class Guild final : public AvatarListModel
70 {
71  public:
73 
74  ~Guild() override final;
75 
79  void setName(const std::string &name)
80  { mName = name; }
81 
85  GuildMember *addMember(const BeingId accountId,
86  const int charId,
87  const std::string &name);
88 
92  GuildMember *addMember(const std::string &name);
93 
99  GuildMember *getMember(const BeingId id) const;
100 
106  GuildMember *getMember(const BeingId accountId,
107  const int charId)
108  const A_WARN_UNUSED;
109 
115  GuildMember *getMemberByCharId(const int charId) const A_WARN_UNUSED;
116 
122  GuildMember *getMember(const std::string &name) const A_WARN_UNUSED;
123 
128  const std::string &getName() const noexcept2 A_WARN_UNUSED
129  { return mName; }
130 
135  int16_t getId() const noexcept2 A_WARN_UNUSED
136  { return mId; }
137 
141  void removeMember(const GuildMember *const member);
142 
146  void removeMember(const BeingId id);
147 
151  void removeMember(const std::string &name);
152 
153  void removeFromMembers();
154 
156  { delete_all(mMembers); mMembers.clear(); }
157 
163  { return CAST_S32(mMembers.size()); }
164 
165  Avatar *getAvatarAt(const int index) override final A_WARN_UNUSED;
166 
172  { return mCanInviteUsers; }
173 
174  void setRights(const int16_t rights);
175 
176  bool isMember(const GuildMember *const member) const A_WARN_UNUSED;
177 
178  bool isMember(const BeingId id) const A_WARN_UNUSED;
179 
180  bool isMember(const std::string &name) const A_WARN_UNUSED;
181 
182  void getNames(StringVect &names) const;
183 
184  void addPos(const int id, const std::string &name);
185 
186  void sort();
187 
188  std::string getPos(const int id) const A_WARN_UNUSED;
189 
190  static Guild *getGuild(const int16_t id) A_WARN_UNUSED;
191 
193  { return mPositions; }
194 
195  void setEmblemId(const int id)
196  { mEmblemId = id; }
197 
199  { return mEmblemId; }
200 
201  static void clearGuilds();
202 
203  void setServerGuild(const bool b)
204  { mServerGuild = b; }
205 
207  { return mServerGuild; }
208 
209  typedef STD_VECTOR<GuildMember*> MemberList;
210 
212  { return &mMembers; }
213 
214  private:
215  typedef std::map<int, Guild*> GuildMap;
216  static GuildMap guilds;
217 
221  explicit Guild(const int16_t id);
222 
225  std::string mName;
227  int16_t mId;
230 };
231 
232 #endif // GUILD_H
int BeingId
Definition: beingid.h:30
#define CAST_S32
Definition: cast.h:30
Definition: avatar.h:41
std::string mName
Definition: avatar.h:189
BeingId mId
Definition: avatar.h:187
std::string getAdditionString() const
Definition: guild.cpp:85
friend class Guild
Definition: guild.h:56
Guild * mGuild
Definition: guild.h:65
int getPos() const
Definition: guild.h:47
int mPos
Definition: guild.h:66
const Guild * getGuild() const
Definition: guild.h:44
void setPos(const int pos)
Definition: guild.h:50
Definition: guild.h:70
int mEmblemId
Definition: guild.h:226
bool mCanInviteUsers
Definition: guild.h:228
void setServerGuild(const bool b)
Definition: guild.h:203
void setName(const std::string &name)
Definition: guild.h:79
MemberList mMembers
Definition: guild.h:223
PositionsMap mPositions
Definition: guild.h:224
bool getInviteRights() const
Definition: guild.h:171
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
const std::string & getName() const
Definition: guild.h:128
const PositionsMap & getPositions() const
Definition: guild.h:192
int getEmblemId() const
Definition: guild.h:198
void clearMembers()
Definition: guild.h:155
bool getServerGuild() const
Definition: guild.h:206
int16_t getId() const
Definition: guild.h:135
int getNumberOfElements()
Definition: guild.h:162
const MemberList * getMembers() const
Definition: guild.h:211
std::map< int, Guild * > GuildMap
Definition: guild.h:215
void setEmblemId(const int id)
Definition: guild.h:195
std::vector< GuildMember * > MemberList
Definition: guild.h:209
void delete_all(Container &c)
Definition: dtor.h:56
std::map< unsigned, std::string > PositionsMap
Definition: guild.h:35
#define override
Definition: localconsts.h:47
#define RETURNS_NONNULL
Definition: localconsts.h:167
#define A_WARN_UNUSED
Definition: localconsts.h:161
#define noexcept2
Definition: localconsts.h:50
#define final
Definition: localconsts.h:46
#define A_DELETE_COPY(func)
Definition: localconsts.h:53
uint32_t guild
std::vector< std::string > StringVect
Definition: stringvector.h:29