| 1013 | | |
|---|
| 1014 | | /* |
|---|
| 1015 | | * Verify use of "wizard" mode |
|---|
| 1016 | | */ |
|---|
| 1017 | | static bool enter_wizard_mode(void) |
|---|
| 1018 | | { |
|---|
| 1019 | | /* Ask first time - unless resurrecting a dead character */ |
|---|
| 1020 | | if (verify_special && !(p_ptr->noscore & 0x0002) && !(p_ptr->is_dead)) |
|---|
| 1021 | | { |
|---|
| 1022 | | /* Mention effects */ |
|---|
| 1023 | | msg_print("You are about to enter 'wizard' mode for the very first time!"); |
|---|
| 1024 | | msg_print("This is a form of cheating, and your game will not be scored!"); |
|---|
| 1025 | | message_flush(); |
|---|
| 1026 | | |
|---|
| 1027 | | /* Verify request */ |
|---|
| 1028 | | if (!get_check("Are you sure you want to enter wizard mode? ")) |
|---|
| 1029 | | { |
|---|
| 1030 | | return (FALSE); |
|---|
| 1031 | | } |
|---|
| 1032 | | } |
|---|
| 1033 | | |
|---|
| 1034 | | /* Mark savefile */ |
|---|
| 1035 | | p_ptr->noscore |= 0x0002; |
|---|
| 1036 | | |
|---|
| 1037 | | /* Success */ |
|---|
| 1038 | | return (TRUE); |
|---|
| 1039 | | } |
|---|
| 1040 | | |
|---|
| 1041 | | |
|---|
| 1042 | | |
|---|
| 1043 | | #ifdef ALLOW_DEBUG |
|---|
| 1044 | | |
|---|
| 1045 | | /* |
|---|
| 1046 | | * Verify use of "debug" mode |
|---|
| 1047 | | */ |
|---|
| 1048 | | static bool verify_debug_mode(void) |
|---|
| 1049 | | { |
|---|
| 1050 | | /* Ask first time */ |
|---|
| 1051 | | if (verify_special && !(p_ptr->noscore & 0x0008)) |
|---|
| 1052 | | { |
|---|
| 1053 | | /* Mention effects */ |
|---|
| 1054 | | msg_print("You are about to use the dangerous, unsupported, debug commands!"); |
|---|
| 1055 | | msg_print("Your machine may crash, and your savefile may become corrupted!"); |
|---|
| 1056 | | message_flush(); |
|---|
| 1057 | | |
|---|
| 1058 | | /* Verify request */ |
|---|
| 1059 | | if (!get_check("Are you sure you want to use the debug commands? ")) |
|---|
| 1060 | | { |
|---|
| 1061 | | return (FALSE); |
|---|
| 1062 | | } |
|---|
| 1063 | | } |
|---|
| 1064 | | |
|---|
| 1065 | | /* Mark savefile */ |
|---|
| 1066 | | p_ptr->noscore |= 0x0008; |
|---|
| 1067 | | |
|---|
| 1068 | | /* Okay */ |
|---|
| 1069 | | return (TRUE); |
|---|
| 1070 | | } |
|---|
| 1071 | | |
|---|
| 1072 | | #endif /* ALLOW_DEBUG */ |
|---|
| 1073 | | |
|---|
| 1074 | | |
|---|
| 1075 | | |
|---|
| 1076 | | #ifdef ALLOW_BORG |
|---|
| 1077 | | |
|---|
| 1078 | | /* |
|---|
| 1079 | | * Verify use of "borg" mode |
|---|
| 1080 | | */ |
|---|
| 1081 | | static bool verify_borg_mode(void) |
|---|
| 1082 | | { |
|---|
| 1083 | | /* Ask first time */ |
|---|
| 1084 | | if (verify_special && !(p_ptr->noscore & 0x0010)) |
|---|
| 1085 | | { |
|---|
| 1086 | | /* Mention effects */ |
|---|
| 1087 | | msg_print("You are about to use the dangerous, unsupported, borg commands!"); |
|---|
| 1088 | | msg_print("Your machine may crash, and your savefile may become corrupted!"); |
|---|
| 1089 | | message_flush(); |
|---|
| 1090 | | |
|---|
| 1091 | | /* Verify request */ |
|---|
| 1092 | | if (!get_check("Are you sure you want to use the borg commands? ")) |
|---|
| 1093 | | { |
|---|
| 1094 | | return (FALSE); |
|---|
| 1095 | | } |
|---|
| 1096 | | } |
|---|
| 1097 | | |
|---|
| 1098 | | /* Mark savefile */ |
|---|
| 1099 | | p_ptr->noscore |= 0x0010; |
|---|
| 1100 | | |
|---|
| 1101 | | /* Okay */ |
|---|
| 1102 | | return (TRUE); |
|---|
| 1103 | | } |
|---|
| 1104 | | |
|---|
| 1105 | | #endif /* ALLOW_BORG */ |
|---|
| 1106 | | |
|---|
| 1107 | | |
|---|
| 1108 | | /* |
|---|
| 1109 | | * Toggle wizard mode |
|---|
| 1110 | | */ |
|---|
| 1111 | | static void do_cmd_toggle_wizard(void) |
|---|
| 1112 | | { |
|---|
| 1113 | | if (p_ptr->wizard) |
|---|
| 1114 | | { |
|---|
| 1115 | | p_ptr->wizard = FALSE; |
|---|
| 1116 | | msg_print("Wizard mode off."); |
|---|
| 1117 | | } |
|---|
| 1118 | | else if (enter_wizard_mode()) |
|---|
| 1119 | | { |
|---|
| 1120 | | p_ptr->wizard = TRUE; |
|---|
| 1121 | | msg_print("Wizard mode on."); |
|---|
| 1122 | | } |
|---|
| 1123 | | |
|---|
| 1124 | | /* Update monsters */ |
|---|
| 1125 | | p_ptr->update |= (PU_MONSTERS); |
|---|
| 1126 | | |
|---|
| 1127 | | /* Redraw "title" */ |
|---|
| 1128 | | p_ptr->redraw |= (PR_TITLE); |
|---|
| 1129 | | } |
|---|
| 1130 | | |
|---|
| 1131 | | #ifdef ALLOW_DEBUG |
|---|
| 1132 | | |
|---|
| 1133 | | static void do_cmd_do_debug(void) |
|---|
| 1134 | | { |
|---|
| 1135 | | if (verify_debug_mode()) do_cmd_debug(); |
|---|
| 1136 | | } |
|---|
| 1137 | | |
|---|
| 1138 | | #endif |
|---|
| 1139 | | |
|---|
| 1140 | | #ifdef ALLOW_BORG |
|---|
| 1141 | | |
|---|
| 1142 | | static void do_cmd_do_borg(void) |
|---|
| 1143 | | { |
|---|
| 1144 | | if (verify_borg_mode()) do_cmd_borg(); |
|---|
| 1145 | | } |
|---|
| 1146 | | |
|---|
| 1147 | | #endif |
|---|
| 1148 | | |
|---|
| 1149 | | static void do_cmd_cast_or_pray(void) |
|---|
| 1150 | | { |
|---|
| 1151 | | if (cp_ptr->spell_book == TV_PRAYER_BOOK) |
|---|
| 1152 | | do_cmd_pray(); |
|---|
| 1153 | | else |
|---|
| 1154 | | do_cmd_cast(); |
|---|
| 1155 | | } |
|---|
| 1156 | | |
|---|
| 1157 | | static void do_cmd_quit(void) |
|---|
| 1158 | | { |
|---|
| 1159 | | /* Stop playing */ |
|---|
| 1160 | | p_ptr->playing = FALSE; |
|---|
| 1161 | | |
|---|
| 1162 | | /* Leaving */ |
|---|
| 1163 | | p_ptr->leaving = TRUE; |
|---|
| 1164 | | } |
|---|
| 1165 | | |
|---|
| 1166 | | static void do_cmd_mouseclick(void) |
|---|
| 1167 | | { |
|---|
| 1168 | | int x, y; |
|---|
| 1169 | | |
|---|
| 1170 | | x = p_ptr->command_cmd_ex.mousex - COL_MAP; |
|---|
| 1171 | | if (use_bigtile) x /= 2; |
|---|
| 1172 | | x += Term->offset_x; |
|---|
| 1173 | | y = p_ptr->command_cmd_ex.mousey - ROW_MAP + Term->offset_y; |
|---|
| 1174 | | |
|---|
| 1175 | | if (x < 0 || y < 0) |
|---|
| 1176 | | return; |
|---|
| 1177 | | |
|---|
| 1178 | | do_cmd_pathfind(y, x); |
|---|
| 1179 | | } |
|---|
| 1180 | | |
|---|
| 1181 | | static void do_cmd_port(void) |
|---|
| 1182 | | { |
|---|
| 1183 | | (void)Term_user(0); |
|---|
| 1184 | | } |
|---|
| 1185 | | |
|---|
| 1186 | | static void do_cmd_xxx_options(void) |
|---|
| 1187 | | { |
|---|
| 1188 | | do_cmd_options(); |
|---|
| 1189 | | do_cmd_redraw(); |
|---|
| 1190 | | } |
|---|
| 1191 | | |
|---|
| 1192 | | static void do_cmd_monlist(void) |
|---|
| 1193 | | { |
|---|
| 1194 | | /* Save the screen and display the list */ |
|---|
| 1195 | | screen_save(); |
|---|
| 1196 | | display_monlist(); |
|---|
| 1197 | | |
|---|
| 1198 | | /* Wait */ |
|---|
| 1199 | | inkey(); |
|---|
| 1200 | | |
|---|
| 1201 | | /* Return */ |
|---|
| 1202 | | screen_load(); |
|---|
| 1203 | | } |
|---|
| 1204 | | |
|---|
| 1205 | | /* |
|---|
| 1206 | | * Useful typedef. |
|---|
| 1207 | | */ |
|---|
| 1208 | | typedef void do_cmd_type(void); |
|---|
| 1209 | | |
|---|
| 1210 | | /* |
|---|
| 1211 | | * List of all commands and their descriptions. |
|---|
| 1212 | | */ |
|---|
| 1213 | | static const struct |
|---|
| 1214 | | { |
|---|
| 1215 | | const char *desc; |
|---|
| 1216 | | unsigned char key; |
|---|
| 1217 | | do_cmd_type *hook; |
|---|
| 1218 | | } commands[] = |
|---|
| 1219 | | { |
|---|
| 1220 | | |
|---|
| 1221 | | /*** Cheating commands ***/ |
|---|
| 1222 | | |
|---|
| 1223 | | { "Toggle wizard mode", KTRL('W'), do_cmd_toggle_wizard }, |
|---|
| 1224 | | |
|---|
| 1225 | | #ifdef ALLOW_DEBUG |
|---|
| 1226 | | { "Debug mode commands", KTRL('A'), do_cmd_do_debug }, |
|---|
| 1227 | | #endif |
|---|
| 1228 | | #ifdef ALLOW_BORG |
|---|
| 1229 | | { "Borg commands", KTRL('Z'), do_cmd_do_borg }, |
|---|
| 1230 | | #endif |
|---|
| 1231 | | |
|---|
| 1232 | | |
|---|
| 1233 | | /*** Inventory commands ***/ |
|---|
| 1234 | | |
|---|
| 1235 | | { "Display equipment listing", 'e', do_cmd_equip }, |
|---|
| 1236 | | { "Display inventory listing", 'i', do_cmd_inven }, |
|---|
| 1237 | | { "Toggle windows", KTRL('E'), toggle_inven_equip }, /* XXX */ |
|---|
| 1238 | | |
|---|
| 1239 | | |
|---|
| 1240 | | /*** Movement commands ***/ |
|---|
| 1241 | | |
|---|
| 1242 | | { "Alter a grid", '+', do_cmd_alter }, |
|---|
| 1243 | | { "Dig a tunnel", 'T', do_cmd_tunnel }, |
|---|
| 1244 | | { "Walk", ';', do_cmd_walk }, |
|---|
| 1245 | | { "Jump (into a trap)", '-', do_cmd_jump }, |
|---|
| 1246 | | |
|---|
| 1247 | | |
|---|
| 1248 | | /*** Running, Resting, Searching, Staying */ |
|---|
| 1249 | | |
|---|
| 1250 | | { "Start running", '.', do_cmd_run }, |
|---|
| 1251 | | { "Hold still for a turn", ',', do_cmd_hold }, |
|---|
| 1252 | | { "Pick up objects", 'g', do_cmd_pickup }, |
|---|
| 1253 | | { "Rest for a while", 'R', do_cmd_rest }, |
|---|
| 1254 | | { "Search for traps/doors", 's', do_cmd_search }, |
|---|
| 1255 | | { "Toggle search mode", 'S', do_cmd_toggle_search }, |
|---|
| 1256 | | |
|---|
| 1257 | | |
|---|
| 1258 | | /*** Stairs and Doors and Chests and Traps ***/ |
|---|
| 1259 | | |
|---|
| 1260 | | { "Enter a store", '_', do_cmd_store }, |
|---|
| 1261 | | { "Go up staircase", '<', do_cmd_go_up }, |
|---|
| 1262 | | { "Go down staircase", '>', do_cmd_go_down }, |
|---|
| 1263 | | { "Open a door or a chest", 'o', do_cmd_open }, |
|---|
| 1264 | | { "Close a door", 'c', do_cmd_close }, |
|---|
| 1265 | | { "Jam a door shut", 'j', do_cmd_spike }, |
|---|
| 1266 | | { "Bash a door open", 'B', do_cmd_bash }, |
|---|
| 1267 | | { "Disarm a trap or chest", 'D', do_cmd_disarm }, |
|---|
| 1268 | | |
|---|
| 1269 | | |
|---|
| 1270 | | /*** Magic and Prayers ***/ |
|---|
| 1271 | | |
|---|
| 1272 | | { "Gain new spells or prayers", 'G', do_cmd_study }, |
|---|
| 1273 | | { "Browse a book", 'b', do_cmd_browse }, |
|---|
| 1274 | | { "Cast a spell", 'm', do_cmd_cast_or_pray }, |
|---|
| 1275 | | { "Pray a prayer", 'p', do_cmd_cast_or_pray }, |
|---|
| 1276 | | |
|---|
| 1277 | | |
|---|
| 1278 | | /*** Use various objects ***/ |
|---|
| 1279 | | |
|---|
| 1280 | | { "Wear/wield an item", 'w', do_cmd_wield }, |
|---|
| 1281 | | { "Take/unwield off an item", 't', do_cmd_takeoff }, |
|---|
| 1282 | | { "Drop an item", 'd', do_cmd_drop }, |
|---|
| 1283 | | { "Destroy an item", 'k', do_cmd_destroy }, |
|---|
| 1284 | | { "Examine an item", 'I', do_cmd_observe }, |
|---|
| 1285 | | { "Inscribe an object", '{', do_cmd_inscribe }, |
|---|
| 1286 | | { "Uninscribe an object", '}', do_cmd_uninscribe }, |
|---|
| 1287 | | { "Activate an object", 'A', do_cmd_activate }, |
|---|
| 1288 | | { "Eat some food", 'E', do_cmd_eat_food }, |
|---|
| 1289 | | { "Fuel your light source", 'F', do_cmd_refill }, |
|---|
| 1290 | | { "Fire your missile weapon", 'f', do_cmd_fire }, |
|---|
| 1291 | | { "Throw an item", 'v', do_cmd_throw }, |
|---|
| 1292 | | { "Aim a wand", 'a', do_cmd_aim_wand }, |
|---|
| 1293 | | { "Zap a rod", 'z', do_cmd_zap_rod }, |
|---|
| 1294 | | { "Quaff a potion", 'q', do_cmd_quaff_potion }, |
|---|
| 1295 | | { "Read a scroll", 'r', do_cmd_read_scroll }, |
|---|
| 1296 | | { "Use a staff", 'u', do_cmd_use_staff }, |
|---|
| 1297 | | |
|---|
| 1298 | | |
|---|
| 1299 | | /*** Looking at Things (nearby or on map) ***/ |
|---|
| 1300 | | |
|---|
| 1301 | | { "Full dungeon map", 'M', do_cmd_view_map }, |
|---|
| 1302 | | { "Locate player on map", 'L', do_cmd_locate }, |
|---|
| 1303 | | { "Look around", 'l', do_cmd_look }, |
|---|
| 1304 | | { "Target monster or location", '*', do_cmd_target }, |
|---|
| 1305 | | |
|---|
| 1306 | | |
|---|
| 1307 | | /*** Help and Such ***/ |
|---|
| 1308 | | |
|---|
| 1309 | | { "Help", '?', do_cmd_help }, |
|---|
| 1310 | | { "Identify symbol", '/', do_cmd_query_symbol }, |
|---|
| 1311 | | { "Character description", 'C', do_cmd_change_name }, |
|---|
| 1312 | | { "Display monster list", '[', do_cmd_monlist }, |
|---|
| 1313 | | |
|---|
| 1314 | | |
|---|
| 1315 | | /*** System Commands ***/ |
|---|
| 1316 | | |
|---|
| 1317 | | { "Load a single pref line", '"', do_cmd_pref }, |
|---|
| 1318 | | { "Interact with options", '=', do_cmd_xxx_options }, |
|---|
| 1319 | | { "Port-specific preferences", '!', do_cmd_port }, |
|---|
| 1320 | | { "Check knowledge", '~', do_cmd_knowledge }, |
|---|
| 1321 | | { "Check knowledge", '|', do_cmd_knowledge }, |
|---|
| 1322 | | |
|---|
| 1323 | | |
|---|
| 1324 | | /*** Misc Commands ***/ |
|---|
| 1325 | | |
|---|
| 1326 | | { "Take notes", ':', do_cmd_note }, |
|---|
| 1327 | | { "Version info", 'V', do_cmd_version }, |
|---|
| 1328 | | { "Repeat level feeling", KTRL('F'), do_cmd_feeling }, |
|---|
| 1329 | | { "Show previous message", KTRL('O'), do_cmd_message_one }, |
|---|
| 1330 | | { "Show previous messages", KTRL('P'), do_cmd_messages }, |
|---|
| 1331 | | { "Redraw the screen", KTRL('R'), do_cmd_redraw }, |
|---|
| 1332 | | { "Save and don't quit", KTRL('S'), do_cmd_save_game }, |
|---|
| 1333 | | { "Save and quit", KTRL('X'), do_cmd_quit }, |
|---|
| 1334 | | { "Quit (commit suicide)", 'Q', do_cmd_suicide }, |
|---|
| 1335 | | |
|---|
| 1336 | | { "Load \"screen dump\"", '(', do_cmd_load_screen }, |
|---|
| 1337 | | { "Save \"screen dump\"", ')', do_cmd_save_screen }, |
|---|
| 1338 | | { "Mouse click", '\xff', do_cmd_mouseclick } |
|---|
| 1339 | | }; |
|---|
| 1340 | | |
|---|
| 1341 | | |
|---|
| 1342 | | /* List indexed by char */ |
|---|
| 1343 | | do_cmd_type *converted_list[UCHAR_MAX+1]; |
|---|
| 1344 | | |
|---|
| 1345 | | |
|---|
| 1346 | | static void do_cmd_unknown(void) |
|---|
| 1347 | | { |
|---|
| 1348 | | prt("Type '?' for help.", 0, 0); |
|---|
| 1349 | | } |
|---|
| 1350 | | |
|---|
| 1351 | | /* |
|---|
| 1352 | | * Parse and execute the current command |
|---|
| 1353 | | * Give "Warning" on illegal commands. |
|---|
| 1354 | | */ |
|---|
| 1355 | | static void process_command(void) |
|---|
| 1356 | | { |
|---|
| 1357 | | static bool first = TRUE; |
|---|
| 1358 | | |
|---|
| 1359 | | #ifdef ALLOW_REPEAT |
|---|
| 1360 | | |
|---|
| 1361 | | /* Handle repeating the last command */ |
|---|
| 1362 | | repeat_check(); |
|---|
| 1363 | | |
|---|
| 1364 | | #endif /* ALLOW_REPEAT */ |
|---|
| 1365 | | |
|---|
| 1366 | | if (first) |
|---|
| 1367 | | { |
|---|
| 1368 | | size_t i; |
|---|
| 1369 | | |
|---|
| 1370 | | first = FALSE; |
|---|
| 1371 | | |
|---|
| 1372 | | /* Fill everything in at first */ |
|---|
| 1373 | | for (i = 0; i < N_ELEMENTS(commands); i++) |
|---|
| 1374 | | { |
|---|
| 1375 | | unsigned char key = commands[i].key; |
|---|
| 1376 | | assert(key < N_ELEMENTS(converted_list)); |
|---|
| 1377 | | converted_list[key] = commands[i].hook; |
|---|
| 1378 | | } |
|---|
| 1379 | | |
|---|
| 1380 | | /* Fill in the rest */ |
|---|
| 1381 | | for (i = 0; i < N_ELEMENTS(converted_list); i++) |
|---|
| 1382 | | { |
|---|
| 1383 | | switch (i) |
|---|
| 1384 | | { |
|---|
| 1385 | | /* Ignore */ |
|---|
| 1386 | | case ESCAPE: |
|---|
| 1387 | | case ' ': |
|---|
| 1388 | | case '\n': |
|---|
| 1389 | | case '\r': |
|---|
| 1390 | | case '\a': |
|---|
| 1391 | | { |
|---|
| 1392 | | break; |
|---|
| 1393 | | } |
|---|
| 1394 | | |
|---|
| 1395 | | default: |
|---|
| 1396 | | { |
|---|
| 1397 | | if (!converted_list[i]) |
|---|
| 1398 | | converted_list[i] = do_cmd_unknown; |
|---|
| 1399 | | } |
|---|
| 1400 | | } |
|---|
| 1401 | | } |
|---|
| 1402 | | } |
|---|
| 1403 | | |
|---|
| 1404 | | /* Handle resize events XXX */ |
|---|
| 1405 | | if (p_ptr->command_cmd_ex.type == EVT_RESIZE) |
|---|
| 1406 | | { |
|---|
| 1407 | | do_cmd_redraw(); |
|---|
| 1408 | | } |
|---|
| 1409 | | else |
|---|
| 1410 | | { |
|---|
| 1411 | | /* Within these boundaries, the cast to unsigned char will have the desired effect */ |
|---|
| 1412 | | assert(p_ptr->command_cmd >= CHAR_MIN && p_ptr->command_cmd <= CHAR_MAX); |
|---|
| 1413 | | |
|---|
| 1414 | | /* Execute the command */ |
|---|
| 1415 | | if (converted_list[(unsigned char) p_ptr->command_cmd]) |
|---|
| 1416 | | converted_list[(unsigned char) p_ptr->command_cmd](); |
|---|
| 1417 | | } |
|---|
| 1418 | | } |
|---|