From aadf40739c45c3396ace5766dd9c60db0c3b1ccc Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 30 May 2015 17:45:27 +0300 Subject: Move relation enum into separate file. --- src/being/being.cpp | 23 +++++++------------ src/being/localplayer.cpp | 2 +- src/being/playerrelation.cpp | 2 +- src/being/playerrelation.h | 16 ++++--------- src/being/playerrelations.cpp | 52 +++++++++++++++++++++---------------------- src/being/playerrelations.h | 9 ++++---- 6 files changed, 45 insertions(+), 59 deletions(-) (limited to 'src/being') diff --git a/src/being/being.cpp b/src/being/being.cpp index ddd0e7473..e30a1e477 100644 --- a/src/being/being.cpp +++ b/src/being/being.cpp @@ -2005,11 +2005,8 @@ void Being::showName() delete2(mDispName); - if (mHideErased && player_relations.getRelation(mName) == - PlayerRelation::ERASED) - { + if (mHideErased && player_relations.getRelation(mName) == Relation::ERASED) return; - } std::string displayName(mName); @@ -2079,7 +2076,7 @@ void Being::updateColors() { mTextColor = &theme->getColor(ThemeColorId::PLAYER, 255); - if (player_relations.getRelation(mName) != PlayerRelation::ERASED) + if (player_relations.getRelation(mName) != Relation::ERASED) mErased = false; else mErased = true; @@ -2103,27 +2100,23 @@ void Being::updateColors() { mNameColor = &userPalette->getColor(UserColorId::GUILD); } - else if (player_relations.getRelation(mName) == - PlayerRelation::FRIEND) + else if (player_relations.getRelation(mName) == Relation::FRIEND) { mNameColor = &userPalette->getColor(UserColorId::FRIEND); } else if (player_relations.getRelation(mName) == - PlayerRelation::DISREGARDED + Relation::DISREGARDED || player_relations.getRelation(mName) == - PlayerRelation::BLACKLISTED) + Relation::BLACKLISTED) { mNameColor = &userPalette->getColor(UserColorId::DISREGARDED); } - else if (player_relations.getRelation(mName) == - PlayerRelation::IGNORED - || player_relations.getRelation(mName) == - PlayerRelation::ENEMY2) + else if (player_relations.getRelation(mName) == Relation::IGNORED + || player_relations.getRelation(mName) == Relation::ENEMY2) { mNameColor = &userPalette->getColor(UserColorId::IGNORED); } - else if (player_relations.getRelation(mName) == - PlayerRelation::ERASED) + else if (player_relations.getRelation(mName) == Relation::ERASED) { mNameColor = &userPalette->getColor(UserColorId::ERASED); } diff --git a/src/being/localplayer.cpp b/src/being/localplayer.cpp index b4f19ef00..a941dc42c 100644 --- a/src/being/localplayer.cpp +++ b/src/being/localplayer.cpp @@ -2614,7 +2614,7 @@ bool LocalPlayer::checAttackPermissions(const Being *const target) return true; case 1: return !(player_relations.getRelation(target->getName()) - == PlayerRelation::FRIEND); + == Relation::FRIEND); case 2: return player_relations.checkBadRelation(target->getName()); default: diff --git a/src/being/playerrelation.cpp b/src/being/playerrelation.cpp index 6737d02d1..1259d2caa 100644 --- a/src/being/playerrelation.cpp +++ b/src/being/playerrelation.cpp @@ -24,7 +24,7 @@ #include "debug.h" -PlayerRelation::PlayerRelation(const Relation relation) : +PlayerRelation::PlayerRelation(const RelationT relation) : mRelation(relation) { } diff --git a/src/being/playerrelation.h b/src/being/playerrelation.h index 5f6e1f42d..22fb3cb64 100644 --- a/src/being/playerrelation.h +++ b/src/being/playerrelation.h @@ -23,6 +23,8 @@ #ifndef BEING_PLAYERRELATION_H #define BEING_PLAYERRELATION_H +#include "enums/being/relation.h" + #include "localconsts.h" struct PlayerRelation final @@ -44,22 +46,12 @@ struct PlayerRelation final | SPEECH_LOG | WHISPER | TRADE; - enum Relation - { - NEUTRAL = 0, - FRIEND = 1, - DISREGARDED = 2, - IGNORED = 3, - ERASED = 4, - BLACKLISTED = 5, - ENEMY2 = 6 - }; - explicit PlayerRelation(const Relation relation); + explicit PlayerRelation(const RelationT relation); A_DELETE_COPY(PlayerRelation) - Relation mRelation; // bitmask for all of the above + RelationT mRelation; // bitmask for all of the above }; #endif // BEING_PLAYERRELATION_H diff --git a/src/being/playerrelations.cpp b/src/being/playerrelations.cpp index 22f685044..20192be07 100644 --- a/src/being/playerrelations.cpp +++ b/src/being/playerrelations.cpp @@ -101,10 +101,10 @@ namespace if (!(*container)[name]) { const int v = cobj->getValueInt(RELATION, - static_cast(PlayerRelation::NEUTRAL)); + static_cast(Relation::NEUTRAL)); (*container)[name] = new PlayerRelation( - static_cast(v)); + static_cast(v)); } // otherwise ignore the duplicate entry @@ -271,19 +271,19 @@ unsigned int PlayerRelationsManager::checkPermissionSilently( switch (r->mRelation) { - case PlayerRelation::NEUTRAL: + case Relation::NEUTRAL: permissions = mDefaultPermissions; break; - case PlayerRelation::FRIEND: + case Relation::FRIEND: permissions |= mDefaultPermissions; // widen break; - case PlayerRelation::DISREGARDED: - case PlayerRelation::IGNORED: - case PlayerRelation::ERASED: - case PlayerRelation::BLACKLISTED: - case PlayerRelation::ENEMY2: + case Relation::DISREGARDED: + case Relation::IGNORED: + case Relation::ERASED: + case Relation::BLACKLISTED: + case Relation::ENEMY2: default: permissions &= mDefaultPermissions; // narrow } @@ -330,10 +330,10 @@ bool PlayerRelationsManager::hasPermission(const std::string &name, } void PlayerRelationsManager::setRelation(const std::string &player_name, - const PlayerRelation::Relation + const RelationT relation) { - if (!localPlayer || (relation != PlayerRelation::NEUTRAL + if (!localPlayer || (relation != Relation::NEUTRAL && localPlayer->getName() == player_name)) { return; @@ -365,7 +365,7 @@ StringVect *PlayerRelationsManager::getPlayers() const } StringVect *PlayerRelationsManager::getPlayersByRelation( - const PlayerRelation::Relation rel) const + const RelationT rel) const { StringVect *const retval = new StringVect(); @@ -388,7 +388,7 @@ void PlayerRelationsManager::removePlayer(const std::string &name) } -PlayerRelation::Relation PlayerRelationsManager::getRelation( +RelationT PlayerRelationsManager::getRelation( const std::string &name) const { const std::map::const_iterator @@ -396,7 +396,7 @@ PlayerRelation::Relation PlayerRelationsManager::getRelation( if (it != mRelations.end()) return (*it).second->mRelation; - return PlayerRelation::NEUTRAL; + return Relation::NEUTRAL; } //////////////////////////////////////// @@ -420,18 +420,18 @@ void PlayerRelationsManager::ignoreTrade(const std::string &name) const if (name.empty()) return; - const PlayerRelation::Relation relation = getRelation(name); + const RelationT relation = getRelation(name); - if (relation == PlayerRelation::IGNORED - || relation == PlayerRelation::DISREGARDED - || relation == PlayerRelation::BLACKLISTED - || relation == PlayerRelation::ERASED) + if (relation == Relation::IGNORED + || relation == Relation::DISREGARDED + || relation == Relation::BLACKLISTED + || relation == Relation::ERASED) { return; } else { - player_relations.setRelation(name, PlayerRelation::BLACKLISTED); + player_relations.setRelation(name, Relation::BLACKLISTED); } } @@ -440,13 +440,13 @@ bool PlayerRelationsManager::checkBadRelation(const std::string &name) const if (name.empty()) return true; - const PlayerRelation::Relation relation = getRelation(name); + const RelationT relation = getRelation(name); - if (relation == PlayerRelation::IGNORED - || relation == PlayerRelation::DISREGARDED - || relation == PlayerRelation::BLACKLISTED - || relation == PlayerRelation::ERASED - || relation == PlayerRelation::ENEMY2) + if (relation == Relation::IGNORED + || relation == Relation::DISREGARDED + || relation == Relation::BLACKLISTED + || relation == Relation::ERASED + || relation == Relation::ENEMY2) { return true; } diff --git a/src/being/playerrelations.h b/src/being/playerrelations.h index 87cd83d75..0976fe167 100644 --- a/src/being/playerrelations.h +++ b/src/being/playerrelations.h @@ -23,6 +23,8 @@ #ifndef BEING_PLAYERRELATIONS_H #define BEING_PLAYERRELATIONS_H +#include "enums/being/relation.h" + #include "utils/stringvector.h" #include "being/playerrelation.h" @@ -88,13 +90,12 @@ class PlayerRelationsManager final * Updates the relationship with this player. */ void setRelation(const std::string &name, - const PlayerRelation::Relation relation); + const RelationT relation); /** * Updates the relationship with this player. */ - PlayerRelation::Relation getRelation(const std::string &name) - const A_WARN_UNUSED; + RelationT getRelation(const std::string &name) const A_WARN_UNUSED; /** * Deletes the information recorded for a player. @@ -151,7 +152,7 @@ class PlayerRelationsManager final */ StringVect *getPlayers() const A_WARN_UNUSED; - StringVect *getPlayersByRelation(const PlayerRelation::Relation rel) + StringVect *getPlayersByRelation(const RelationT rel) const A_WARN_UNUSED; /** -- cgit v1.2.3-60-g2f50