Ted's notes

To:   Fellow users of Tyrsis' Inventory System
From: Ted Shutes

In the process of beta-testing this Inventory System, I actually went through the exercise of adding several items to it to see how hard it it and what all has to be done.  It actually isn't all that difficult but it can be tedious.
A checklist of things to do helps a lot:

Main.c:
-------
    __ if the item is to be "countable", add two counters: one for the number  of this item in Dink's inventory,
         and another for the number in the  trunk.
 

Item script (my examples: item-pig.c [non-countable], item-bom.c [countable];
-----------                                           item-fb.c  [magic]
  arm() procedure:
    __ "&chest_item = #" (weapon item) or "&chest_magic = #" (magic item),
          where "#" is an item number from 2-31 (note 1)
    __ if "countable", say() the number of items remaining.
  disarm() proc:
    __ "&chest_item = 0" or "&chest_magic = 0" (note 2)
  use() proc:
    __ if "countable", decrement the count, make Dink say() the new count,
         and if zero, kill_cur_item(). (note 3)
 

"add_item()" script (e.g. healer.c)
-------------------
    __ if "countable", check the current count or (better) use count_item()
         to see whether Dink already has any.  Require a free slot, and do
         the add_item(), only if Dink owns none.  Increment the count
         regardless.
 

Pre-stocking script (e.g. dchest.c, filtrunk.c)
-------------------
    __ if the item is to exist in the trunk already when Dink first finds it,
         compute 2 raised to the power "# minus 1", where "#" is the item's
         &chest_item number (note 1), and add the result to the current
         initial value of &chest_cont. (note 4)
 

Store-item-in-chest script (key-71.c in this dmod)
--------------------------
  if "countable":
    __ add a line after the comment, "//Elixirs (and all countable items) may
         be added to the chest"
    __ after the comment, "// Countable items go here," "roll" the inventory
         counter into the trunk counter (note 7)
 

Browse-chest script (key-78.c in this dmod)
-------------------
  main() proc:
    __ initialize &chest_maxi to the highest item number used (notes 1, 8)
    __ loop3: add entry based on &chest_item to show inventory graphic
  getitem() proc:
    __ do an add_item() based on &chest_item
    __ make Dink say() what has been retrieved from the chest
    __ if "countable",
         . do the add_item() only if Dink is not already carrying some
         . "roll" the trunk counter into the inventory counter (note 7)

Drop-item script (key_88.c in this dmod) (note 9)
----------------
    __ if "countable", reset the inventory to 0 if the item is actually dropped.
 

Footnotes:
==========

 (1) The item number is the slot the item will occupy when it is stored in the
     chest.  It must be unique within the dmod.  Ideally, it should be the next
     number in sequence from numbers assigned already -- gaps in the range of
     used slot numbers are permitted but should be used sparingly.

 (2) Even if this inventory system is used in a dmod, it is by no means
     necessary for all its items to use this system.  By doing a "&chest_item
     = 0;" (or "&chest_magic = 0") in the disarm() procs of all the items that
     can be stored in the chest, items that cannot be stored need no attention
     at all.

 (3) Remember that the dink engine responds to kill_cur_item() by running these
     procs if they are found in the script: holdingdrop(), disarm(), and drop()
     (in that order).  Technically, holdingdrop() is probably a better place to
     put the draw_status() than in disarm(), but that is just a nit.

 (4) As a minimum, &chest_cont must be 1, representing the unused "fist slot".

 (notes 5 & 6 have been deleted -- they applied to key-71.c, which has been
     rewritten such that non-countable items need no modification to this
     script.

 (7) "Roll" is an old mainframe programmer's term for adding one counter into
     another and then clearing the first counter to 0.  In this case, see the
     code for item-eli (&chest_item == 7) or item-bom (&chest_item == 10) for
     an example.

 (8) Variable &chest_maxi exists only to speed up the browse (especially on
     older computers) when it cycles from the last item around to the first
     or vice-versa.  This efficiency is also the only reason to avoid creating
     large gaps of unused slots .

 (9) A delete-item script such as key-88.c is NOT required when using this
     Inventory System.  Personally, I deactivate scripts such as this in a
     dmod, and would probably never write one, but that is a matter of opinion.
     You may certainly choose to include such a script in your dmod, and if you
     do, I have listed the only consideration it need give to this System.



 
Hosted by www.Geocities.ws

1