Macros | Functions | Variables
ui-game.c File Reference

Game management for the traditional text UI. More...

#include "angband.h"
#include "cmds.h"
#include "datafile.h"
#include "game-world.h"
#include "grafmode.h"
#include "init.h"
#include "mon-lore.h"
#include "mon-make.h"
#include "obj-knowledge.h"
#include "obj-util.h"
#include "player-attack.h"
#include "player-calcs.h"
#include "player-path.h"
#include "player-properties.h"
#include "player-util.h"
#include "savefile.h"
#include "target.h"
#include "ui-birth.h"
#include "ui-command.h"
#include "ui-context.h"
#include "ui-death.h"
#include "ui-display.h"
#include "ui-game.h"
#include "ui-help.h"
#include "ui-init.h"
#include "ui-input.h"
#include "ui-keymap.h"
#include "ui-knowledge.h"
#include "ui-map.h"
#include "ui-object.h"
#include "ui-output.h"
#include "ui-player.h"
#include "ui-prefs.h"
#include "ui-spell.h"
#include "ui-score.h"
#include "ui-signals.h"
#include "ui-store.h"
#include "ui-target.h"


#define KEYMAP_MAX   2


void cmd_init (void)
 Initialise the command list. More...
unsigned char cmd_lookup_key (cmd_code lookup_cmd, int mode)
unsigned char cmd_lookup_key_unktrl (cmd_code lookup_cmd, int mode)
cmd_code cmd_lookup (unsigned char key, int mode)
void textui_process_command (void)
 Parse and execute the current command Give "Warning" on illegal commands. More...
errr textui_get_cmd (cmd_context context)
void check_for_player_interrupt (game_event_type type, game_event_data *data, void *user)
 Allow for user abort during repeated commands, running and resting. More...
void pre_turn_refresh (void)
static void start_game (bool new_game)
 Start actually playing a game, either by loading a savefile or creating a new character. More...
void play_game (bool new_game)
 Play Angband. More...
void savefile_set_name (const char *fname, bool make_safe, bool strip_suffix)
 Set the savefile name. More...
void save_game (void)
 Save the game. More...
void close_game (void)
 Close up the current game (player may or may not be dead) More...


bool arg_wizard
char savefile [1024]
 Buffer to hold the current savefile name. More...
struct cmd_info cmd_item []
 Here are lists of commands, stored in this format so that they can be easily maniuplated for e.g. More...
struct cmd_info cmd_action []
 General actions. More...
struct cmd_info cmd_item_manage []
 Item management commands. More...
struct cmd_info cmd_info []
 Information access commands. More...
struct cmd_info cmd_util []
 Utility/assorted commands. More...
struct cmd_info cmd_hidden []
 Commands that shouldn't be shown to the user. More...
struct command_list cmds_all []
 List of command lists. More...
static struct cmd_infoconverted_list [KEYMAP_MAX][UCHAR_MAX+1]

Detailed Description

Game management for the traditional text UI.

Copyright (c) 1997 Ben Harrison, James E. Wilson, Robert A. Koeneke Copyright (c) 2015 Nick McConnell

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Macro Definition Documentation


#define KEYMAP_MAX   2

Function Documentation

◆ check_for_player_interrupt()

void check_for_player_interrupt ( game_event_type  type,
game_event_data data,
void user 

Allow for user abort during repeated commands, running and resting.

This will only check during every 128th game turn while resting.

References cmd_get_nrepeats(), disturb(), EVENT_INPUT_FLUSH, event_signal(), EVT_NONE, inkey_ex(), inkey_scan, msg, player_is_resting(), player_upkeep::running, SCAN_INSTANT, turn, ui_event::type, and player::upkeep.

Referenced by ui_enter_world(), and ui_leave_world().

◆ close_game()

void close_game ( void  )

Close up the current game (player may or may not be dead)

Note that the savefile is not saved until the tombstone is actually displayed and the player has a chance to examine the inventory and such. This allows cheating if the game is equipped with a "quit without save" method. XXX XXX XXX

References cave, keypress::code, deactivate_randart_file(), death_knowledge(), death_screen(), ESCAPE, EVENT_INPUT_FLUSH, EVENT_LEAVE_GAME, EVENT_LEAVE_WORLD, EVENT_MESSAGE_FLUSH, event_signal(), handle_stuff(), inkey(), player::is_dead, term::mapped_flag, msg, OPT, predict_score(), prt(), save_game(), savefile, savefile_save(), screen_save_depth, signals_handle_tstp(), signals_ignore_tstp(), Term, and wipe_mon_list().

Referenced by handle_signal_simple(), and play_game().

◆ cmd_init()

void cmd_init ( void  )

Initialise the command list.

References i, cmd_info::key, command_list::len, command_list::list, and N_ELEMENTS.

Referenced by setup_tests(), and textui_init().

◆ cmd_lookup()

cmd_code cmd_lookup ( unsigned char  key,
int  mode 

◆ cmd_lookup_key()

unsigned char cmd_lookup_key ( cmd_code  lookup_cmd,
int  mode 

◆ cmd_lookup_key_unktrl()

unsigned char cmd_lookup_key_unktrl ( cmd_code  lookup_cmd,
int  mode 

References cmd_lookup_key(), and UN_KTRL.

◆ play_game()

void play_game ( bool  new_game)

◆ pre_turn_refresh()

void pre_turn_refresh ( void  )

◆ save_game()

void save_game ( void  )

◆ savefile_set_name()

void savefile_set_name ( const char *  fname,
bool  make_safe,
bool  strip_suffix 

◆ start_game()

static void start_game ( bool  new_game)

◆ textui_get_cmd()

errr textui_get_cmd ( cmd_context  context)

References CTX_GAME, and textui_process_command().

Referenced by main().

◆ textui_process_command()

void textui_process_command ( void  )

Variable Documentation

◆ arg_wizard

bool arg_wizard

Referenced by main(), and start_game().

◆ cmd_action

struct cmd_info cmd_action[]
Initial value:
{ "Disarm a trap or chest", { 'D' }, CMD_DISARM, NULL, NULL },
{ "Rest for a while", { 'R' }, CMD_NULL, textui_cmd_rest, NULL },
{ "Look around", { 'l', 'x' }, CMD_NULL, do_cmd_look, NULL },
{ "Target monster or location", { '*' }, CMD_NULL, textui_target, NULL },
{ "Target closest monster", { '\'' }, CMD_NULL, textui_target_closest, NULL },
{ "Dig a tunnel", { 'T', KTRL('T') }, CMD_TUNNEL, NULL, NULL },
{ "Go up staircase", {'<' }, CMD_GO_UP, NULL, NULL },
{ "Go down staircase", { '>' }, CMD_GO_DOWN, NULL, NULL },
{ "Open a door or a chest", { 'o' }, CMD_OPEN, NULL, NULL },
{ "Close a door", { 'c' }, CMD_CLOSE, NULL, NULL },
{ "Fire at nearest target", { 'h', KC_TAB }, CMD_NULL, do_cmd_fire_at_nearest, NULL },
{ "Throw an item", { 'v' }, CMD_THROW, NULL, NULL },
{ "Walk into a trap", { 'W', '-' }, CMD_JUMP, NULL, NULL },
void do_cmd_fire_at_nearest(void)
Front-end command which fires at the nearest target with default ammo.
Definition: player-attack.c:1296
void textui_target(void)
Target command.
Definition: ui-target.c:742
void textui_target_closest(void)
Target closest monster.
Definition: ui-target.c:756
Definition: cmd-core.h:89
Definition: cmd-core.h:88
void textui_cmd_rest(void)
Get input for the rest command.
Definition: ui-command.c:227
Definition: cmd-core.h:57
Definition: cmd-core.h:90
#define KTRL(X)
Given a character X, turn it into a control character.
Definition: ui-event.h:94
Definition: cmd-core.h:86
Definition: cmd-core.h:82
#define KC_TAB
Definition: ui-event.h:139
Definition: cmd-core.h:58
void do_cmd_look(void)
Look command.
Definition: ui-knowledge.c:3051
Definition: cmd-core.h:30
Definition: cmd-core.h:60

General actions.

◆ cmd_hidden

struct cmd_info cmd_hidden[]
Initial value:
{ "Take notes", { ':' }, CMD_NULL, do_cmd_note, NULL },
{ "Version info", { 'V' }, CMD_NULL, do_cmd_version, NULL },
{ "Load a single pref line", { '"' }, CMD_NULL, do_cmd_pref, NULL },
{ "Toggle windows", { KTRL('E') }, CMD_NULL, toggle_inven_equip, NULL },
{ "Alter a grid", { '+' }, CMD_ALTER, NULL, NULL },
{ "Steal from a monster", { 's' }, CMD_STEAL, NULL, NULL },
{ "Walk", { ';' }, CMD_WALK, NULL, NULL },
{ "Start running", { '.', ',' }, CMD_RUN, NULL, NULL },
{ "Stand still", { ',', '.' }, CMD_HOLD, NULL, NULL },
{ "Center map", { KTRL('L'), '@' }, CMD_NULL, do_cmd_center_map, NULL },
{ "Toggle wizard mode", { KTRL('W') }, CMD_NULL, do_cmd_wizard, NULL },
{ "Repeat previous command", { 'n', KTRL('V') }, CMD_REPEAT, NULL, NULL },
{ "Do autopickup", { KTRL('G') }, CMD_AUTOPICKUP, NULL, NULL },
{ "Debug mode commands", { KTRL('A') }, CMD_NULL, textui_cmd_debug, NULL },
Definition: cmd-core.h:93
void textui_cmd_debug(void)
Verify use of "debug" mode.
Definition: ui-command.c:174
Definition: cmd-core.h:91
void do_cmd_pref(void)
Ask for a "user pref line" and process it.
Definition: ui-prefs.c:1457
Definition: cmd-core.h:94
Definition: cmd-core.h:107
Definition: cmd-core.h:59
void do_cmd_center_map(void)
Centers the map on the player.
Definition: ui-knowledge.c:3427
#define KTRL(X)
Given a character X, turn it into a control character.
Definition: ui-event.h:94
void do_cmd_version(void)
Print the version and copyright notice.
Definition: ui-command.c:155
Definition: cmd-core.h:84
void do_cmd_wizard(void)
Toggle wizard mode.
Definition: cmd-misc.c:37
Definition: cmd-core.h:92
void do_cmd_note(void)
Record the player&#39;s thoughts as a note.
Definition: cmd-misc.c:90
void toggle_inven_equip(void)
Flip "inven" and "equip" in any sub-windows.
Definition: ui-display.c:1481
Definition: cmd-core.h:30

Commands that shouldn't be shown to the user.

◆ cmd_info

struct cmd_info cmd_info[]
Initial value:
{ "Browse a book", { 'b', 'P' }, CMD_BROWSE_SPELL, textui_spell_browse, NULL },
{ "Gain new spells", { 'G' }, CMD_STUDY, NULL, player_can_study_prereq },
{ "View abilities", { 'S' }, CMD_NULL, do_cmd_abilities, NULL },
{ "Cast a spell", { 'm' }, CMD_CAST, NULL, player_can_cast_prereq },
{ "Cast a spell", { 'p' }, CMD_CAST, NULL, player_can_cast_prereq },
{ "Full dungeon map", { 'M' }, CMD_NULL, do_cmd_view_map, NULL },
{ "Toggle ignoring of items", { 'K', 'O' }, CMD_NULL, textui_cmd_toggle_ignore, NULL },
{ "Display visible item list", { ']' }, CMD_NULL, do_cmd_itemlist, NULL },
{ "Display visible monster list", { '[' }, CMD_NULL, do_cmd_monlist, NULL },
{ "Locate player on map", { 'L', 'W' }, CMD_NULL, do_cmd_locate, NULL },
{ "Help", { '?' }, CMD_NULL, do_cmd_help, NULL },
{ "Identify symbol", { '/' }, CMD_NULL, do_cmd_query_symbol, NULL },
{ "Character description", { 'C' }, CMD_NULL, do_cmd_change_name, NULL },
{ "Check knowledge", { '~' }, CMD_NULL, textui_browse_knowledge, NULL },
{ "Repeat level feeling", { KTRL('F') }, CMD_NULL, do_cmd_feeling, NULL },
{ "Show previous message", { KTRL('O') }, CMD_NULL, do_cmd_message_one, NULL },
{ "Show previous messages", { KTRL('P') }, CMD_NULL, do_cmd_messages, NULL }
void do_cmd_abilities(void)
Interact with abilities -BR-.
Definition: player-properties.c:216
Definition: cmd-core.h:70
void textui_cmd_toggle_ignore(void)
Definition: ui-object.c:1730
void do_cmd_query_symbol(void)
Identify a character, allow recall of monsters.
Definition: ui-knowledge.c:3267
Definition: cmd-core.h:69
void do_cmd_locate(void)
Allow the player to examine other sectors on the map.
Definition: ui-knowledge.c:3070
bool player_can_study_prereq(void)
Prerequiste function for command.
Definition: player-util.c:1024
void do_cmd_monlist(void)
Display the main-screen monster list.
Definition: ui-knowledge.c:3437
#define KTRL(X)
Given a character X, turn it into a control character.
Definition: ui-event.h:94
void do_cmd_feeling(void)
Definition: cmd-cave.c:1523
void textui_spell_browse(void)
Browse the given book.
Definition: ui-spell.c:274
Definition: cmd-core.h:71
void do_cmd_view_map(void)
Definition: ui-map.c:749
void textui_browse_knowledge(void)
Display the "player knowledge" menu, greying out items that won&#39;t display anything.
Definition: ui-knowledge.c:2657
void do_cmd_messages(void)
Show previous messages to the user.
Definition: ui-knowledge.c:2732
void do_cmd_itemlist(void)
Display the main-screen item list.
Definition: ui-knowledge.c:3452
void do_cmd_message_one(void)
Other knowledge functions
Definition: ui-knowledge.c:2710
void do_cmd_help(void)
Peruse the On-Line-Help.
Definition: ui-help.c:471
Definition: cmd-core.h:30
bool player_can_cast_prereq(void)
Prerequiste function for command.
Definition: player-util.c:1016
void do_cmd_change_name(void)
Hack – change name.
Definition: ui-player.c:1154

Information access commands.

◆ cmd_item

struct cmd_info cmd_item[]
Initial value:
{ "Inscribe an object", { '{' }, CMD_INSCRIBE, NULL, NULL },
{ "Uninscribe an object", { '}' }, CMD_UNINSCRIBE, NULL, NULL },
{ "Wear/wield an item", { 'w' }, CMD_WIELD, NULL, NULL },
{ "Take off/unwield an item", { 't', 'T'}, CMD_TAKEOFF, NULL, NULL },
{ "Examine an item", { 'I' }, CMD_NULL, textui_obj_examine, NULL },
{ "Drop an item", { 'd' }, CMD_DROP, NULL, NULL },
{ "Fire your missile weapon", { 'f', 't' }, CMD_FIRE, NULL, player_can_fire_prereq },
{ "Use a staff", { 'u', 'Z' }, CMD_USE_STAFF, NULL, NULL },
{ "Aim a wand", {'a', 'z'}, CMD_USE_WAND, NULL, NULL },
{ "Zap a rod", {'z', 'a'}, CMD_USE_ROD, NULL, NULL },
{ "Activate an object", {'A' }, CMD_ACTIVATE, NULL, NULL },
{ "Eat some food", { 'E' }, CMD_EAT, NULL, NULL },
{ "Quaff a potion", { 'q' }, CMD_QUAFF, NULL, NULL },
{ "Read a scroll", { 'r' }, CMD_READ_SCROLL, NULL, player_can_read_prereq },
{ "Fuel your light source", { 'F' }, CMD_REFILL, NULL, player_can_refuel_prereq },
{ "Use an item", { 'U', 'X' }, CMD_USE, NULL, NULL }
Definition: cmd-core.h:67
Definition: cmd-core.h:80
Definition: cmd-core.h:75
bool player_can_read_prereq(void)
Prerequiste function for command.
Definition: player-util.c:1032
void textui_obj_examine(void)
Examine an object.
Definition: ui-object.c:1561
Definition: cmd-core.h:72
Definition: cmd-core.h:77
bool player_can_refuel_prereq(void)
Prerequiste function for command.
Definition: player-util.c:1048
bool player_can_fire_prereq(void)
Prerequiste function for command.
Definition: player-util.c:1040
Definition: cmd-core.h:63
Definition: cmd-core.h:64
Definition: cmd-core.h:73
Definition: cmd-core.h:81
Definition: cmd-core.h:78
Definition: cmd-core.h:66
Definition: cmd-core.h:76
Definition: cmd-core.h:74
Definition: cmd-core.h:79
Definition: cmd-core.h:30
Definition: cmd-core.h:68

Here are lists of commands, stored in this format so that they can be easily maniuplated for e.g.

help displays, or if a port wants to provide a native menu containing a command list.

Consider a two-paned layout for the command menus. XXX Item commands

◆ cmd_item_manage

struct cmd_info cmd_item_manage[]
Initial value:
{ "Display equipment listing", { 'e' }, CMD_NULL, do_cmd_equip, NULL },
{ "Display inventory listing", { 'i' }, CMD_NULL, do_cmd_inven, NULL },
{ "Display quiver listing", { '|' }, CMD_NULL, do_cmd_quiver, NULL },
{ "Pick up objects", { 'g' }, CMD_PICKUP, NULL, NULL },
{ "Ignore an item", { 'k', KTRL('D') }, CMD_IGNORE, textui_cmd_ignore, NULL },
void textui_cmd_ignore(void)
Definition: ui-object.c:1716
Definition: cmd-core.h:85
void do_cmd_quiver(void)
Display equipment.
Definition: ui-knowledge.c:3003
void do_cmd_inven(void)
Display inventory.
Definition: ui-knowledge.c:2910
#define KTRL(X)
Given a character X, turn it into a control character.
Definition: ui-event.h:94
Definition: cmd-core.h:83
Definition: cmd-core.h:30
void do_cmd_equip(void)
Display equipment.
Definition: ui-knowledge.c:2955

Item management commands.

◆ cmd_util

struct cmd_info cmd_util[]
Initial value:
{ "Interact with options", { '=' }, CMD_NULL, do_cmd_xxx_options, NULL },
{ "Save and don't quit", { KTRL('S') }, CMD_NULL, save_game, NULL },
{ "Save and quit", { KTRL('X') }, CMD_NULL, textui_quit, NULL },
{ "Kill character and quit", { 'Q' }, CMD_NULL, textui_cmd_suicide, NULL },
{ "Redraw the screen", { KTRL('R') }, CMD_NULL, do_cmd_redraw, NULL },
{ "Save \"screen dump\"", { ')' }, CMD_NULL, do_cmd_save_screen, NULL }
void do_cmd_xxx_options(void)
Display the options and redraw afterward.
Definition: ui-command.c:136
void save_game(void)
Save the game.
Definition: ui-game.c:496
void textui_cmd_suicide(void)
Verify the suicide command.
Definition: ui-command.c:198
void do_cmd_save_screen(void)
Hack – save a screen dump to a file.
Definition: ui-command.c:512
#define KTRL(X)
Given a character X, turn it into a control character.
Definition: ui-event.h:94
Definition: cmd-core.h:30
void do_cmd_redraw(void)
Redraw the screen.
Definition: ui-command.c:65
void textui_quit(void)
Quit the game.
Definition: ui-command.c:264

Utility/assorted commands.

◆ cmds_all

struct command_list cmds_all[]
Initial value:
{ "Items", cmd_item, N_ELEMENTS(cmd_item) },
{ "Action commands", cmd_action, N_ELEMENTS(cmd_action) },
{ "Information", cmd_info, N_ELEMENTS(cmd_info) },
{ "Utility", cmd_util, N_ELEMENTS(cmd_util) },
{ "Hidden", cmd_hidden, N_ELEMENTS(cmd_hidden) },
{ NULL, NULL, 0 }
#define N_ELEMENTS(a)
Useful fairly generic macros
Definition: h-basic.h:206
struct cmd_info cmd_hidden[]
Commands that shouldn&#39;t be shown to the user.
Definition: ui-game.c:173
Holds a generic command - if cmd is set to other than CMD_NULL it simply pushes that command to the g...
Definition: ui-input.h:32
struct cmd_info cmd_item[]
Here are lists of commands, stored in this format so that they can be easily maniuplated for e...
Definition: ui-game.c:79
struct cmd_info cmd_item_manage[]
Item management commands.
Definition: ui-game.c:122
struct cmd_info cmd_info[]
Information access commands.
Definition: ui-game.c:134
struct cmd_info cmd_util[]
Utility/assorted commands.
Definition: ui-game.c:158
struct cmd_info cmd_action[]
General actions.
Definition: ui-game.c:102

List of command lists.

Referenced by cmd_list_action(), cmd_list_entry(), context_menu_command(), and textui_action_menu_choose().

◆ converted_list

struct cmd_info* converted_list[KEYMAP_MAX][UCHAR_MAX+1]

◆ savefile

char savefile[1024]