Changeset 1448

Show
Ignore:
Timestamp:
06/22/09 19:46:19 (15 months ago)
Author:
ajps
Message:

Change the command system so that it prompts for missing directions, etc, at the point of command execution, not insertion into the queue - needed for an 'aim this thing' macro to work. Disable the 'repeat previous command' command when the pack has been reordered. Ensure we prompt for a target when the previous target is no longer valid.

Location:
trunk/src
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/cmd-obj.c

    r1445 r1448  
    403403        int spell; 
    404404        const magic_type *s_ptr; 
     405        int dir; 
    405406 
    406407        cptr verb = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "cast" : "recite"); 
     
    435436        } 
    436437 
    437         cmd_insert(CMD_CAST, spell, DIR_UNKNOWN); 
     438        if (!get_aim_dir(&dir)) 
     439                return; 
     440 
     441        cmd_insert(CMD_CAST, spell, dir); 
    438442} 
    439443 
     
    869873                item_actions[act].action(o_ptr, item); 
    870874        else if (obj_needs_aim(o_ptr)) 
    871                 cmd_insert(item_actions[act].command, item, DIR_UNKNOWN); 
     875        { 
     876                int dir; 
     877                if (!get_aim_dir(&dir)) 
     878                        return; 
     879 
     880                cmd_insert(item_actions[act].command, item, dir); 
     881        } 
    872882        else 
    873883                cmd_insert(item_actions[act].command, item); 
  • trunk/src/cmd2.c

    r1436 r1448  
    952952                        dir = coords_to_dir(y, x); 
    953953                } 
     954        } 
     955        else 
     956        { 
     957                if (!get_rep_dir(&dir)) 
     958                        return; 
    954959        } 
    955960 
     
    12701275void textui_cmd_tunnel(void) 
    12711276{ 
    1272         cmd_insert(CMD_TUNNEL, DIR_UNKNOWN); 
     1277        int dir; 
     1278        if (!get_rep_dir(&dir)) return; 
     1279        cmd_insert(CMD_TUNNEL, dir); 
    12731280} 
    12741281 
     
    14811488                                dir = coords_to_dir(y, x); 
    14821489                } 
     1490        } 
     1491        else 
     1492        { 
     1493                if (!get_rep_dir(&dir)) 
     1494                        return; 
    14831495        } 
    14841496 
     
    16641676void textui_cmd_bash(void) 
    16651677{ 
    1666         cmd_insert(CMD_BASH, DIR_UNKNOWN); 
     1678        int dir; 
     1679        if (!get_rep_dir(&dir)) 
     1680                return; 
     1681 
     1682        cmd_insert(CMD_BASH, dir); 
    16671683} 
    16681684 
     
    17761792void textui_cmd_alter(void) 
    17771793{ 
    1778         cmd_insert(CMD_ALTER, DIR_UNKNOWN); 
     1794        int dir; 
     1795 
     1796        if (!get_rep_dir(&dir)) 
     1797                return; 
     1798 
     1799        cmd_insert(CMD_ALTER, dir); 
    17791800} 
    17801801 
     
    19251946void textui_cmd_spike(void) 
    19261947{ 
    1927         cmd_insert(CMD_JAM, DIR_UNKNOWN); 
     1948        int dir; 
     1949        if (!get_rep_dir(&dir)) 
     1950                return; 
     1951 
     1952        cmd_insert(CMD_JAM, dir); 
    19281953} 
    19291954 
     
    20412066void textui_cmd_walk(void) 
    20422067{ 
    2043         cmd_insert(CMD_WALK, DIR_UNKNOWN); 
     2068        int dir; 
     2069        if (!get_rep_dir(&dir)) 
     2070                return; 
     2071 
     2072        cmd_insert(CMD_WALK, dir); 
    20442073} 
    20452074 
     
    20662095void textui_cmd_jump(void) 
    20672096{ 
    2068         cmd_insert(CMD_JUMP, DIR_UNKNOWN); 
     2097        int dir; 
     2098        if (!get_rep_dir(&dir)) 
     2099                return; 
     2100 
     2101        cmd_insert(CMD_JUMP, dir); 
    20692102} 
    20702103 
     
    21032136void textui_cmd_run(void) 
    21042137{ 
    2105         cmd_insert(CMD_RUN, DIR_UNKNOWN); 
     2138        int dir; 
     2139        if (!get_rep_dir(&dir)) 
     2140                return; 
     2141 
     2142        cmd_insert(CMD_RUN, dir); 
    21062143} 
    21072144 
  • trunk/src/game-cmd.c

    r1436 r1448  
    1212static int cmd_tail = 0; 
    1313static game_command cmd_queue[CMD_QUEUE_SIZE]; 
     14static bool repeat_prev_allowed = FALSE; 
     15 
     16enum cmd_arg_type { 
     17        arg_STRING, 
     18        arg_CHOICE, 
     19        arg_NUMBER, 
     20        arg_ITEM, 
     21        arg_DIRECTION, 
     22        arg_TARGET, 
     23        arg_POINT, 
     24        arg_END 
     25}; 
     26 
     27/* A simple list of commands and their handling functions. */ 
     28static struct 
     29{ 
     30        cmd_code cmd; 
     31        enum cmd_arg_type arg_type[3]; 
     32        cmd_handler_fn fn; 
     33        bool repeat_allowed; 
     34} game_cmds[] = 
     35{ 
     36        { CMD_LOADFILE, { arg_END }, NULL, FALSE }, 
     37        { CMD_NEWGAME, { arg_END }, NULL, FALSE }, 
     38 
     39        { CMD_BIRTH_RESET, { arg_END }, NULL, FALSE }, 
     40        { CMD_CHOOSE_SEX, { arg_CHOICE, arg_END }, NULL, FALSE }, 
     41        { CMD_CHOOSE_RACE, { arg_CHOICE, arg_END }, NULL, FALSE }, 
     42        { CMD_CHOOSE_CLASS, { arg_CHOICE, arg_END }, NULL, FALSE }, 
     43        { CMD_BUY_STAT, { arg_CHOICE, arg_END }, NULL, FALSE }, 
     44        { CMD_SELL_STAT, { arg_CHOICE, arg_END }, NULL, FALSE }, 
     45        { CMD_RESET_STATS, { arg_END }, NULL, FALSE }, 
     46        { CMD_ROLL_STATS, { arg_END }, NULL, FALSE }, 
     47        { CMD_PREV_STATS, { arg_END }, NULL, FALSE }, 
     48        { CMD_NAME_CHOICE, { arg_STRING, arg_END }, NULL, FALSE }, 
     49        { CMD_ACCEPT_CHARACTER, { arg_END }, NULL, FALSE }, 
     50 
     51        { CMD_GO_UP, { arg_END }, do_cmd_go_up, FALSE }, 
     52        { CMD_GO_DOWN, { arg_END }, do_cmd_go_down, FALSE }, 
     53        { CMD_SEARCH, { arg_END }, do_cmd_search, TRUE }, 
     54        { CMD_TOGGLE_SEARCH, { arg_END }, do_cmd_toggle_search, FALSE }, 
     55        { CMD_WALK, { arg_DIRECTION, arg_END }, do_cmd_walk, TRUE }, 
     56        { CMD_RUN, { arg_DIRECTION, arg_END }, do_cmd_run, FALSE }, 
     57        { CMD_JUMP, { arg_DIRECTION, arg_END }, do_cmd_jump, FALSE }, 
     58        { CMD_OPEN, { arg_DIRECTION, arg_END }, do_cmd_open, TRUE }, 
     59        { CMD_CLOSE, { arg_DIRECTION, arg_END }, do_cmd_close, TRUE }, 
     60        { CMD_TUNNEL, { arg_DIRECTION, arg_END }, do_cmd_tunnel, TRUE }, 
     61        { CMD_HOLD, { arg_END }, do_cmd_hold, TRUE }, 
     62        { CMD_DISARM, { arg_DIRECTION, arg_END }, do_cmd_disarm, TRUE }, 
     63        { CMD_BASH, { arg_DIRECTION, arg_END }, do_cmd_bash, TRUE }, 
     64        { CMD_ALTER, { arg_DIRECTION, arg_END }, do_cmd_alter, TRUE }, 
     65        { CMD_JAM, { arg_DIRECTION, arg_END }, do_cmd_spike, FALSE }, 
     66        { CMD_REST, { arg_CHOICE, arg_END }, do_cmd_rest, FALSE }, 
     67        { CMD_PATHFIND, { arg_POINT, arg_END }, do_cmd_pathfind, FALSE }, 
     68        { CMD_PICKUP, { arg_ITEM, arg_END }, do_cmd_pickup, FALSE }, 
     69        { CMD_WIELD, { arg_ITEM, arg_END }, do_cmd_wield, FALSE }, 
     70        { CMD_TAKEOFF, { arg_ITEM, arg_END }, do_cmd_takeoff, FALSE }, 
     71        { CMD_DROP, { arg_ITEM, arg_END }, do_cmd_drop, FALSE }, 
     72        { CMD_UNINSCRIBE, { arg_ITEM, arg_END }, do_cmd_uninscribe, FALSE }, 
     73        { CMD_EAT, { arg_ITEM, arg_END }, do_cmd_use, FALSE }, 
     74        { CMD_QUAFF, { arg_ITEM, arg_TARGET, arg_END }, do_cmd_use, FALSE }, 
     75        { CMD_USE_ROD, { arg_ITEM, arg_TARGET, arg_END }, do_cmd_use, FALSE }, 
     76        { CMD_USE_STAFF, { arg_ITEM }, do_cmd_use, FALSE }, 
     77        { CMD_USE_WAND, { arg_ITEM, arg_TARGET, arg_END }, do_cmd_use, FALSE }, 
     78        { CMD_READ_SCROLL, { arg_ITEM, arg_TARGET, arg_END }, do_cmd_use, FALSE }, 
     79        { CMD_ACTIVATE, { arg_ITEM, arg_TARGET, arg_END }, do_cmd_use, FALSE }, 
     80        { CMD_REFILL, { arg_ITEM, arg_END }, do_cmd_refill, FALSE }, 
     81        { CMD_FIRE, { arg_ITEM, arg_TARGET, arg_END }, do_cmd_fire, FALSE }, 
     82        { CMD_THROW, { arg_ITEM, arg_TARGET, arg_END }, do_cmd_throw, FALSE }, 
     83        { CMD_DESTROY, { arg_ITEM, arg_NUMBER, arg_END }, do_cmd_destroy, FALSE }, 
     84        { CMD_ENTER_STORE, { arg_END }, do_cmd_store, FALSE }, 
     85        { CMD_INSCRIBE, { arg_ITEM, arg_STRING, arg_END }, do_cmd_inscribe, FALSE }, 
     86        { CMD_STUDY_SPELL, { arg_CHOICE, arg_END }, do_cmd_study_spell, FALSE }, 
     87        { CMD_STUDY_BOOK, { arg_ITEM, arg_END }, do_cmd_study_book, FALSE }, 
     88        { CMD_CAST, { arg_CHOICE, arg_TARGET, arg_END }, do_cmd_cast, FALSE }, 
     89        { CMD_SELL, { arg_ITEM, arg_NUMBER, arg_END }, do_cmd_sell, FALSE }, 
     90        { CMD_STASH, { arg_ITEM, arg_NUMBER, arg_END }, do_cmd_stash, FALSE }, 
     91        { CMD_BUY, { arg_ITEM, arg_NUMBER, arg_END }, do_cmd_buy, FALSE }, 
     92        { CMD_RETRIEVE, { arg_ITEM, arg_NUMBER, arg_END }, do_cmd_retrieve, FALSE } 
     93, 
     94        { CMD_SUICIDE, { arg_END }, do_cmd_suicide, FALSE }, 
     95        { CMD_SAVE, { arg_END }, do_cmd_save_game, FALSE }, 
     96        { CMD_QUIT, { arg_END }, do_cmd_quit, FALSE }, 
     97        { CMD_HELP, { arg_END }, NULL, FALSE }, 
     98        { CMD_REPEAT, { arg_END }, NULL, FALSE }, 
     99}; 
     100 
     101 
    14102 
    15103errr cmd_insert_s(game_command *cmd) 
     
    26114        else 
    27115        { 
     116                int cmd_prev = cmd_head - 1; 
     117 
     118                if (!repeat_prev_allowed) return 1; 
     119 
    28120                /* If we're repeating a command, we duplicate the previous command  
    29121                   in the next command "slot". */ 
    30                 int cmd_prev = cmd_head - 1; 
    31122                if (cmd_prev < 0) cmd_prev = CMD_QUEUE_SIZE - 1; 
    32123                 
     
    58149                *cmd = cmd_queue[cmd_tail++]; 
    59150                if (cmd_tail == CMD_QUEUE_SIZE) cmd_tail = 0; 
     151 
    60152                return 0; 
    61153        } 
     
    63155        /* Failure to get a command. */ 
    64156        return 1; 
     157} 
     158 
     159int cmd_idx(cmd_code code) 
     160{ 
     161        int i; 
     162 
     163        for (i = 0; i < N_ELEMENTS(game_cmds); i++) 
     164        { 
     165                if (game_cmds[i].cmd == code) 
     166                { 
     167                        return i; 
     168                } 
     169        } 
     170 
     171        return -1; 
    65172} 
    66173 
     
    72179        game_command cmd = {0}; 
    73180        va_list vp; 
     181        int j = 0; 
     182        int idx = cmd_idx(c); 
     183 
     184        if (idx == -1) return 1; 
    74185 
    75186        /* Begin the Varargs Stuff */ 
     
    78189        cmd.command = c; 
    79190 
    80         switch (c) 
    81         { 
    82                 /* These commands take no arguments. */ 
    83                 case CMD_NULL: 
    84                 case CMD_QUIT: 
    85                 case CMD_SAVE: 
    86                 case CMD_SUICIDE: 
    87                 case CMD_LOADFILE: 
    88                 case CMD_NEWGAME: 
    89                 case CMD_ROLL_STATS: 
    90                 case CMD_PREV_STATS: 
    91                 case CMD_ACCEPT_CHARACTER: 
    92                 case CMD_HELP: 
    93                 case CMD_GO_UP: 
    94                 case CMD_GO_DOWN: 
    95                 case CMD_SEARCH: 
    96                 case CMD_TOGGLE_SEARCH: 
    97                 case CMD_HOLD: 
    98                 case CMD_PICKUP: 
    99                 case CMD_ENTER_STORE: 
    100                 case CMD_REPEAT: 
     191        for (j = 0; (game_cmds[idx].arg_type[j] != arg_END &&  
     192                                 j < N_ELEMENTS(game_cmds[idx].arg_type)); j++) 
     193        { 
     194                switch (game_cmds[idx].arg_type[j]) 
    101195                { 
    102                         break; 
    103                 } 
    104  
    105                 /* These take one integer argument - a "choice" */ 
    106                 case CMD_BIRTH_RESET: 
    107                 case CMD_CHOOSE_SEX: 
    108                 case CMD_CHOOSE_RACE: 
    109                 case CMD_CHOOSE_CLASS: 
    110                 case CMD_BUY_STAT: 
    111                 case CMD_SELL_STAT: 
    112                 case CMD_RESET_STATS: 
    113                 case CMD_REST: 
    114                 case CMD_STUDY_SPELL: 
    115                 { 
    116                         cmd.args[0].choice = va_arg(vp, int); 
    117                         break; 
    118                 } 
    119  
    120                 /* These take a string argument. */ 
    121                 case CMD_NAME_CHOICE: 
    122                 { 
    123                         /* Take a copy, it'll last longer. */ 
    124                         /* XXX Should we free this automatically when the slot 
    125                            in the queue gets reused, or just continue to let 
    126                            the command processor worry about it? */ 
    127                         cmd.args[0].string = string_make(va_arg(vp, const char *)); 
    128                         break; 
    129                 } 
    130  
    131                 /* These take a direction as an argument. */ 
    132                 case CMD_WALK: 
    133                 case CMD_RUN: 
    134                 case CMD_JUMP: 
    135                 case CMD_OPEN: 
    136                 case CMD_CLOSE: 
    137                 case CMD_TUNNEL: 
    138                 case CMD_DISARM: 
    139                 case CMD_BASH: 
    140                 case CMD_ALTER: 
    141                 case CMD_JAM: 
    142                 { 
    143                         cmd.args[0].direction = va_arg(vp, int); 
    144  
    145                         /* Direction hasn't been specified, so we ask for one. */ 
    146                         if (cmd.args[0].direction == DIR_UNKNOWN) 
    147                         { 
    148                                 /*  
    149                                  * If no direction supplied, abort the command.  
    150                                  * XXX Eventually replace the get_rep_dir call 
    151                                  * with something more generalised. 
    152                                  */ 
    153                                 if (!get_rep_dir(&cmd.args[0].direction)) 
    154                                         return 1; 
    155                         } 
    156                          
    157                         break; 
    158                 } 
    159  
    160                 /* These take a point (y, x) on the map as an argument. */ 
    161                 case CMD_PATHFIND: 
    162                 { 
    163                         cmd.args[0].point.y = va_arg(vp, int); 
    164                         cmd.args[0].point.x = va_arg(vp, int); 
    165                         break;                   
    166                 } 
    167  
    168                 /* These take an item number. */ 
    169                 case CMD_UNINSCRIBE: 
    170                 case CMD_WIELD: 
    171                 case CMD_TAKEOFF: 
    172                 case CMD_REFILL: 
    173                 case CMD_STUDY_BOOK: 
    174                 /* Note that if the effects change for the following, they  
    175                    might need to take a target as well, as below. */ 
    176                 case CMD_USE_STAFF: 
    177                 case CMD_EAT: 
    178                 { 
    179                         cmd.args[0].item = va_arg(vp, int); 
    180                         break; 
    181                 } 
    182                    
    183                 /*  
    184                  * These take an item number and a  "target" as arguments,  
    185                  * though a target isn't always actually needed, so we'll  
    186                  * only prompt for it via callback 
    187                  * if the item being used needs it. 
    188                  */ 
    189                 case CMD_USE_WAND: 
    190                 case CMD_USE_ROD: 
    191                 case CMD_QUAFF: 
    192                 case CMD_ACTIVATE: 
    193                 case CMD_READ_SCROLL: 
    194                 case CMD_FIRE: 
    195                 case CMD_THROW: 
    196                 { 
    197                         cmd.args[0].item = va_arg(vp, int); 
    198                         cmd.args[1].direction = va_arg(vp, int); 
    199  
    200                         if (cmd.args[1].direction == DIR_UNKNOWN &&  
    201                                 obj_needs_aim(object_from_item_idx(cmd.args[0].choice))) 
    202                         { 
    203                                 if (!get_aim_dir(&cmd.args[1].direction)) 
    204                                         return 1; 
    205                         } 
    206  
    207                         break; 
    208                 } 
    209  
    210                 /* This takes a choice and a direction. */ 
    211                 case CMD_CAST: 
    212                 { 
    213                         cmd.args[0].choice = va_arg(vp, int); 
    214                         cmd.args[1].direction = va_arg(vp, int); 
    215  
    216                         if (cmd.args[1].direction == DIR_UNKNOWN &&  
    217                                 spell_needs_aim(cp_ptr->spell_book, cmd.args[0].choice)) 
    218                         { 
    219                                 if (!get_aim_dir(&cmd.args[1].direction)) 
    220                                         return 1; 
    221                         } 
    222  
    223                         break; 
    224                 } 
    225  
    226                 /* These take an item number and a number of those items to process. */ 
    227                 case CMD_DROP: 
    228                 case CMD_DESTROY: 
    229                 case CMD_SELL: 
    230                 case CMD_BUY: 
    231                 case CMD_STASH: 
    232                 case CMD_RETRIEVE: 
    233                 { 
    234                         /* TODO: Number should probably be replaced by 'repeat'ing */ 
    235                         cmd.args[0].item = va_arg(vp, int); 
    236                         cmd.args[1].number = va_arg(vp, int); 
    237                         break; 
    238                 } 
    239  
    240                 /* Takes an item number and a string to inscribe. */ 
    241                 case CMD_INSCRIBE: 
    242                 { 
    243                         cmd.args[0].item = va_arg(vp, int); 
    244                         cmd.args[1].string = string_make(va_arg(vp, const char *)); 
    245                         break; 
     196                        case arg_CHOICE: 
     197                        { 
     198                                cmd.args[j].choice = va_arg(vp, int); 
     199                                break; 
     200                        } 
     201 
     202                        case arg_STRING: 
     203                        { 
     204                                cmd.args[j].string = string_make(va_arg(vp, const char *)); 
     205                                break; 
     206                        } 
     207                         
     208                        case arg_DIRECTION: 
     209                        case arg_TARGET: 
     210                        { 
     211                                cmd.args[j].direction = va_arg(vp, int); 
     212                                break; 
     213                        } 
     214                         
     215                        case arg_POINT: 
     216                        { 
     217                                cmd.args[j].point.y = va_arg(vp, int); 
     218                                cmd.args[j].point.x = va_arg(vp, int); 
     219                                break; 
     220                        } 
     221                         
     222                        case arg_ITEM: 
     223                        { 
     224                                cmd.args[j].item = va_arg(vp, int); 
     225                                break; 
     226                        } 
     227                         
     228                        case arg_NUMBER: 
     229                        { 
     230                                cmd.args[j].number = va_arg(vp, int); 
     231                                break; 
     232                        } 
     233 
     234                        case arg_END: 
     235                        { 
     236                                break; 
     237                        } 
    246238                } 
    247239        } 
     
    253245} 
    254246 
    255  
    256 /* A simple list of commands and their handling functions. */ 
    257 static struct 
    258 { 
    259         cmd_code cmd; 
    260         cmd_handler_fn fn; 
    261         bool repeat_allowed; 
    262 } game_cmds[] = 
    263 { 
    264         { CMD_GO_UP, do_cmd_go_up, FALSE }, 
    265         { CMD_GO_DOWN, do_cmd_go_down, FALSE }, 
    266         { CMD_SEARCH, do_cmd_search, TRUE }, 
    267         { CMD_TOGGLE_SEARCH, do_cmd_toggle_search, FALSE }, 
    268         { CMD_WALK, do_cmd_walk, TRUE }, 
    269         { CMD_RUN, do_cmd_run, FALSE }, 
    270         { CMD_JUMP, do_cmd_jump, FALSE }, 
    271         { CMD_OPEN, do_cmd_open, TRUE }, 
    272         { CMD_CLOSE, do_cmd_close, TRUE }, 
    273         { CMD_TUNNEL, do_cmd_tunnel, TRUE }, 
    274         { CMD_HOLD, do_cmd_hold, TRUE }, 
    275         { CMD_DISARM, do_cmd_disarm, TRUE }, 
    276         { CMD_BASH, do_cmd_bash, TRUE }, 
    277         { CMD_ALTER, do_cmd_alter, TRUE }, 
    278         { CMD_JAM, do_cmd_spike, FALSE }, 
    279         { CMD_REST, do_cmd_rest, FALSE }, 
    280         { CMD_PATHFIND, do_cmd_pathfind, FALSE }, 
    281         { CMD_PICKUP, do_cmd_pickup, FALSE }, 
    282         { CMD_SUICIDE, do_cmd_suicide, FALSE }, 
    283         { CMD_SAVE, do_cmd_save_game, FALSE }, 
    284         { CMD_QUIT, do_cmd_quit, FALSE }, 
    285         { CMD_WIELD, do_cmd_wield, FALSE }, 
    286         { CMD_TAKEOFF, do_cmd_takeoff, FALSE }, 
    287         { CMD_DROP, do_cmd_drop, FALSE }, 
    288         { CMD_UNINSCRIBE, do_cmd_uninscribe, FALSE }, 
    289         { CMD_EAT, do_cmd_use, FALSE }, 
    290         { CMD_QUAFF, do_cmd_use, FALSE }, 
    291         { CMD_USE_ROD, do_cmd_use, FALSE }, 
    292         { CMD_USE_STAFF, do_cmd_use, FALSE }, 
    293         { CMD_USE_WAND, do_cmd_use, FALSE }, 
    294         { CMD_READ_SCROLL, do_cmd_use, FALSE }, 
    295         { CMD_ACTIVATE, do_cmd_use, FALSE }, 
    296         { CMD_REFILL, do_cmd_refill, FALSE }, 
    297         { CMD_FIRE, do_cmd_fire, FALSE }, 
    298         { CMD_THROW, do_cmd_throw, FALSE }, 
    299         { CMD_DESTROY, do_cmd_destroy, FALSE }, 
    300         { CMD_ENTER_STORE, do_cmd_store, FALSE }, 
    301         { CMD_INSCRIBE, do_cmd_inscribe, FALSE }, 
    302         { CMD_STUDY_SPELL, do_cmd_study_spell, FALSE }, 
    303         { CMD_STUDY_BOOK, do_cmd_study_book, FALSE }, 
    304         { CMD_CAST, do_cmd_cast, FALSE }, 
    305         { CMD_SELL, do_cmd_sell, FALSE }, 
    306         { CMD_STASH, do_cmd_stash, FALSE }, 
    307         { CMD_BUY, do_cmd_buy, FALSE }, 
    308         { CMD_RETRIEVE, do_cmd_retrieve, FALSE }, 
    309 }; 
    310247 
    311248/* 
     
    338275void process_command(cmd_context ctx, bool no_request) 
    339276{ 
    340         int i; 
     277        int idx; 
    341278        game_command cmd; 
    342279 
     
    344281        if (cmd_get(ctx, &cmd, !no_request) == 0) 
    345282        { 
    346                 /* Obviously inefficient - can tune later if needed. */ 
    347                 for (i = 0; i < N_ELEMENTS(game_cmds); i++) 
     283                idx = cmd_idx(cmd.command); 
     284 
     285                if (idx == -1) return; 
     286 
     287                /* Do some sanity checking on those arguments that might have  
     288                   been declared as "unknown", such as directions and targets. */ 
     289                switch (cmd.command) 
    348290                { 
    349                         if (game_cmds[i].cmd == cmd.command) 
    350                         { 
    351                                 if (game_cmds[i].repeat_allowed) 
    352                                         allow_repeated_command(); 
     291                        case CMD_WALK: 
     292                        case CMD_RUN: 
     293                        case CMD_JUMP: 
     294                        case CMD_OPEN: 
     295                        case CMD_CLOSE: 
     296                        case CMD_TUNNEL: 
     297                        case CMD_DISARM: 
     298                        case CMD_BASH: 
     299                        case CMD_ALTER: 
     300                        case CMD_JAM: 
     301                        { 
     302                                /* Direction hasn't been specified, so we ask for one. */ 
     303                                if (cmd.args[0].direction == DIR_UNKNOWN) 
     304                                { 
     305                                        if (!get_rep_dir(&cmd.args[0].direction)) 
     306                                                return; 
     307                                } 
    353308                                 
    354                                 game_cmds[i].fn(cmd.command, cmd.args); 
     309                                break; 
     310                        } 
     311                         
     312                         
     313                        /*  
     314                         * These take an item number and a  "target" as arguments,  
     315                         * though a target isn't always actually needed, so we'll  
     316                         * only prompt for it via callback if the item being used needs it. 
     317                         */ 
     318                        case CMD_USE_WAND: 
     319                        case CMD_USE_ROD: 
     320                        case CMD_QUAFF: 
     321                        case CMD_ACTIVATE: 
     322                        case CMD_READ_SCROLL: 
     323                        case CMD_FIRE: 
     324                        case CMD_THROW: 
     325                        { 
     326                                bool get_target = FALSE; 
     327 
     328                                if (obj_needs_aim(object_from_item_idx(cmd.args[0].choice))) 
     329                                { 
     330                                        if (cmd.args[1].direction == DIR_UNKNOWN) 
     331                                                get_target = TRUE; 
     332 
     333                                        if (cmd.args[1].direction == DIR_TARGET && !target_okay()) 
     334                                                get_target = TRUE; 
     335                                } 
     336 
     337                                if (get_target && !get_aim_dir(&cmd.args[1].direction)) 
     338                                                return; 
     339 
     340                                break; 
     341                        } 
     342                         
     343                        /* This takes a choice and a direction. */ 
     344                        case CMD_CAST: 
     345                        { 
     346                                bool get_target = FALSE; 
     347 
     348                                if (spell_needs_aim(cp_ptr->spell_book, cmd.args[0].choice)) 
     349                                { 
     350                                        if (cmd.args[1].direction == DIR_UNKNOWN) 
     351                                                get_target = TRUE; 
     352 
     353                                        if (cmd.args[1].direction == DIR_TARGET && !target_okay()) 
     354                                                get_target = TRUE; 
     355                                } 
     356 
     357                                if (get_target && !get_aim_dir(&cmd.args[1].direction)) 
     358                                                return; 
     359                                 
     360                                break; 
     361                        } 
     362 
     363                        default:  
     364                        { 
     365                /* I can see the point of the compiler warning, but still... */ 
     366                                break; 
    355367                        } 
    356368                } 
    357         } 
    358 } 
    359  
    360  
     369                 
     370                if (game_cmds[idx].repeat_allowed) 
     371                        allow_repeated_command(); 
     372 
     373                repeat_prev_allowed = TRUE; 
     374 
     375                if (game_cmds[idx].fn) 
     376                        game_cmds[idx].fn(cmd.command, cmd.args); 
     377        } 
     378} 
     379 
     380void cmd_disable_repeat(void) 
     381{ 
     382        repeat_prev_allowed = FALSE; 
     383} 
  • trunk/src/game-cmd.h

    r1436 r1448  
    102102 
    103103#define DIR_UNKNOWN 0 
     104#define DIR_TARGET 5 
    104105 
    105106enum  
     
    173174void process_command(cmd_context c, bool no_request); 
    174175 
     176void cmd_disable_repeat(void); 
     177 
    175178#endif 
  • trunk/src/object/obj-util.c

    r1446 r1448  
    2020#include "tvalsval.h" 
    2121#include "effects.h" 
     22#include "game-cmd.h" 
    2223 
    2324/* 
     
    30013002        } 
    30023003 
    3003         /* Message */ 
    3004         if (flag) msg_print("You reorder some items in your pack."); 
     3004        if (flag)  
     3005        { 
     3006                msg_print("You reorder some items in your pack."); 
     3007 
     3008                /* Stop "repeat last command" from working. */ 
     3009                cmd_disable_repeat(); 
     3010        } 
    30053011} 
    30063012