home » builders » builder's lessons » quest bits on objects
Quest bits on objects
Builders now have the ability to set quest bits on items. Quest bits can be set on ALL of the values, but it is recommended in most instances that bits only be set on value5. The other values are used by objects for different settings, value5 is not used by any object.
mposet $o value5bitsmpoadd $o value5bits if value5bits( , ,$o) ==
They work just like
mpmset $n questmpmadd $n quest if quest( , ,$n) ==
Up to now, we could store (easily) only one value on objects, in value5. That works well for, say, a charged item with 4 charges of a given spell. In this case, the object's value5 represented the number of charges left. Yet, it was quite tricky to code objects with charges of more than one spell (for example, a ring of spell storing for cure light wounds, levitate, and bless).
The new commands allow us to slice value5 into several parts. In the example of the ring of spell storing for cure light wounds, levitate and bless, we could use 1 bit to indicate whether or not the cure light wounds charge is available or not, another bit for the levitate charge, and a third bit fot the bless charge. If we number those bits 0, 1, and 2, we can now use the following programs:
>intercept_prog curelighttrigger~ if wear_loc($o) != -1 if value5bits(0,1,$o) == 1 cast 'cure light' $n mposet on $n $o value5bits 0 1 0 else mpechoat $n Nothing happens. endif else mpechoat $n You should wear the ring first. endif ~ >intercept_prog blesstrigger~ if wear_loc($o) != -1 if value5bits(2,1,$o) == 1 cast bless $n mposet on $n $o value5bits 2 1 0 else mpechoat $n Nothing happens. endif else mpechoat $n You should wear the ring first. endif ~ >intercept_prog curelightrecharge~ if wear_loc($o) != -1 if value5bits(0,1,$o) == 1 mpechoat $n The ring does not need to be recharged. else if skilllevel($n,cure light) < 6 or manaamt($n) < 40 mpechoat $n That does not work. else mpmadd $n currmana -40 mposet on $n $o value5bits 0 1 1 mpechoat $n You recharge the ring. endif endif else mpechoat $n You should wear the ring first. endif ~
Another application for these new commands: objects with "memory", that is, objects that should react to a sequence of actions. An in-game example: the harp in Shadowdale. The "reaction" of the objects depends on the last five notes that have been played.
Coding such an object without the new commands required to use base-7 representation of numbers (after numbering the strings/notes from 0 to 6). Value5 was used to store a number representing the strings that have been plucked. That yielded programs that are hard to read and hard to modify.
0,3 : number of first string plucked 3,3 : number of second string plucked 6,3 : number of third string plucked 9,3 : number of fourth string plucked 12,3 : number of fifth string plucked (eventually: 15,2 : number of strings already plucked)
Initially, we would have
value5bits 0,3 == 0 value5bits 3,3 == 0 value5bits 6,3 == 0 value5bits 9,3 == 0 value5bits 12,3 == 0 value5bits 15,2 == 0
If someone plucks string 4, the values become
value5bits 0,3 == 4 value5bits 3,3 == 0 value5bits 6,3 == 0 value5bits 9,3 == 0 value5bits 12,3 == 0 value5bits 15,2 == 1
If someone then plucks strings 3, 2 then 5, the values become
value5bits 0,3 == 4 value5bits 3,3 == 3 value5bits 6,3 == 2 value5bits 9,3 == 7 value5bits 12,3 == 0 value5bits 15,2 == 4
At this point, if someone plucks a fifth string, we can trigger an effect if it is needed.
The object could have intercept progs for each string (plucka, ..., pluckg for example). If the A string is coded as 0, B as 1, ..., D as 3, ..., G as 6, the programs will look like this:
>intercept_prog pluckd~ if value5bits(15,2,$o) == 0 mposet value5bits $o 0 3 3 endif if value5bits(15,2,$o) == 1 mposet value5bits $o 0 6 3 endif if value5bits(15,2,$o) == 2 mposet value5bits $o 0 9 3 endif if value5bits(15,2,$o) == 3 mposet value5bits $o 0 12 3 endif if value5bits(15,2,$o) == 4 mposet value5bits $o 0 15 3 endif mpoadd $o value5bits 15 2 1 if value5bits(15,2,$o) == 5 (check for effect) (then reset the values:) mposet $o value5bits 0 17 0 endif ~
The same could be used for any object to which several sequences of actions can be applied.