I've had two people trying to help me understand this and I really, really appreciate any help.
It's just that all tries to explain bitmasking start somewhere in the middle of the topic instead of the beginning and looking at existing scripts isn't very helpful.
I've received many links, probably these two are the most important ones:
http://pastebin.com/6Jj65wX3
https://github.com/themanaworld/tmwa-se ... -quest.txt
So to start from the beginning:
1. What is bitmasking (in a nutshell!)?
2. Why do we need bitmasking?
If I understood correctly this would be a good (short) answer to both questions:
Bitmasking allows to use many different quest states which is necessary when you want to create a quest in which several tasks can be done in any order.
Example (picking the Witch Cult Quest I'm working on):
Code: Select all
Task NPC Description Comment
1 Troll Mask Guy Read the story and accepted the task -
2 Torch1 Disabled the torch Torches 1-9 can be disabled in any order
3 Torch2 Disabled the torch Torches 1-9 can be disabled in any order
4 Torch3 Disabled the torch Torches 1-9 can be disabled in any order
5 Torch4 Disabled the torch Torches 1-9 can be disabled in any order
6 Torch5 Disabled the torch Torches 1-9 can be disabled in any order
7 Torch6 Disabled the torch Torches 1-9 can be disabled in any order
8 Torch7 Disabled the torch Torches 1-9 can be disabled in any order
9 Torch8 Disabled the torch Torches 1-9 can be disabled in any order
10 Torch9 Disabled the torch Torches 1-9 can be disabled in any order
11 Kalinoir Torch Defeated Kalinoir -
12 Troll Mask Guy Received first reward -
13 Troll Mask Guy Listened to his offer -
14 Troll Mask Guy Offer accepted, received second reward -
- one for "Torch 1 disabled"
- one for "Torch 1+2 disabled"
- one for "Torch 2+3+7 disabled"
- one for "Torch 4+6+8+9 disabled" and so on
3. How does bitmasking work?
I would start at this point:
There are different ways to use bitmasking:
- Bytes which have a range of 0-255
- Nibbles which have a range of 0-15
- 2Bits (or TWOBIT) which have a range of 0-3
- Bits which have a range of 0-1
I think my example shows how to decide between those:
The 9 Torches which require bitmasking only need two states: torch enabled, torch disabled.
Bits can only be 0 or 1, that's perfect, so:
0 = torch enabled, 1 = torch disabled
This is where my understanding stops so far.
In this file there are things like:
TWOBIT_0_SHIFT 0
TWOBIT_0_MASK 3
The documentation sucks so much.
You can see nowhere what that means.
Meanwhile I figured out that I need this file again.
So "TWOBIT_0_SHIFT 0" refers to byte 0 and "TWOBIT_0_MASK 3" refers to the four (0-3) 2Bits in it.
But that's all I understood.
So what are shift and mask doing?
How do I use them?
Also I see Bytes, Nibbles and 2Bits in there, but no Bits?
Phew... I need sleep now, been at this for hours today.
Thanks for every help