Hercules
Hercules copied to clipboard
Add bitcount() script command
REOPENED FROM #3344
Pull Request Prelude
- [x] I have followed proper Hercules code styling.
- [x] I have read and understood the contribution guidelines before making this PR.
- [x] I am aware that this PR may be closed if the above-mentioned criteria are not fulfilled.
Changes Proposed
Add bitcount() script command to return the number of active bits in an integer. Also commonly called popcount. It is a basic operation that is usefull when dealing with bitmasks. Now, I know it can be done using functions, but isn't it nice to have a built-in command instead of relying on callfunc() for something that simple?
Script example:
NPC 1
if(bitcount(quest) < 2)
mes "You need to talk to 2 different NPCs.";
else
mes "Here is your reward!";
NPC 2
if(quest & 1)
mes "You already talked to me.";
else
quest |= 1;
NPC 3
if(quest & 2)
mes "You already talked to me.";
else
quest |= 2;
NPC 4
if(quest & 4)
mes "You already talked to me.";
else
quest |= 4;