Angband
cmd-core.h
Go to the documentation of this file.
1 
20 #ifndef INCLUDED_CMD_CORE_H
21 #define INCLUDED_CMD_CORE_H
22 
23 #include "object.h"
24 #include "z-type.h"
25 
29 typedef enum cmd_code {
30  CMD_NULL = 0, /* A "do nothing" command so that there's something
31  UIs can use as a "no command yet" sentinel. */
32  /*
33  * Splash screen commands
34  */
37 
38  /*
39  * Birth commands
40  */
53 
54  /*
55  * The main game commands
56  */
62 
71  CMD_CAST, /* Casting a spell /or/ praying. */
95 
96  /* Store commands */
101 
102  /* Hors categorie Commands */
104 
107 } cmd_code;
108 
109 typedef enum cmd_context {
115 } cmd_context;
116 
117 enum {
119  DIR_NW = 7,
120  DIR_N = 8,
121  DIR_NE = 9,
122  DIR_W = 4,
124  DIR_NONE = 5,
125  DIR_E = 6,
126  DIR_SW = 1,
127  DIR_S = 2,
128  DIR_SE = 3,
129 };
130 
140  const char *string;
141 
142  int choice;
143  struct object *obj;
144  int number;
146 
147  struct loc point;
148 };
149 
154  arg_NONE = 0,
162 };
163 
167 struct cmd_arg {
170  char name[20]; /* Better than dynamic allocation */
171 };
172 
173 
177 #define CMD_MAX_ARGS 4
178 
179 
180 
188 struct command {
189  /* What context this is happening in */
191 
192  /* A valid command code. */
194 
195  /* Number of times to attempt to repeat command. */
196  int nrepeats;
197 
198  /* Arguments */
199  struct cmd_arg arg[CMD_MAX_ARGS];
200 };
201 
202 
207  CMD_OK = 0,
211 };
212 
213 
218 typedef void (*cmd_handler_fn)(struct command *cmd);
219 
220 
226 /* Return the verb that goes alongside the given command. */
227 const char *cmd_verb(cmd_code cmd);
228 
229 
238 struct command *cmdq_peek(void);
239 
243 extern errr (*cmd_get_hook)(cmd_context c);
244 
248 bool cmdq_pop(cmd_context c);
249 
253 errr cmdq_push_copy(struct command *cmd);
256 
257 
261 void cmdq_execute(cmd_context ctx);
262 
271 void cmd_cancel_repeat(void);
272 
276 void cmd_set_repeat(int nrepeats);
277 
282 void cmd_disable_repeat(void);
283 
288 int cmd_get_nrepeats(void);
289 
290 
291 
300 void cmd_set_arg_choice(struct command *cmd, const char *arg, int choice);
301 void cmd_set_arg_string(struct command *cmd, const char *arg, const char *str);
302 void cmd_set_arg_direction(struct command *cmd, const char *arg, int dir);
303 void cmd_set_arg_target(struct command *cmd, const char *arg, int target);
304 void cmd_set_arg_point(struct command *cmd, const char *arg, int x, int y);
305 void cmd_set_arg_item(struct command *cmd, const char *arg, struct object *obj);
306 void cmd_set_arg_number(struct command *cmd, const char *arg, int amt);
307 
308 
312 int cmd_get_arg_choice(struct command *cmd, const char *arg, int *choice);
313 int cmd_get_arg_string(struct command *cmd, const char *arg, const char **str);
314 int cmd_get_arg_direction(struct command *cmd, const char *arg, int *dir);
315 int cmd_get_arg_target(struct command *cmd, const char *arg, int *target);
316 int cmd_get_arg_point(struct command *cmd, const char *arg, int *x, int *y);
317 int cmd_get_arg_item(struct command *cmd, const char *arg, struct object **obj);
318 int cmd_get_arg_number(struct command *cmd, const char *arg, int *amt);
319 
323 int cmd_get_direction(struct command *cmd, const char *arg, int *dir,
324  bool allow_5);
325 int cmd_get_target(struct command *cmd, const char *arg, int *target);
326 int cmd_get_item(struct command *cmd, const char *arg, struct object **obj,
327  const char *prompt, const char *reject, item_tester filter,
328  int mode);
329 int cmd_get_quantity(struct command *cmd, const char *arg, int *amt, int max);
330 int cmd_get_string(struct command *cmd, const char *arg, const char **str,
331  const char *initial, const char *title, const char *prompt);
332 int cmd_get_spell(struct command *cmd, const char *arg, int *spell,
333  const char *verb, item_tester book_filter, const char *error,
334  bool (*spell_filter)(int spell));
335 
336 #endif
Definition: cmd-core.h:67
Definition: cmd-core.h:93
bool(* item_tester)(const struct object *)
Definition: object.h:508
Definition: cmd-core.h:80
Definition: cmd-core.h:41
Definition: cmd-core.h:127
int cmd_get_arg_number(struct command *cmd, const char *arg, int *amt)
Get argument 'n' as a number.
Definition: cmd-core.c:747
int choice
Definition: cmd-core.h:142
Definition: cmd-core.h:47
Definition: cmd-core.h:75
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
Definition: cmd-core.h:156
Definition: z-type.h:24
Definition: cmd-core.h:85
void cmd_set_arg_target(struct command *cmd, const char *arg, int target)
Targets
Definition: cmd-core.c:607
void cmdq_execute(cmd_context ctx)
Process all commands presently in the queue.
Definition: cmd-core.c:289
The struct command type is used to return details of the command the game should carry out...
Definition: cmd-core.h:188
Definition: cmd-core.h:210
errr(* cmd_get_hook)(cmd_context c)
A function called by the game to get a command from the UI.
Definition: cmd-core.c:35
Definition: cmd-core.h:89
Definition: cmd-core.h:44
Definition: cmd-core.h:36
Definition: cmd-core.h:70
#define CMD_MAX_ARGS
Maximum number of arguments a command needs to take.
Definition: cmd-core.h:177
int cmd_get_direction(struct command *cmd, const char *arg, int *dir, bool allow_5)
Try a bit harder.
Definition: cmd-core.c:573
struct loc point
Definition: cmd-core.h:147
Definition: cmd-core.h:91
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.
Definition: cmd-core.c:761
static term_data data[MAX_TERM_DATA]
Definition: main-nds.c:156
Definition: cmd-core.h:72
Definition: cmd-core.h:49
Definition: cmd-core.h:50
Definition: cmd-core.h:160
Definition: cmd-core.h:161
Definition: cmd-core.h:45
Definition: cmd-core.h:88
Definition: cmd-core.h:120
int errr
ANSI C headers.
Definition: h-basic.h:164
Definition: cmd-core.h:65
Definition: cmd-core.h:77
int cmd_get_arg_point(struct command *cmd, const char *arg, int *x, int *y)
Retrieve argument 'n' if it's a point.
Definition: cmd-core.c:669
static const char * prompt
Definition: ui-object.c:574
cmd_code code
Definition: cmd-core.h:193
Definition: cmd-core.h:69
const char * cmd_verb(cmd_code cmd)
Command type functions
Definition: cmd-core.c:112
struct object * obj
Definition: cmd-core.h:143
Object information, for a specific object.
Definition: object.h:394
void cmd_set_arg_direction(struct command *cmd, const char *arg, int dir)
Directions
Definition: cmd-core.c:549
Definition: cmd-core.h:63
void cmd_set_repeat(int nrepeats)
Update the number of repeats pending for the current command.
Definition: cmd-core.c:319
Definition: cmd-core.h:100
int cmd_get_arg_choice(struct command *cmd, const char *arg, int *choice)
Get the args of a command.
Definition: cmd-core.c:442
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.
Definition: cmd-core.c:258
Definition: cmd-core.h:57
void cmd_cancel_repeat(void)
Command repeat manipulation
Definition: cmd-core.c:302
cmd_arg_type
The type of the data.
Definition: cmd-core.h:153
Definition: cmd-core.h:112
Definition: cmd-core.h:90
Definition: cmd-core.h:158
Definition: cmd-core.h:42
Definition: cmd-core.h:64
Definition: cmd-core.h:154
Definition: cmd-core.h:43
Definition: cmd-core.h:159
Definition: cmd-core.h:61
int type
Definition: mon-msg.c:80
bool cmdq_pop(cmd_context c)
Gets the next command from the queue and processes it.
Definition: cmd-core.c:232
void cmd_set_arg_item(struct command *cmd, const char *arg, struct object *obj)
Item arguments
Definition: cmd-core.c:690
int direction
Definition: cmd-core.h:145
Definition: cmd-core.h:73
cmd_context
Definition: cmd-core.h:109
int nrepeats
Definition: cmd-core.h:196
Definition: cmd-core.h:110
Definition: cmd-core.h:106
Definition: cmd-core.h:59
Definition: cmd-core.h:113
void cmd_set_arg_choice(struct command *cmd, const char *arg, int choice)
Command type functions
Definition: cmd-core.c:432
Definition: cmd-core.h:52
void cmd_set_arg_point(struct command *cmd, const char *arg, int x, int y)
Points (presently unused)
Definition: cmd-core.c:659
Definition: cmd-core.h:124
cmd_code
All valid game commands.
Definition: cmd-core.h:29
const char * string
Definition: cmd-core.h:140
void cmd_set_arg_number(struct command *cmd, const char *arg, int amt)
Numbers, quantities
Definition: cmd-core.c:737
Definition: cmd-core.h:48
Definition: cmd-core.h:208
Definition: cmd-core.h:121
Support various data types.
Definition: cmd-core.h:111
int cmd_get_arg_string(struct command *cmd, const char *arg, const char **str)
Retrieve arg 'n' if a string.
Definition: cmd-core.c:502
A single argument.
Definition: cmd-core.h:167
cmd_context context
Definition: cmd-core.h:190
Definition: cmd-core.h:86
Definition: cmd-core.h:81
Definition: cmd-core.h:78
Definition: cmd-core.h:35
Definition: cmd-core.h:71
Definition: cmd-core.h:82
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.
Definition: cmd-core.c:457
Definition: cmd-core.h:119
basic object structs and enums
errr cmdq_push_copy(struct command *cmd)
Insert commands in the queue.
Definition: cmd-core.c:161
Definition: cmd-core.h:83
Definition: cmd-core.h:126
Definition: cmd-core.h:84
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.
Definition: cmd-core.c:714
Definition: cmd-core.h:94
Definition: cmd-core.h:99
Definition: cmd-core.h:58
Definition: cmd-core.h:92
Definition: cmd-core.h:125
Definition: cmd-core.h:66
Definition: cmd-core.h:76
Definition: cmd-core.h:114
int cmd_get_nrepeats(void)
Returns the number of repeats left for the current command.
Definition: cmd-core.c:334
Definition: cmd-core.h:46
int cmd_get_arg_direction(struct command *cmd, const char *arg, int *dir)
Retrieve arg 'n' if a direction.
Definition: cmd-core.c:559
void cmd_set_arg_string(struct command *cmd, const char *arg, const char *str)
Strings
Definition: cmd-core.c:492
errr cmdq_push(cmd_code c)
Inserts a command in the queue to be carried out.
Definition: cmd-core.c:279
Definition: cmd-core.h:209
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.
Definition: cmd-core.c:516
void(* cmd_handler_fn)(struct command *cmd)
Command handlers will take a pointer to the command structure so that they can access any arguments s...
Definition: cmd-core.h:218
Intialize random names
Definition: init.c:756
Definition: cmd-core.h:74
Definition: cmd-core.h:97
Definition: cmd-core.h:103
Definition: cmd-core.h:79
Definition: cmd-core.h:98
int number
Definition: cmd-core.h:144
Definition: cmd-core.h:207
Definition: cmd-core.h:51
Definition: cmd-core.h:118
Definition: cmd-core.h:157
Definition: cmd-core.h:105
Definition: cmd-core.h:30
int cmd_get_target(struct command *cmd, const char *arg, int *target)
Get a target, first from command or prompt otherwise.
Definition: cmd-core.c:631
Definition: cmd-core.h:68
Definition: cmd-core.h:155
Definition: cmd-core.h:60
Argument structures
Definition: cmd-core.h:139
struct command * cmdq_peek(void)
Command queue functions
Definition: cmd-core.c:152
int cmd_get_arg_item(struct command *cmd, const char *arg, struct object **obj)
Retrieve argument 'n' as an item.
Definition: cmd-core.c:700
Definition: cmd-core.h:87
int cmd_get_arg_target(struct command *cmd, const char *arg, int *target)
Retrieve arg 'n' if it's a target.
Definition: cmd-core.c:617
Definition: cmd-core.h:128
void cmd_disable_repeat(void)
Call to disallow the current command from being repeated with the "Repeat last command" command...
Definition: cmd-core.c:344
cmd_return_codes
Return codes for cmd_get_arg()
Definition: cmd-core.h:206
Definition: cmd-core.h:123
Definition: cmd-core.h:122