diff options
author | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-10-29 16:19:55 +0100 |
---|---|---|
committer | Thorbjørn Lindeijer <bjorn@lindeijer.nl> | 2024-10-29 17:16:37 +0100 |
commit | 6cd8881f1b11c99f8e72735017e743c50094e922 (patch) | |
tree | 7f6726d2ed01fe39b78c4e2eb6cc4561c6e0db80 /src/playerrelations.h | |
parent | 93ad5ec32de124dfa0c054acfd1f2a378cb9ca75 (diff) | |
download | mana-6cd8881f1b11c99f8e72735017e743c50094e922.tar.gz mana-6cd8881f1b11c99f8e72735017e743c50094e922.tar.bz2 mana-6cd8881f1b11c99f8e72735017e743c50094e922.tar.xz mana-6cd8881f1b11c99f8e72735017e743c50094e922.zip |
Turned the PlayerRelation struct into an enum class
Less code to achieve the same thing (strong type and namespaced values).
The permissions related values have been moved to a PlayerPermissions
struct, which is also a bit less confusing.
Diffstat (limited to 'src/playerrelations.h')
-rw-r--r-- | src/playerrelations.h | 57 |
1 files changed, 23 insertions, 34 deletions
diff --git a/src/playerrelations.h b/src/playerrelations.h index e3183da6..45102fd9 100644 --- a/src/playerrelations.h +++ b/src/playerrelations.h @@ -1,7 +1,7 @@ /* * The Mana Client * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2012 The Mana Developers + * Copyright (C) 2009-2024 The Mana Developers * * This file is part of The Mana Client. * @@ -29,38 +29,28 @@ class Being; -struct PlayerRelation +enum class PlayerRelation { - static const unsigned int EMOTE = (1 << 0); - static const unsigned int SPEECH_FLOAT = (1 << 1); - static const unsigned int SPEECH_LOG = (1 << 2); - static const unsigned int WHISPER = (1 << 3); - static const unsigned int TRADE = (1 << 4); - - /** - * There are four types of relations: - * NEUTRAL, FRIEND, DISREGARDED, and IGNORED. - */ - static const unsigned int RELATIONS_NR = 4; - static const unsigned int RELATION_PERMISSIONS[RELATIONS_NR]; - - static const unsigned int DEFAULT = EMOTE - | SPEECH_FLOAT - | SPEECH_LOG - | WHISPER - | TRADE; - enum Relation { - NEUTRAL = 0, - FRIEND = 1, - DISREGARDED = 2, - IGNORED = 3 - }; - - explicit PlayerRelation(Relation relation = NEUTRAL); - - Relation mRelation; // bitmask for all of the above + NEUTRAL = 0, + FRIEND = 1, + DISREGARDED = 2, + IGNORED = 3 }; +constexpr unsigned int RELATIONS_NR = 4; +struct PlayerPermissions +{ + // Used as flags + enum { + EMOTE = 1 << 0, + SPEECH_FLOAT = 1 << 1, + SPEECH_LOG = 1 << 2, + WHISPER = 1 << 3, + TRADE = 1 << 4, + + DEFAULT = EMOTE | SPEECH_FLOAT | SPEECH_LOG | WHISPER | TRADE + }; +}; /** * Ignore strategy: describes how we should handle ignores. @@ -133,13 +123,12 @@ public: /** * Updates the relationship with this player. */ - void setRelation(const std::string &name, - PlayerRelation::Relation relation); + void setRelation(const std::string &name, PlayerRelation relation); /** * Updates the relationship with this player. */ - PlayerRelation::Relation getRelation(const std::string &name) const; + PlayerRelation getRelation(const std::string &name) const; /** * Deletes the information recorded for a player. @@ -225,7 +214,7 @@ private: void signalUpdate(); bool mPersistIgnores = false; // If NOT set, we delete the ignored data upon reloading - unsigned int mDefaultPermissions = PlayerRelation::DEFAULT; + unsigned int mDefaultPermissions = PlayerPermissions::DEFAULT; PlayerIgnoreStrategy *mIgnoreStrategy = nullptr; std::map<std::string, PlayerRelation> mRelations; |