-
Notifications
You must be signed in to change notification settings - Fork 89
/
keypress.cpp
214 lines (209 loc) · 3.83 KB
/
keypress.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#include "keypress.h"
#include "action.h"
#include "game.h"
long input()
{
long ch = getch();
switch (ch) {
case KEY_UP: return 'k';
case KEY_LEFT: return 'h';
case KEY_RIGHT: return 'l';
case KEY_DOWN: return 'j';
case 459: return '\n';
default: return ch;
}
}
void get_direction(int &x, int &y, char ch)
{
x = 0;
y = 0;
switch (ch) {
case 'y':
x = -1;
y = -1;
return;
case 'u':
x = 1;
y = -1;
return;
case 'h':
x = -1;
return;
case 'j':
y = 1;
return;
case 'k':
y = -1;
return;
case 'l':
x = 1;
return;
case 'b':
x = -1;
y = 1;
return;
case 'n':
x = 1;
y = 1;
return;
case '.':
case ',':
case 'g':
x = 0;
y = 0;
return;
default:
x = -2;
y = -2;
}
}
void get_direction(game *g, int &x, int &y, char ch)
{
x = 0;
y = 0;
action_id act;
if (g->keymap.find(ch) == g->keymap.end())
act = ACTION_NULL;
else
act = g->keymap[ch];
switch (act) {
case ACTION_MOVE_NW:
x = -1;
y = -1;
return;
case ACTION_MOVE_NE:
x = 1;
y = -1;
return;
case ACTION_MOVE_W:
x = -1;
return;
case ACTION_MOVE_S:
y = 1;
return;
case ACTION_MOVE_N:
y = -1;
return;
case ACTION_MOVE_E:
x = 1;
return;
case ACTION_MOVE_SW:
x = -1;
y = 1;
return;
case ACTION_MOVE_SE:
x = 1;
y = 1;
return;
case ACTION_PAUSE:
case ACTION_PICKUP:
x = 0;
y = 0;
return;
default:
x = -2;
y = -2;
}
}
std::string default_keymap_txt()
{
return "\
# This is the keymapping for Cataclysm.\n\
# You can start a line with # to make it a comment--it will be ignored.\n\
# Blank lines are ignored too.\n\
# Extra whitespace, including tab, is ignored, so format things how you like.\n\
# If you wish to restore defaults, simply remove this file.\n\
\n\
# The format for each line is an action identifier, followed by several\n\
# keys. Any action may have an unlimited number of keys bound to it.\n\
# If you bind the same key to multiple actions, the second and subsequent\n\
# bindings will be ignored--and you'll get a warning when the game starts.\n\
# Keys are case-sensitive, of course; c and C are different.\n\
\n\
# WARNING: If you skip an action identifier, there will be no key bound to\n\
# that action! You will be NOT be warned of this when the game starts.\n\
# If you're going to mess with stuff, maybe you should back this file up?\n\
\n\
# It is okay to split commands across lines.\n\
# pause . 5 is equivalent to:\n\
# pause .\n\
# pause 5\n\
\n\
# Note that movement keybindings ONLY apply to movement (for now).\n\
# That is, binding w to move_n will let you use w to move north, but you\n\
# cannot use w to smash north, examine to the north, etc.\n\
# For now, you must use vikeys, the numpad, or arrow keys for those actions.\n\
# This is planned to change in the future.\n\
\n\
# Finally, there is no support for special keys, like spacebar, Home, and\n\
# so on. This is not a planned feature, but if it's important to you, please\n\
# let me know.\n\
\n\
# MOVEMENT:\n\
pause . 5\n\
move_n k 8\n\
move_ne u 9\n\
move_e l 6\n\
move_se n 3\n\
move_s j 2\n\
move_sw b 1\n\
move_w h 4\n\
move_nw y 7\n\
move_down >\n\
move_up <\n\
\n\
# ENVIRONMENT INTERACTION\n\
open o\n\
close c\n\
smash s\n\
examine e\n\
pickup , g\n\
butcher B\n\
chat C\n\
look ; x\n\
\n\
# INVENTORY & QUASI-INVENTORY INTERACTION\n\
inventory i\n\
organize =\n\
apply a\n\
wear W\n\
take_off T\n\
eat E\n\
read R\n\
wield w\n\
pick_style _\n\
reload r\n\
unload U\n\
throw t\n\
fire f\n\
fire_burst F\n\
drop d\n\
drop_adj D\n\
bionics p\n\
\n\
# LONG TERM & SPECIAL ACTIONS\n\
wait ^\n\
craft &\n\
construct *\n\
sleep $\n\
safemode !\n\
autosafe \"\n\
ignore_enemy '\n\
save S\n\
quit Q\n\
\n\
# INFO SCREENS\n\
player_data @\n\
map m :\n\
missions M\n\
factions #\n\
morale %\n\
messages P\n\
help ?\n\
\n\
# DEBUG FUNCTIONS\n\
debug_mode ~\n\
# debug Z\n\
# debug_scent -\n\
";
}