questbits.txt

Uploaded: 16 Dec, 2008
Previous uploads by this submitter: 0

Author: Igor van den Hoven

Downloads: 260

The idea of this snippet is to move away from the traditional if value == (number between -2 and +2 billion) check.

Given the average quest has around 10 steps you only need 4 bits of a 32 bit integer to store it. If you have a large area and a quest value assigned for a player for that area you can add a total of eight 10 step quests stored in a 32 bit integer.

Using quest[MAX_VNUM / 100] is an easy way to create a quest value for each area, and you can access it with: ch->pcdata->quest[mob->in_room->low_r_vnum / 100] with ch being the player and mob being the mob setting the quest value.

In this code you define a bit range by giving the first bit, next giving the number of bits, followed by the value you want those bits to hold. 4 bits would give a value between 0 and 15, 8 bits a value between 0 and 255 (which should be enough for everyone).

To set a quest value you'd use: mpmset $n quest 0 4 1. 0 would be the first bit, 4 would be the total number of bits, and 1 is the value to assign to them. To check if bit 1 to 4 has the value 1 you'd use: if quest (0,4,$n) == 1.

When adding another quest you'd start out with: if quest (4,4,$n) == 0 to see if the player has started the quest assigned to bit 5 to 8, and mpmset $n quest 4 4 1 to set the value to 1.

Methods for saving and reading aren't included, this is pretty much a proof of concept.