ENCODE_KTRL() and auto-pickup (CTRL-G)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • PowerWyrm
    Prophet
    • Apr 2008
    • 2986

    ENCODE_KTRL() and auto-pickup (CTRL-G)

    Someone reported to me that in my variant, when you pick up gold that a monster dropped under the character with the 'g' command, it is placed as an item in the inventory instead of filling the purse.

    I tracked the problem and found something quite intriguing:

    - when you pick up something with 'g', there's a keymap stored in pref.prf that translates 'g' as '^Gg' for autopickup + pickup
    - when the keymap is parsed in keypress_from_text(), the ctrl-G part is again translated to '\a' by the STORE() macro, which calls ENCODE_KTRL() to see if the value is between 0x40 and 0x5F and then removes 0x40 and KC_MOD_CONTROL from the value
    - when the key 'g' is executed, two commands are then processed: '\a' and 'g'
    - the '\a' part is discarded by textui_process_key()
    - only the 'g' part is processed, which does pickup without autopickup and therefore doesn't process gold correctly, treating it as if it was an item

    Since my code is roughly based on V 3.4 (and the problem still exists in my latest source which is based on V3.5-dev), I assume that the bug also exists in V.

    Can someone tell me the reason for the STORE/ENCODE_KTRL macros? I don't see why values between 0x40 and 0x5F are different from other values...

    Checking playing.txt for the command list, I noted that
    - CTRL-I is reserved (special - tab)
    - CTRL-J is reserved (special - line feed)
    - CTRl-M is reserved (special - return)

    This seems related to the ENCODE_KTRL() macro mapping these commands to '\t', '\n' and '\r'. For what I see, CTRL-G should not be used for the same reason. Otherwise, the checks for '\a' should be removed.
    PWMAngband variant maintainer - check https://github.com/draconisPW/PWMAngband (or http://www.mangband.org/forum/viewforum.php?f=9) to learn more about this new variant!
Working...
😀
😂
🥰
😘
🤢
😎
😞
😡
👍
👎