forked from Whales/Cataclysm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.cpp
334 lines (325 loc) · 7.49 KB
/
action.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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
#include "game.h"
#include "keypress.h"
#include <fstream>
void game::load_keyboard_settings()
{
std::ifstream fin;
fin.open("data/keymap.txt");
if (!fin) { // It doesn't exist
std::ofstream fout;
fout.open("data/keymap.txt");
fout << default_keymap_txt();
fout.close();
fin.open("data/keymap.txt");
}
if (!fin) { // Still can't open it--probably bad permissions
debugmsg("Can't open data/keymap.txt. This may be a permissions issue.");
return;
}
while (!fin.eof()) {
std::string id;
fin >> id;
if (id == "")
getline(fin, id); // Empty line, chomp it
else if (id[0] != '#') {
action_id act = look_up_action(id);
if (act == ACTION_NULL)
debugmsg("\
Warning! data/keymap.txt contains an unknown action, \"%s\"\n\
Fix data/keymap.txt at your next chance!", id.c_str());
else {
while (fin.peek() != '\n' && !fin.eof()) {
char ch;
fin >> ch;
if (keymap.find(ch) != keymap.end())
debugmsg("\
Warning! '%c' assigned twice in the keymap!\n\
%s is being ignored.\n\
Fix data/keymap.txt at your next chance!", ch, id.c_str());
else
keymap[ ch ] = act;
}
}
} else {
getline(fin, id); // Clear the whole line
}
}
}
void game::save_keymap()
{
std::ofstream fout;
fout.open("data/keymap.txt");
if (!fout) { // It doesn't exist
debugmsg("Can't open data/keymap.txt.");
fout.close();
return;
}
std::map<char, action_id>::iterator it;
for (it = keymap.begin(); it != keymap.end(); it++)
fout << action_ident( (*it).second ) << " " << (*it).first << std::endl;
fout.close();
}
std::vector<char> game::keys_bound_to(action_id act)
{
std::vector<char> ret;
std::map<char, action_id>::iterator it;
for (it = keymap.begin(); it != keymap.end(); it++) {
if ( (*it).second == act )
ret.push_back( (*it).first );
}
return ret;
}
void game::clear_bindings(action_id act)
{
std::map<char, action_id>::iterator it;
for (it = keymap.begin(); it != keymap.end(); it++) {
if ( (*it).second == act ) {
keymap.erase(it);
it = keymap.begin();
}
}
}
std::string action_ident(action_id act)
{
switch (act) {
case ACTION_PAUSE:
return "pause";
case ACTION_MOVE_N:
return "move_n";
case ACTION_MOVE_NE:
return "move_ne";
case ACTION_MOVE_E:
return "move_e";
case ACTION_MOVE_SE:
return "move_se";
case ACTION_MOVE_S:
return "move_s";
case ACTION_MOVE_SW:
return "move_sw";
case ACTION_MOVE_W:
return "move_w";
case ACTION_MOVE_NW:
return "move_nw";
case ACTION_MOVE_DOWN:
return "move_down";
case ACTION_MOVE_UP:
return "move_up";
case ACTION_OPEN:
return "open";
case ACTION_CLOSE:
return "close";
case ACTION_SMASH:
return "smash";
case ACTION_EXAMINE:
return "examine";
case ACTION_PICKUP:
return "pickup";
case ACTION_BUTCHER:
return "butcher";
case ACTION_CHAT:
return "chat";
case ACTION_LOOK:
return "look";
case ACTION_INVENTORY:
return "inventory";
case ACTION_ORGANIZE:
return "organize";
case ACTION_USE:
return "apply";
case ACTION_WEAR:
return "wear";
case ACTION_TAKE_OFF:
return "take_off";
case ACTION_EAT:
return "eat";
case ACTION_READ:
return "read";
case ACTION_WIELD:
return "wield";
case ACTION_PICK_STYLE:
return "pick_style";
case ACTION_RELOAD:
return "reload";
case ACTION_UNLOAD:
return "unload";
case ACTION_THROW:
return "throw";
case ACTION_FIRE:
return "fire";
case ACTION_FIRE_BURST:
return "fire_burst";
case ACTION_DROP:
return "drop";
case ACTION_DIR_DROP:
return "drop_adj";
case ACTION_BIONICS:
return "bionics";
case ACTION_WAIT:
return "wait";
case ACTION_CRAFT:
return "craft";
case ACTION_CONSTRUCT:
return "construct";
case ACTION_SLEEP:
return "sleep";
case ACTION_TOGGLE_SAFEMODE:
return "safemode";
case ACTION_TOGGLE_AUTOSAFE:
return "autosafe";
case ACTION_IGNORE_ENEMY:
return "ignore_enemy";
case ACTION_SAVE:
return "save";
case ACTION_QUIT:
return "quit";
case ACTION_PL_INFO:
return "player_data";
case ACTION_MAP:
return "map";
case ACTION_MISSIONS:
return "missions";
case ACTION_FACTIONS:
return "factions";
case ACTION_MORALE:
return "morale";
case ACTION_MESSAGES:
return "messages";
case ACTION_HELP:
return "help";
case ACTION_DEBUG:
return "debug";
case ACTION_DISPLAY_SCENT:
return "debug_scent";
case ACTION_TOGGLE_DEBUGMON:
return "debug_mode";
case ACTION_NULL:
return "null";
}
return "unknown";
}
action_id look_up_action(std::string ident)
{
for (int i = 0; i < NUM_ACTIONS; i++) {
if (action_ident( action_id(i) ) == ident)
return action_id(i);
}
return ACTION_NULL;
}
std::string action_name(action_id act)
{
switch (act) {
case ACTION_PAUSE:
return "Pause";
case ACTION_MOVE_N:
return "Move North";
case ACTION_MOVE_NE:
return "Move Northeast";
case ACTION_MOVE_E:
return "Move East";
case ACTION_MOVE_SE:
return "Move Southeast";
case ACTION_MOVE_S:
return "Move South";
case ACTION_MOVE_SW:
return "Move Southwest";
case ACTION_MOVE_W:
return "Move West";
case ACTION_MOVE_NW:
return "Move Northwest";
case ACTION_MOVE_DOWN:
return "Descend Stairs";
case ACTION_MOVE_UP:
return "Ascend Stairs";
case ACTION_OPEN:
return "Open Door";
case ACTION_CLOSE:
return "Close Door";
case ACTION_SMASH:
return "Smash Nearby Terrain";
case ACTION_EXAMINE:
return "Examine Nearby Terrain";
case ACTION_PICKUP:
return "Pick Item(s) Up";
case ACTION_BUTCHER:
return "Butcher";
case ACTION_CHAT:
return "Chat with NPC";
case ACTION_LOOK:
return "Look Around";
case ACTION_INVENTORY:
return "Open Inventory";
case ACTION_ORGANIZE:
return "Swap Inventory Letters";
case ACTION_USE:
return "Apply or Use Item";
case ACTION_WEAR:
return "Wear Item";
case ACTION_TAKE_OFF:
return "Take Off Worn Item";
case ACTION_EAT:
return "Eat";
case ACTION_READ:
return "Read";
case ACTION_WIELD:
return "Wield";
case ACTION_PICK_STYLE:
return "Select Unarmed Style";
case ACTION_RELOAD:
return "Reload Wielded Item";
case ACTION_UNLOAD:
return "Unload or Empty Wielded Item";
case ACTION_THROW:
return "Throw Item";
case ACTION_FIRE:
return "Fire Wielded Item";
case ACTION_FIRE_BURST:
return "Burst-Fire Wielded Item";
case ACTION_DROP:
return "Drop Item";
case ACTION_DIR_DROP:
return "Drop Item to Adjacent Tile";
case ACTION_BIONICS:
return "View/Activate Bionics";
case ACTION_WAIT:
return "Wait for Several Minutes";
case ACTION_CRAFT:
return "Craft Items";
case ACTION_CONSTRUCT:
return "Construct Terrain";
case ACTION_SLEEP:
return "Sleep";
case ACTION_TOGGLE_SAFEMODE:
return "Toggle Safemode";
case ACTION_TOGGLE_AUTOSAFE:
return "Toggle Auto-Safemode";
case ACTION_IGNORE_ENEMY:
return "Ignore Nearby Enemy";
case ACTION_SAVE:
return "Save and Quit";
case ACTION_QUIT:
return "Commit Suicide";
case ACTION_PL_INFO:
return "View Player Info";
case ACTION_MAP:
return "View Map";
case ACTION_MISSIONS:
return "View Missions";
case ACTION_FACTIONS:
return "View Factions";
case ACTION_MORALE:
return "View Morale";
case ACTION_MESSAGES:
return "View Message Log";
case ACTION_HELP:
return "View Help";
case ACTION_DEBUG:
return "Debug Menu";
case ACTION_DISPLAY_SCENT:
return "View Scentmap";
case ACTION_TOGGLE_DEBUGMON:
return "Toggle Debug Messages";
case ACTION_NULL:
return "No Action";
}
return "Someone forgot to name an action.";
}