keys (z for casting).
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@3530 c06c8d41-db1a-0410-9941-cceddc491573
LNW53A3J35SCWIDDB7GPGFRK2SOQ7RHHRJEC7GKWDOJXJ7JORO4QC For the most part, people will probably want command macros. They allowfor things like making a key run a sequence of commands (e.g. associatinga key stroke to the casting of a certain spell) without having to worryabout messing up what that key does at prompts (e.g. you can macro anumber or letter without worrying about it making the substitution whenyou're trying to drop an item).
For the most part, people will probably want command macros. They allowfor things like making a key run a sequence of commands (e.g.associating a key stroke to the casting of a certain spell) withouthaving to worry about messing up what that key does at prompts (e.g.you can macro a number or letter without worrying about it making thesubstitution when you're trying to drop an item).
Keymaps are for when you want to fix layout and behavioural problems onyour keyboard (i.e. unrecognised numpad sequences can by mapped intotheir numbers, foreign keyboard layouts can be modified to be morecomfortable). There are also special sets of keymaps for the level-mapand targeting modes, which allow for keymaps that are restricted to justthose situations.
Keymaps are for when you want to fix layout and behavioural problems onyour keyboard (i.e. unrecognised numpad sequences can by mapped intotheir numbers, foreign keyboard layouts can be modified to be morecomfortable). There are also special sets of keymaps for the level map,the targeting mode and confirmation prompts, which allow for mappingsthat are restricted to just those situations.
[The keymap system is currently being overhauled. I hope that theexamples below will also work in the new version.From what I gather, the keybindings will be moved to a file (which isgood). I hope that it will still be possible to define macros in-game:this makes testing so convenient. And it should be possible to havemacros at all three levels (main, level map, targeting).]
How to create macros?---------------------The simplest way is in-game: press the '~' key (this may be a bitawkward on certain keyboard layouts). Then choose a key to assignfor your macro, and enter the command sequence. In some cases, Crawlwill display a funny number. These numbers are the key codes forcertain (non-alpanumeric) keys, and can vary between differentsystems.
How to create macros and keymaps?=================================
The following keys and combinations are sensible to use:- The function keys are good choices, possibly modified by Shift, Ctrl,or Shift-Ctrl.- On some systems, it is possible to also incorporate the Alt (meta) key.- All alphanumerical keys. Alphanumerical keys can also be combined withShift or Ctrl keys (note that usually Ctrl-Shift-A is the same thing asCtrl-A). Be careful that you do not redefine important game keys.- All special keys: digits, punctation, etc. These can also be combinedwith Ctrl. Alt may also work. Again, do not redefine vital game commands.
The simplest way is in-game: Press the '~' key (this may be a bitawkward on certain keyboard layouts, see below for how to edit themacro.txt file directly and for an example how to remap it), select'm' to define a macro, then choose a key to assign for your macro andenter the command sequence. For some keys (or key combinations), Crawlwill display a strange number (for example \{13} for the Return key).These numbers are the key codes for certain non-alpanumeric keys andcan vary between different systems.
For example, on my home system (Windows), I get key codesF1 \{368} A AShift-F1 \{1392} Ctrl-A \{1}Ctrl-F1 \{880} Alt-A aAlt-F1 \{2416} Ctrl-Shift-A \{1}Ctrl-Shift-F1 \{1904} Ctrl-Shift-Alt-A \{3905}Ctrl-Alt-F1 \{2928}Shift-Alt-F1 \{3440}Ctrl-Shift-Alt-F1 \{3952}
By default, most upper- and lowercase alphanumeric keys are alreadyassigned functions in Crawl. While you are free to remap those keys aswell, it might be best to start with some of the currently unused keys,such as Tab or the function keys (F1 to F12), possibly combined withCtrl, Shift or both. On some systems, it may also be possible toincorporate the Alt (Meta) key.
After defining such a macro, you should test it. If you are comfortablewith the macro you have defined, you should then save the macro.To save all macros and keymaps, press '~' and then 's' to savemacros at the tilde prompt).
Defining keymaps works in exactly the same way. Just press 'k'(default), 'x' (level-map), 't' (targeting) or 'c' (confirmation)instead of 'm' after pressing '~'.
The macros are stored in the file macro.txt in your main Crawl directory.(You can change where the file is read from and written to by specifying analternate directory on the command line with -macro <dir>.)This file is human readable and editablel you just have to figure out themagic numbers as shown above for F1, Ctrl-A, etc. When using strangekeys as triggers for a macro, you may need to edit macro.txt manually.
After defining such a macro or keymap, you should test it. If you arecomfortable with it, you should then save the macro. To save all macrosand keymaps, press '~' and then 's' to save macros at the tilde prompt).
Keymaps work in exactly the same way. There are three different keymaps:one for the main view, one for the level map, and onefor the targeting map. In macro.txt, these are differentiated byK - main screenK1 - level mapK2 - targetingHowever, you should not keymap alphabet letters; otherwise youwill meet difficulties accessing your inventory!
Macros and keymaps are stored in a file called macro.txt in your mainCrawl directory or your home directory. You can change where the fileis read from and written to by specifying an alternate directory onthe command line with -macro <dir> or with the crawl_dir option in yourinit file (see crawl_options.txt for details). The macro.txt file ishuman readable and editable, but you might have to figure out the keycodes for non-alphanumeric keys through in-game experimentation orexternal utilities.
Here are some macros and keymaps that have been considered useful byat least a few players. For the sake of completeness, both key line andcommand line are given, but you should really substitute your own keyshere; these may not always work for you :)
Lines beginning with the '#' are comments and will be ignored. Notethat Crawl won't necessarily preserve your comments when saving macrosand keymaps to the macro.txt file.
Spellcasting.-------------# F1: cast spell a at previous targetM:\{368}A:Zap
Each macro definition consists of exactly two lines. The first onedescribes the macro trigger key and consists of "M:" followed by thecharacter or keycode of that key (for example 'a', 'A' or \{9} forthe A, Shift-A or Tab keys). The second one describes the macro actionand consists of "A:" followed by the command sequence to be associatedwith the above key (for example "zap" for zapping the spell in slot aat the previous target). Individual macro definitions should beseparated by empty lines.
This sets up your portable altar, prays there, confirms, and picks it upagain. The sequence assumes that the altar carries the inscription {@w0}.Actually, this can be achieved automatically with the init.txt lineautoinscribe = portable altar:@w0If you have your weapon on slot a, feel free to add 'wa' to the end ofthe sequence.
This section contains some examples to give you an idea what macros andkeymaps can be used for. Note that for the sake of completeness, bothkey line and command line are given, but that you should probablysubstitute your own keys here as these may not always work for you.
Here I use '0' for the numpad, but 'x' would also be a good choice (thenyou should set K2:x A:* only).This makes going through items in the surroundings very easy. You can useEnter to go directly to the item under the cursor.Options you may want to check here aretarget_wrap, target_oos, target_los_first.If you want to cycle through items out of sight, setstash_tracking = alltarget_oos = true(as only out-of-sight _stashes_ will be checked).
# 0: add macroK:0A:~
I find the Ctrl-O key awkward to type, so I have mapped it to F5. Thesecond keymap makes F5 in target mode do two things: leave target mode(\{32} is the Escape key) and then starts exploring.Users of BSD terminals will definitely want to remap Ctrl-O, as the terminalintercepts it by default.General Keybindings.--------------------With my German keyboard layout, the keys '^' and '@' do not workproperly. The first problem is dealt with the map
# @: display character status
Lua snippets.=============
Playing a summoner can be annoying because you often need to cast thesame spells multiple times in a row, each casting requiring multiplekeystrokes. This macro allows casting the spell in slot 'a' with asingle keystroke. Note that you can redefine spell slots with the '='key. We emphasise again that the F1 key may get a different code onyour system.
You can copy the following lua code verbatim in your init.txt; it is upto you to apply appropriate modifications. It would be nice of course,if someday these snippets turn into full-grown lua files with their ownoptions.
# F1: cast spell 'a'M:\{368}A:za
Advanced autopick: ch_autopickup.---------------------------------Using a Lua script, you can define a function "ch_autopickup" to selectadditional items for autopickup. Let's say you want autopickup to onlygrab food if your character can eat it. You could use the following(if '%' is not in the autopickup option):
Now that we've taken care of summoning, we still need to command oursummoned creatures. The following macro should make that easier aswell. Note that this macro assumes that the default_target option isset to true (it is by default; see crawl_options.txt for details).
{-- The mummy special. Remove % and ! from your autopickup option if you-- use this.function ch_autopickup(it)return food.can_eat(it, false)or ( item.class(it) == "Potions" and you.race() ~= "Mummy" )end}Advanced autopick: conditional ban_pickup.------------------------------------------There is an overlap in functionality with the above mummy function.# mummies can't quaff or hunger<if you.race() == "Mummy" then>ban_pickup = potionban_pickup = sustenance<end>
Conjurers need a slightly different macros for casting, such as thisone, as they need to press '.' or Return to confirm firing at a target.Again, this macro assumes that the default_target option is set totrue.
# ban harmful potions for non-Transmuters<if you.class() ~= "Transmuter" then>ban_pickup = degeneration, decay, potions? of poisonban_pickup = potions? of confusion, potions? of slowing,ban_pickup = potions? of paralysis, strong poison<end>
# F1: cast spell 'a' at your previous or the nearest targetM:\{368}A:za.
# Trog doesn't like Spellcasting#<if you.religion() == "Trog" then> # (doesn't work), so
However, even conjurers might not always want to fire at their previoustarget, so the following set of macros allows them to cast the spellin slot 'a' and then cycle through the available targets with the samekey and then confirming with the same key we used for firing in theprevious macro. This example also tries to illustrate how to takeadvantage of the fact that keys can have different functions in thedifferent keymaps.
Ignoring certain monsters when running.---------------------------------------Defining a "ch_stop_run" function affects the monster stop condition for *all*run modes: shift-running, travel, explore and interlevel travel.
# Shift-F1: cycle through targets when in targetting modeK2:\{1392}A:+
{function ch_stop_run(mons)local name = mons.name-- Stop running only if these monsters get closer than 3 squaresif name == "swamp worm" or name == "big fish"or name == "giant goldfish" or name == "lava worm"or name == "butterfly" then-- mons.x and y coords are relative to the player.local dist = mons.x * mons.x + mons.y * mons.yif dist >= 9 then return false endendreturn trueend}
# F1: fire at target when in targetting modeK2:\{368}A:.