Angband
Data Structures | Macros | Functions | Variables
cmd-core.c File Reference

Handles the queueing of game commands. More...

#include "angband.h"
#include "cmds.h"
#include "cmd-core.h"
#include "game-input.h"
#include "obj-chest.h"
#include "obj-desc.h"
#include "obj-tval.h"
#include "obj-util.h"
#include "player-attack.h"
#include "player-birth.h"
#include "player-spell.h"
#include "store.h"
#include "target.h"

Data Structures

struct  command_info
 
A simple list of commands and their handling functions. More...

Macros

#define CMD_QUEUE_SIZE   20
 
The command queue.
#define prev_cmd_idx(idx)   ((idx + CMD_QUEUE_SIZE - 1) % CMD_QUEUE_SIZE)

Functions

const char * cmd_verb (cmd_code cmd)
 

Command type functions


static int cmd_idx (cmd_code code)
 Return the index of the given command in the command array.
struct commandcmdq_peek (void)
 

Command queue functions


errr cmdq_push_copy (struct command *cmd)
 Insert the given command into the command queue.
void process_command (cmd_context ctx, struct command *cmd)
 Process a game command from the UI or the command queue and carry out whatever actions go along with it.
bool cmdq_pop (cmd_context c)
 Get the next game command from the queue and process it.
errr cmdq_push_repeat (cmd_code c, int nrepeats)
 Inserts a command in the queue to be carried out, with the given number of repeats.
errr cmdq_push (cmd_code c)
 Inserts a command in the queue to be carried out.
void cmdq_execute (cmd_context ctx)
 Shorthand to execute all commands in the queue right now, no waiting for input.
void cmd_cancel_repeat (void)
 

Handling of repeated commands


void cmd_set_repeat (int nrepeats)
 Update the number of repeats pending for the current command.
int cmd_get_nrepeats (void)
 Return the number of repeats pending for the current command.
void cmd_disable_repeat (void)
 Do not allow the current command to be repeated by the user using the "repeat last command" command.
static void cmd_set_arg (struct command *cmd, const char *name, enum cmd_arg_type type, union cmd_arg_data data)
 

Argument setting/getting generics


static int cmd_get_arg (struct command *cmd, const char *arg, enum cmd_arg_type type, union cmd_arg_data *data)
 Get an argument with name 'arg'.
void cmd_set_arg_choice (struct command *cmd, const char *arg, int choice)
 

'Choice' type


int cmd_get_arg_choice (struct command *cmd, const char *arg, int *choice)
 Retrive an argument 'n' if it's a choice.
int cmd_get_spell (struct command *cmd, const char *arg, int *spell, const char *verb, item_tester book_filter, const char *error, bool(*spell_filter)(int spell))
 Get a spell from the user, trying the command first but then prompting.
void cmd_set_arg_string (struct command *cmd, const char *arg, const char *str)
 

Strings


int cmd_get_arg_string (struct command *cmd, const char *arg, const char **str)
 Retrieve arg 'n' if a string.
int cmd_get_string (struct command *cmd, const char *arg, const char **str, const char *initial, const char *title, const char *prompt)
 Get a string, first from the command or failing that prompt the user.
void cmd_set_arg_direction (struct command *cmd, const char *arg, int dir)
 

Directions


int cmd_get_arg_direction (struct command *cmd, const char *arg, int *dir)
 Retrieve arg 'n' if a direction.
int cmd_get_direction (struct command *cmd, const char *arg, int *dir, bool allow_5)
 Get a direction, first from command or prompt otherwise.
void cmd_set_arg_target (struct command *cmd, const char *arg, int target)
 

Targets


int cmd_get_arg_target (struct command *cmd, const char *arg, int *target)
 Retrieve arg 'n' if it's a target.
int cmd_get_target (struct command *cmd, const char *arg, int *target)
 Get a target, first from command or prompt otherwise.
void cmd_set_arg_point (struct command *cmd, const char *arg, int x, int y)
 

Points (presently unused)


int cmd_get_arg_point (struct command *cmd, const char *arg, int *x, int *y)
 Retrieve argument 'n' if it's a point.
void cmd_set_arg_item (struct command *cmd, const char *arg, struct object *obj)
 

Item arguments


int cmd_get_arg_item (struct command *cmd, const char *arg, struct object **obj)
 Retrieve argument 'n' as an item.
int cmd_get_item (struct command *cmd, const char *arg, struct object **obj, const char *prompt, const char *reject, item_tester filter, int mode)
 Get an item, first from the command or try the UI otherwise.
void cmd_set_arg_number (struct command *cmd, const char *arg, int amt)
 

Numbers, quantities


int cmd_get_arg_number (struct command *cmd, const char *arg, int *amt)
 Get argument 'n' as a number.
int cmd_get_quantity (struct command *cmd, const char *arg, int *amt, int max)
 Get argument 'n' as a number; failing that, prompt for input.

Variables

errr(* cmd_get_hook )(cmd_context c)
 A function called by the game to get a command from the UI.
static struct command_info game_cmds []
static int cmd_head = 0
static int cmd_tail = 0
static struct command cmd_queue [CMD_QUEUE_SIZE]
static bool repeat_prev_allowed = FALSE
static bool repeating = FALSE

Detailed Description

Handles the queueing of game commands.

Copyright (c) 2008-9 Antony Sidwell Copyright (c) 2014 Andi Sidwell

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 CMD_QUEUE_SIZE   20


The command queue.


Referenced by cmdq_pop(), and cmdq_push_copy().

#define prev_cmd_idx (   idx)    ((idx + CMD_QUEUE_SIZE - 1) % CMD_QUEUE_SIZE)

Function Documentation

void cmd_cancel_repeat ( void  )


Handling of repeated commands


Command repeat manipulation

Remove any pending repeats from the current command.

References cmd_queue, cmd_tail, FALSE, command::nrepeats, PR_STATE, prev_cmd_idx, player_upkeep::redraw, repeating, and player::upkeep.

Referenced by cmd_get_direction(), and disturb().

void cmd_disable_repeat ( void  )

Do not allow the current command to be repeated by the user using the "repeat last command" command.

Call to disallow the current command from being repeated with the "Repeat last command" command.

References FALSE, and repeat_prev_allowed.

Referenced by combine_pack(), and gear_object_for_use().

static int cmd_get_arg ( struct command cmd,
const char *  arg,
enum cmd_arg_type  type,
union cmd_arg_data data 
)
static
int cmd_get_arg_choice ( struct command cmd,
const char *  arg,
int choice 
)

Retrive an argument 'n' if it's a choice.

Get the args of a command.

References arg_CHOICE, cmd_arg_data::choice, cmd_get_arg(), and CMD_OK.

Referenced by cmd_get_spell(), do_cmd_buy_stat(), do_cmd_choose_class(), do_cmd_choose_race(), do_cmd_reset_stats(), do_cmd_rest(), and do_cmd_sell_stat().

int cmd_get_arg_direction ( struct command cmd,
const char *  arg,
int dir 
)

Retrieve arg 'n' if a direction.

References arg_DIRECTION, cmd_get_arg(), CMD_OK, and cmd_arg_data::direction.

Referenced by cmd_get_direction(), do_cmd_close(), do_cmd_disarm(), and do_cmd_open().

int cmd_get_arg_item ( struct command cmd,
const char *  arg,
struct object **  obj 
)
int cmd_get_arg_number ( struct command cmd,
const char *  arg,
int amt 
)

Get argument 'n' as a number.

References arg_NUMBER, cmd_get_arg(), CMD_OK, and cmd_arg_data::number.

Referenced by cmd_get_quantity(), do_cmd_buy(), do_cmd_retrieve(), and do_cmd_sell().

int cmd_get_arg_point ( struct command cmd,
const char *  arg,
int x,
int y 
)

Retrieve argument 'n' if it's a point.

References arg_POINT, cmd_get_arg(), CMD_OK, cmd_arg_data::point, loc::x, and loc::y.

Referenced by do_cmd_pathfind().

int cmd_get_arg_string ( struct command cmd,
const char *  arg,
const char **  str 
)

Retrieve arg 'n' if a string.

References arg_STRING, cmd_get_arg(), CMD_OK, and cmd_arg_data::string.

Referenced by cmd_get_string(), do_cmd_choose_history(), and do_cmd_choose_name().

int cmd_get_arg_target ( struct command cmd,
const char *  arg,
int target 
)

Retrieve arg 'n' if it's a target.

References arg_TARGET, cmd_get_arg(), CMD_OK, and cmd_arg_data::direction.

Referenced by cmd_get_target().

int cmd_get_direction ( struct command cmd,
const char *  arg,
int dir,
bool  allow_5 
)
int cmd_get_item ( struct command cmd,
const char *  arg,
struct object **  obj,
const char *  prompt,
const char *  reject,
item_tester  filter,
int  mode 
)
int cmd_get_nrepeats ( void  )

Return the number of repeats pending for the current command.

Returns the number of repeats left for the current command.

References cmd_queue, cmd_tail, command::nrepeats, and prev_cmd_idx.

Referenced by check_for_player_interrupt(), move_player(), process_command(), process_player(), and prt_state().

int cmd_get_quantity ( struct command cmd,
const char *  arg,
int amt,
int  max 
)

Get argument 'n' as a number; failing that, prompt for input.

References CMD_ARG_ABORTED, cmd_get_arg_number(), CMD_OK, cmd_set_arg_number(), and get_quantity().

Referenced by do_cmd_drop(), and do_cmd_stash().

int cmd_get_spell ( struct command cmd,
const char *  arg,
int spell,
const char *  verb,
item_tester  book_filter,
const char *  error,
bool(*)(int spell)  spell_filter 
)

Get a spell from the user, trying the command first but then prompting.

References CMD_ARG_ABORTED, cmd_get_arg_choice(), cmd_get_arg_item(), CMD_OK, cmd_set_arg_choice(), command::code, get_spell(), get_spell_from_book(), and TRUE.

Referenced by do_cmd_cast(), and do_cmd_study_spell().

int cmd_get_string ( struct command cmd,
const char *  arg,
const char **  str,
const char *  initial,
const char *  title,
const char *  prompt 
)

Get a string, first from the command or failing that prompt the user.

References CMD_ARG_ABORTED, cmd_get_arg_string(), CMD_OK, cmd_set_arg_string(), EVENT_MESSAGE_FLUSH, event_signal(), get_string(), msg, and my_strcpy().

Referenced by do_cmd_inscribe().

int cmd_get_target ( struct command cmd,
const char *  arg,
int target 
)

Get a target, first from command or prompt otherwise.

References CMD_ARG_ABORTED, cmd_get_arg_target(), CMD_OK, cmd_set_arg_target(), DIR_TARGET, DIR_UNKNOWN, get_aim_dir(), and target_okay().

Referenced by do_cmd_cast(), do_cmd_fire(), do_cmd_throw(), and use_aux().

static int cmd_idx ( cmd_code  code)
static

Return the index of the given command in the command array.

References command_info::cmd, CMD_ARG_NOT_PRESENT, i, and N_ELEMENTS.

Referenced by cmdq_push_repeat(), and process_command().

static void cmd_set_arg ( struct command cmd,
const char *  name,
enum cmd_arg_type  type,
union cmd_arg_data  data 
)
static
void cmd_set_arg_choice ( struct command cmd,
const char *  arg,
int  choice 
)


'Choice' type


Command type functions

XXX This type is a hack. The only places that use this are:

  • resting
  • birth choices
  • store items
  • spells

Each of these should have its own type, which will allow for proper validity checking of data. Set arg 'n' to 'choice'

References arg_CHOICE, cmd_arg_data::choice, and cmd_set_arg().

Referenced by cmd_get_spell(), do_cmd_rest(), menu_question(), point_based_command(), test_magic_missile(), test_newgame(), and textui_cmd_rest().

void cmd_set_arg_direction ( struct command cmd,
const char *  arg,
int  dir 
)
void cmd_set_arg_item ( struct command cmd,
const char *  arg,
struct object obj 
)
void cmd_set_arg_number ( struct command cmd,
const char *  arg,
int  amt 
)
void cmd_set_arg_point ( struct command cmd,
const char *  arg,
int  x,
int  y 
)


Points (presently unused)

Set argument 'n' to point x,y

References arg_POINT, cmd_set_arg(), loc(), and cmd_arg_data::point.

Referenced by context_menu_cave(), target_set_interactive(), and textui_process_click().

void cmd_set_arg_string ( struct command cmd,
const char *  arg,
const char *  str 
)
void cmd_set_arg_target ( struct command cmd,
const char *  arg,
int  target 
)


Targets

XXX Should this be unified with the arg_DIRECTION type?

XXX Should we abolish DIR_TARGET and instead pass a struct target which contains all relevant info? Set arg 'n' to target

References arg_TARGET, cmd_set_arg(), and cmd_arg_data::direction.

Referenced by cmd_get_target(), context_menu_cave(), do_cmd_fire_at_nearest(), test_magic_missile(), and textui_process_click().

void cmd_set_repeat ( int  nrepeats)

Update the number of repeats pending for the current command.

References cmd_queue, cmd_tail, FALSE, command::nrepeats, PR_STATE, prev_cmd_idx, player_upkeep::redraw, repeating, TRUE, and player::upkeep.

Referenced by move_player(), and process_command().

const char* cmd_verb ( cmd_code  cmd)


Command type functions

References i, N_ELEMENTS, and command_info::verb.

Referenced by get_item_allow().

void cmdq_execute ( cmd_context  ctx)

Shorthand to execute all commands in the queue right now, no waiting for input.

Process all commands presently in the queue.

References cmdq_pop().

Referenced by test_magic_missile(), test_newgame(), test_prefs(), and textui_do_birth().

struct command* cmdq_peek ( void  )
read
bool cmdq_pop ( cmd_context  c)

Get the next game command from the queue and process it.

Gets the next command from the queue and processes it.

References cmd_head, cmd_queue, CMD_QUEUE_SIZE, cmd_tail, FALSE, prev_cmd_idx, process_command(), repeating, and TRUE.

Referenced by cmdq_execute(), process_player(), and store_menu_handle().

errr cmdq_push ( cmd_code  c)
errr cmdq_push_copy ( struct command cmd)

Insert the given command into the command queue.

Insert commands in the queue.

References cmd_head, CMD_NULL, cmd_queue, CMD_QUEUE_SIZE, CMD_REPEAT, cmd_tail, code, command::code, and repeat_prev_allowed.

Referenced by cmdq_push_repeat().

errr cmdq_push_repeat ( cmd_code  c,
int  nrepeats 
)

Inserts a command in the queue to be carried out, with the given number of repeats.

References cmd_idx(), cmdq_push_copy(), command::code, and command::nrepeats.

Referenced by cmdq_push(), store_process_command_key(), and textui_process_command().

void process_command ( cmd_context  ctx,
struct command cmd 
)

Process a game command from the UI or the command queue and carry out whatever actions go along with it.

References cmd_get_nrepeats(), cmd_idx(), cmd_set_repeat(), command::code, player_upkeep::command_wrk, command::context, FALSE, command_info::fn, command::nrepeats, repeat_prev_allowed, repeating, TRUE, and player::upkeep.

Referenced by cmdq_pop().

Variable Documentation

errr(* cmd_get_hook)(cmd_context c)

A function called by the game to get a command from the UI.

Referenced by main(), and play_game().

int cmd_head = 0
static

Referenced by cmdq_peek(), cmdq_pop(), and cmdq_push_copy().

struct command cmd_queue[CMD_QUEUE_SIZE]
static
int cmd_tail = 0
static
struct command_info game_cmds[]
static
bool repeat_prev_allowed = FALSE
static
bool repeating = FALSE
static