User:Ardub23/YANI

From NetHackWiki
Jump to navigation Jump to search

A place to gather (and perhaps workshop) YANIs. Feel free to edit constructively! — Ardub23 (talk)

Preferred slots

Add an option for preferred slots, to save the trouble of #adjusting items to the slots you always use. In the options file, the user can map regular expressions to inventory slot letters. When the hero picks up an item or gains it in their starting inventory, it will be placed in the inventory slot associated with a matching regex.

An additional argument for each preferred slot can be used to specify what to do if the preferred slot is already occupied, or if the (re-)acquired item was in a different slot and fixinv is enabled. Options for this argument could be:

  • weak: Use this slot unless it's occupied or the acquired item is fixinv'd to another slot.
  • normal: Use this slot unless it's occupied (forget fixinv).
  • replace: Replace the previous item in this slot, unless it also prefers this slot.
  • force: Always replace any item occupying the slot.

Whenever an item is shunted out of its current slot by another item—whether because of a preferred slot or a manual #adjust—it should try to go to its own preferred slot. In this case, though, occupied slots should always be overlooked to avoid domino chains and infinite loops. In other words, an item can only be shunted to an unoccupied slot.

Syntax mockup:

# Put something inedible on 'y', unless something else is there already
PREFERRED_SLOT="stone" y normal

# Put an unlocking tool on 'k', unless another unlocking tool is there
PREFERRED_SLOT="credit card|key|lock pick" k replace

# Footrice corpses go to capital letters, less likely to type by accident
PREFERRED_SLOT="trice corpse" X normal
PREFERRED_SLOT="trice corpse" C force

If an item matches more than one rule, the strongest rule is applied first (e.g. force applies before replace). In a tie, the last usable matching rule applies. In the above example, a footrice corpse you pick up would go to C and shunt out any item that's there, even if it's another footrice corpse. And if the shunted item is another footrice corpse, that one will try to go to X, because it can't be shunted to the occupied slot C; if X is occupied too, then it gets assigned an arbitrary letter.