Changeset 1436

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

Change how we define which commands are repeatable - this is now declared in game-cmd.c rather than by a function call from the command when it is being used.

Change how the "repeat last command" command works to duplicate the last game command rather than remembering keypress sequences, etc. This means it will no longer repeat commands such as "help" or "browse spellbook", but hopefully this isn't a problem in practice.

Location:
trunk/src
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/cmd0.c

    r1417 r1436  
    167167 
    168168        { "Toggle wizard mode",  KTRL('W'), CMD_NULL, do_cmd_wizard }, 
     169        { "Repeat previous command",  KTRL('V'), CMD_REPEAT, NULL }, 
    169170 
    170171#ifdef ALLOW_DEBUG 
     
    650651 
    651652        /* Handle repeating the last command */ 
    652         repeat_check(); 
     653        /* repeat_check();*/ 
    653654 
    654655        /* Handle resize events XXX */ 
  • trunk/src/cmd2.c

    r1417 r1436  
    8989void do_cmd_search(cmd_code code, cmd_arg args[]) 
    9090{ 
    91         /* Allow repeated command */ 
    92         allow_repeated_command(); 
    93          
    9491        /* Take a turn */ 
    9592        p_ptr->energy_use = 100; 
     
    768765 
    769766 
    770         /* Allow repeated command */ 
    771         allow_repeated_command(); 
    772  
    773767        /* Monster */ 
    774768        if (cave_m_idx[y][x] > 0) 
     
    924918        } 
    925919 
    926  
    927         /* Allow repeated command */ 
    928         allow_repeated_command(); 
    929920 
    930921        /* Monster */ 
     
    12561247 
    12571248 
    1258         /* Allow repeated command */ 
    1259         allow_repeated_command(); 
    1260  
    12611249        /* Monster */ 
    12621250        if (cave_m_idx[y][x] > 0) 
     
    14411429        } 
    14421430 
    1443  
    1444         /* Allow repeated command */ 
    1445         allow_repeated_command(); 
    14461431 
    14471432        /* Monster */ 
     
    16551640 
    16561641 
    1657         /* Allow repeated command */ 
    1658         allow_repeated_command(); 
    1659  
    16601642        /* Monster */ 
    16611643        if (cave_m_idx[y][x] > 0) 
     
    17291711        } 
    17301712 
    1731  
    1732         /* Allow repeated command */ 
    1733         allow_repeated_command(); 
    17341713 
    17351714        /* Attack monsters */ 
     
    20512030        if (!do_cmd_walk_test(y, x)) return; 
    20522031 
    2053  
    2054         /* Allow repeated command */ 
    2055         allow_repeated_command(); 
    20562032 
    20572033        /* Move the player */ 
     
    21622138void do_cmd_hold(cmd_code code, cmd_arg args[]) 
    21632139{ 
    2164         /* Allow repeated command */ 
    2165         allow_repeated_command(); 
    2166  
    21672140        /* Take a turn */ 
    21682141        p_ptr->energy_use = 100; 
  • trunk/src/cmd5.c

    r1432 r1436  
    243243        cptr p = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "spell" : "prayer"); 
    244244 
    245         int result; 
    246  
    247         /* Get the spell, if available */ 
    248         if (repeat_pull(&result)) 
    249         { 
    250                 /* Verify the spell */ 
    251                 if (spell_okay(result, known, browse)) 
    252                 { 
    253                         /* Success */ 
    254                         return (result); 
    255                 } 
    256                 else 
    257                 { 
    258                         /* Invalid repeat - reset it */ 
    259                         repeat_clear(); 
    260                 } 
    261         } 
    262  
    263245        /* Extract spells */ 
    264246        for (i = 0; i < SPELLS_PER_BOOK; i++) 
     
    406388        /* Abort if needed */ 
    407389        if (!flag) return (-1); 
    408  
    409         repeat_push(spell); 
    410390 
    411391        /* Success */ 
  • trunk/src/externs.h

    r1435 r1436  
    626626extern void grid_data_as_text(grid_data *g, byte *ap, char *cp, byte *tap, char *tcp); 
    627627extern void pause_line(int row); 
    628 extern void allow_repeated_command(void); 
    629628extern void request_command(void); 
    630629extern bool is_a_vowel(int ch); 
     
    637636extern byte gamma_table[256]; 
    638637#endif /* SUPPORT_GAMMA */ 
    639  
    640 /* util.c */ 
    641 extern void repeat_push(int what); 
    642 extern bool repeat_pull(int *what); 
    643 extern void repeat_clear(void); 
    644 extern void repeat_check(void); 
    645638 
    646639/* x-spell.c */ 
  • trunk/src/game-cmd.c

    r1435 r1436  
    2020 
    2121        /* Insert command into queue. */ 
    22         cmd_queue[cmd_head] = *cmd; 
     22        if (cmd->command != CMD_REPEAT) 
     23        { 
     24                cmd_queue[cmd_head] = *cmd; 
     25        } 
     26        else 
     27        { 
     28                /* If we're repeating a command, we duplicate the previous command  
     29                   in the next command "slot". */ 
     30                int cmd_prev = cmd_head - 1; 
     31                if (cmd_prev < 0) cmd_prev = CMD_QUEUE_SIZE - 1; 
     32                 
     33                if (cmd_queue[cmd_prev].command != CMD_NULL) 
     34                        cmd_queue[cmd_head] = cmd_queue[cmd_prev]; 
     35        } 
    2336 
    2437        /* Advance point in queue, wrapping around at the end */ 
     
    8598                case CMD_PICKUP: 
    8699                case CMD_ENTER_STORE: 
     100                case CMD_REPEAT: 
    87101                { 
    88102                        break; 
     
    245259        cmd_code cmd; 
    246260        cmd_handler_fn fn; 
     261        bool repeat_allowed; 
    247262} game_cmds[] = 
    248263{ 
    249         { CMD_GO_UP, do_cmd_go_up }, 
    250         { CMD_GO_DOWN, do_cmd_go_down }, 
    251         { CMD_SEARCH, do_cmd_search }, 
    252         { CMD_TOGGLE_SEARCH, do_cmd_toggle_search }, 
    253         { CMD_WALK, do_cmd_walk }, 
    254         { CMD_RUN, do_cmd_run }, 
    255         { CMD_JUMP, do_cmd_jump }, 
    256         { CMD_OPEN, do_cmd_open }, 
    257         { CMD_CLOSE, do_cmd_close }, 
    258         { CMD_TUNNEL, do_cmd_tunnel }, 
    259         { CMD_HOLD, do_cmd_hold }, 
    260         { CMD_DISARM, do_cmd_disarm }, 
    261         { CMD_BASH, do_cmd_bash }, 
    262         { CMD_ALTER, do_cmd_alter }, 
    263         { CMD_JAM, do_cmd_spike }, 
    264         { CMD_REST, do_cmd_rest }, 
    265         { CMD_PATHFIND, do_cmd_pathfind }, 
    266         { CMD_PICKUP, do_cmd_pickup }, 
    267         { CMD_SUICIDE, do_cmd_suicide }, 
    268         { CMD_SAVE, do_cmd_save_game }, 
    269         { CMD_QUIT, do_cmd_quit }, 
    270         { CMD_WIELD, do_cmd_wield }, 
    271         { CMD_TAKEOFF, do_cmd_takeoff }, 
    272         { CMD_DROP, do_cmd_drop }, 
    273         { CMD_UNINSCRIBE, do_cmd_uninscribe }, 
    274         { CMD_EAT, do_cmd_use }, 
    275         { CMD_QUAFF, do_cmd_use }, 
    276         { CMD_USE_ROD, do_cmd_use }, 
    277         { CMD_USE_STAFF, do_cmd_use }, 
    278         { CMD_USE_WAND, do_cmd_use }, 
    279         { CMD_READ_SCROLL, do_cmd_use }, 
    280         { CMD_ACTIVATE, do_cmd_use }, 
    281         { CMD_REFILL, do_cmd_refill }, 
    282         { CMD_FIRE, do_cmd_fire }, 
    283         { CMD_THROW, do_cmd_throw }, 
    284         { CMD_DESTROY, do_cmd_destroy }, 
    285         { CMD_ENTER_STORE, do_cmd_store }, 
    286         { CMD_INSCRIBE, do_cmd_inscribe }, 
    287         { CMD_STUDY_SPELL, do_cmd_study_spell }, 
    288         { CMD_STUDY_BOOK, do_cmd_study_book }, 
    289         { CMD_CAST, do_cmd_cast }, 
    290         { CMD_SELL, do_cmd_sell }, 
    291         { CMD_STASH, do_cmd_stash }, 
    292         { CMD_BUY, do_cmd_buy }, 
    293         { CMD_RETRIEVE, do_cmd_retrieve }, 
     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 }, 
    294309}; 
    295310 
     311/* 
     312 * Mark a command as "allowed to be repeated". 
     313 * 
     314 * When a command is executed, the user has the option to request that 
     315 * it be repeated by the UI setting p_ptr->command_arg.  If the command 
     316 * permits repetition, then it calls this function to set  
     317 * p_ptr->command_rep to make it repeat until an interruption. 
     318 */ 
     319static void allow_repeated_command(void) 
     320{ 
     321        if (p_ptr->command_arg) 
     322        { 
     323                /* Set repeat count */ 
     324                p_ptr->command_rep = p_ptr->command_arg - 1; 
     325                 
     326                /* Redraw the state */ 
     327                p_ptr->redraw |= (PR_STATE); 
     328                 
     329                /* Cancel the arg */ 
     330                p_ptr->command_arg = 0; 
     331        } 
     332} 
    296333 
    297334/*  
     
    311348                { 
    312349                        if (game_cmds[i].cmd == cmd.command) 
     350                        { 
     351                                if (game_cmds[i].repeat_allowed) 
     352                                        allow_repeated_command(); 
     353                                 
    313354                                game_cmds[i].fn(cmd.command, cmd.args); 
    314                 } 
    315         } 
    316 } 
    317  
    318  
     355                        } 
     356                } 
     357        } 
     358} 
     359 
     360 
  • trunk/src/game-cmd.h

    r1435 r1436  
    8787/*      CMD_OPTIONS, -- probably won't be a command in this sense*/ 
    8888        CMD_QUIT, 
    89         CMD_HELP 
     89        CMD_HELP, 
     90        CMD_REPEAT 
    9091} 
    9192cmd_code; 
  • trunk/src/object/obj-ui.c

    r1420 r1436  
    753753 
    754754        bool show_list = OPT(show_lists) ? TRUE : FALSE; 
    755  
    756  
    757         /* Get the item index */ 
    758         if (repeat_pull(cp)) 
    759         { 
    760                 /* Verify the item */ 
    761                 if (get_item_okay(*cp)) 
    762                 { 
    763                         /* Forget the item_tester_tval restriction */ 
    764                         item_tester_tval = 0; 
    765  
    766                         /* Forget the item_tester_hook restriction */ 
    767                         item_tester_hook = NULL; 
    768  
    769                         /* Success */ 
    770                         return (TRUE); 
    771                 } 
    772                 else 
    773                 { 
    774                         /* Invalid repeat - reset it */ 
    775                         repeat_clear(); 
    776                 } 
    777         } 
    778755 
    779756 
     
    14461423        if (oops && str) msg_print(str); 
    14471424 
    1448         /* Save item if available */ 
    1449         if (item) repeat_push(*cp); 
    1450  
    14511425        /* Result */ 
    14521426        return (item); 
  • trunk/src/util.c

    r1433 r1436  
    26122612        } 
    26132613 
    2614         /* Get the item index */ 
    2615         else if ((max != 1) && repeat_pull(&amt)) 
    2616         { 
    2617                 /* nothing */ 
    2618         } 
    2619  
    26202614        /* Prompt if needed */ 
    26212615        else if ((max != 1)) 
     
    26532647        /* Enforce the minimum */ 
    26542648        if (amt < 0) amt = 0; 
    2655  
    2656         if (amt) repeat_push(amt); 
    26572649 
    26582650        /* Return the result */ 
     
    28292821 
    28302822 
    2831 /* 
    2832  * Mark a command as "allowed to be repeated". 
    2833  * 
    2834  * When a command is executed, the user has the option to request that 
    2835  * it be repeated by the UI setting p_ptr->command_arg.  If the command 
    2836  * permits repetition, then it calls this function to set  
    2837  * p_ptr->command_rep to make it repeat until an interruption. 
    2838  */ 
    2839 void allow_repeated_command(void) 
    2840 { 
    2841         if (p_ptr->command_arg) 
    2842         { 
    2843                 /* Set repeat count */ 
    2844                 p_ptr->command_rep = p_ptr->command_arg - 1; 
    2845                  
    2846                 /* Redraw the state */ 
    2847                 p_ptr->redraw |= (PR_STATE); 
    2848                  
    2849                 /* Cancel the arg */ 
    2850                 p_ptr->command_arg = 0; 
    2851         } 
    2852 } 
    28532823 
    28542824/* 
     
    32563226        /* Oops */ 
    32573227        return "Icky"; 
    3258 } 
    3259  
    3260  
    3261  
    3262 #define REPEAT_MAX 20 
    3263  
    3264 /* Number of chars saved */ 
    3265 static int repeat__cnt = 0; 
    3266  
    3267 /* Current index */ 
    3268 static int repeat__idx = 0; 
    3269  
    3270 /* Saved "stuff" */ 
    3271 static int repeat__key[REPEAT_MAX]; 
    3272  
    3273  
    3274 /* 
    3275  * Push data. 
    3276  */ 
    3277 void repeat_push(int what) 
    3278 { 
    3279         /* Too many keys */ 
    3280         if (repeat__cnt == REPEAT_MAX) return; 
    3281  
    3282         /* Push the "stuff" */ 
    3283         repeat__key[repeat__cnt++] = what; 
    3284  
    3285         /* Prevents us from pulling keys */ 
    3286         ++repeat__idx; 
    3287 } 
    3288  
    3289  
    3290 /* 
    3291  * Pull data. 
    3292  */ 
    3293 bool repeat_pull(int *what) 
    3294 { 
    3295         /* All out of keys */ 
    3296         if (repeat__idx == repeat__cnt) return (FALSE); 
    3297  
    3298         /* Grab the next key, advance */ 
    3299         *what = repeat__key[repeat__idx++]; 
    3300  
    3301         /* Success */ 
    3302         return (TRUE); 
    3303 } 
    3304  
    3305  
    3306 void repeat_clear(void) 
    3307 { 
    3308         /* Start over from the failed pull */ 
    3309         if (repeat__idx) 
    3310                 repeat__cnt = --repeat__idx; 
    3311  
    3312         /* Paranoia */ 
    3313         else 
    3314                 repeat__cnt = repeat__idx; 
    3315  
    3316         return; 
    3317 } 
    3318  
    3319  
    3320 /* 
    3321  * Repeat previous command, or begin memorizing new command. 
    3322  */ 
    3323 void repeat_check(void) 
    3324 { 
    3325         int what; 
    3326  
    3327         /* Ignore some commands */ 
    3328         if (p_ptr->command_cmd == ESCAPE) return; 
    3329         if (p_ptr->command_cmd == ' ') return; 
    3330         if (p_ptr->command_cmd == '\n') return; 
    3331         if (p_ptr->command_cmd == '\r') return; 
    3332  
    3333         /* Repeat Last Command */ 
    3334         if (p_ptr->command_cmd == KTRL('V')) 
    3335         { 
    3336                 /* Reset */ 
    3337                 repeat__idx = 0; 
    3338  
    3339                 /* Get the command */ 
    3340                 if (repeat_pull(&what)) 
    3341                 { 
    3342                         /* Save the command */ 
    3343                         p_ptr->command_cmd = what; 
    3344                 } 
    3345         } 
    3346  
    3347         /* Start saving new command */ 
    3348         else 
    3349         { 
    3350                 /* Reset */ 
    3351                 repeat__cnt = 0; 
    3352                 repeat__idx = 0; 
    3353  
    3354                 /* Get the current command */ 
    3355                 what = p_ptr->command_cmd; 
    3356  
    3357                 /* Save this command */ 
    3358                 repeat_push(what); 
    3359         } 
    33603228} 
    33613229 
  • trunk/src/xtra2.c

    r1249 r1436  
    510510        /* Initialize */ 
    511511        (*dp) = 0; 
    512  
    513         if (repeat_pull(dp)) 
    514         { 
    515                 /* Verify */ 
    516                 if (!(*dp == 5 && !target_okay())) 
    517                 { 
    518                         /* Use the direction */ 
    519                         dir = *dp; 
    520                 } 
    521                 else 
    522                 { 
    523                         /* Invalid repeat - reset it */ 
    524                         repeat_clear(); 
    525                 } 
    526         } 
    527512 
    528513        /* Hack -- auto-target if requested */ 
     
    631616        } 
    632617 
    633         /* Remember the direction if it is new */ 
    634         if (!repeat_pull(dp)) repeat_push(dir); 
    635  
    636618        /* Save direction */ 
    637619        (*dp) = dir; 
     
    662644 
    663645        ui_event_data ke; 
    664  
    665         if (repeat_pull(dp)) 
    666         { 
    667                 return (TRUE); 
    668         } 
    669646 
    670647        /* Initialize */ 
     
    774751        (*dp) = dir; 
    775752 
    776         repeat_push(dir); 
    777  
    778753        /* Success */ 
    779754        return (TRUE);