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. */
96 
97  /* Store commands */
102 
103  /* Hors categorie Commands */
105 
109 } cmd_code;
110 
111 typedef enum cmd_context {
117 } cmd_context;
118 
128  const char *string;
129 
130  int choice;
131  struct object *obj;
132  int number;
134 
135  struct loc point;
136 };
137 
142  arg_NONE = 0,
150 };
151 
155 struct cmd_arg {
158  char name[20]; /* Better than dynamic allocation */
159 };
160 
161 
165 #define CMD_MAX_ARGS 4
166 
167 
168 
176 struct command {
177  /* What context this is happening in */
179 
180  /* A valid command code. */
182 
183  /* Number of times to attempt to repeat command. */
184  int nrepeats;
185 
186  /* Arguments */
187  struct cmd_arg arg[CMD_MAX_ARGS];
188 };
189 
190 
195  CMD_OK = 0,
199 };
200 
201 
206 typedef void (*cmd_handler_fn)(struct command *cmd);
207 
208 
214 /* Return the verb that goes alongside the given command. */
215 const char *cmd_verb(cmd_code cmd);
216 
217 
226 struct command *cmdq_peek(void);
227 
231 extern errr (*cmd_get_hook)(cmd_context c);
232 
236 bool cmdq_pop(cmd_context c);
237 
241 errr cmdq_push_copy(struct command *cmd);
244 
245 
249 void cmdq_execute(cmd_context ctx);
250 
254 void cmdq_flush(void);
255 
264 void cmd_cancel_repeat(void);
265 
269 void cmd_set_repeat(int nrepeats);
270 
275 void cmd_disable_repeat(void);
276 
281 int cmd_get_nrepeats(void);
282 
283 
284 
293 void cmd_set_arg_choice(struct command *cmd, const char *arg, int choice);
294 void cmd_set_arg_string(struct command *cmd, const char *arg, const char *str);
295 void cmd_set_arg_direction(struct command *cmd, const char *arg, int dir);
296 void cmd_set_arg_target(struct command *cmd, const char *arg, int target);
297 void cmd_set_arg_point(struct command *cmd, const char *arg, int x, int y);
298 void cmd_set_arg_item(struct command *cmd, const char *arg, struct object *obj);
299 void cmd_set_arg_number(struct command *cmd, const char *arg, int amt);
300 
301 
305 int cmd_get_arg_choice(struct command *cmd, const char *arg, int *choice);
306 int cmd_get_arg_string(struct command *cmd, const char *arg, const char **str);
307 int cmd_get_arg_direction(struct command *cmd, const char *arg, int *dir);
308 int cmd_get_arg_target(struct command *cmd, const char *arg, int *target);
309 int cmd_get_arg_point(struct command *cmd, const char *arg, int *x, int *y);
310 int cmd_get_arg_item(struct command *cmd, const char *arg, struct object **obj);
311 int cmd_get_arg_number(struct command *cmd, const char *arg, int *amt);
312 
316 int cmd_get_direction(struct command *cmd, const char *arg, int *dir,
317  bool allow_5);
318 int cmd_get_target(struct command *cmd, const char *arg, int *target);
319 int cmd_get_item(struct command *cmd, const char *arg, struct object **obj,
320  const char *prompt, const char *reject, item_tester filter,
321  int mode);
322 int cmd_get_quantity(struct command *cmd, const char *arg, int *amt, int max);
323 int cmd_get_string(struct command *cmd, const char *arg, const char **str,
324  const char *initial, const char *title, const char *prompt);
325 int cmd_get_spell(struct command *cmd, const char *arg, int *spell,
326  const char *verb, item_tester book_filter, const char *error,
327  bool (*spell_filter)(int spell));
328 
329 #endif
Definition: cmd-core.h:67
Definition: cmd-core.h:93
bool(* item_tester)(const struct object *)
Definition: object.h:513
Definition: cmd-core.h:114
Definition: cmd-core.h:80
Definition: cmd-core.h:41
int cmd_get_arg_number(struct command *cmd, const char *arg, int *amt)
Get argument 'n' as a number.
Definition: cmd-core.c:775
int choice
Definition: cmd-core.h:130
Definition: cmd-core.h:47
Definition: cmd-core.h:75
typedef void(PNGAPI *png_error_ptr) PNGARG((png_structp
Definition: cmd-core.h:144
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:630
Definition: cmd-core.h:112
void cmdq_execute(cmd_context ctx)
Process all commands presently in the queue.
Definition: cmd-core.c:304
The struct command type is used to return details of the command the game should carry out...
Definition: cmd-core.h:176
Definition: cmd-core.h:198
errr(* cmd_get_hook)(cmd_context c)
A function called by the game to get a command from the UI.
Definition: cmd-core.c:37
Definition: cmd-core.h:89
Definition: cmd-core.h:44
Definition: cmd-core.h:36
Definition: cmd-core.h:115
Definition: cmd-core.h:70
#define CMD_MAX_ARGS
Maximum number of arguments a command needs to take.
Definition: cmd-core.h:165
int cmd_get_direction(struct command *cmd, const char *arg, int *dir, bool allow_5)
Try a bit harder.
Definition: cmd-core.c:596
struct loc point
Definition: cmd-core.h:135
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:789
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:148
Definition: cmd-core.h:149
Definition: cmd-core.h:45
Definition: cmd-core.h:88
int errr
ANSI C headers.
Definition: h-basic.h:164
Definition: cmd-core.h:65
Definition: cmd-core.h:77
Definition: cmd-core.h:113
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:692
static const char * prompt
Definition: ui-object.c:592
cmd_code code
Definition: cmd-core.h:181
Definition: cmd-core.h:69
const char * cmd_verb(cmd_code cmd)
Command type functions
Definition: cmd-core.c:117
struct object * obj
Definition: cmd-core.h:131
Object information, for a specific object.
Definition: object.h:401
void cmd_set_arg_direction(struct command *cmd, const char *arg, int dir)
Directions
Definition: cmd-core.c:572
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:342
Definition: cmd-core.h:101
int cmd_get_arg_choice(struct command *cmd, const char *arg, int *choice)
Get the args of a command.
Definition: cmd-core.c:465
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:273
Definition: cmd-core.h:57
void cmd_cancel_repeat(void)
Command repeat manipulation
Definition: cmd-core.c:325
cmd_arg_type
The type of the data.
Definition: cmd-core.h:141
Definition: cmd-core.h:90
Definition: cmd-core.h:146
Definition: cmd-core.h:42
Definition: cmd-core.h:64
Definition: cmd-core.h:142
Definition: cmd-core.h:43
Definition: cmd-core.h:147
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:247
void cmd_set_arg_item(struct command *cmd, const char *arg, struct object *obj)
Item arguments
Definition: cmd-core.c:713
int direction
Definition: cmd-core.h:133
Definition: cmd-core.h:73
cmd_context
Definition: cmd-core.h:111
int nrepeats
Definition: cmd-core.h:184
Definition: cmd-core.h:94
Definition: cmd-core.h:107
Definition: cmd-core.h:108
Definition: cmd-core.h:59
void cmd_set_arg_choice(struct command *cmd, const char *arg, int choice)
Command type functions
Definition: cmd-core.c:455
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:682
cmd_code
All valid game commands.
Definition: cmd-core.h:29
const char * string
Definition: cmd-core.h:128
void cmd_set_arg_number(struct command *cmd, const char *arg, int amt)
Numbers, quantities
Definition: cmd-core.c:765
Definition: cmd-core.h:48
Definition: cmd-core.h:196
Support various data types.
int cmd_get_arg_string(struct command *cmd, const char *arg, const char **str)
Retrieve arg 'n' if a string.
Definition: cmd-core.c:525
A single argument.
Definition: cmd-core.h:155
cmd_context context
Definition: cmd-core.h:178
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:480
basic object structs and enums
errr cmdq_push_copy(struct command *cmd)
Insert commands in the queue.
Definition: cmd-core.c:166
Definition: cmd-core.h:83
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:737
Definition: cmd-core.h:95
Definition: cmd-core.h:100
Definition: cmd-core.h:58
Definition: cmd-core.h:92
Definition: cmd-core.h:66
Definition: cmd-core.h:76
int cmd_get_nrepeats(void)
Returns the number of repeats left for the current command.
Definition: cmd-core.c:357
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:582
void cmd_set_arg_string(struct command *cmd, const char *arg, const char *str)
Strings
Definition: cmd-core.c:515
errr cmdq_push(cmd_code c)
Inserts a command in the queue to be carried out.
Definition: cmd-core.c:294
Definition: cmd-core.h:197
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:539
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:206
Intialize random names
Definition: init.c:847
Definition: cmd-core.h:74
Definition: cmd-core.h:98
Definition: cmd-core.h:104
Definition: cmd-core.h:79
Definition: cmd-core.h:99
int number
Definition: cmd-core.h:132
Definition: cmd-core.h:195
Definition: cmd-core.h:51
Definition: cmd-core.h:145
void cmdq_flush(void)
Remove all commands from the queue.
Definition: cmd-core.c:312
Definition: cmd-core.h:116
Definition: cmd-core.h:106
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:654
Definition: cmd-core.h:68
Definition: cmd-core.h:143
Definition: cmd-core.h:60
Definition: target.h:39
Argument structures
Definition: cmd-core.h:127
struct command * cmdq_peek(void)
Command queue functions
Definition: cmd-core.c:157
int cmd_get_arg_item(struct command *cmd, const char *arg, struct object **obj)
Retrieve argument 'n' as an item.
Definition: cmd-core.c:723
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:640
void cmd_disable_repeat(void)
Call to disallow the current command from being repeated with the "Repeat last command" command...
Definition: cmd-core.c:367
cmd_return_codes
Return codes for cmd_get_arg()
Definition: cmd-core.h:194