Angband
Data Structures | Macros | Typedefs | Enumerations | Functions | Variables
cmd-core.h File Reference

Handles the queueing of game commands. More...

#include "object.h"
#include "z-type.h"

Go to the source code of this file.

Data Structures

union  cmd_arg_data
 

Argument structures

More...
struct  cmd_arg
 A single argument. More...
struct  command
 The struct command type is used to return details of the command the game should carry out. More...

Macros

#define CMD_MAX_ARGS   4
 Maximum number of arguments a command needs to take.

Typedefs

typedef enum cmd_code cmd_code
 All valid game commands.
typedef enum cmd_context cmd_context
typedef void(* cmd_handler_fn )(struct command *cmd)
 Command handlers will take a pointer to the command structure so that they can access any arguments supplied.

Enumerations

enum  cmd_code {
  CMD_NULL = 0, CMD_LOADFILE, CMD_NEWGAME, CMD_BIRTH_INIT,
  CMD_BIRTH_RESET, CMD_CHOOSE_RACE, CMD_CHOOSE_CLASS, CMD_BUY_STAT,
  CMD_SELL_STAT, CMD_RESET_STATS, CMD_ROLL_STATS, CMD_PREV_STATS,
  CMD_NAME_CHOICE, CMD_HISTORY_CHOICE, CMD_ACCEPT_CHARACTER, CMD_GO_UP,
  CMD_GO_DOWN, CMD_SEARCH, CMD_TOGGLE_SEARCH, CMD_WALK,
  CMD_JUMP, CMD_PATHFIND, CMD_INSCRIBE, CMD_UNINSCRIBE,
  CMD_AUTOINSCRIBE, CMD_TAKEOFF, CMD_WIELD, CMD_DROP,
  CMD_BROWSE_SPELL, CMD_STUDY, CMD_CAST, CMD_USE_STAFF,
  CMD_USE_WAND, CMD_USE_ROD, CMD_ACTIVATE, CMD_EAT,
  CMD_QUAFF, CMD_READ_SCROLL, CMD_REFILL, CMD_USE,
  CMD_FIRE, CMD_THROW, CMD_PICKUP, CMD_AUTOPICKUP,
  CMD_IGNORE, CMD_DISARM, CMD_REST, CMD_TUNNEL,
  CMD_OPEN, CMD_CLOSE, CMD_RUN, CMD_HOLD,
  CMD_ALTER, CMD_SLEEP, CMD_SELL, CMD_BUY,
  CMD_STASH, CMD_RETRIEVE, CMD_SUICIDE, CMD_HELP,
  CMD_REPEAT
}
 All valid game commands. More...
enum  cmd_context {
  CMD_INIT, CMD_BIRTH, CMD_GAME, CMD_STORE,
  CMD_DEATH
}
enum  {
  DIR_UNKNOWN = 0, DIR_NW = 7, DIR_N = 8, DIR_NE = 9,
  DIR_W = 4, DIR_TARGET = 5, DIR_NONE = 5, DIR_E = 6,
  DIR_SW = 1, DIR_S = 2, DIR_SE = 3
}
enum  cmd_arg_type {
  arg_NONE = 0, arg_STRING = 1, arg_CHOICE, arg_ITEM,
  arg_NUMBER, arg_DIRECTION, arg_TARGET, arg_POINT
}
 The type of the data. More...
enum  cmd_return_codes { CMD_OK = 0, CMD_ARG_NOT_PRESENT = -1, CMD_ARG_WRONG_TYPE = -2, CMD_ARG_ABORTED = -3 }
 Return codes for cmd_get_arg() More...

Functions

const char * cmd_verb (cmd_code cmd)
 

Command type functions


struct commandcmdq_peek (void)
 

Command queue functions


bool cmdq_pop (cmd_context c)
 Gets the next command from the queue and processes it.
errr cmdq_push_copy (struct command *cmd)
 Insert commands in the queue.
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)
 Process all commands presently in the queue.
void cmd_cancel_repeat (void)
 

Command repeat manipulation


void cmd_set_repeat (int nrepeats)
 Update the number of repeats pending for the current command.
void cmd_disable_repeat (void)
 Call to disallow the current command from being repeated with the "Repeat last command" command.
int cmd_get_nrepeats (void)
 Returns the number of repeats left for the current command.
void cmd_set_arg_choice (struct command *cmd, const char *arg, int choice)
 

Command type functions


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

Strings


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

Directions


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

Targets


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

Points (presently unused)


void cmd_set_arg_item (struct command *cmd, const char *arg, struct object *obj)
 

Item arguments


void cmd_set_arg_number (struct command *cmd, const char *arg, int amt)
 

Numbers, quantities


int cmd_get_arg_choice (struct command *cmd, const char *arg, int *choice)
 Get the args of a command.
int cmd_get_arg_string (struct command *cmd, const char *arg, const char **str)
 Retrieve arg 'n' if a string.
int cmd_get_arg_direction (struct command *cmd, const char *arg, int *dir)
 Retrieve arg 'n' if a direction.
int cmd_get_arg_target (struct command *cmd, const char *arg, int *target)
 Retrieve arg 'n' if it's a target.
int cmd_get_arg_point (struct command *cmd, const char *arg, int *x, int *y)
 Retrieve argument 'n' if it's a point.
int cmd_get_arg_item (struct command *cmd, const char *arg, struct object **obj)
 Retrieve argument 'n' as an item.
int cmd_get_arg_number (struct command *cmd, const char *arg, int *amt)
 Get argument 'n' as a number.
int cmd_get_direction (struct command *cmd, const char *arg, int *dir, bool allow_5)
 Try a bit harder.
int cmd_get_target (struct command *cmd, const char *arg, int *target)
 Get a target, first from command or prompt otherwise.
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.
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.
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.
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.

Variables

errr(* cmd_get_hook )(cmd_context c)
 A function called by the game to get a command from the UI.

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_MAX_ARGS   4

Maximum number of arguments a command needs to take.

Referenced by cmd_get_arg(), and cmd_set_arg().

Typedef Documentation

typedef enum cmd_code cmd_code

All valid game commands.

Not all implemented yet.

typedef enum cmd_context cmd_context
typedef void(* cmd_handler_fn)(struct command *cmd)

Command handlers will take a pointer to the command structure so that they can access any arguments supplied.

Enumeration Type Documentation

anonymous enum
Enumerator:
DIR_UNKNOWN 
DIR_NW 
DIR_N 
DIR_NE 
DIR_W 
DIR_TARGET 
DIR_NONE 
DIR_E 
DIR_SW 
DIR_S 
DIR_SE 

The type of the data.

Enumerator:
arg_NONE 
arg_STRING 
arg_CHOICE 
arg_ITEM 
arg_NUMBER 
arg_DIRECTION 
arg_TARGET 
arg_POINT 
enum cmd_code

All valid game commands.

Not all implemented yet.

Enumerator:
CMD_NULL 
CMD_LOADFILE 
CMD_NEWGAME 
CMD_BIRTH_INIT 
CMD_BIRTH_RESET 
CMD_CHOOSE_RACE 
CMD_CHOOSE_CLASS 
CMD_BUY_STAT 
CMD_SELL_STAT 
CMD_RESET_STATS 
CMD_ROLL_STATS 
CMD_PREV_STATS 
CMD_NAME_CHOICE 
CMD_HISTORY_CHOICE 
CMD_ACCEPT_CHARACTER 
CMD_GO_UP 
CMD_GO_DOWN 
CMD_SEARCH 
CMD_TOGGLE_SEARCH 
CMD_WALK 
CMD_JUMP 
CMD_PATHFIND 
CMD_INSCRIBE 
CMD_UNINSCRIBE 
CMD_AUTOINSCRIBE 
CMD_TAKEOFF 
CMD_WIELD 
CMD_DROP 
CMD_BROWSE_SPELL 
CMD_STUDY 
CMD_CAST 
CMD_USE_STAFF 
CMD_USE_WAND 
CMD_USE_ROD 
CMD_ACTIVATE 
CMD_EAT 
CMD_QUAFF 
CMD_READ_SCROLL 
CMD_REFILL 
CMD_USE 
CMD_FIRE 
CMD_THROW 
CMD_PICKUP 
CMD_AUTOPICKUP 
CMD_IGNORE 
CMD_DISARM 
CMD_REST 
CMD_TUNNEL 
CMD_OPEN 
CMD_CLOSE 
CMD_RUN 
CMD_HOLD 
CMD_ALTER 
CMD_SLEEP 
CMD_SELL 
CMD_BUY 
CMD_STASH 
CMD_RETRIEVE 
CMD_SUICIDE 
CMD_HELP 
CMD_REPEAT 
Enumerator:
CMD_INIT 
CMD_BIRTH 
CMD_GAME 
CMD_STORE 
CMD_DEATH 

Return codes for cmd_get_arg()

Enumerator:
CMD_OK 
CMD_ARG_NOT_PRESENT 
CMD_ARG_WRONG_TYPE 
CMD_ARG_ABORTED 

Function Documentation

void cmd_cancel_repeat ( void  )


Command repeat manipulation

Remove any pending repeats from the current command.


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  )

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().

int cmd_get_arg_choice ( struct command cmd,
const char *  arg,
int choice 
)
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  )

Returns the number of repeats left for the current command.

i.e. zero if not repeating.

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().

void cmd_set_arg_choice ( struct command cmd,
const char *  arg,
int  choice 
)


Command type functions

Set the args of a command.


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)

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)

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 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().

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().