forked from cataclysmbnteam/Cataclysm-BN
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.h
586 lines (554 loc) · 20.5 KB
/
action.h
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
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
#pragma once
#ifndef CATA_SRC_ACTION_H
#define CATA_SRC_ACTION_H
#include <functional>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <optional>
struct tripoint;
struct point;
/**
* Enumerates all discrete actions that can be performed by player
*/
enum action_id : int {
/** Invalid action used for various lookup errors */
ACTION_NULL = 0,
// Mouse actions
/**@{*/
/** Click on a point with primary mouse button (usually left button) */
ACTION_SELECT,
/** Click on a point with secondary mouse button (usually right button) */
ACTION_SEC_SELECT,
/**@}*/
// Character movement actions
/**@{*/
/** Pause an on-going activity. */
ACTION_PAUSE,
/** Input timeout */
ACTION_TIMEOUT,
/** Move towards top of screen / accelerate */
ACTION_MOVE_FORTH,
/** Move towards top-right of screen / accelerate and steer right */
ACTION_MOVE_FORTH_RIGHT,
/** Move / steer right */
ACTION_MOVE_RIGHT,
/** Move towards bottom-right of screen / decelerate and steer right */
ACTION_MOVE_BACK_RIGHT,
/** Move towards bottom of screen / decelerate */
ACTION_MOVE_BACK,
/** Move towards bottom-left of screen / decelerate and steer left */
ACTION_MOVE_BACK_LEFT,
/** Move / steer left */
ACTION_MOVE_LEFT,
/** Move towards top-left of screen / accelerate and steer left */
ACTION_MOVE_FORTH_LEFT,
/** Descend a staircase */
ACTION_MOVE_DOWN,
/** Ascend a staircase */
ACTION_MOVE_UP,
/** Cycle run/walk/crouch mode */
ACTION_CYCLE_MOVE,
/** Reset movement mode to walk */
ACTION_RESET_MOVE,
/** Toggle run on/off */
ACTION_TOGGLE_RUN,
/** Toggle crouch on/off */
ACTION_TOGGLE_CROUCH,
/** Open movement mode menu */
ACTION_OPEN_MOVEMENT,
/**@}*/
// Viewport movement actions and related
/**@{*/
/** Toggle memorized tiles being shown */
ACTION_TOGGLE_MAP_MEMORY,
/** Center the viewport on character */
ACTION_CENTER,
/** Move viewport north */
ACTION_SHIFT_N,
/** Move viewport north-east */
ACTION_SHIFT_NE,
/** Move viewport east */
ACTION_SHIFT_E,
/** Move viewport south-east */
ACTION_SHIFT_SE,
/** Move viewport south */
ACTION_SHIFT_S,
/** Move viewport south-west */
ACTION_SHIFT_SW,
/** Move viewport west */
ACTION_SHIFT_W,
/** Move viewport north-west */
ACTION_SHIFT_NW,
/**@}*/
// Environment Interaction Actions
/**@{*/
/** Open an item (e.g. a door) */
ACTION_OPEN,
/** Close an item (e.g. a door) */
ACTION_CLOSE,
/** Smash something */
ACTION_SMASH,
/** Examine or pick up items from adjacent square */
ACTION_EXAMINE,
/** Pick up items from current/adjacent squares */
ACTION_PICKUP,
/** Pick up items from current square. Auto pickup if only one item */
ACTION_PICKUP_FEET,
/** Grab or let go of an object */
ACTION_GRAB,
/** Haul pile of items, or let go of them */
ACTION_HAUL,
/** Butcher or disassemble objects in current square */
ACTION_BUTCHER,
/** Chat with something */
ACTION_CHAT,
/** Toggle look mode */
ACTION_LOOK,
/** Peek through something (e.g. out of a curtained window) */
ACTION_PEEK,
/** List items and monsters in a given square */
ACTION_LIST_ITEMS,
/** Open the zone manager */
ACTION_ZONES,
/** Sort out the loot */
ACTION_LOOT,
/**@}*/
// Inventory Interaction (including quasi-inventories like bionics)
/**@{*/
/** Open the primary inventory screen */
ACTION_INVENTORY,
/** Open the advanced inventory screen */
ACTION_ADVANCEDINV,
/** Open the item compare screen */
ACTION_COMPARE,
/** Swap inventory letters */
ACTION_ORGANIZE,
/** Open the use menu */
ACTION_USE,
/** Use currently wielded item */
ACTION_USE_WIELDED,
/** Open the wear clothing selection menu */
ACTION_WEAR,
/** Open the take-off clothing selection menu */
ACTION_TAKE_OFF,
/** Open the default consume item menu */
ACTION_EAT,
/** Open the custom consume item menu */
ACTION_OPEN_CONSUME,
/** Open the read menu */
ACTION_READ,
/** Open the wield menu */
ACTION_WIELD,
/** Open the martial-arts style menu */
ACTION_PICK_STYLE,
/** Open the load item (e.g. firearms) select menu */
ACTION_RELOAD_ITEM,
/** Attempt to reload wielded weapon, then fall back to the load item select menu */
ACTION_RELOAD_WEAPON,
/** Attempt to reload wielded object*/
ACTION_RELOAD_WIELDED,
/** Open the unload item (e.g. firearms) select menu */
ACTION_UNLOAD,
/** Open the mending menu (e.g. when using a sewing kit) */
ACTION_MEND,
/** Open the throw menu */
ACTION_THROW,
/** Fire the wielded weapon, or open fire menu if none */
ACTION_FIRE,
/** Burst-fire the current weapon */
ACTION_FIRE_BURST,
/** Change fire mode of the current weapon */
ACTION_SELECT_FIRE_MODE,
/** Change default ammo for current weapon */
ACTION_SELECT_DEFAULT_AMMO,
/** Cast a spell (only if any spells are known) */
ACTION_CAST_SPELL,
/** Open the drop-item menu */
ACTION_DROP,
/** Drop items in a given direction */
ACTION_DIR_DROP,
/** Open the bionics menu */
ACTION_BIONICS,
/** Open the mutations menu */
ACTION_MUTATIONS,
/** Open the armor sorting menu */
ACTION_SORT_ARMOR,
/** Auto select and attack hostile creature within range */
ACTION_AUTOATTACK,
/**@}*/
// Long-term / special actions
/**@{*/
/** Open wait menu */
ACTION_WAIT,
/** Open crafting menu */
ACTION_CRAFT,
/** Repeat last craft command */
ACTION_RECRAFT,
/** Open batch crafting menu */
ACTION_LONGCRAFT,
/** Open construct menu */
ACTION_CONSTRUCT,
/** Open disassemble menu */
ACTION_DISASSEMBLE,
/** Open sleep menu */
ACTION_SLEEP,
/** Open vehicle control menu */
ACTION_CONTROL_VEHICLE,
/** Turn auto travel mode on/off */
ACTION_TOGGLE_AUTO_TRAVEL_MODE,
/** Turn safemode on/off, while leaving autosafemode intact */
ACTION_TOGGLE_SAFEMODE,
/** Turn automatic triggering of safemode on/off */
ACTION_TOGGLE_AUTOSAFE,
/** Toggle permanent attitude to stealing */
ACTION_TOGGLE_THIEF_MODE,
/** Ignore the enemy that triggered safemode */
ACTION_IGNORE_ENEMY,
/** Whitelist the enemy that triggered safemode */
ACTION_WHITELIST_ENEMY,
/** Save the game and quit */
ACTION_SAVE,
/** Quicksave the game */
ACTION_QUICKSAVE,
/** Quickload the game */
ACTION_QUICKLOAD,
/** Commit suicide */
ACTION_SUICIDE,
/**@}*/
// Info Screens
/**@{*/
/** Display player status screen */
ACTION_PL_INFO,
/** Display over-map */
ACTION_MAP,
/** Show sky state for trying to predict weather */
ACTION_SKY,
/** Display missions screen */
ACTION_MISSIONS,
/** Display scores screen */
ACTION_SCORES,
/** Display factions screen */
ACTION_FACTIONS,
/** Display morale effects screen */
ACTION_MORALE,
/** Display messages screen */
ACTION_MESSAGES,
/** Display help screen */
ACTION_HELP,
/** Display main menu */
ACTION_MAIN_MENU,
/** Display diary window */
ACTION_DIARY,
/** Display keybindings list */
ACTION_KEYBINDINGS,
/** Display options window */
ACTION_OPTIONS,
/** Open autopickup manager */
ACTION_AUTOPICKUP,
/** Open autonotes manager */
ACTION_AUTONOTES,
/** Open safemode manager */
ACTION_SAFEMODE,
/** Open color manager */
ACTION_COLOR,
/** Open active world mods */
ACTION_WORLD_MODS,
/** Open distraction manager */
ACTION_DISTRACTION_MANAGER,
/**@}*/
// Debug Functions
/**@{*/
/** Toggle full-screen mode */
ACTION_TOGGLE_FULLSCREEN,
/** Open debug menu */
ACTION_DEBUG,
/** Toggle scent map */
ACTION_DISPLAY_SCENT,
/** Toggle scent type map */
ACTION_DISPLAY_SCENT_TYPE,
/** Toggle debug mode */
ACTION_TOGGLE_DEBUG_MODE,
/** Zoom view in */
ACTION_ZOOM_OUT,
/** Zoom view out */
ACTION_ZOOM_IN,
/** Open the action menu */
ACTION_ACTIONMENU,
/** Open the item uses menu */
ACTION_ITEMACTION,
/** Turn pixel minimap on/off */
ACTION_TOGGLE_PIXEL_MINIMAP,
/** Turn admin panel on/off */
ACTION_TOGGLE_PANEL_ADM,
/** panels management */
ACTION_PANEL_MGMT,
/** Reload current tileset */
ACTION_RELOAD_TILESET,
/** Turn auto features on/off */
ACTION_TOGGLE_AUTO_FEATURES,
/** Change auto pulp/butcher mode */
ACTION_TOGGLE_AUTO_PULP_BUTCHER,
/** Turn auto mining on/off */
ACTION_TOGGLE_AUTO_MINING,
/** Turn auto foraging on/off */
ACTION_TOGGLE_AUTO_FORAGING,
/** Turn auto pickup on/off */
ACTION_TOGGLE_AUTO_PICKUP,
/** Toggle temperature map */
ACTION_DISPLAY_TEMPERATURE,
/** Toggle vehicle autopilot data */
ACTION_DISPLAY_VEHICLE_AI,
/** Toggle visibility map */
ACTION_DISPLAY_VISIBILITY,
/** Toggle lighting conditions map */
ACTION_DISPLAY_LIGHTING,
/** Toggle radiation map */
ACTION_DISPLAY_RADIATION,
/** Toggle transparency map */
ACTION_DISPLAY_TRANSPARENCY,
/** Toggle submap grid overlay */
ACTION_DISPLAY_SUBMAP_GRID,
/** Toggle timing of the game hours */
ACTION_TOGGLE_HOUR_TIMER,
/** Not an action, serves as count of enumerated actions */
NUM_ACTIONS
/**@}*/
};
/**
* Get list of keys bound to an action ID.
*
* Returns a vector of all keys currently bound to the given action. If not keys are bound to the
* given action then the returned vector is simply left empty.
*
* @param act Action ID to lookup in keymap
* @param restrict_to_printable If `true` the function returns the bound keys only if they are printable. If `false`, all keys (whether they are printable or not) are returned.
* @returns all keys (as characters) currently bound to a give action ID
*/
std::vector<char> keys_bound_to( action_id act, bool restrict_to_printable = true );
/**
* Get the key for an action, used in the action menu to give each action the hotkey it is bound to.
* @param action Action ID to lookup in keymap.
* @param restrict_to_printable If `true` the function returns the bound key only if it is printable. If `false`, any key (whether they it is printable or not) is returned.
* @returns the key code for the hotkey or -1 if no key is associated with the given action.
* @note We ignore bindings to '?' because that will already do something else in this menu (open the menu keybindings).
*/
int hotkey_for_action( action_id action, bool restrict_to_printable = true );
/**
* Lookup an action ID by its unique string identifier
*
* Translates a unique string identifier into an @ref action_id. This identifier is generally the
* value used in a keymap configuration file. If no corresponding action_id is found for this
* identifier then ACTION_NULL is returned instead.
*
* @param ident Unique string identifier corresponding to an @ref action_id
* @returns Corresponding action_id for the supplied string identifier
*/
action_id look_up_action( const std::string &ident );
/**
* Lookup a unique string identifier for a given action ID.
*
* Translates an @ref action_id into a unique string identifier. This is the value recorded in the
* keymap configuration file.
*
* @note The values we use here are more or less human-readable, but are not always suitable for
* display directly to the user.
*
* @param act The action ID to lookup an identifier for
* @returns The string identifier for the specified action ID.
*/
std::string action_ident( action_id act );
/**
* Lookup whether an action can affect the state of the game world.
*
* Looks an action ID up and determines if that action can change world state in any case. This
* is a static determination from a hard-coded list.
*
* This function can be used to count the number of user actions that actually affected the game
* state separate from other actions that only result in view and menu navigation. The only current
* example of this is @ref game::user_action_counter.
*
* @param act action ID to lookup in table
* @returns true if action has potential to alter world state, otherwise returns false.
*/
bool can_action_change_worldstate( action_id act );
/**
* Lookup the action ID assigned to a given key.
*
* Looks up a key by character and returns the @ref action_id currently mapped to that key. If no
* key is currently mapped then ACTION_NULL is returned instead
*
* @param ch The character corresponding to the key to look up
* @returns The action id of the specified key
*/
action_id action_from_key( char ch );
/**
* Request player input of adjacent tile, possibly including vertical tiles
*
* Asks the player to input desired direction of an adjacent tile, for example when executing
* an examine or directional item drop. This version of the function supports selection of tiles
* above and below the player if an appropriate flag is set.
*
* @param[in] message Message used in assembling the prompt to the player
* @param[in] allow_vertical Allows player to select tiles above/below them if true
*/
std::optional<tripoint> choose_adjacent( const std::string &message, bool allow_vertical = false );
/**
* Request player input of a direction, possibly including vertical component
*
* Asks the player to input a desired direction. This differs from @ref choose_adjacent in that
* the selected direction is returned as an offset to the player's current position rather than
* coordinate of a tile. This version of the function allows selection of the tile above and below
* the player if the appropriate flag is set.
*
* @param[in] message Message used in assembling the prompt to the player
* @param[in] allow_vertical Allows direction vector to have vertical component if true
*/
std::optional<tripoint> choose_direction( const std::string &message,
bool allow_vertical = false );
/**
* Request player input of adjacent tile with highlighting, possibly on different z-level
*
* Asks the player to input desired direction of an adjacent tile, for example when executing
* an examine or directional item drop. This version of the function allows the player to select
* a tile above or below.
*
* This function is identical to @ref choose_adjacent except that squares are highlighted for
* the player to indicate valid squares for a given @ref action_id
*
* @param[in] message Message used in assembling the prompt to the player
* @param[in] failure_message Message used if there is no vaild adjacent tile
* @param[in] action An action ID to drive the highlighting output
* @param[in] allow_vertical Allows direction vector to have vertical component if true
*/
std::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, action_id action, bool allow_vertical = false );
/**
* Request player input of adjacent tile with highlighting, possibly on different z-level
*
* Asks the player to input desired direction of an adjacent tile, for example when executing
* an examine or directional item drop. This version of the function allows the player to select
* a tile above or below.
*
* This function is identical to @ref choose_adjacent except that squares are highlighted for
* the player to indicate valid squares, based on the result of the provided @ref should_highlight
* function.
*
* @param[in] message Message used in assembling the prompt to the player
* @param[in] failure_message Message used if there is no vaild adjacent tile
* @param[in] allowed A function that will be called to determine if a given location is allowed for selection
* @param[in] allow_vertical Allows direction vector to have vertical component if true
*/
std::optional<tripoint> choose_adjacent_highlight( const std::string &message,
const std::string &failure_message, const std::function<bool( const tripoint & )> &allowed,
bool allow_vertical = false );
// (Press X (or Y)|Try) to Z
std::string press_x( action_id act );
std::string press_x( action_id act, const std::string &key_bound,
const std::string &key_unbound );
std::string press_x( action_id act, const std::string &key_bound_pre,
const std::string &key_bound_suf, const std::string &key_unbound );
// ('Z'ing|zing) (X( or Y)))
std::string press_x( action_id act, const std::string &act_desc );
// Return "Press X" or nullopt if not bound
std::optional<std::string> press_x_if_bound( action_id act );
// only has effect in iso mode
enum class iso_rotate {
no, yes
};
// Helper function to convert coordinate delta to a movement action
/**
* Translate coordinate delta into movement action
*
* For a given coordinate delta, this function returns the associated user movement action
* that would generated that delta. See @ref action_id for the list of available movement
* commands that may be generated. This function takes iso mode into account.
*
* The only valid values for the coordinates of \p d are -1, 0 and 1
*
* @note: This function does not sanitize its inputs, which can result in some strange behavior:
* 1. If d.z is valid and non-zero, then d.x and d.y are ignored.
* 2. If d.z is invalid, it is treated as if it were zero.
* 3. If d.z is 0 or invalid, then any invalid d.x or d.y results in @ref ACTION_MOVE_FORTH_LEFT
* 4. If d.z is 0 or invalid, then a d.x == d.y == 0 results in @ref ACTION_MOVE_FORTH_LEFT
*
* @param[in] d coordinate delta, each coordinate should be -1, 0, or 1
* @returns ID of corresponding move action (usually... see note above)
*/
action_id get_movement_action_from_delta( const tripoint &d, iso_rotate rot );
// Helper function to convert movement action to coordinate delta point
point get_delta_from_movement_action( action_id act, iso_rotate rot );
/**
* Show the action menu
*
* Prompts the user with the action menu, and returns any action requested by user input at
* that menu.
*
* @returns action_id ID of action requested by user at menu.
*/
action_id handle_action_menu();
/**
* Show in-game main menu
*
* Prompts the user with the main game menu, and returns any action requested by user input at
* that menu.
*
* @returns action_id ID of action requested by user at menu.
*/
action_id handle_main_menu();
/**
* Test whether it is possible to perform a given action.
*
* Checks whether we can interact with something using the specified action and the given tile.
*
* @note: This is part of a new API that will allow for a more robust user interface. Possible
* features include: Extending the "select a nearby tile" widget to highlight tiles that can be
* interacted with, "suggest" context-sensitive actions to the user that are currently relevant.
*
* @param action The action ID to perform the test for
* @param p Point to perform test at
* @returns true if movement is possible in the indicated direction
*/
bool can_interact_at( action_id action, const tripoint &p );
/**
* Test whether it is possible to perform butcher action
*
* Checks whether the butcher action makes sense at a given point. Checks for both corpses
* and items that can be disassembled.
*
* This is part of a new API that will allow for a more robust user interface. See the note in
* @ref can_interact_at()
*
* @param p Point to perform the test at
* @returns true if there is a corpse or item that can be disassembled at a point, otherwise false
*/
bool can_butcher_at( const tripoint &p );
/**
* Test whether vertical movement is possible
*
* Checks whether it is possible to perform up or down movement actions at this location, defined
* as whether it is possible to swim up/down at this location, or if there is an up or down
* staircase at this location.
*
* This is part of a new API that will allow for a more robust user interface. See the note in
* @ref can_interact_at()
*
* @param p Point to perform test at
* @param movez Direction to move. -1 for down, all other values for up
* @returns true if movement is possible in the indicated direction, otherwise false
*/
bool can_move_vertical_at( const tripoint &p, int movez );
/**
* Test whether examine is possible
*
* Checks whether the examine action makes sense at a given point.
*
* This is part of a new API that will allow for a more robust user interface. See the note in
* @ref can_interact_at()
*
* @param p Point to perform the test at
* @returns true if the examine action is possible at this point, otherwise false
*/
bool can_examine_at( const tripoint &p );
#endif // CATA_SRC_ACTION_H