diff options
author | Jesusaves <cpntb1@ymail.com> | 2021-05-23 16:21:44 -0300 |
---|---|---|
committer | Jesusaves <cpntb1@ymail.com> | 2021-05-23 16:21:44 -0300 |
commit | 0679bd5326d0f884100d286b22f8989a6c312e9c (patch) | |
tree | 0ddac5e5f12a9c283707012eafbd1fd4b56f0752 /npc/functions/bitwise.txt | |
parent | 50110fb267f1c46d34febb65e7069a64da0ec2e8 (diff) | |
download | serverdata-0679bd5326d0f884100d286b22f8989a6c312e9c.tar.gz serverdata-0679bd5326d0f884100d286b22f8989a6c312e9c.tar.bz2 serverdata-0679bd5326d0f884100d286b22f8989a6c312e9c.tar.xz serverdata-0679bd5326d0f884100d286b22f8989a6c312e9c.zip |
Add more wrappers
Diffstat (limited to 'npc/functions/bitwise.txt')
-rw-r--r-- | npc/functions/bitwise.txt | 113 |
1 files changed, 111 insertions, 2 deletions
diff --git a/npc/functions/bitwise.txt b/npc/functions/bitwise.txt index f7e595a27..fb9b1493c 100644 --- a/npc/functions/bitwise.txt +++ b/npc/functions/bitwise.txt @@ -6,8 +6,7 @@ * * @arg 0 - the variable * @arg 1 - mask - * @arg 2 - shift - */ + * @arg 2 - shift */ function script bitwise_get { .@shift = getarg(2, 0); @@ -65,3 +64,113 @@ function script bitmask_count { return .@p; } +///////////////////////////////////////////////////////////////////////////////// +// A Nibble can go up to 15. There are 7 nibbles. +// get_nibble(VAR, NIBBLEID) +function script get_nibble { + .@v=getarg(0); + switch (getarg(1)) { + case 0: + .@s=0; .@m=0xF; break; + case 1: + .@s=4; .@m=0XF0; break; + case 2: + .@s=8; .@m=0XF00; break; + case 3: + .@s=12; .@m=0XF000; break; + case 4: + .@s=16; .@m=0XF0000; break; + case 5: + .@s=20; .@m=0XF00000; break; + case 6: + .@s=24; .@m=0XF000000; break; + default: + Exception("Invalid Nibble: "+getarg(1), RB_DEFAULT, .@v); + } + + return bitwise_get(.@v, .@m, .@s); +} + +// A Byte can go up to 255. There are 3 bytes. The forth can go up to 127. +// get_nibble(VAR, BYTEID) +function script get_byte { + .@v=getarg(0); + switch (getarg(1)) { + case 0: + .@s=0; .@m=0xFF; break; + case 1: + .@s=8; .@m=0XFF00; break; + case 2: + .@s=16; .@m=0XFF0000; break; + case 3: + .@s=24; .@m=0X7F000000; break; + default: + Exception("Invalid Byte: "+getarg(1), RB_DEFAULT, .@v); + } + + return bitwise_get(.@v, .@m, .@s); +} + +// A Bitword can go up to 65535 and is fixed in position to handle Soul EXP. +// get_bitword(VAR) +function script get_bitword { + .@v=getarg(0); + + return bitwise_get(.@v, 0x7FFF800, 11); +} + +///////////////////////////////////////////////////////////////////////////////// +// A Nibble can go up to 15. There are 7 nibbles. +// set_nibble(VAR, VAL, NIBBLEID) +function script set_nibble { + .@v=getarg(0); + switch (getarg(2)) { + case 0: + .@s=0; .@m=0xF; break; + case 1: + .@s=4; .@m=0XF0; break; + case 2: + .@s=8; .@m=0XF00; break; + case 3: + .@s=12; .@m=0XF000; break; + case 4: + .@s=16; .@m=0XF0000; break; + case 5: + .@s=20; .@m=0XF00000; break; + case 6: + .@s=24; .@m=0XF000000; break; + default: + Exception("Invalid SNibble: "+getarg(2), RB_DEFAULT); + } + + return bitwise_set(.@v, .@m, .@s, getarg(1)); +} + +// A Byte can go up to 255. There are 3 bytes. The forth can go up to 127. +// set_nibble(VAR, VAL, BYTEID) +function script set_byte { + .@v=getarg(0); + switch (getarg(2)) { + case 0: + .@s=0; .@m=0xFF; break; + case 1: + .@s=8; .@m=0XFF00; break; + case 2: + .@s=16; .@m=0XFF0000; break; + case 3: + .@s=24; .@m=0X7F000000; break; + default: + Exception("Invalid SByte: "+getarg(2), RB_DEFAULT); + } + + return bitwise_set(.@v, .@m, .@s, getarg(1)); +} + +// A Bitword can go up to 65535 and is fixed in position to handle Soul EXP. +// set_bitword(VAR, VAL) +function script set_bitword { + .@v=getarg(0); + + return bitwise_set(.@v, 0x7FFF800, 11, getarg(1)); +} + |