Jump to content

Bitwise in mangos with spells


Auntie Mangos

Recommended Posts

Use SpellWork and don't even bother with the DBC editor.

http://getmangos.eu/community/topic/13617/spell-work-in-c/

The main advantage to hex is that each hex character turns into exactly 4 binary characters, so it is very easy to convert and see as binary. With decimal, it is much more confusing.

e.g. 0xFFA1 translates into 1111 1111 1010 0001, which I can do without any tools in seconds, since I just turn each character into a series of 4 bits (i.e. F is 1111, A is 1010 or 10 (8+2), and 1 is simply 0001). In decimal it is 65441, which is harder to convert into binary.

Link to comment
Share on other sites

  • 41 years later...

I dont understand how the bitwise operators in mangos are used in spells

I read alot of bitwise operators but still dont understand .

Operators like : << >> & |

Example: Spellfamily[x] & 0x50 , i understand 0x50 is hex but what does it do exactly?(calculation?)

Other question is how to find spellfamily and the hexdecimal? I know i can find it in dbc, but i never could find and i check DBCstructureer.h but still dont understand :S

Could someone make this clear, since i really think this is nessesary to know how this work to for example to fix spells

PS: i know that spellfamily and hex is related to a spell with all ranks

Link to comment
Share on other sites

Ye but i still dont understand , i udnerstand how bitwise are working but i dont understand why you need to do that in spellfamily for example?

Example:

Spellfamily[0] = 00100
0x2

Then you got this code

if (Spellfamily[0] | 0x2)
{
Spellfamily[0] | 0x2 == 00110;
}

Other example with same variables

if (Spellfamily[0] & 0x2)
{
  Spellfamily[0] & 0x2 == 00000;
}

Is this correct?? And how to find those hexdec and Spellfamily? Please dont say only in .dbc files, since i already looked in

Link to comment
Share on other sites

No idea what you're trying to do...

If you mean operations on SpellEntry::SpellFamilyFlags, then yes, those values are from Spell.dbc of course, because SpellEntry only contains data parsed from Spell.dbc.

Most player related spells just have some unique combination of SpellFamilyName and bits set in SpellFamilyFlags/SpellFamilyFlags2.

Checking for those bits simply allows to identify abilities (say "Fireball") independent of its rank.

And we use hexadecimal notation just because it's easier to read, with "0x20001" everyone can easily see it has only two bits set, if you use the decimal version "131073" in code, no one know how many flags you're checking...you can convert decimal<->hexadecimal with every halfway decent calculator...

Link to comment
Share on other sites

remark that numbers are numbers, so

793 (decimal) == 1100011001 (dual) == 319(hex) [ 0x319] == 13.13 (babylonian) == 2.12.11 (17)

so possible you will see in dbcs only decimal values, then you need to translate them for yourself to whatever format you need

Link to comment
Share on other sites

No idea what you're trying to do...

If you mean operations on SpellEntry::SpellFamilyFlags, then yes, those values are from Spell.dbc of course, because SpellEntry only contains data parsed from Spell.dbc.

Most player related spells just have some unique combination of SpellFamilyName and bits set in SpellFamilyFlags/SpellFamilyFlags2.

Checking for those bits simply allows to identify abilities (say "Fireball") independent of its rank.

And we use hexadecimal notation just because it's easier to read, with "0x20001" everyone can easily see it has only two bits set, if you use the decimal version "131073" in code, no one know how many flags you're checking...you can convert decimal<->hexadecimal with every halfway decent calculator...

Sorry , i mean SpellfamilyFlags ofcourse, i wonder when you know what array and what hex(dec) you need to use, what excactly .dbc file and table it stand?

But other way why you need here bitwise????

And what do you mean with: everyone can easily see it has only two bits set

Example:

//slice and dice
if (spellproto->SpellFamilyFlags[0] & 0x40000)

But if (>0) is always true, i just dont understand how you can use 2 variables with bitwise operator as statement?

Since it is calculation

Link to comment
Share on other sites

Okay now we're back at the very basics of programming, i can only refer you to DasBlub's post again.

And in C(++) every expression yielding a value != 0 is considered true, and "a & b" is an expression.

You could aswell write "if ((spellproto->SpellFamilyFlags[0] & 0x40000) != 0)" but that's just redundant.

Link to comment
Share on other sites

Like i said lynx3d, sorry maybe my english not good

But that means in line like

For example SpellFamilyFlags[0] = 00100(bin)

if (SpellFamilyFlags[0] & 0x4)
{
// this will be get executed since SpellFamilyFlags[0] & 0x4 ==  00100
}

And if you get this

if (SpellFamilyFlags[0] & 0x2)
{
//this wont get executed since SpellFamilyFlags[0] & 0x2 ==  00000
}

Ok , am i right?

But you said:

everyone can easily see it has only two bits set,

What do you mean exactly by it?

I think i dont understand the content of a flag completly

And where are those SpellFamilyFlags[x] are written in dbc exactly? (Spell.dbc i cant find it :( )

Link to comment
Share on other sites

Yes those examples are correct, that's how it works.

What i meant with hexadecimal vs. decimal is that sicne 16 is a power of two, it "naturally" groups 4 bits on one digit.

1, 2, 4 and 8 are powers of two, and so are (in hex) 10, 20, 40 and 80, aswell as 100, 200, 400, 800 etc.

so if you have 0x20001 you can see the '2' digit is one set bit and the '1' at the end is another one. But no average human being can tell how many bits the decimal value 131073 has set just by looking at it.

-edit-

Oh about where in Spell.dbc, i don't feel like counting colums now because there are a LOT of them, get some dbc viewer that has named columns, or look around for sql version with named columns, or even get some more specialized programs like SpellWork.

Link to comment
Share on other sites

Comparison of using hex to binary to dec:

0x0402 = 0000 0100 0000 0010 = dec 1026
0x0001 = 0000 0000 0000 0001 = dec 1
0x0040 = 0000 0000 0100 0000 = dec 64

Add the three together:

0x0443 = 0000 0100 0100 0011 = dec 1091

It's a bit easier to use the hex as opposed to trying to add the decimal values together or subtract back them out.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. Privacy Policy Terms of Use