TrinityCore
PhaseShift.h
Go to the documentation of this file.
1/*
2 * This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the
6 * Free Software Foundation; either version 2 of the License, or (at your
7 * option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 * more details.
13 *
14 * You should have received a copy of the GNU General Public License along
15 * with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef PhaseShift_h__
19#define PhaseShift_h__
20
21#include "Define.h"
22#include "EnumFlag.h"
23#include "FlatSet.h"
24#include "ObjectGuid.h"
25#include <map>
26
27class PhasingHandler;
28struct Condition;
29struct TerrainSwapInfo;
30
31#define DEFAULT_PHASE 169
32
34{
35 None = 0x00,
36 AlwaysVisible = 0x01, // Ignores all phasing, can see everything and be seen by everything
37 Inverse = 0x02, // By default having at least one shared phase for two objects means they can see each other
38 // this flag makes objects see each other if they have at least one non-shared phase
39 InverseUnphased = 0x04,
40 Unphased = 0x08,
41 NoCosmetic = 0x10 // This flag ignores shared cosmetic phases (two players that both have shared cosmetic phase but no other phase cannot see each other)
42};
43
44enum class PhaseFlags : uint16
45{
46 None = 0x0,
47 Cosmetic = 0x1,
48 Personal = 0x2
49};
50
53
55{
56public:
57 struct PhaseRef
58 {
59 PhaseRef(uint32 id, PhaseFlags flags, std::vector<Condition> const* conditions)
60 : Id(id), Flags(flags), References(0), AreaConditions(conditions) { }
61
65 std::vector<Condition> const* AreaConditions;
66 std::strong_ordering operator<=>(PhaseRef const& right) const { return Id <=> right.Id; }
67 bool operator==(PhaseRef const& right) const { return Id == right.Id; }
68 bool IsPersonal() const { return Flags.HasFlag(PhaseFlags::Personal); }
69 };
71 {
72 int32 References = 0;
73 TerrainSwapInfo const* VisibleMapInfo = nullptr;
74 };
76 {
77 int32 References = 0;
78 };
79 template<typename Container>
81 {
82 typename Container::iterator Iterator;
83 bool Erased;
84 };
86 using VisibleMapIdContainer = std::map<uint32, VisibleMapIdRef>;
87 using UiMapPhaseIdContainer = std::map<uint32, UiMapPhaseIdRef>;
88
90 PhaseShift(PhaseShift const& right);
91 PhaseShift(PhaseShift&& right) noexcept;
93 PhaseShift& operator=(PhaseShift&& right) noexcept;
95
96 ObjectGuid GetPersonalGuid() const { return PersonalGuid; }
97
98 bool AddPhase(uint32 phaseId, PhaseFlags flags, std::vector<Condition> const* areaConditions, int32 references = 1);
99 EraseResult<PhaseContainer> RemovePhase(uint32 phaseId);
100 bool HasPhase(uint32 phaseId) const { return Phases.find(PhaseRef(phaseId, PhaseFlags::None, nullptr)) != Phases.end(); }
101 PhaseContainer const& GetPhases() const { return Phases; }
102
103 bool AddVisibleMapId(uint32 visibleMapId, TerrainSwapInfo const* visibleMapInfo, int32 references = 1);
104 EraseResult<VisibleMapIdContainer> RemoveVisibleMapId(uint32 visibleMapId);
105 bool HasVisibleMapId(uint32 visibleMapId) const { return VisibleMapIds.find(visibleMapId) != VisibleMapIds.end(); }
106 VisibleMapIdContainer const& GetVisibleMapIds() const { return VisibleMapIds; }
107
108 bool AddUiMapPhaseId(uint32 uiMapPhaseId, int32 references = 1);
109 EraseResult<UiMapPhaseIdContainer> RemoveUiMapPhaseId(uint32 uiMapPhaseId);
110 bool HasUiMapPhaseId(uint32 uiMapPhaseId) const { return UiMapPhaseIds.find(uiMapPhaseId) != UiMapPhaseIds.end(); }
111 UiMapPhaseIdContainer const& GetUiMapPhaseIds() const { return UiMapPhaseIds; }
112
113 void Clear();
114 void ClearPhases();
115
116 bool CanSee(PhaseShift const& other) const;
117
118 bool HasPersonalPhase() const;
119
120protected:
121 friend class PhasingHandler;
122
128
129 void ModifyPhasesReferences(PhaseContainer::iterator itr, int32 references);
130 void UpdateUnphasedFlag();
131 void UpdatePersonalGuid();
132 int32 NonCosmeticReferences = 0;
133 int32 CosmeticReferences = 0;
134 int32 PersonalReferences = 0;
135 int32 DefaultReferences = 0;
136 bool IsDbPhaseShift = false;
137};
138
139#endif // PhaseShift_h__
#define TC_GAME_API
Definition: Define.h:123
int32_t int32
Definition: Define.h:138
uint16_t uint16
Definition: Define.h:143
uint32_t uint32
Definition: Define.h:142
uint16 flags
Definition: DisableMgr.cpp:49
PhaseFlags
Definition: PhaseShift.h:45
DEFINE_ENUM_FLAG(PhaseShiftFlags)
PhaseShiftFlags
Definition: PhaseShift.h:34
constexpr bool HasFlag(T flag) const
Definition: EnumFlag.h:106
VisibleMapIdContainer const & GetVisibleMapIds() const
Definition: PhaseShift.h:106
PhaseShift(PhaseShift const &right)
PhaseShift & operator=(PhaseShift const &right)
ObjectGuid PersonalGuid
Definition: PhaseShift.h:124
bool HasPhase(uint32 phaseId) const
Definition: PhaseShift.h:100
PhaseContainer const & GetPhases() const
Definition: PhaseShift.h:101
PhaseShift & operator=(PhaseShift &&right) noexcept
std::map< uint32, UiMapPhaseIdRef > UiMapPhaseIdContainer
Definition: PhaseShift.h:87
UiMapPhaseIdContainer const & GetUiMapPhaseIds() const
Definition: PhaseShift.h:111
bool HasVisibleMapId(uint32 visibleMapId) const
Definition: PhaseShift.h:105
ObjectGuid GetPersonalGuid() const
Definition: PhaseShift.h:96
std::map< uint32, VisibleMapIdRef > VisibleMapIdContainer
Definition: PhaseShift.h:86
bool HasUiMapPhaseId(uint32 uiMapPhaseId) const
Definition: PhaseShift.h:110
UiMapPhaseIdContainer UiMapPhaseIds
Definition: PhaseShift.h:127
PhaseShift(PhaseShift &&right) noexcept
PhaseContainer Phases
Definition: PhaseShift.h:125
VisibleMapIdContainer VisibleMapIds
Definition: PhaseShift.h:126
bool CanSee(Player const *player, VignetteData const &vignette)
Definition: Vignette.cpp:112
Container::iterator Iterator
Definition: PhaseShift.h:82
std::vector< Condition > const * AreaConditions
Definition: PhaseShift.h:65
PhaseRef(uint32 id, PhaseFlags flags, std::vector< Condition > const *conditions)
Definition: PhaseShift.h:59
std::strong_ordering operator<=>(PhaseRef const &right) const
Definition: PhaseShift.h:66
bool operator==(PhaseRef const &right) const
Definition: PhaseShift.h:67
bool IsPersonal() const
Definition: PhaseShift.h:68
EnumFlag< PhaseFlags > Flags
Definition: PhaseShift.h:63