Quest bits on items

For builders to discuss and ask building questions.
Post Reply
Dalvyn
Sword Grand Master
Sword Grand Master
Posts: 4708
Joined: Tue Jul 15, 2003 9:26 pm
Location: House of Wonder, Waterdeep

Quest bits on items

Post by Dalvyn » Tue May 04, 2004 2:01 pm

Greg coded these new commands and test (which should be available to builders after the update bringing player accounts).

Code: Select all

mposet $o value5bits <first_bit_number> <number_of_bits> <value>
mpoadd $o value5bits <first_bit_number> <number_of_bits> <value>
if value5bits(<first_bit_number>,<number_of_bits>,$o) == <value>
They work just like

Code: Select all

mpmset $n quest <first_bit_number> <number_of_bits> <value>
mpmadd $n quest <first_bit_number> <number_of_bits> <value>
if quest(<first_bit_number>,<number_of_bits>,$n) == <value>
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:

Code: Select all

>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
~
Last edited by Dalvyn on Tue May 04, 2004 3:16 pm, edited 1 time in total.
Image
Dalvyn
Sword Grand Master
Sword Grand Master
Posts: 4708
Joined: Tue Jul 15, 2003 9:26 pm
Location: House of Wonder, Waterdeep

Post by Dalvyn » Tue May 04, 2004 2:21 pm

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.

With the slicing of value5 into bits, we can use something like this:
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:

Code: Select all

>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.
Image
Post Reply