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

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

#include "angband.h"
#include "cmds.h"
#include "game-world.h"
#include "init.h"
#include "mon-lore.h"
#include "obj-util.h"
#include "player-attack.h"
#include "player-path.h"
#include "player-util.h"
#include "savefile.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-input.h"
#include "ui-keymap.h"
#include "ui-knowledge.h"
#include "ui-map.h"
#include "ui-obj.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"

Macros

#define KEYMAP_MAX   2

Functions

void cmd_init (void)
 Initialise the command list.
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.
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.
static void start_game (bool new_game)
 Start actually playing a game, either by loading a savefile or creating a new character.
void play_game (bool new_game)
 Play Angband.
void savefile_set_name (const char *fname)
 Set the savefile name.
void save_game (void)
 Save the game.
void close_game (void)
 Close up the current game (player may or may not be dead)

Variables

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

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_game(), and ui_leave_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 keypress::code, death_knowledge(), death_screen(), ESCAPE, EVENT_INPUT_FLUSH, EVENT_LEAVE_GAME, EVENT_MESSAGE_FLUSH, event_signal(), handle_stuff(), inkey(), player::is_dead, lore_save(), term::mapped_flag, msg, predict_score(), prt(), save_game(), savefile, savefile_save(), screen_save_depth, signals_handle_tstp(), signals_ignore_tstp(), Term, and player::upkeep.

Referenced by handle_signal_simple(), and play_game().

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_code cmd_lookup ( unsigned char  key,
int  mode 
)
unsigned char cmd_lookup_key ( cmd_code  lookup_cmd,
int  mode 
)
unsigned char cmd_lookup_key_unktrl ( cmd_code  lookup_cmd,
int  mode 
)

References cmd_lookup_key(), and UN_KTRL.

void play_game ( bool  new_game)
void save_game ( void  )
void savefile_set_name ( const char *  fname)

Set the savefile name.

References ANGBAND_DIR_SAVE, path, path_build(), player_uid, savefile, and strnfmt().

Referenced by main(), and ui_leave_birthscreen().

static void start_game ( bool  new_game)
static
errr textui_get_cmd ( cmd_context  context)

References CMD_GAME, and textui_process_command().

Referenced by main().

void textui_process_command ( void  )

Variable Documentation

bool arg_wizard

Referenced by main(), and start_game().

struct cmd_info cmd_action[]
Initial value:
{
{ "Search for traps/doors", { 's' }, CMD_SEARCH },
{ "Disarm a trap or chest", { 'D' }, CMD_DISARM },
{ "Rest for a while", { 'R' }, CMD_NULL, textui_cmd_rest },
{ "Look around", { 'l', 'x' }, CMD_NULL, do_cmd_look },
{ "Target monster or location", { '*' }, CMD_NULL, textui_target },
{ "Target closest monster", { '\'' }, CMD_NULL, textui_target_closest },
{ "Dig a tunnel", { 'T', KTRL('T') }, CMD_TUNNEL },
{ "Go up staircase", {'<' }, CMD_GO_UP },
{ "Go down staircase", { '>' }, CMD_GO_DOWN },
{ "Toggle search mode", { 'S', '#' }, CMD_TOGGLE_SEARCH },
{ "Open a door or a chest", { 'o' }, CMD_OPEN },
{ "Close a door", { 'c' }, CMD_CLOSE },
{ "Fire at nearest target", { 'h', KC_TAB }, CMD_NULL, do_cmd_fire_at_nearest },
{ "Throw an item", { 'v' }, CMD_THROW },
{ "Walk into a trap", { 'W', '-' }, CMD_JUMP, NULL },
}

General actions.

struct cmd_info cmd_hidden[]
Initial value:
{
{ "Take notes", { ':' }, CMD_NULL, do_cmd_note },
{ "Version info", { 'V' }, CMD_NULL, do_cmd_version },
{ "Load a single pref line", { '"' }, CMD_NULL, do_cmd_pref },
{ "Enter a store", { '_' }, CMD_NULL, textui_enter_store },
{ "Toggle windows", { KTRL('E') }, CMD_NULL, toggle_inven_equip },
{ "Alter a grid", { '+' }, CMD_ALTER, NULL },
{ "Walk", { ';' }, CMD_WALK, NULL },
{ "Start running", { '.', ',' }, CMD_RUN, NULL },
{ "Stand still", { ',', '.' }, CMD_HOLD, NULL },
{ "Center map", { KTRL('L'), '@' }, CMD_NULL, do_cmd_center_map },
{ "Toggle wizard mode", { KTRL('W') }, CMD_NULL, do_cmd_wizard },
{ "Repeat previous command", { 'n', KTRL('V') }, CMD_REPEAT, NULL },
{ "Do autopickup", { KTRL('G') }, CMD_AUTOPICKUP, NULL },
{ "Debug mode commands", { KTRL('A') }, CMD_NULL, textui_cmd_debug },
}

Commands that shouldn't be shown to the user.

struct cmd_info cmd_info[]
Initial value:
{
{ "Browse a book", { 'b', 'P' }, CMD_BROWSE_SPELL, textui_spell_browse },
{ "Gain new spells", { 'G' }, CMD_STUDY, NULL, player_can_study_prereq },
{ "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 },
{ "Toggle ignoring of items", { 'K', 'O' }, CMD_NULL, textui_cmd_toggle_ignore },
{ "Display visible item list", { ']' }, CMD_NULL, do_cmd_itemlist },
{ "Display visible monster list", { '[' }, CMD_NULL, do_cmd_monlist },
{ "Locate player on map", { 'L', 'W' }, CMD_NULL, do_cmd_locate },
{ "Help", { '?' }, CMD_NULL, do_cmd_help },
{ "Identify symbol", { '/' }, CMD_NULL, do_cmd_query_symbol },
{ "Character description", { 'C' }, CMD_NULL, do_cmd_change_name },
{ "Check knowledge", { '~' }, CMD_NULL, textui_browse_knowledge },
{ "Repeat level feeling", { KTRL('F') }, CMD_NULL, do_cmd_feeling },
{ "Show previous message", { KTRL('O') }, CMD_NULL, do_cmd_message_one },
{ "Show previous messages", { KTRL('P') }, CMD_NULL, do_cmd_messages }
}

Information access commands.

struct cmd_info cmd_item[]
Initial value:
{
{ "Inscribe an object", { '{' }, CMD_INSCRIBE },
{ "Uninscribe an object", { '}' }, CMD_UNINSCRIBE },
{ "Wear/wield an item", { 'w' }, CMD_WIELD },
{ "Take off/unwield an item", { 't', 'T'}, CMD_TAKEOFF },
{ "Examine an item", { 'I' }, CMD_NULL, textui_obj_examine },
{ "Drop an item", { 'd' }, CMD_DROP },
{ "Fire your missile weapon", { 'f', 't' }, CMD_FIRE, NULL, player_can_fire_prereq },
{ "Use a staff", { 'u', 'Z' }, CMD_USE_STAFF },
{ "Aim a wand", {'a', 'z'}, CMD_USE_WAND },
{ "Zap a rod", {'z', 'a'}, CMD_USE_ROD },
{ "Activate an object", {'A' }, CMD_ACTIVATE },
{ "Eat some food", { 'E' }, CMD_EAT },
{ "Quaff a potion", { 'q' }, CMD_QUAFF },
{ "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 }
}

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

struct cmd_info cmd_item_manage[]
Initial value:
{
{ "Display equipment listing", { 'e' }, CMD_NULL, do_cmd_equip },
{ "Display inventory listing", { 'i' }, CMD_NULL, do_cmd_inven },
{ "Pick up objects", { 'g' }, CMD_PICKUP, NULL },
{ "Ignore an item", { 'k', KTRL('D') }, CMD_IGNORE, textui_cmd_ignore },
}

Item management commands.

struct cmd_info cmd_util[]
Initial value:
{
{ "Interact with options", { '=' }, CMD_NULL, do_cmd_xxx_options },
{ "Save and don't quit", { KTRL('S') }, CMD_NULL, save_game },
{ "Save and quit", { KTRL('X') }, CMD_NULL, textui_quit },
{ "Quit (commit suicide)", { 'Q' }, CMD_NULL, textui_cmd_suicide },
{ "Redraw the screen", { KTRL('R') }, CMD_NULL, do_cmd_redraw },
{ "Load \"screen dump\"", { '(' }, CMD_NULL, do_cmd_load_screen },
{ "Save \"screen dump\"", { ')' }, CMD_NULL, do_cmd_save_screen }
}

Utility/assorted commands.

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) },
{ 0 }
}

List of command lists.

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

struct cmd_info* converted_list[KEYMAP_MAX][UCHAR_MAX+1]
static
char savefile[1024]