TrinityCore
Loading...
Searching...
No Matches
RaceMask.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 TRINITYCORE_RACE_MASK_H
19#define TRINITYCORE_RACE_MASK_H
20
21#include "Define.h"
22#include <array>
23#include <type_traits>
24
25// EnumUtils: DESCRIBE THIS
27{
28 RACE_NONE = 0, // SKIP
29 RACE_HUMAN = 1, // TITLE Human
30 RACE_ORC = 2, // TITLE Orc
31 RACE_DWARF = 3, // TITLE Dwarf
32 RACE_NIGHTELF = 4, // TITLE Night Elf
33 RACE_UNDEAD_PLAYER = 5, // TITLE Undead
34 RACE_TAUREN = 6, // TITLE Tauren
35 RACE_GNOME = 7, // TITLE Gnome
36 RACE_TROLL = 8, // TITLE Troll
37 RACE_GOBLIN = 9, // TITLE Goblin
38 RACE_BLOODELF = 10, // TITLE Blood Elf
39 RACE_DRAENEI = 11, // TITLE Draenei
40 //RACE_FEL_ORC = 12,
41 //RACE_NAGA = 13,
42 //RACE_BROKEN = 14,
43 //RACE_SKELETON = 15,
44 //RACE_VRYKUL = 16,
45 //RACE_TUSKARR = 17,
46 //RACE_FOREST_TROLL = 18,
47 //RACE_TAUNKA = 19,
48 //RACE_NORTHREND_SKELETON = 20,
49 //RACE_ICE_TROLL = 21,
50 RACE_WORGEN = 22, // TITLE Worgen
51 //RACE_GILNEAN = 23,
52 RACE_PANDAREN_NEUTRAL = 24, // TITLE Pandaren DESCRIPTION Pandaren (Neutral)
53 RACE_PANDAREN_ALLIANCE = 25, // TITLE Pandaren DESCRIPTION Pandaren (Alliance)
54 RACE_PANDAREN_HORDE = 26, // TITLE Pandaren DESCRIPTION Pandaren (Horde)
55 RACE_NIGHTBORNE = 27, // TITLE Nightborne
56 RACE_HIGHMOUNTAIN_TAUREN = 28, // TITLE Highmountain Tauren
57 RACE_VOID_ELF = 29, // TITLE Void Elf
58 RACE_LIGHTFORGED_DRAENEI = 30, // TITLE Lightforged Draenei
59 RACE_ZANDALARI_TROLL = 31, // TITLE Zandalari Troll
60 RACE_KUL_TIRAN = 32, // TITLE Kul Tiran
61 //RACE_THIN_HUMAN = 33,
62 RACE_DARK_IRON_DWARF = 34, // TITLE Dark Iron Dwarf DESCRIPTION Dark Iron Dwarf (RaceMask bit 11)
63 RACE_VULPERA = 35, // TITLE Vulpera DESCRIPTION Vulpera (RaceMask bit 12)
64 RACE_MAGHAR_ORC = 36, // TITLE Mag'har Orc DESCRIPTION Mag'har Orc (RaceMask bit 13)
65 RACE_MECHAGNOME = 37, // TITLE Mechagnome DESCRIPTION Mechagnome (RaceMask bit 14)
66 RACE_DRACTHYR_ALLIANCE = 52, // TITLE Dracthyr DESCRIPTION Dracthyr (Alliance) (RaceMask bit 16)
67 RACE_DRACTHYR_HORDE = 70, // TITLE Dracthyr DESCRIPTION Dracthyr (Horde) (RaceMask bit 15)
68 //RACE_COMPANION_DRAKE = 71,
69 //RACE_COMPANION_PROTO_DRAGON = 72,
70 //RACE_COMPANION_SERPENT = 73,
71 //RACE_COMPANION_WYVERN = 74,
72 //RACE_DRACTHYR_VISAGE_ALLIANCE = 75,
73 //RACE_DRACTHYR_VISAGE_HORDE = 76,
74 //RACE_COMPANION_PTERRODAX = 77,
75 //RACE_COMPANION_NETHERWING_DRAKE = 80,
76 //RACE_ROSTRUM_STORM_GRYPHON = 82,
77 //RACE_ROSTRUM_FAERIE_DRAGON = 83,
78 RACE_EARTHEN_DWARF_HORDE = 84, // TITLE Earthen DESCRIPTION Earthen (Horde) (RaceMask bit 17)
79 RACE_EARTHEN_DWARF_ALLIANCE = 85, // TITLE Earthen DESCRIPTION Earthen (Alliance) (RaceMask bit 18)
80 RACE_HARANIR_ALLIANCE = 86, // TITLE Haranir DESCRIPTION Haranir (Alliance) (RaceMask bit 20)
81 //RACE_ROSTRUM_AIRSHIP_SEASON_1 = 87,
82 //RACE_ROSTRUM_AIRSHIP_SEASON_2 = 90,
83 RACE_HARANIR_HORDE = 91, // TITLE Haranir DESCRIPTION Haranir (Horde) (RaceMask bit 19)
84 //RACE_ROSTRUM_AIRSHIP_SEASON_3 = 92,
85};
86
87namespace Trinity
88{
89template<typename T>
91{
92 static_assert(std::is_integral_v<T>, "RaceMask<T> must be integral");
93
95
96 constexpr bool HasRace(uint32 raceId) const
97 {
98 return (RawValue & GetMaskForRace(raceId).RawValue) != 0;
99 }
100
101 static constexpr int32 GetRaceBit(uint32 raceId)
102 {
103 switch (raceId)
104 {
105 case RACE_HUMAN:
106 case RACE_ORC:
107 case RACE_DWARF:
108 case RACE_NIGHTELF:
110 case RACE_TAUREN:
111 case RACE_GNOME:
112 case RACE_TROLL:
113 case RACE_GOBLIN:
114 case RACE_BLOODELF:
115 case RACE_DRAENEI:
116 case RACE_WORGEN:
120 case RACE_NIGHTBORNE:
122 case RACE_VOID_ELF:
125 case RACE_KUL_TIRAN:
126 return raceId - 1;
128 return 11;
129 case RACE_VULPERA:
130 return 12;
131 case RACE_MAGHAR_ORC:
132 return 13;
133 case RACE_MECHAGNOME:
134 return 14;
136 return 16;
138 return 15;
140 return 17;
142 return 18;
144 return 19;
146 return 20;
147 default:
148 break;
149 }
150 return -1;
151 }
152
153 static constexpr RaceMask GetMaskForRace(uint32 raceId)
154 {
155 int32 raceBit = GetRaceBit(raceId);
156 return { .RawValue = raceBit >= 0 && uint32(raceBit) < sizeof(T) * 8 ? (T(1) << raceBit) : T(0) };
157 }
158
159 constexpr bool operator==(RaceMask const&) const = default;
160
161 constexpr bool IsEmpty() const { return RawValue == T(0); }
162
163 constexpr RaceMask operator&(RaceMask right) const { return { RawValue & right.RawValue }; }
164 constexpr RaceMask operator|(RaceMask right) const { return { RawValue | right.RawValue }; }
165 constexpr RaceMask operator~() const { return { ~RawValue }; }
166};
167
168template<typename T, size_t N>
169struct RaceMask<std::array<T, N>>
170{
171 static_assert(std::is_integral_v<T>, "RaceMask<T> must be integral");
172
173 std::array<T, N> RawValue;
174
175 constexpr bool HasRace(uint32 raceId) const
176 {
177 int32 raceBit = RaceMask<T>::GetRaceBit(raceId);
178 return raceBit >= 0 && uint32(raceBit) < sizeof(T) * 8 * N
179 && (RawValue[raceBit / (sizeof(T) * 8)] & (T(1) << (raceBit % (sizeof(T) * 8)))) != T(0);
180 }
181
182 static constexpr RaceMask GetMaskForRace(uint32 raceId)
183 {
184 RaceMask result = { };
185 int32 raceBit = RaceMask<T>::GetRaceBit(raceId);
186 if (raceBit >= 0 && uint32(raceBit) < sizeof(T) * 8 * N)
187 result.RawValue[raceBit / (sizeof(T) * 8)] = T(1) << (raceBit % (sizeof(T) * 8));
188 return result;
189 }
190
191 constexpr bool operator==(RaceMask const&) const = default;
192
193 constexpr bool IsEmpty() const
194 {
195 for (T rawValue : RawValue)
196 if (rawValue != T(0))
197 return false;
198 return true;
199 }
200
201 constexpr RaceMask operator&(RaceMask right) const
202 {
203 RaceMask result = { };
204 for (std::size_t i = 0; i < N; ++i)
205 result.RawValue[i] = RawValue[i] & right.RawValue[i];
206 return result;
207 }
208
209 constexpr RaceMask operator|(RaceMask right) const
210 {
211 RaceMask result = { };
212 for (std::size_t i = 0; i < N; ++i)
213 result.RawValue[i] = RawValue[i] | right.RawValue[i];
214 return result;
215 }
216
217 constexpr RaceMask operator~() const
218 {
219 RaceMask result = { };
220 for (std::size_t i = 0; i < N; ++i)
221 result.RawValue[i] = ~RawValue[i];
222 return result;
223 }
224};
225}
226
227template <typename T>
228inline constexpr Trinity::RaceMask<T> RACEMASK_ALL_v = ~Trinity::RaceMask<T>{};
229
230template <typename T>
263
264template <typename T>
266
267template <typename T>
284
285template <typename T>
286inline constexpr Trinity::RaceMask<T> RACEMASK_HORDE_v = RACEMASK_ALL_PLAYABLE_v<T> & ~(RACEMASK_NEUTRAL_v<T> | RACEMASK_ALLIANCE_v<T>);
287
288inline constexpr Trinity::RaceMask<uint64> RACEMASK_ALL = RACEMASK_ALL_v<uint64>;
289inline constexpr Trinity::RaceMask<uint64> RACEMASK_ALL_PLAYABLE = RACEMASK_ALL_PLAYABLE_v<uint64>;
290inline constexpr Trinity::RaceMask<uint64> RACEMASK_NEUTRAL = RACEMASK_NEUTRAL_v<uint64>;
291inline constexpr Trinity::RaceMask<uint64> RACEMASK_ALLIANCE = RACEMASK_ALLIANCE_v<uint64>;
292inline constexpr Trinity::RaceMask<uint64> RACEMASK_HORDE = RACEMASK_HORDE_v<uint64>;
293
294#endif // TRINITYCORE_RACE_MASK_H
int32_t int32
Definition Define.h:150
uint32_t uint32
Definition Define.h:154
constexpr Trinity::RaceMask< uint64 > RACEMASK_ALL_PLAYABLE
Definition RaceMask.h:289
constexpr Trinity::RaceMask< T > RACEMASK_NEUTRAL_v
Definition RaceMask.h:265
constexpr Trinity::RaceMask< uint64 > RACEMASK_ALLIANCE
Definition RaceMask.h:291
constexpr Trinity::RaceMask< T > RACEMASK_ALL_PLAYABLE_v
Definition RaceMask.h:231
constexpr Trinity::RaceMask< T > RACEMASK_HORDE_v
Definition RaceMask.h:286
constexpr Trinity::RaceMask< uint64 > RACEMASK_NEUTRAL
Definition RaceMask.h:290
constexpr Trinity::RaceMask< uint64 > RACEMASK_HORDE
Definition RaceMask.h:292
constexpr Trinity::RaceMask< T > RACEMASK_ALL_v
Definition RaceMask.h:228
Races
Definition RaceMask.h:27
@ RACE_DARK_IRON_DWARF
Definition RaceMask.h:62
@ RACE_TROLL
Definition RaceMask.h:36
@ RACE_UNDEAD_PLAYER
Definition RaceMask.h:33
@ RACE_PANDAREN_NEUTRAL
Definition RaceMask.h:52
@ RACE_ORC
Definition RaceMask.h:30
@ RACE_LIGHTFORGED_DRAENEI
Definition RaceMask.h:58
@ RACE_NONE
Definition RaceMask.h:28
@ RACE_DRAENEI
Definition RaceMask.h:39
@ RACE_EARTHEN_DWARF_HORDE
Definition RaceMask.h:78
@ RACE_NIGHTBORNE
Definition RaceMask.h:55
@ RACE_HIGHMOUNTAIN_TAUREN
Definition RaceMask.h:56
@ RACE_HARANIR_HORDE
Definition RaceMask.h:83
@ RACE_EARTHEN_DWARF_ALLIANCE
Definition RaceMask.h:79
@ RACE_DRACTHYR_HORDE
Definition RaceMask.h:67
@ RACE_ZANDALARI_TROLL
Definition RaceMask.h:59
@ RACE_VOID_ELF
Definition RaceMask.h:57
@ RACE_NIGHTELF
Definition RaceMask.h:32
@ RACE_BLOODELF
Definition RaceMask.h:38
@ RACE_DWARF
Definition RaceMask.h:31
@ RACE_GNOME
Definition RaceMask.h:35
@ RACE_GOBLIN
Definition RaceMask.h:37
@ RACE_KUL_TIRAN
Definition RaceMask.h:60
@ RACE_HUMAN
Definition RaceMask.h:29
@ RACE_DRACTHYR_ALLIANCE
Definition RaceMask.h:66
@ RACE_WORGEN
Definition RaceMask.h:50
@ RACE_PANDAREN_ALLIANCE
Definition RaceMask.h:53
@ RACE_VULPERA
Definition RaceMask.h:63
@ RACE_MECHAGNOME
Definition RaceMask.h:65
@ RACE_HARANIR_ALLIANCE
Definition RaceMask.h:80
@ RACE_MAGHAR_ORC
Definition RaceMask.h:64
@ RACE_PANDAREN_HORDE
Definition RaceMask.h:54
@ RACE_TAUREN
Definition RaceMask.h:34
constexpr Trinity::RaceMask< uint64 > RACEMASK_ALL
Definition RaceMask.h:288
constexpr Trinity::RaceMask< T > RACEMASK_ALLIANCE_v
Definition RaceMask.h:268
STL namespace.
constexpr RaceMask operator&(RaceMask right) const
Definition RaceMask.h:201
constexpr bool HasRace(uint32 raceId) const
Definition RaceMask.h:175
constexpr RaceMask operator~() const
Definition RaceMask.h:217
constexpr bool operator==(RaceMask const &) const =default
static constexpr RaceMask GetMaskForRace(uint32 raceId)
Definition RaceMask.h:182
constexpr RaceMask operator|(RaceMask right) const
Definition RaceMask.h:209
static constexpr int32 GetRaceBit(uint32 raceId)
Definition RaceMask.h:101
constexpr bool operator==(RaceMask const &) const =default
constexpr bool IsEmpty() const
Definition RaceMask.h:161
constexpr RaceMask operator|(RaceMask right) const
Definition RaceMask.h:164
static constexpr RaceMask GetMaskForRace(uint32 raceId)
Definition RaceMask.h:153
constexpr bool HasRace(uint32 raceId) const
Definition RaceMask.h:96
constexpr RaceMask operator&(RaceMask right) const
Definition RaceMask.h:163
constexpr RaceMask operator~() const
Definition RaceMask.h:165