Changeset 1436
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/cmd0.c
r1417 r1436 167 167 168 168 { "Toggle wizard mode", KTRL('W'), CMD_NULL, do_cmd_wizard }, 169 { "Repeat previous command", KTRL('V'), CMD_REPEAT, NULL }, 169 170 170 171 #ifdef ALLOW_DEBUG … … 650 651 651 652 /* Handle repeating the last command */ 652 repeat_check();653 /* repeat_check();*/ 653 654 654 655 /* Handle resize events XXX */ -
trunk/src/cmd2.c
r1417 r1436 89 89 void do_cmd_search(cmd_code code, cmd_arg args[]) 90 90 { 91 /* Allow repeated command */92 allow_repeated_command();93 94 91 /* Take a turn */ 95 92 p_ptr->energy_use = 100; … … 768 765 769 766 770 /* Allow repeated command */771 allow_repeated_command();772 773 767 /* Monster */ 774 768 if (cave_m_idx[y][x] > 0) … … 924 918 } 925 919 926 927 /* Allow repeated command */928 allow_repeated_command();929 920 930 921 /* Monster */ … … 1256 1247 1257 1248 1258 /* Allow repeated command */1259 allow_repeated_command();1260 1261 1249 /* Monster */ 1262 1250 if (cave_m_idx[y][x] > 0) … … 1441 1429 } 1442 1430 1443 1444 /* Allow repeated command */1445 allow_repeated_command();1446 1431 1447 1432 /* Monster */ … … 1655 1640 1656 1641 1657 /* Allow repeated command */1658 allow_repeated_command();1659 1660 1642 /* Monster */ 1661 1643 if (cave_m_idx[y][x] > 0) … … 1729 1711 } 1730 1712 1731 1732 /* Allow repeated command */1733 allow_repeated_command();1734 1713 1735 1714 /* Attack monsters */ … … 2051 2030 if (!do_cmd_walk_test(y, x)) return; 2052 2031 2053 2054 /* Allow repeated command */2055 allow_repeated_command();2056 2032 2057 2033 /* Move the player */ … … 2162 2138 void do_cmd_hold(cmd_code code, cmd_arg args[]) 2163 2139 { 2164 /* Allow repeated command */2165 allow_repeated_command();2166 2167 2140 /* Take a turn */ 2168 2141 p_ptr->energy_use = 100; -
trunk/src/cmd5.c
r1432 r1436 243 243 cptr p = ((cp_ptr->spell_book == TV_MAGIC_BOOK) ? "spell" : "prayer"); 244 244 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 else257 {258 /* Invalid repeat - reset it */259 repeat_clear();260 }261 }262 263 245 /* Extract spells */ 264 246 for (i = 0; i < SPELLS_PER_BOOK; i++) … … 406 388 /* Abort if needed */ 407 389 if (!flag) return (-1); 408 409 repeat_push(spell);410 390 411 391 /* Success */ -
trunk/src/externs.h
r1435 r1436 626 626 extern void grid_data_as_text(grid_data *g, byte *ap, char *cp, byte *tap, char *tcp); 627 627 extern void pause_line(int row); 628 extern void allow_repeated_command(void);629 628 extern void request_command(void); 630 629 extern bool is_a_vowel(int ch); … … 637 636 extern byte gamma_table[256]; 638 637 #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);645 638 646 639 /* x-spell.c */ -
trunk/src/game-cmd.c
r1435 r1436 20 20 21 21 /* 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 } 23 36 24 37 /* Advance point in queue, wrapping around at the end */ … … 85 98 case CMD_PICKUP: 86 99 case CMD_ENTER_STORE: 100 case CMD_REPEAT: 87 101 { 88 102 break; … … 245 259 cmd_code cmd; 246 260 cmd_handler_fn fn; 261 bool repeat_allowed; 247 262 } game_cmds[] = 248 263 { 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 }, 294 309 }; 295 310 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 */ 319 static 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 } 296 333 297 334 /* … … 311 348 { 312 349 if (game_cmds[i].cmd == cmd.command) 350 { 351 if (game_cmds[i].repeat_allowed) 352 allow_repeated_command(); 353 313 354 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 87 87 /* CMD_OPTIONS, -- probably won't be a command in this sense*/ 88 88 CMD_QUIT, 89 CMD_HELP 89 CMD_HELP, 90 CMD_REPEAT 90 91 } 91 92 cmd_code; -
trunk/src/object/obj-ui.c
r1420 r1436 753 753 754 754 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 else773 {774 /* Invalid repeat - reset it */775 repeat_clear();776 }777 }778 755 779 756 … … 1446 1423 if (oops && str) msg_print(str); 1447 1424 1448 /* Save item if available */1449 if (item) repeat_push(*cp);1450 1451 1425 /* Result */ 1452 1426 return (item); -
trunk/src/util.c
r1433 r1436 2612 2612 } 2613 2613 2614 /* Get the item index */2615 else if ((max != 1) && repeat_pull(&amt))2616 {2617 /* nothing */2618 }2619 2620 2614 /* Prompt if needed */ 2621 2615 else if ((max != 1)) … … 2653 2647 /* Enforce the minimum */ 2654 2648 if (amt < 0) amt = 0; 2655 2656 if (amt) repeat_push(amt);2657 2649 2658 2650 /* Return the result */ … … 2829 2821 2830 2822 2831 /*2832 * Mark a command as "allowed to be repeated".2833 *2834 * When a command is executed, the user has the option to request that2835 * it be repeated by the UI setting p_ptr->command_arg. If the command2836 * permits repetition, then it calls this function to set2837 * 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 }2853 2823 2854 2824 /* … … 3256 3226 /* Oops */ 3257 3227 return "Icky"; 3258 }3259 3260 3261 3262 #define REPEAT_MAX 203263 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 else3314 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 else3349 {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 }3360 3228 } 3361 3229 -
trunk/src/xtra2.c
r1249 r1436 510 510 /* Initialize */ 511 511 (*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 else522 {523 /* Invalid repeat - reset it */524 repeat_clear();525 }526 }527 512 528 513 /* Hack -- auto-target if requested */ … … 631 616 } 632 617 633 /* Remember the direction if it is new */634 if (!repeat_pull(dp)) repeat_push(dir);635 636 618 /* Save direction */ 637 619 (*dp) = dir; … … 662 644 663 645 ui_event_data ke; 664 665 if (repeat_pull(dp))666 {667 return (TRUE);668 }669 646 670 647 /* Initialize */ … … 774 751 (*dp) = dir; 775 752 776 repeat_push(dir);777 778 753 /* Success */ 779 754 return (TRUE);
