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 //RACE_COMPANION_NETHERWING_DRAKE = 80,
75 //RACE_ROSTRUM_STORM_GRYPHON = 82,
76 //RACE_ROSTRUM_FAERIE_DRAGON = 83,
77 RACE_EARTHEN_DWARF_HORDE = 84, // TITLE Earthen DESCRIPTION Earthen (Horde) (RaceMask bit 17)
78 RACE_EARTHEN_DWARF_ALLIANCE = 85, // TITLE Earthen DESCRIPTION Earthen (Alliance) (RaceMask bit 18)
79 //RACE_HARRONIR = 86,
80 //RACE_ROSTRUM_AIRSHIP = 87,
81};
82
83// max+1 for player race
84#define MAX_RACES 88
85
86namespace Trinity
87{
88template<typename T>
90{
91 static_assert(std::is_integral_v<T>, "RaceMask<T> must be integral");
92
94
95 constexpr bool HasRace(uint8 raceId) const
96 {
97 return (RawValue & GetMaskForRace(raceId)) != 0;
98 }
99
100 static constexpr int32 GetRaceBit(uint8 raceId)
101 {
102 switch (raceId)
103 {
104 case RACE_HUMAN:
105 case RACE_ORC:
106 case RACE_DWARF:
107 case RACE_NIGHTELF:
109 case RACE_TAUREN:
110 case RACE_GNOME:
111 case RACE_TROLL:
112 case RACE_GOBLIN:
113 case RACE_BLOODELF:
114 case RACE_DRAENEI:
115 case RACE_WORGEN:
119 case RACE_NIGHTBORNE:
121 case RACE_VOID_ELF:
124 case RACE_KUL_TIRAN:
125 return raceId - 1;
127 return 11;
128 case RACE_VULPERA:
129 return 12;
130 case RACE_MAGHAR_ORC:
131 return 13;
132 case RACE_MECHAGNOME:
133 return 14;
135 return 16;
137 return 15;
139 return 17;
141 return 18;
142 default:
143 break;
144 }
145 return -1;
146 }
147
148 static constexpr T GetMaskForRace(uint8 raceId)
149 {
150 int32 raceBit = GetRaceBit(raceId);
151 return raceBit >= 0 && uint32(raceBit) < sizeof(T) * 8 ? (T(1) << raceBit) : T(0);
152 }
153
154 constexpr bool IsEmpty() const { return RawValue == T(0); }
155
156 constexpr RaceMask operator&(RaceMask right) const { return { RawValue & right.RawValue }; }
157 constexpr RaceMask operator|(RaceMask right) const { return { RawValue | right.RawValue }; }
158 constexpr RaceMask operator~() const { return { ~RawValue }; }
159};
160}
161
162constexpr Trinity::RaceMask<uint64> RACEMASK_ALL_PLAYABLE = { std::integral_constant<uint64,
163 // force compile time evaluation via integral_constant
192
193constexpr Trinity::RaceMask<uint64> RACEMASK_NEUTRAL = { std::integral_constant<uint64, Trinity::RaceMask<uint64>::GetMaskForRace(RACE_PANDAREN_NEUTRAL)>::value };
194
195constexpr Trinity::RaceMask<uint64> RACEMASK_ALLIANCE = { std::integral_constant<uint64,
210
211constexpr Trinity::RaceMask<uint64> RACEMASK_HORDE = { std::integral_constant<uint64, (RACEMASK_ALL_PLAYABLE & ~(RACEMASK_NEUTRAL | RACEMASK_ALLIANCE)).RawValue>::value };
212
213#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:162
constexpr Trinity::RaceMask< uint64 > RACEMASK_ALLIANCE
Definition: RaceMask.h:195
constexpr Trinity::RaceMask< uint64 > RACEMASK_NEUTRAL
Definition: RaceMask.h:193
constexpr Trinity::RaceMask< uint64 > RACEMASK_HORDE
Definition: RaceMask.h:211
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_EARTHEN_DWARF_HORDE
Definition: RaceMask.h:77
@ RACE_NIGHTBORNE
Definition: RaceMask.h:54
@ RACE_HIGHMOUNTAIN_TAUREN
Definition: RaceMask.h:55
@ RACE_EARTHEN_DWARF_ALLIANCE
Definition: RaceMask.h:78
@ 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:95
static constexpr int32 GetRaceBit(uint8 raceId)
Definition: RaceMask.h:100
static constexpr T GetMaskForRace(uint8 raceId)
Definition: RaceMask.h:148
constexpr bool IsEmpty() const
Definition: RaceMask.h:154
constexpr RaceMask operator|(RaceMask right) const
Definition: RaceMask.h:157
constexpr RaceMask operator&(RaceMask right) const
Definition: RaceMask.h:156
constexpr RaceMask operator~() const
Definition: RaceMask.h:158