This page:
Page history
Links to here

Last modified:
2005-12-23 at 13:51

Stacking

This page is the current status page of the new stacking patch.


The patch

Aim:

  • a reliable, bug-free, corner-case aware implementation of tracking of individual charges within a stack of wands/staves/rods

Current status:

  • fairly reliable patch which seems to work

Things that need doing:

  • scour new code and comment it
  • rename functions to something more appropriate
  • follow the various comments in object2.c
  • ensure that all cases are covered
  • fix debug mode tweaking of items, if possible
  • make the charge selection submenu into a normal Angband menu, with better error checking
  • add option to choose between highest/lowest-charged item in stack

Notes

Object names will end up overly long ("6 wands of Fire Bolts (2, 2x4, 2x8, 9 charges)") if you collect lots of them. There is the UI option "total_charges" which turns this into "35 charges total".

If you try very hard, you may be able to collect every charge of wand from 0 to 23. This isn't a problem. However, one more is.

Stacks only apply in the player's inventory, not stores or the floor. This means that even two wands with the same charge would not be stacked anymore on the floor.


Reference

There were various other alternatives proposed before work started on the patch. These included:

  • store more charges
  • be less likely to blow up when recharging
  • be less easily destroyed by monsters.

Implementation

I added an extra field to object_type, of type void * (as suggested on Code?). This is used for all rechargeables (i.e. rods/wands/staves) as a pointer to byte array, which contains a list of charges (or timeouts in the case of rods).

There are various functions, prefixed with rc_, which do the following things:

  • add a new charge to the stack
  • remove a charge from the stack
  • drain x charges from an item in the stack
  • recharge x charges to a item in the stack
  • get one random item from the stack (used for random drainings)
  • get one item from the stack, with user prompt (unless there's only one in the stack, in which case no user prompt is given)
  • transfer charges from one stack to another (either individually or in groups)
  • get number of charges in a stack, or charge for a given index into the stack
  • use a charge from a stack, using either the lowest- or highest-charged item the stack, according to user choice

Apart from that, there's various code around the place that needed tweaking or small rewrites to make it work properly with the new code.