[7602] Fixed possible crash at instant stealth aura apply interrupt at internal visib...
[AHbot.git] / src / game / ReputationMgr.h
blobb81634119df11da74947470d0a073a16ec8a1f78
1 /*
2 * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #ifndef __MANGOS_REPUTATION_MGR_H
20 #define __MANGOS_REPUTATION_MGR_H
22 #include "Common.h"
23 #include "SharedDefines.h"
24 #include "DBCStructure.h"
25 #include <map>
27 enum FactionFlags
29 FACTION_FLAG_VISIBLE = 0x01, // makes visible in client (set or can be set at interaction with target of this faction)
30 FACTION_FLAG_AT_WAR = 0x02, // enable AtWar-button in client. player controlled (except opposition team always war state), Flag only set on initial creation
31 FACTION_FLAG_HIDDEN = 0x04, // hidden faction from reputation pane in client (player can gain reputation, but this update not sent to client)
32 FACTION_FLAG_INVISIBLE_FORCED = 0x08, // always overwrite FACTION_FLAG_VISIBLE and hide faction in rep.list, used for hide opposite team factions
33 FACTION_FLAG_PEACE_FORCED = 0x10, // always overwrite FACTION_FLAG_AT_WAR, used for prevent war with own team factions
34 FACTION_FLAG_INACTIVE = 0x20, // player controlled, state stored in characters.data ( CMSG_SET_FACTION_INACTIVE )
35 FACTION_FLAG_RIVAL = 0x40 // flag for the two competing outland factions
38 typedef uint32 RepListID;
39 struct FactionState
41 uint32 ID;
42 RepListID ReputationListID;
43 uint32 Flags;
44 int32 Standing;
45 bool Changed;
48 typedef std::map<RepListID,FactionState> FactionStateList;
49 typedef std::pair<FactionStateList::const_iterator,FactionStateList::const_iterator> FactionStateListPair;
51 typedef std::map<uint32,ReputationRank> ForcedReactions;
53 class Player;
54 class QueryResult;
56 class ReputationMgr
58 public: // constructors and global modifiers
59 explicit ReputationMgr(Player* owner) : m_player(owner),
60 m_visibleFactionCount(0), m_honoredFactionCount(0), m_reveredFactionCount(0), m_exaltedFactionCount(0) {}
61 ~ReputationMgr() {}
63 void SaveToDB();
64 void LoadFromDB(QueryResult *result);
65 public: // statics
66 static const int32 PointsInRank[MAX_REPUTATION_RANK];
67 static const int32 Reputation_Cap = 42999;
68 static const int32 Reputation_Bottom = -42000;
70 static ReputationRank ReputationToRank(int32 standing);
71 public: // accessors
72 uint8 GetVisibleFactionCount() const { return m_visibleFactionCount; }
73 uint8 GetHonoredFactionCount() const { return m_honoredFactionCount; }
74 uint8 GetReveredFactionCount() const { return m_reveredFactionCount; }
75 uint8 GetExaltedFactionCount() const { return m_exaltedFactionCount; }
77 FactionStateList const& GetStateList() const { return m_factions; }
79 FactionState const* GetState(FactionEntry const* factionEntry) const
81 return factionEntry->reputationListID >= 0 ? GetState(factionEntry->reputationListID) : NULL;
84 FactionState const* GetState(RepListID id) const
86 FactionStateList::const_iterator repItr = m_factions.find (id);
87 return repItr != m_factions.end() ? &repItr->second : NULL;
90 int32 GetReputation(uint32 faction_id) const;
91 int32 GetReputation(FactionEntry const* factionEntry) const;
92 int32 GetBaseReputation(FactionEntry const* factionEntry) const;
94 ReputationRank GetRank(FactionEntry const* factionEntry) const;
95 ReputationRank GetBaseRank(FactionEntry const* factionEntry) const;
97 ReputationRank const* GetForcedRankIfAny(FactionTemplateEntry const* factionTemplateEntry) const
99 ForcedReactions::const_iterator forceItr = m_forcedReactions.find(factionTemplateEntry->faction);
100 return forceItr != m_forcedReactions.end() ? &forceItr->second : NULL;
103 public: // modifiers
104 bool SetReputation(FactionEntry const* factionEntry, int32 standing)
106 return SetReputation(factionEntry, standing, false);
108 bool ModifyReputation(FactionEntry const* factionEntry, int32 standing)
110 return SetReputation(factionEntry, standing, true);
113 void SetVisible(FactionTemplateEntry const* factionTemplateEntry);
114 void SetVisible(FactionEntry const* factionEntry);
115 void SetAtWar(RepListID repListID, bool on);
116 void SetInactive(RepListID repListID, bool on);
118 void ApplyForceReaction(uint32 faction_id,ReputationRank rank,bool apply);
120 public: // senders
121 void SendInitialReputations();
122 void SendForceReactions();
123 void SendState(FactionState const* faction) const;
124 void SendStates() const;
126 private: // internal helper functions
127 void Initilize();
128 uint32 GetDefaultStateFlags(const FactionEntry *factionEntry) const;
129 bool SetReputation(FactionEntry const* factionEntry, int32 standing, bool incremental);
130 bool SetOneFactionReputation(FactionEntry const* factionEntry, int32 standing, bool incremental);
131 void SetVisible(FactionState* faction);
132 void SetAtWar(FactionState* faction, bool atWar);
133 void SetInactive(FactionState* faction, bool inactive);
134 void SendVisible(FactionState const* faction) const;
135 void UpdateRankCounters( ReputationRank old_rank, ReputationRank new_rank );
136 private:
137 Player* m_player;
138 FactionStateList m_factions;
139 ForcedReactions m_forcedReactions;
140 uint8 m_visibleFactionCount :8;
141 uint8 m_honoredFactionCount :8;
142 uint8 m_reveredFactionCount :8;
143 uint8 m_exaltedFactionCount :8;
146 #endif