OSDN Git Service

[Fix/Feature] 飛行モンスターが深い穴を超えられない現象を解消 #177
[hengbandforosx/hengbandosx.git] / src / io / command-repeater.cpp
1 #include "io/command-repeater.h"
2 #include "input-key-requester.h"
3 #include "util/int-char-converter.h"
4
5 #define REPEAT_MAX 20
6
7 /* Number of chars saved */
8 static int repeat__cnt = 0;
9
10 /* Current index */
11 static int repeat__idx = 0;
12
13 /* Saved "stuff" */
14 static COMMAND_CODE repeat__key[REPEAT_MAX];
15
16 void repeat_push(COMMAND_CODE what)
17 {
18     if (repeat__cnt == REPEAT_MAX)
19         return;
20
21     repeat__key[repeat__cnt++] = what;
22     ++repeat__idx;
23 }
24
25 bool repeat_pull(COMMAND_CODE *what)
26 {
27     if (repeat__idx == repeat__cnt)
28         return FALSE;
29
30     *what = repeat__key[repeat__idx++];
31     return TRUE;
32 }
33
34 void repeat_check(void)
35 {
36     if (command_cmd == ESCAPE)
37         return;
38     if (command_cmd == ' ')
39         return;
40     if (command_cmd == '\r')
41         return;
42     if (command_cmd == '\n')
43         return;
44
45     COMMAND_CODE what;
46     if (command_cmd == 'n') {
47         repeat__idx = 0;
48         if (repeat_pull(&what)) {
49             command_cmd = what;
50         }
51     } else {
52         repeat__cnt = 0;
53         repeat__idx = 0;
54         what = command_cmd;
55         repeat_push(what);
56     }
57 }