TrinityCore
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 RaceMask_h__
19#define RaceMask_h__
20
21#include "Define.h"
22#include <type_traits>
23
24// EnumUtils: DESCRIBE THIS
26{
27 RACE_NONE = 0, // SKIP
28 RACE_HUMAN = 1, // TITLE Human
29 RACE_ORC = 2, // TITLE Orc
30 RACE_DWARF = 3, // TITLE Dwarf
31 RACE_NIGHTELF = 4, // TITLE Night Elf
32 RACE_UNDEAD_PLAYER = 5, // TITLE Undead
33 RACE_TAUREN = 6, // TITLE Tauren
34 RACE_GNOME = 7, // TITLE Gnome
35 RACE_TROLL = 8, // TITLE Troll
36 RACE_GOBLIN = 9, // TITLE Goblin
37 RACE_BLOODELF = 10, // TITLE Blood Elf
38 RACE_DRAENEI = 11, // TITLE Draenei
39 //RACE_FEL_ORC = 12,
40 //RACE_NAGA = 13,
41 //RACE_BROKEN = 14,
42 //RACE_SKELETON = 15,
43 //RACE_VRYKUL = 16,
44 //RACE_TUSKARR = 17,
45 //RACE_FOREST_TROLL = 18,
46 //RACE_TAUNKA = 19,
47 //RACE_NORTHREND_SKELETON = 20,
48 //RACE_ICE_TROLL = 21,
49 RACE_WORGEN = 22, // TITLE Worgen
50 //RACE_GILNEAN = 23,
51 RACE_PANDAREN_NEUTRAL = 24, // TITLE Pandaren DESCRIPTION Pandaren (Neutral)
52 RACE_PANDAREN_ALLIANCE = 25, // TITLE Pandaren DESCRIPTION Pandaren (Alliance)
53 RACE_PANDAREN_HORDE = 26, // TITLE Pandaren DESCRIPTION Pandaren (Horde)
54 RACE_NIGHTBORNE = 27, // TITLE Nightborne
55 RACE_HIGHMOUNTAIN_TAUREN = 28, // TITLE Highmountain Tauren
56 RACE_VOID_ELF = 29, // TITLE Void Elf
57 RACE_LIGHTFORGED_DRAENEI = 30, // TITLE Lightforged Draenei
58 RACE_ZANDALARI_TROLL = 31, // TITLE Zandalari Troll
59 RACE_KUL_TIRAN = 32, // TITLE Kul Tiran
60 //RACE_THIN_HUMAN = 33,
61 RACE_DARK_IRON_DWARF = 34, // TITLE Dark Iron Dwarf DESCRIPTION Dark Iron Dwarf (RaceMask bit 11)
62 RACE_VULPERA = 35, // TITLE Vulpera DESCRIPTION Vulpera (RaceMask bit 12)
63 RACE_MAGHAR_ORC = 36, // TITLE Mag'har Orc DESCRIPTION Mag'har Orc (RaceMask bit 13)
64 RACE_MECHAGNOME = 37, // TITLE Mechagnome DESCRIPTION Mechagnome (RaceMask bit 14)
65 RACE_DRACTHYR_ALLIANCE = 52, // TITLE Dracthyr DESCRIPTION Dracthyr (Alliance) (RaceMask bit 16)
66 RACE_DRACTHYR_HORDE = 70, // TITLE Dracthyr DESCRIPTION Dracthyr (Horde) (RaceMask bit 15)
67 //RACE_COMPANION_DRAKE = 71,
68 //RACE_COMPANION_PROTO_DRAGON = 72,
69 //RACE_COMPANION_SERPENT = 73,
70 //RACE_COMPANION_WYVERN = 74,
71 //RACE_DRACTHYR_VISAGE_ALLIANCE = 75,
72 //RACE_DRACTHYR_VISAGE_HORDE= 76,
73 //RACE_COMPANION_PTERRODAX = 77
74};
75
76// max+1 for player race
77#define MAX_RACES 78
78
79namespace Trinity
80{
81template<typename T>
83{
84 static_assert(std::is_integral_v<T>, "RaceMask<T> must be integral");
85
87
88 constexpr bool HasRace(uint8 raceId) const
89 {
90 return (RawValue & GetMaskForRace(raceId)) != 0;
91 }
92
93 static constexpr int32 GetRaceBit(uint8 raceId)
94 {
95 switch (raceId)
96 {
97 case RACE_HUMAN:
98 case RACE_ORC:
99 case RACE_DWARF:
100 case RACE_NIGHTELF:
102 case RACE_TAUREN:
103 case RACE_GNOME:
104 case RACE_TROLL:
105 case RACE_GOBLIN:
106 case RACE_BLOODELF:
107 case RACE_DRAENEI:
108 case RACE_WORGEN:
112 case RACE_NIGHTBORNE:
114 case RACE_VOID_ELF:
117 case RACE_KUL_TIRAN:
118 return raceId - 1;
120 return 11;
121 case RACE_VULPERA:
122 return 12;
123 case RACE_MAGHAR_ORC:
124 return 13;
125 case RACE_MECHAGNOME:
126 return 14;
128 return 16;
130 return 15;
131 default:
132 break;
133 }
134 return -1;
135 }
136
137 static constexpr T GetMaskForRace(uint8 raceId)
138 {
139 int32 raceBit = GetRaceBit(raceId);
140 return raceBit >= 0 && uint32(raceBit) < sizeof(T) * 8 ? (T(1) << raceBit) : T(0);
141 }
142
143 constexpr bool IsEmpty() const { return RawValue == T(0); }
144
145 constexpr RaceMask operator&(RaceMask right) const { return { RawValue & right.RawValue }; }
146 constexpr RaceMask operator|(RaceMask right) const { return { RawValue | right.RawValue }; }
147 constexpr RaceMask operator~() const { return { ~RawValue }; }
148};
149}
150
151constexpr Trinity::RaceMask<uint64> RACEMASK_ALL_PLAYABLE = { std::integral_constant<uint64,
152 // force compile time evaluation via integral_constant
180
181constexpr Trinity::RaceMask<uint64> RACEMASK_NEUTRAL = { std::integral_constant<uint64, Trinity::RaceMask<uint64>::GetMaskForRace(RACE_PANDAREN_NEUTRAL)>::value };
182
183constexpr Trinity::RaceMask<uint64> RACEMASK_ALLIANCE = { std::integral_constant<uint64,
197
198constexpr Trinity::RaceMask<uint64> RACEMASK_HORDE = { std::integral_constant<uint64, (RACEMASK_ALL_PLAYABLE & ~(RACEMASK_NEUTRAL | RACEMASK_ALLIANCE)).RawValue>::value };
199
200#endif // RaceMask_h__
uint8_t uint8
Definition: Define.h:144
int32_t int32
Definition: Define.h:138
uint64_t uint64
Definition: Define.h:141
uint32_t uint32
Definition: Define.h:142
constexpr Trinity::RaceMask< uint64 > RACEMASK_ALL_PLAYABLE
Definition: RaceMask.h:151
constexpr Trinity::RaceMask< uint64 > RACEMASK_ALLIANCE
Definition: RaceMask.h:183
constexpr Trinity::RaceMask< uint64 > RACEMASK_NEUTRAL
Definition: RaceMask.h:181
constexpr Trinity::RaceMask< uint64 > RACEMASK_HORDE
Definition: RaceMask.h:198
Races
Definition: RaceMask.h:26
@ RACE_DARK_IRON_DWARF
Definition: RaceMask.h:61
@ RACE_TROLL
Definition: RaceMask.h:35
@ RACE_UNDEAD_PLAYER
Definition: RaceMask.h:32
@ RACE_PANDAREN_NEUTRAL
Definition: RaceMask.h:51
@ RACE_ORC
Definition: RaceMask.h:29
@ RACE_LIGHTFORGED_DRAENEI
Definition: RaceMask.h:57
@ RACE_NONE
Definition: RaceMask.h:27
@ RACE_DRAENEI
Definition: RaceMask.h:38
@ RACE_NIGHTBORNE
Definition: RaceMask.h:54
@ RACE_HIGHMOUNTAIN_TAUREN
Definition: RaceMask.h:55
@ RACE_DRACTHYR_HORDE
Definition: RaceMask.h:66
@ RACE_ZANDALARI_TROLL
Definition: RaceMask.h:58
@ RACE_VOID_ELF
Definition: RaceMask.h:56
@ RACE_NIGHTELF
Definition: RaceMask.h:31
@ RACE_BLOODELF
Definition: RaceMask.h:37
@ RACE_DWARF
Definition: RaceMask.h:30
@ RACE_GNOME
Definition: RaceMask.h:34
@ RACE_GOBLIN
Definition: RaceMask.h:36
@ RACE_KUL_TIRAN
Definition: RaceMask.h:59
@ RACE_HUMAN
Definition: RaceMask.h:28
@ RACE_DRACTHYR_ALLIANCE
Definition: RaceMask.h:65
@ RACE_WORGEN
Definition: RaceMask.h:49
@ RACE_PANDAREN_ALLIANCE
Definition: RaceMask.h:52
@ RACE_VULPERA
Definition: RaceMask.h:62
@ RACE_MECHAGNOME
Definition: RaceMask.h:64
@ RACE_MAGHAR_ORC
Definition: RaceMask.h:63
@ RACE_PANDAREN_HORDE
Definition: RaceMask.h:53
@ RACE_TAUREN
Definition: RaceMask.h:33
constexpr bool HasRace(uint8 raceId) const
Definition: RaceMask.h:88
static constexpr int32 GetRaceBit(uint8 raceId)
Definition: RaceMask.h:93
static constexpr T GetMaskForRace(uint8 raceId)
Definition: RaceMask.h:137
constexpr bool IsEmpty() const
Definition: RaceMask.h:143
constexpr RaceMask operator|(RaceMask right) const
Definition: RaceMask.h:146
constexpr RaceMask operator&(RaceMask right) const
Definition: RaceMask.h:145
constexpr RaceMask operator~() const
Definition: RaceMask.h:147