1 #pragma once 2 #ifndef CATA_SRC_ACTION_H 3 #define CATA_SRC_ACTION_H 4 5 #include <functional> 6 #include <iosfwd> 7 #include <map> 8 #include <set> 9 #include <vector> 10 11 namespace cata 12 { 13 template<typename T> 14 class optional; 15 } // namespace cata 16 struct input_event; 17 struct point; 18 struct tripoint; 19 20 /** 21 * Enumerates all discrete actions that can be performed by player 22 */ 23 enum action_id : int { 24 /** Invalid action used for various lookup errors */ 25 ACTION_NULL = 0, 26 27 // Mouse actions 28 /**@{*/ 29 /** Click on a point with primary mouse button (usually left button) */ 30 ACTION_SELECT, 31 /** Click on a point with secondary mouse button (usually right button) */ 32 ACTION_SEC_SELECT, 33 /**@}*/ 34 35 // Character movement actions 36 /**@{*/ 37 /** Pause an on-going activity. */ 38 ACTION_PAUSE, 39 /** Input timeout */ 40 ACTION_TIMEOUT, 41 /** Move towards top of screen / accelerate */ 42 ACTION_MOVE_FORTH, 43 /** Move towards top-right of screen / accelerate and steer right */ 44 ACTION_MOVE_FORTH_RIGHT, 45 /** Move / steer right */ 46 ACTION_MOVE_RIGHT, 47 /** Move towards bottom-right of screen / decelerate and steer right */ 48 ACTION_MOVE_BACK_RIGHT, 49 /** Move towards bottom of screen / decelerate */ 50 ACTION_MOVE_BACK, 51 /** Move towards bottom-left of screen / decelerate and steer left */ 52 ACTION_MOVE_BACK_LEFT, 53 /** Move / steer left */ 54 ACTION_MOVE_LEFT, 55 /** Move towards top-left of screen / accelerate and steer left */ 56 ACTION_MOVE_FORTH_LEFT, 57 /** Descend a staircase */ 58 ACTION_MOVE_DOWN, 59 /** Ascend a staircase */ 60 ACTION_MOVE_UP, 61 /** Cycle run/walk/crouch mode */ 62 ACTION_CYCLE_MOVE, 63 /** Reset movement mode to walk */ 64 ACTION_RESET_MOVE, 65 /** Toggle run on/off */ 66 ACTION_TOGGLE_RUN, 67 /** Toggle crouch on/off */ 68 ACTION_TOGGLE_CROUCH, 69 /** Open movement mode menu */ 70 ACTION_OPEN_MOVEMENT, 71 /**@}*/ 72 73 // Viewport movement actions and related 74 /**@{*/ 75 /** Toggle memorized tiles being shown */ 76 ACTION_TOGGLE_MAP_MEMORY, 77 /** Center the viewport on character */ 78 ACTION_CENTER, 79 /** Move viewport north */ 80 ACTION_SHIFT_N, 81 /** Move viewport north-east */ 82 ACTION_SHIFT_NE, 83 /** Move viewport east */ 84 ACTION_SHIFT_E, 85 /** Move viewport south-east */ 86 ACTION_SHIFT_SE, 87 /** Move viewport south */ 88 ACTION_SHIFT_S, 89 /** Move viewport south-west */ 90 ACTION_SHIFT_SW, 91 /** Move viewport west */ 92 ACTION_SHIFT_W, 93 /** Move viewport north-west */ 94 ACTION_SHIFT_NW, 95 /**@}*/ 96 97 // Environment Interaction Actions 98 /**@{*/ 99 /** Open an item (e.g. a door) */ 100 ACTION_OPEN, 101 /** Close an item (e.g. a door) */ 102 ACTION_CLOSE, 103 /** Smash something */ 104 ACTION_SMASH, 105 /** Examine or pick up items from adjacent square */ 106 ACTION_EXAMINE, 107 /** Pick up items from current/adjacent squares */ 108 ACTION_PICKUP, 109 /** Pick up items from current square. Auto pickup if only one item */ 110 ACTION_PICKUP_FEET, 111 /** Grab or let go of an object */ 112 ACTION_GRAB, 113 /** Haul pile of items, or let go of them */ 114 ACTION_HAUL, 115 /** Butcher or disassemble objects in current square */ 116 ACTION_BUTCHER, 117 /** Chat with something */ 118 ACTION_CHAT, 119 /** Toggle look mode */ 120 ACTION_LOOK, 121 /** Peek through something (e.g. out of a curtained window) */ 122 ACTION_PEEK, 123 /** List items and monsters in a given square */ 124 ACTION_LIST_ITEMS, 125 /** Open the zone manager */ 126 ACTION_ZONES, 127 /** Sort out the loot */ 128 ACTION_LOOT, 129 /**@}*/ 130 131 // Inventory Interaction (including quasi-inventories like bionics) 132 /**@{*/ 133 /** Open the primary inventory screen */ 134 ACTION_INVENTORY, 135 /** Open the advanced inventory screen */ 136 ACTION_ADVANCEDINV, 137 /** Open the item compare screen */ 138 ACTION_COMPARE, 139 /** Swap inventory letters */ 140 ACTION_ORGANIZE, 141 /** Open the use menu */ 142 ACTION_USE, 143 /** Use currently wielded item */ 144 ACTION_USE_WIELDED, 145 /** Open the wear clothing selection menu */ 146 ACTION_WEAR, 147 /** Open the take-off clothing selection menu */ 148 ACTION_TAKE_OFF, 149 /** Open the default consume item menu */ 150 ACTION_EAT, 151 /** Open the custom consume item menu */ 152 ACTION_OPEN_CONSUME, 153 /** Open the read menu */ 154 ACTION_READ, 155 /** Open the wield menu */ 156 ACTION_WIELD, 157 /** Open the martial-arts style menu */ 158 ACTION_PICK_STYLE, 159 /** Open the load item (e.g. firearms) select menu */ 160 ACTION_RELOAD_ITEM, 161 /** Attempt to reload wielded weapon, then fall back to the load item select menu */ 162 ACTION_RELOAD_WEAPON, 163 /** Attempt to reload wielded object*/ 164 ACTION_RELOAD_WIELDED, 165 /** Open the unload item (e.g. firearms) select menu */ 166 ACTION_UNLOAD, 167 /** Open the mending menu (e.g. when using a sewing kit) */ 168 ACTION_MEND, 169 /** Open the throw menu */ 170 ACTION_THROW, 171 /** Fire the wielded weapon, or open fire menu if none */ 172 ACTION_FIRE, 173 /** Burst-fire the current weapon */ 174 ACTION_FIRE_BURST, 175 /** Change fire mode of the current weapon */ 176 ACTION_SELECT_FIRE_MODE, 177 /** Cast a spell (only if any spells are known) */ 178 ACTION_CAST_SPELL, 179 /** Open the drop-item menu */ 180 ACTION_DROP, 181 /** Drop items in a given direction */ 182 ACTION_DIR_DROP, 183 /** Open the bionics menu */ 184 ACTION_BIONICS, 185 /** Open the mutations menu */ 186 ACTION_MUTATIONS, 187 /** Open the armor sorting menu */ 188 ACTION_SORT_ARMOR, 189 /** Auto select and attack hostile creature within range */ 190 ACTION_AUTOATTACK, 191 /**@}*/ 192 193 // Long-term / special actions 194 /**@{*/ 195 /** Open wait menu */ 196 ACTION_WAIT, 197 /** Open crafting menu */ 198 ACTION_CRAFT, 199 /** Repeat last craft command */ 200 ACTION_RECRAFT, 201 /** Open batch crafting menu */ 202 ACTION_LONGCRAFT, 203 /** Open construct menu */ 204 ACTION_CONSTRUCT, 205 /** Open disassemble menu */ 206 ACTION_DISASSEMBLE, 207 /** Open sleep menu */ 208 ACTION_SLEEP, 209 /** Open vehicle control menu */ 210 ACTION_CONTROL_VEHICLE, 211 /** Turn auto travel mode on/off */ 212 ACTION_TOGGLE_AUTO_TRAVEL_MODE, 213 /** Turn safemode on/off, while leaving autosafemode intact */ 214 ACTION_TOGGLE_SAFEMODE, 215 /** Turn automatic triggering of safemode on/off */ 216 ACTION_TOGGLE_AUTOSAFE, 217 /** Toggle permanent attitude to stealing */ 218 ACTION_TOGGLE_THIEF_MODE, 219 /** Ignore the enemy that triggered safemode */ 220 ACTION_IGNORE_ENEMY, 221 /** Whitelist the enemy that triggered safemode */ 222 ACTION_WHITELIST_ENEMY, 223 /** Open workout menu */ 224 ACTION_WORKOUT, 225 /** Save the game and quit */ 226 ACTION_SAVE, 227 /** Quicksave the game */ 228 ACTION_QUICKSAVE, 229 /** Quickload the game */ 230 ACTION_QUICKLOAD, 231 /** Commit suicide */ 232 ACTION_SUICIDE, 233 /**@}*/ 234 235 // Info Screens 236 /**@{*/ 237 /** Display player status screen */ 238 ACTION_PL_INFO, 239 /** Display over-map */ 240 ACTION_MAP, 241 /** Show sky state for trying to predict weather */ 242 ACTION_SKY, 243 /** Display missions screen */ 244 ACTION_MISSIONS, 245 /** Display scores screen */ 246 ACTION_SCORES, 247 /** Display factions screen */ 248 ACTION_FACTIONS, 249 /** Display morale effects screen */ 250 ACTION_MORALE, 251 /** Display messages screen */ 252 ACTION_MESSAGES, 253 /** Display help screen */ 254 ACTION_HELP, 255 /** Display main menu */ 256 ACTION_MAIN_MENU, 257 /** Display keybindings list */ 258 ACTION_KEYBINDINGS, 259 /** Display options window */ 260 ACTION_OPTIONS, 261 /** Open autopickup manager */ 262 ACTION_AUTOPICKUP, 263 /** Open autonotes manager */ 264 ACTION_AUTONOTES, 265 /** Open safemode manager */ 266 ACTION_SAFEMODE, 267 /** Open color manager */ 268 ACTION_COLOR, 269 /** Open active world mods */ 270 ACTION_WORLD_MODS, 271 /**@}*/ 272 273 // Debug Functions 274 /**@{*/ 275 /** Toggle full-screen mode */ 276 ACTION_TOGGLE_FULLSCREEN, 277 /** Open debug menu */ 278 ACTION_DEBUG, 279 /** Toggle scent map */ 280 ACTION_DISPLAY_SCENT, 281 /** Toggle scent type map */ 282 ACTION_DISPLAY_SCENT_TYPE, 283 /** Toggle debug mode */ 284 ACTION_TOGGLE_DEBUG_MODE, 285 /** Zoom view in */ 286 ACTION_ZOOM_OUT, 287 /** Zoom view out */ 288 ACTION_ZOOM_IN, 289 /** Open the action menu */ 290 ACTION_ACTIONMENU, 291 /** Open the item uses menu */ 292 ACTION_ITEMACTION, 293 /** Turn pixel minimap on/off */ 294 ACTION_TOGGLE_PIXEL_MINIMAP, 295 /** Turn admin panel on/off */ 296 ACTION_TOGGLE_PANEL_ADM, 297 /** panels management */ 298 ACTION_PANEL_MGMT, 299 /** Reload current tileset */ 300 ACTION_RELOAD_TILESET, 301 /** Turn auto features on/off */ 302 ACTION_TOGGLE_AUTO_FEATURES, 303 /** Change auto pulp/butcher mode */ 304 ACTION_TOGGLE_AUTO_PULP_BUTCHER, 305 /** Turn auto mining on/off */ 306 ACTION_TOGGLE_AUTO_MINING, 307 /** Turn auto foraging on/off */ 308 ACTION_TOGGLE_AUTO_FORAGING, 309 /** Turn auto pickup on/off */ 310 ACTION_TOGGLE_AUTO_PICKUP, 311 /** Toggle temperature map */ 312 ACTION_DISPLAY_TEMPERATURE, 313 /** Toggle vehicle autopilot data */ 314 ACTION_DISPLAY_VEHICLE_AI, 315 /** Toggle visibility map */ 316 ACTION_DISPLAY_VISIBILITY, 317 /** Toggle lighting conditions map */ 318 ACTION_DISPLAY_LIGHTING, 319 /** Toggle radiation map */ 320 ACTION_DISPLAY_RADIATION, 321 /** Toggle transparency map */ 322 ACTION_DISPLAY_TRANSPARENCY, 323 /** Toggle reachability zones map */ 324 ACTION_DISPLAY_REACHABILITY_ZONES, 325 /** Toggle timing of the game hours */ 326 ACTION_TOGGLE_HOUR_TIMER, 327 /** Not an action, serves as count of enumerated actions */ 328 NUM_ACTIONS 329 /**@}*/ 330 }; 331 332 /** 333 * Load keymap from disk 334 * 335 * Sets the state of a keymap in memory to the state of a keymap state saved to disk. 336 * The actual filename we read the keymap from is returned by reference, not specified in this 337 * function call. The filename used is set elsewhere (in a variety of places). Take a look at 338 * @ref path_info to see where this happens. The returned file name is used to detect errors, such 339 * as a non-existent file or a file that didn't actually contain a keymap. 340 * 341 * Output is returned as two separate maps: 342 * 1. The keymap parameter is used to store the set of keys that were mapped by the file. This 343 * is not a complete map of all available action IDs, rather it contains only those IDs explicitly 344 * set by the file. 345 * 346 * 2. The unbound_keymap parameter contains keys that the file specifically unmaps. 347 * 348 * The caller of this function is intended to set those keys explicitly set in parameter keymap, and 349 * unset those keys explicitly unbound in parameter unbound_keymap. Actions and/or keys that are not 350 * mentioned in either output are left in place. See @ref input_manager::init() for the current way 351 * that this is done. 352 * 353 * @param[out] keymap Place in which to store the keys explicitly bound by the file 354 * @param[out] keymap_file_loaded_from Name of file that keymap was loaded from 355 * @param[out] unbound_keymap Place to store the keys explicitly unbound by the file 356 */ 357 void load_keyboard_settings( std::map<char, action_id> &keymap, 358 std::string &keymap_file_loaded_from, 359 std::set<action_id> &unbound_keymap ); 360 361 /** 362 * Get list of keys bound to an action ID. 363 * 364 * Returns a vector of all keys currently bound to the given action. If not keys are bound to the 365 * given action then the returned vector is simply left empty. 366 * 367 * @param act Action ID to lookup in keymap 368 * @param maximum_modifier_count Maximum number of modifiers allowed for 369 * the returned action. <0 means any number is allowed. 370 * @param restrict_to_printable If `true` the function returns the bound 371 * keys only if they are printable (space counts as non-printable 372 * here). If `false`, all keys (whether they are printable or not) 373 * are returned. 374 * @returns all keys (as input events) currently bound to a give action ID 375 */ 376 std::vector<input_event> keys_bound_to( action_id act, 377 int maximum_modifier_count = -1, 378 bool restrict_to_printable = true ); 379 380 /** 381 * Get the key for an action, used in the action menu to give each action the hotkey it is bound to. 382 * @param action Action ID to lookup in keymap. 383 * @param maximum_modifier_count Maximum number of modifiers allowed for 384 * the returned action. <0 means any number is allowed. 385 * @param restrict_to_printable If `true` the function returns the bound 386 * keys only if they are printable (space counts as non-printable 387 * here). If `false`, all keys (whether they are printable or not) 388 * are returned. 389 * @returns the input event for the hotkey or cata::nullopt if no key is associated with the given action. 390 */ 391 cata::optional<input_event> hotkey_for_action( action_id action, 392 int maximum_modifier_count = -1, bool restrict_to_printable = true ); 393 394 /** 395 * Lookup an action ID by its unique string identifier 396 * 397 * Translates a unique string identifier into an @ref action_id. This identifier is generally the 398 * value used in a keymap configuration file. If no corresponding action_id is found for this 399 * identifier then ACTION_NULL is returned instead. 400 * 401 * @param ident Unique string identifier corresponding to an @ref action_id 402 * @returns Corresponding action_id for the supplied string identifier 403 */ 404 action_id look_up_action( const std::string &ident ); 405 406 /** 407 * Lookup a unique string identifier for a given action ID. 408 * 409 * Translates an @ref action_id into a unique string identifier. This is the value recorded in the 410 * keymap configuration file. 411 * 412 * @note The values we use here are more or less human-readable, but are not always suitable for 413 * display directly to the user. 414 * 415 * @param act The action ID to lookup an identifier for 416 * @returns The string identifier for the specified action ID. 417 */ 418 std::string action_ident( action_id act ); 419 420 /** 421 * Lookup whether an action can affect the state of the game world. 422 * 423 * Looks an action ID up and determines if that action can change world state in any case. This 424 * is a static determination from a hard-coded list. 425 * 426 * This function can be used to count the number of user actions that actually affected the game 427 * state separate from other actions that only result in view and menu navigation. The only current 428 * example of this is @ref game::user_action_counter. 429 * 430 * @param act action ID to lookup in table 431 * @returns true if action has potential to alter world state, otherwise returns false. 432 */ 433 bool can_action_change_worldstate( action_id act ); 434 435 /** 436 * Request player input of adjacent tile, possibly including vertical tiles 437 * 438 * Asks the player to input desired direction of an adjacent tile, for example when executing 439 * an examine or directional item drop. This version of the function supports selection of tiles 440 * above and below the player if an appropriate flag is set. 441 * 442 * @param[in] message Message used in assembling the prompt to the player 443 * @param[in] allow_vertical Allows player to select tiles above/below them if true 444 */ 445 cata::optional<tripoint> choose_adjacent( const std::string &message, bool allow_vertical = false ); 446 447 /** 448 * Request player input of a direction, possibly including vertical component 449 * 450 * Asks the player to input a desired direction. This differs from @ref choose_adjacent in that 451 * the selected direction is returned as an offset to the player's current position rather than 452 * coordinate of a tile. This version of the function allows selection of the tile above and below 453 * the player if the appropriate flag is set. 454 * 455 * @param[in] message Message used in assembling the prompt to the player 456 * @param[in] allow_vertical Allows direction vector to have vertical component if true 457 */ 458 cata::optional<tripoint> choose_direction( const std::string &message, 459 bool allow_vertical = false ); 460 461 /** 462 * Request player input of adjacent tile with highlighting, possibly on different z-level 463 * 464 * Asks the player to input desired direction of an adjacent tile, for example when executing 465 * an examine or directional item drop. This version of the function allows the player to select 466 * a tile above or below. 467 * 468 * This function is identical to @ref choose_adjacent except that squares are highlighted for 469 * the player to indicate valid squares for a given @ref action_id 470 * 471 * @param[in] message Message used in assembling the prompt to the player 472 * @param[in] failure_message Message used if there is no valid adjacent tile 473 * @param[in] action An action ID to drive the highlighting output 474 * @param[in] allow_vertical Allows direction vector to have vertical component if true 475 */ 476 cata::optional<tripoint> choose_adjacent_highlight( const std::string &message, 477 const std::string &failure_message, action_id action, bool allow_vertical = false ); 478 479 /** 480 * Request player input of adjacent tile with highlighting, possibly on different z-level 481 * 482 * Asks the player to input desired direction of an adjacent tile, for example when executing 483 * an examine or directional item drop. This version of the function allows the player to select 484 * a tile above or below. 485 * 486 * This function is identical to @ref choose_adjacent except that squares are highlighted for 487 * the player to indicate valid squares, based on the result of the provided @ref should_highlight 488 * function. 489 * 490 * @param[in] message Message used in assembling the prompt to the player 491 * @param[in] failure_message Message used if there is no valid adjacent tile 492 * @param[in] allowed A function that will be called to determine if a given location is allowed for selection 493 * @param[in] allow_vertical Allows direction vector to have vertical component if true 494 */ 495 cata::optional<tripoint> choose_adjacent_highlight( const std::string &message, 496 const std::string &failure_message, const std::function<bool( const tripoint & )> &allowed, 497 bool allow_vertical = false ); 498 499 // (Press X (or Y)|Try) to Z 500 std::string press_x( action_id act ); 501 std::string press_x( action_id act, const std::string &key_bound, 502 const std::string &key_unbound ); 503 std::string press_x( action_id act, const std::string &key_bound_pre, 504 const std::string &key_bound_suf, const std::string &key_unbound ); 505 // ('Z'ing|zing) (X( or Y))) 506 std::string press_x( action_id act, const std::string &act_desc ); 507 // Return "Press X" or nullopt if not bound 508 cata::optional<std::string> press_x_if_bound( action_id act ); 509 510 // only has effect in iso mode 511 enum class iso_rotate : int { 512 no, 513 yes 514 }; 515 516 // Helper function to convert coordinate delta to a movement action 517 /** 518 * Translate coordinate delta into movement action 519 * 520 * For a given coordinate delta, this function returns the associated user movement action 521 * that would generated that delta. See @ref action_id for the list of available movement 522 * commands that may be generated. This function takes iso mode into account. 523 * 524 * The only valid values for the coordinates of \p d are -1, 0 and 1 525 * 526 * @note: This function does not sanitize its inputs, which can result in some strange behavior: 527 * 1. If d.z is valid and non-zero, then d.x and d.y are ignored. 528 * 2. If d.z is invalid, it is treated as if it were zero. 529 * 3. If d.z is 0 or invalid, then any invalid d.x or d.y results in @ref ACTION_MOVE_FORTH_LEFT 530 * 4. If d.z is 0 or invalid, then a d.x == d.y == 0 results in @ref ACTION_MOVE_FORTH_LEFT 531 * 532 * @param[in] d coordinate delta, each coordinate should be -1, 0, or 1 533 * @returns ID of corresponding move action (usually... see note above) 534 */ 535 action_id get_movement_action_from_delta( const tripoint &d, iso_rotate rot ); 536 537 // Helper function to convert movement action to coordinate delta point 538 point get_delta_from_movement_action( action_id act, iso_rotate rot ); 539 540 /** 541 * Show the action menu 542 * 543 * Prompts the user with the action menu, and returns any action requested by user input at 544 * that menu. 545 * 546 * @returns action_id ID of action requested by user at menu. 547 */ 548 action_id handle_action_menu(); 549 550 /** 551 * Show in-game main menu 552 * 553 * Prompts the user with the main game menu, and returns any action requested by user input at 554 * that menu. 555 * 556 * @returns action_id ID of action requested by user at menu. 557 */ 558 action_id handle_main_menu(); 559 560 /** 561 * Test whether it is possible to perform a given action. 562 * 563 * Checks whether we can interact with something using the specified action and the given tile. 564 * 565 * @note: This is part of a new API that will allow for a more robust user interface. Possible 566 * features include: Extending the "select a nearby tile" widget to highlight tiles that can be 567 * interacted with, "suggest" context-sensitive actions to the user that are currently relevant. 568 * 569 * @param action The action ID to perform the test for 570 * @param p Point to perform test at 571 * @returns true if movement is possible in the indicated direction 572 */ 573 bool can_interact_at( action_id action, const tripoint &p ); 574 575 /** 576 * Test whether it is possible to perform butcher action 577 * 578 * Checks whether the butcher action makes sense at a given point. Checks for both corpses 579 * and items that can be disassembled. 580 * 581 * This is part of a new API that will allow for a more robust user interface. See the note in 582 * @ref can_interact_at() 583 * 584 * @param p Point to perform the test at 585 * @returns true if there is a corpse or item that can be disassembled at a point, otherwise false 586 */ 587 bool can_butcher_at( const tripoint &p ); 588 589 /** 590 * Test whether vertical movement is possible 591 * 592 * Checks whether it is possible to perform up or down movement actions at this location, defined 593 * as whether it is possible to swim up/down at this location, or if there is an up or down 594 * staircase at this location. 595 * 596 * This is part of a new API that will allow for a more robust user interface. See the note in 597 * @ref can_interact_at() 598 * 599 * @param p Point to perform test at 600 * @param movez Direction to move. -1 for down, all other values for up 601 * @returns true if movement is possible in the indicated direction, otherwise false 602 */ 603 bool can_move_vertical_at( const tripoint &p, int movez ); 604 605 /** 606 * Test whether examine is possible 607 * 608 * Checks whether the examine action makes sense at a given point. 609 * 610 * This is part of a new API that will allow for a more robust user interface. See the note in 611 * @ref can_interact_at() 612 * 613 * @param p Point to perform the test at 614 * @returns true if the examine action is possible at this point, otherwise false 615 */ 616 bool can_examine_at( const tripoint &p ); 617 618 #endif // CATA_SRC_ACTION_H 619