CommandSystem
Problem: the standard way of dealing with commands (switch statement) doesn't work well with the mouse and is hard to manipulate
Solution: switch to using various tables to describe the data, in order to:
- create a Hengband-style command menu
- allow mouseclicks on inventory items to bring up contextual menu relating to the selected item
- create automatic command summaries
Item selection
We can use a struct like this to describe item actions:
struct command_menu
{
bool filter(object_type *o_ptr, int equip_mode);
void action(void);
char sel;
cptr name;
int mode;
} item_actions [] =
{
{ item_tester_hook_true, do_cmd_pickup, 'g', "pick up", USE_FLOOR },
{ item_tester_hook_wear, do_cmd_wield, 'w', "wield or wear", USE_FLOOR | USE_INVEN },
{ item_tester_hook_cast, do_cmd_cast, 'm', "cast a spell", 'USE_FLOOR | USE_INVEN },
{ item_tester_hook_activate, do_cmd_activate, 'A', "activate", USE_EQUIP },
{ item_tester_hook_remove, do_cmd_take_off, 'T', "take off", USE_EQUIP },
};
This allows compatibility with the already existing command table system, without casting function pointers around, if a new p_ptr->command variable is introduced, say "command_inv", which is negative when no item has been pre-selected, but contains an index anyway. This is in keeping with the existing method of doing things.
Future
It may become feisable to allow editing of command sets by simply overwriting values already in the table, which would remove complication around the roguelike keyset and macros. It would be nice if this editor could be in-game, too. To achieve this, commands would have to be assigned an ID, and then different keysets would just be different key->command mappings, thus removing key to key mapping as used at the moment.
When mouseclicks on inventory items work, creating a unified use/handle command is much, much less invasive.
Ports may want to display native action menus containing lists of all commands.
