Faction IDs
List of Faction IDs
[6.2.4] https://docs.google.com/spreadsheets/d/1XcojgRK-aFPKbJ2jlsiPLB4zEAQUGnpBSOeR9Z5yLao/edit?usp=sharing
[4.3.4] https://docs.google.com/spreadsheets/d/1BV-78fuiAMqI5Rq-rbCxdF9X4fkwDRtyK9Rv9CbKNzc/edit?usp=sharing
(Right side of 3.3.5 spreadsheet are values that can be used in-game using .mod faction or .npc set faction)
Explanations & Calculations
(From http://www.trinitycore.info/FactionTemplate.dbc_tc2)
Each different entry has different relations towards any other faction.
The easiest calculation when calculating hostility or friendliness is to look at the Friend factions and Enemy factions columns in the table below. If our faction has the other faction's ID in the Enemy factions list, then it is hostile to that faction (at least). The same thing applies for a friendliness check on the Friend factions column.
If our faction doesn't have the other faction's ID in the enemy or friend faction list, then we'll have to get more complicated in calculating hostility or friendliness.
First, let's define the four faction groups:
IDBitName
0
1
All players (and pets)
1
2
Alliance players (and their pets)
2
4
Horde players (and their pets)
3
8
Monster (Not a player nor a pet)
The first mask (ourMask) defines what type of faction we are dealing with. Eg, faction 1 (PLAYER, Human) has 3 as ourMask; that means that it has the first two bits set so it classifies as both 'All players' and 'Alliance players'.
The second mask (friendlyMask) defines what faction groups this faction is friendly with. That means that if this field contains the bit for a faction group, then it is friendly with that faction. Eg, faction 5 (PLAYER, Undead) has 4 as friendlyMask; that means that it has the third bit set so it is friendly with 'Horde players'.
The third mask (hostileMask) defines what faction groups this faction is hostile with. This faction will be hostile to any faction group whose bit is set in this field. For example, let's examine the first two Stormwind factions. The first one (faction 11) has hostileMask 12. The binary representation of this is 1100, with the third and fourth bits set. The second Stormwind faction (faction 12) has hostileMask 4. The binary representation of this is 0100, with the third bit set. Applying the formulas to these two values, we can see that faction 11 is hostile to Horde players and also anything that is not a player while faction 12 is only hostile to Horde players. Faction 12 will not aggro any creature that is part of the monster faction group.
For the mathematically inclined, the basic formula to test for friendliness is
(friendlyMask & other.ourMask) != 0
...where other is another faction. The same thing applies for hostility:
(hostileMask & other.ourMask) != 0
For the not so mathematically inclined, we'll have to compare two binary numbers. First, you will need to convert all of the masks to binary form with four digits; so 1 becomes 0001, 2 becomes 0010, 3 becomes 0011, etc.
Second, line up the friendlyMask or hostileMask value with the ourMask value. For example:
1100 //hostileMask of faction 11
1000 //ourMask of faction 14
Next, perform a logical 'AND' on the two numbers, the bottom one with the one on top and follow these rules:
- 1 and 1 is 1
- 1 and 0 is 0
- 0 and 1 is 0
- 0 and 0 is 0
So, continuing our example:
1100
1000
----
1000
Finally, check the result that you get with the value 0. Only 0000 will equal 0, anything else will not equal 0. If the result 'does not' equal 0, then the faction is hostile/friendly to the other faction. In our example, it is obvious that we do not have 0 (we have 8 in fact if you convert to base 10 again), so faction 11 is hostile to faction 14 and will aggro it.
From all of the above calculations, we notice that if ourMask for a faction is 0 (that means 0000), it will be neutral to everything (not necessarily friendly). If the friendlyMask for a faction is 0, then it will never be friendly to anything or anyone (unless it has other faction IDs in the Friend factions column in the table below). Finally, if the hostileMask for a faction is 0, it will never be hostile to anything or anyone (again there may be exceptions in the Enemy factions column in the table below).
To summarize, you should follow these steps to calculate if faction A is hostile to faction B:
- Look for faction B in the Enemy faction list of faction A in the table below
- If found, then faction A is hostile to faction B and you can stop
- If not found, then continue with the next steps
- Look up hostileMask for faction A in table below
- Look up ourMask for faction B in table below
- Do the and (&) operation on the two values
- If the result is 0, then faction A is not hostile to faction B (but not necessarily friendly either)
- If the result is not 0, then faction A IS hostile to faction B
And these steps to calculate if faction A is friendly to faction B:
- Look for faction B in the Friend faction list of faction A in the table below
- If found, then faction A is friendly to faction B and you can stop
- If not found, then continue with the next steps
- Look up friendlyMask for faction A in table below
- Look up ourMask for faction B in table below
- Do the and (&) operation on the two values
- If the result is 0, then faction A is not friendly to faction B (but not necessarily hostile either)
- If the result is not 0, then faction A IS friendly to faction B