This page:
Page history
Links to here

Last modified:
2007-04-26 at 21:52

Stores


Status

Things for future consideration:

  • improve the pricing of items generally
  • if you sell bad items a lot, make things more expensive; if you sell good items a lot, make things slightly cheaper

Item selection

Here follows a look at the different ways of selecting items.

Zangband

Zangband has an slightly different way of handling stores, due to its entire object generation system having been tweaked fairly majorly, along, I believe, the lines of OAngband. There are four values (combat, magic, tools, tresure) which add up to 100 which specify how likely the store is to stock an item of that kind. Then it uses get_obj_num_prep() to set up these probabilities so the object selection code will only select items of that kind, and then it just uses get_obj_num() to select an item, with a filter hook to decide whether to keep an item or throw it away (so that you don't stock dirty rags or other rubbish, for instance).

Advantages:

  • Takes into account "natural" rarities, which would be useful for more varied stores
  • Means the black market doesn't have to be special-cased (it currently uses this method)

John Rauser's stocking patch

This patch makes shopkeepers remember which items you purchase frequently, and keep those in stock. Essentially, this patch works by having a counter which keeps track of buyings of an item for each store (each buying increments the corresponding counter by 50). Whenever shopkeepers shuffle their inventory, this is decremented by 1.

When a new item is created, the "inventory control" counters are consulted, and for each item there, the code checks it against the current in-stock list, and if that item isn't in the inventory, it is set as the item to create.

Advantages:

  • it does actually keep track of items, thus helping the player actually buy what he wants
  • it exists, works, and is a fairly simple patch

Disadvantages:

  • a rather primitive method, and doesn't address the underlying problem of stores not being particularly clever about what to stock

Possible: Simple selection algorithm

Essentially the current V system, using the obj_get_num_prep() idea from Z, and more intelligent stocking.

To make this work in Vanilla, get the store object table:

     { TV_FOOD, SV_FOOD_RATION },
     { TV_FOOD, SV_FOOD_RATION },
     { TV_FOOD, SV_FOOD_RATION },
     { TV_FOOD, SV_FOOD_RATION },
     { TV_FOOD, SV_FOOD_RATION },
     { TV_FOOD, SV_FOOD_BISCUIT },
     { TV_FOOD, SV_FOOD_JERKY },
     { TV_FOOD, SV_FOOD_JERKY },
     (etc)

And convert it to something cleverer, like

     /* tval,   sval,           weighting */
     { TV_FOOD, SV_FOOD_RATION,         5 },
     { TV_FOOD, SV_FOOD_BISCUIT,        1 },
     { TV_FOOD, SV_FOOD_JERKY,          2 },
     { TV_FOOD, SV_FOOD_PINT_OF_WINE,   1 },
     { TV_FOOD, SV_FOOD_PINT_OF_ALE,    1 },
     { TV_LITE, SV_LITE_TORCH,          4 },
     { TV_LITE, SV_LITE_LANTERN,        2 },

     (etc.  Assume this is all a store stocks.)  

We something like obj_get_num_prep() which doesn't take into account natural rarities at all, but rather works with a calculated weighting, like (weighting * 100) + times bought. Essentially, something that relies chiefly on the weighting and isn't affected massively by the numer of times something is bought (though this will gradually become less true for often-bought items, and very untrue after, say, 200 buys for a 2-weighted item). This formula will need tweaking.

Possible: "Staple" system

This is the current one implemented. It makes store restocking a two step process. It needs refinement, obviously.

Step one is based on a "staples" table for the store. This could include food, healing potions, or Word of Recall scrolls, depending on the store, and each staple could have a chance of being restocked when there are non in stock. This is independent from the chance of buying in extra items when they are already in stock (i.e. the current system). As such, you can try and make sure that (barring RNG intervention), the player will never have to wait very long for Word of Recall, and that food will never, ever, even with a hate-filled RNG, not be available in town.

For example:

     /* tval,   sval,           likelihood */

     /* Always stack food and a light source */
     { TV_FOOD, SV_FOOD_RATION,       100 },
     { TV_LITE, SV_LITE_TORCH,        100 },

     /* We like to keep WoR around in the Magic Store */
     { TV_SCROLL, SV_SCROLL_WORD_OF_RECALL, 90 },

Having done the restocking of out-of-stock items, you then rely on the general stocking method to buy more things for you, whatever system that is (V or Z).


Externalising store information

What store information we can externalise depends to a large extent how store stocking is going to be done.

However, something like this could be considered

 N:number             # new store
 L:min:max            # minimum and maximum generation levels
 P:min_cost:greed     # (P for Pickiness) lowest priced item allowed, greed centered at 100
 I:tval:sval:num      # tval/sval pairs and number of slots allocated to that kind of item
 I:tval:sval:num
 S:tval:sval:chance:min  # staple items
 S:tval:sval:chance:min
 F:flags              # what flags?
 ...etc

All normal stores have levels 1 - 5, black market is 25 - 50. It might be nice to make the black market stock deeper items the deeper in the dungeon you go past 50.