chiark / gitweb /
Use a proper union in struct config_item.
[sgt-puzzles.git] / puzzles.h
1 /*
2  * puzzles.h: header file for my puzzle collection
3  */
4
5 #ifndef PUZZLES_PUZZLES_H
6 #define PUZZLES_PUZZLES_H
7
8 #include <stdio.h>  /* for FILE */
9 #include <stdlib.h> /* for size_t */
10 #include <limits.h> /* for UINT_MAX */
11
12 #ifndef TRUE
13 #define TRUE 1
14 #endif
15 #ifndef FALSE
16 #define FALSE 0
17 #endif
18
19 #define PI 3.141592653589793238462643383279502884197169399
20
21 #define lenof(array) ( sizeof(array) / sizeof(*(array)) )
22
23 #define STR_INT(x) #x
24 #define STR(x) STR_INT(x)
25
26 /* NB not perfect because they evaluate arguments multiple times. */
27 #ifndef max
28 #define max(x,y) ( (x)>(y) ? (x) : (y) )
29 #endif /* max */
30 #ifndef min
31 #define min(x,y) ( (x)<(y) ? (x) : (y) )
32 #endif /* min */
33
34 enum {
35     LEFT_BUTTON = 0x0200,
36     MIDDLE_BUTTON,
37     RIGHT_BUTTON,
38     LEFT_DRAG,
39     MIDDLE_DRAG,
40     RIGHT_DRAG,
41     LEFT_RELEASE,
42     MIDDLE_RELEASE,
43     RIGHT_RELEASE,
44     CURSOR_UP,
45     CURSOR_DOWN,
46     CURSOR_LEFT,
47     CURSOR_RIGHT,
48     CURSOR_SELECT,
49     CURSOR_SELECT2,
50     /* UI_* are special keystrokes generated by front ends in response
51      * to menu actions, never passed to back ends */
52     UI_LOWER_BOUND,
53     UI_QUIT,
54     UI_NEWGAME,
55     UI_SOLVE,
56     UI_UNDO,
57     UI_REDO,
58     UI_UPPER_BOUND,
59     
60     /* made smaller because of 'limited range of datatype' errors. */
61     MOD_CTRL       = 0x1000,
62     MOD_SHFT       = 0x2000,
63     MOD_NUM_KEYPAD = 0x4000,
64     MOD_MASK       = 0x7000 /* mask for all modifiers */
65 };
66
67 #define IS_MOUSE_DOWN(m) ( (unsigned)((m) - LEFT_BUTTON) <= \
68                                (unsigned)(RIGHT_BUTTON - LEFT_BUTTON))
69 #define IS_MOUSE_DRAG(m) ( (unsigned)((m) - LEFT_DRAG) <= \
70                                (unsigned)(RIGHT_DRAG - LEFT_DRAG))
71 #define IS_MOUSE_RELEASE(m) ( (unsigned)((m) - LEFT_RELEASE) <= \
72                                (unsigned)(RIGHT_RELEASE - LEFT_RELEASE))
73 #define IS_CURSOR_MOVE(m) ( (m) == CURSOR_UP || (m) == CURSOR_DOWN || \
74                             (m) == CURSOR_RIGHT || (m) == CURSOR_LEFT )
75 #define IS_CURSOR_SELECT(m) ( (m) == CURSOR_SELECT || (m) == CURSOR_SELECT2)
76 #define IS_UI_FAKE_KEY(m) ( (m) > UI_LOWER_BOUND && (m) < UI_UPPER_BOUND )
77
78 /*
79  * Flags in the back end's `flags' word.
80  */
81 /* Bit flags indicating mouse button priorities */
82 #define BUTTON_BEATS(x,y) ( 1 << (((x)-LEFT_BUTTON)*3+(y)-LEFT_BUTTON) )
83 /* Flag indicating that Solve operations should be animated */
84 #define SOLVE_ANIMATES ( 1 << 9 )
85 /* Pocket PC: Game requires right mouse button emulation */
86 #define REQUIRE_RBUTTON ( 1 << 10 )
87 /* Pocket PC: Game requires numeric input */
88 #define REQUIRE_NUMPAD ( 1 << 11 )
89 /* end of `flags' word definitions */
90
91 #ifdef _WIN32_WCE
92   /* Pocket PC devices have small, portrait screen that requires more vivid colours */
93   #define SMALL_SCREEN
94   #define PORTRAIT_SCREEN
95   #define VIVID_COLOURS
96   #define STYLUS_BASED
97 #endif
98
99 #define IGNOREARG(x) ( (x) = (x) )
100
101 typedef struct frontend frontend;
102 typedef struct config_item config_item;
103 typedef struct midend midend;
104 typedef struct random_state random_state;
105 typedef struct game_params game_params;
106 typedef struct game_state game_state;
107 typedef struct game_ui game_ui;
108 typedef struct game_drawstate game_drawstate;
109 typedef struct game game;
110 typedef struct blitter blitter;
111 typedef struct document document;
112 typedef struct drawing_api drawing_api;
113 typedef struct drawing drawing;
114 typedef struct psdata psdata;
115
116 #define ALIGN_VNORMAL 0x000
117 #define ALIGN_VCENTRE 0x100
118
119 #define ALIGN_HLEFT   0x000
120 #define ALIGN_HCENTRE 0x001
121 #define ALIGN_HRIGHT  0x002
122
123 #define FONT_FIXED    0
124 #define FONT_VARIABLE 1
125
126 /* For printing colours */
127 #define HATCH_SLASH     1
128 #define HATCH_BACKSLASH 2
129 #define HATCH_HORIZ     3
130 #define HATCH_VERT      4
131 #define HATCH_PLUS      5
132 #define HATCH_X         6
133
134 /*
135  * Structure used to pass configuration data between frontend and
136  * game
137  */
138 enum { C_STRING, C_CHOICES, C_BOOLEAN, C_END };
139 struct config_item {
140     /* Not dynamically allocated */
141     const char *name;
142     /* Value from the above C_* enum */
143     int type;
144     union {
145         struct { /* if type == C_STRING */
146             /* Always dynamically allocated and non-NULL */
147             char *sval;
148         } string;
149         struct { /* if type == C_CHOICES */
150             /*
151              * choicenames is non-NULL, not dynamically allocated, and
152              * contains a set of option strings separated by a
153              * delimiter. The delimiter is also the first character in
154              * the string, so for example ":Foo:Bar:Baz" gives three
155              * options `Foo', `Bar' and `Baz'.
156              */
157             const char *choicenames;
158             /*
159              * Indicates the chosen index from the options in
160              * choicenames. In the above example, 0==Foo, 1==Bar and
161              * 2==Baz.
162              */
163             int selected;
164         } choices;
165         struct {
166             /* just TRUE or FALSE */
167             int bval;
168         } boolean;
169     } u;
170 };
171
172 /*
173  * Structure used to communicate the presets menu from midend to
174  * frontend. In principle, it's also used to pass the same information
175  * from game to midend, though games that don't specify a menu
176  * hierarchy (i.e. most of them) will use the simpler fetch_preset()
177  * function to return an unstructured list.
178  *
179  * A tree of these structures always belongs to the midend, and only
180  * the midend should ever need to free it. The front end should treat
181  * them as read-only.
182  */
183 struct preset_menu_entry {
184     char *title;
185     /* Exactly one of the next two fields is NULL, depending on
186      * whether this entry is a submenu title or an actual preset */
187     game_params *params;
188     struct preset_menu *submenu;
189     /* Every preset menu entry has a number allocated by the mid-end,
190      * so that midend_which_preset() can return a value that
191      * identifies an entry anywhere in the menu hierarchy. The values
192      * will be allocated reasonably densely from 1 upwards (so it's
193      * reasonable for the front end to use them as array indices if it
194      * needs to store GUI state per menu entry), but no other
195      * guarantee is given about their ordering.
196      *
197      * Entries containing submenus have ids too - not only the actual
198      * presets are numbered. */
199     int id;
200 };
201 struct preset_menu {
202     int n_entries;             /* number of entries actually in use */
203     int entries_size;          /* space currently allocated in this array */
204     struct preset_menu_entry *entries;
205 };
206 /* For games which do want to directly return a tree of these, here
207  * are convenience routines (in midend.c) for constructing one. These
208  * assume that 'title' and 'encoded_params' are already dynamically
209  * allocated by the caller; the resulting preset_menu tree takes
210  * ownership of them. */
211 struct preset_menu *preset_menu_new(void);
212 struct preset_menu *preset_menu_add_submenu(struct preset_menu *parent,
213                                             char *title);
214 void preset_menu_add_preset(struct preset_menu *menu,
215                             char *title, game_params *params);
216 /* Helper routine front ends can use for one of the ways they might
217  * want to organise their preset menu usage */
218 game_params *preset_menu_lookup_by_id(struct preset_menu *menu, int id);
219
220 /*
221  * Platform routines
222  */
223
224 /* We can't use #ifdef DEBUG, because Cygwin defines it by default. */
225 #ifdef DEBUGGING
226 #define debug(x) (debug_printf x)
227 void debug_printf(char *fmt, ...);
228 #else
229 #define debug(x)
230 #endif
231
232 void fatal(char *fmt, ...);
233 void frontend_default_colour(frontend *fe, float *output);
234 void deactivate_timer(frontend *fe);
235 void activate_timer(frontend *fe);
236 void get_random_seed(void **randseed, int *randseedsize);
237
238 /*
239  * drawing.c
240  */
241 drawing *drawing_new(const drawing_api *api, midend *me, void *handle);
242 void drawing_free(drawing *dr);
243 void draw_text(drawing *dr, int x, int y, int fonttype, int fontsize,
244                int align, int colour, char *text);
245 void draw_rect(drawing *dr, int x, int y, int w, int h, int colour);
246 void draw_line(drawing *dr, int x1, int y1, int x2, int y2, int colour);
247 void draw_polygon(drawing *dr, int *coords, int npoints,
248                   int fillcolour, int outlinecolour);
249 void draw_circle(drawing *dr, int cx, int cy, int radius,
250                  int fillcolour, int outlinecolour);
251 void draw_thick_line(drawing *dr, float thickness,
252                      float x1, float y1, float x2, float y2, int colour);
253 void clip(drawing *dr, int x, int y, int w, int h);
254 void unclip(drawing *dr);
255 void start_draw(drawing *dr);
256 void draw_update(drawing *dr, int x, int y, int w, int h);
257 void end_draw(drawing *dr);
258 char *text_fallback(drawing *dr, const char *const *strings, int nstrings);
259 void status_bar(drawing *dr, char *text);
260 blitter *blitter_new(drawing *dr, int w, int h);
261 void blitter_free(drawing *dr, blitter *bl);
262 /* save puts the portion of the current display with top-left corner
263  * (x,y) to the blitter. load puts it back again to the specified
264  * coords, or else wherever it was saved from
265  * (if x = y = BLITTER_FROMSAVED). */
266 void blitter_save(drawing *dr, blitter *bl, int x, int y);
267 #define BLITTER_FROMSAVED (-1)
268 void blitter_load(drawing *dr, blitter *bl, int x, int y);
269 void print_begin_doc(drawing *dr, int pages);
270 void print_begin_page(drawing *dr, int number);
271 void print_begin_puzzle(drawing *dr, float xm, float xc,
272                         float ym, float yc, int pw, int ph, float wmm,
273                         float scale);
274 void print_end_puzzle(drawing *dr);
275 void print_end_page(drawing *dr, int number);
276 void print_end_doc(drawing *dr);
277 void print_get_colour(drawing *dr, int colour, int printing_in_colour,
278                       int *hatch, float *r, float *g, float *b);
279 int print_mono_colour(drawing *dr, int grey); /* 0==black, 1==white */
280 int print_grey_colour(drawing *dr, float grey);
281 int print_hatched_colour(drawing *dr, int hatch);
282 int print_rgb_mono_colour(drawing *dr, float r, float g, float b, int mono);
283 int print_rgb_grey_colour(drawing *dr, float r, float g, float b, float grey);
284 int print_rgb_hatched_colour(drawing *dr, float r, float g, float b,
285                              int hatch);
286 void print_line_width(drawing *dr, int width);
287 void print_line_dotted(drawing *dr, int dotted);
288
289 /*
290  * midend.c
291  */
292 midend *midend_new(frontend *fe, const game *ourgame,
293                    const drawing_api *drapi, void *drhandle);
294 void midend_free(midend *me);
295 const game *midend_which_game(midend *me);
296 void midend_set_params(midend *me, game_params *params);
297 game_params *midend_get_params(midend *me);
298 void midend_size(midend *me, int *x, int *y, int user_size);
299 void midend_reset_tilesize(midend *me);
300 void midend_new_game(midend *me);
301 void midend_restart_game(midend *me);
302 void midend_stop_anim(midend *me);
303 int midend_process_key(midend *me, int x, int y, int button);
304 void midend_force_redraw(midend *me);
305 void midend_redraw(midend *me);
306 float *midend_colours(midend *me, int *ncolours);
307 void midend_freeze_timer(midend *me, float tprop);
308 void midend_timer(midend *me, float tplus);
309 struct preset_menu *midend_get_presets(midend *me, int *id_limit);
310 int midend_which_preset(midend *me);
311 int midend_wants_statusbar(midend *me);
312 enum { CFG_SETTINGS, CFG_SEED, CFG_DESC, CFG_FRONTEND_SPECIFIC };
313 config_item *midend_get_config(midend *me, int which, char **wintitle);
314 char *midend_set_config(midend *me, int which, config_item *cfg);
315 char *midend_game_id(midend *me, char *id);
316 char *midend_get_game_id(midend *me);
317 char *midend_get_random_seed(midend *me);
318 int midend_can_format_as_text_now(midend *me);
319 char *midend_text_format(midend *me);
320 char *midend_solve(midend *me);
321 int midend_status(midend *me);
322 int midend_can_undo(midend *me);
323 int midend_can_redo(midend *me);
324 void midend_supersede_game_desc(midend *me, char *desc, char *privdesc);
325 char *midend_rewrite_statusbar(midend *me, char *text);
326 void midend_serialise(midend *me,
327                       void (*write)(void *ctx, void *buf, int len),
328                       void *wctx);
329 char *midend_deserialise(midend *me,
330                          int (*read)(void *ctx, void *buf, int len),
331                          void *rctx);
332 char *identify_game(char **name, int (*read)(void *ctx, void *buf, int len),
333                     void *rctx);
334 void midend_request_id_changes(midend *me, void (*notify)(void *), void *ctx);
335 /* Printing functions supplied by the mid-end */
336 char *midend_print_puzzle(midend *me, document *doc, int with_soln);
337 int midend_tilesize(midend *me);
338
339 /*
340  * malloc.c
341  */
342 void *smalloc(size_t size);
343 void *srealloc(void *p, size_t size);
344 void sfree(void *p);
345 char *dupstr(const char *s);
346 #define snew(type) \
347     ( (type *) smalloc (sizeof (type)) )
348 #define snewn(number, type) \
349     ( (type *) smalloc ((number) * sizeof (type)) )
350 #define sresize(array, number, type) \
351     ( (type *) srealloc ((array), (number) * sizeof (type)) )
352
353 /*
354  * misc.c
355  */
356 void free_cfg(config_item *cfg);
357 void obfuscate_bitmap(unsigned char *bmp, int bits, int decode);
358
359 /* allocates output each time. len is always in bytes of binary data.
360  * May assert (or just go wrong) if lengths are unchecked. */
361 char *bin2hex(const unsigned char *in, int inlen);
362 unsigned char *hex2bin(const char *in, int outlen);
363
364 /* Sets (and possibly dims) background from frontend default colour,
365  * and auto-generates highlight and lowlight colours too. */
366 void game_mkhighlight(frontend *fe, float *ret,
367                       int background, int highlight, int lowlight);
368 /* As above, but starts from a provided background colour rather
369  * than the frontend default. */
370 void game_mkhighlight_specific(frontend *fe, float *ret,
371                                int background, int highlight, int lowlight);
372
373 /* Randomly shuffles an array of items. */
374 void shuffle(void *array, int nelts, int eltsize, random_state *rs);
375
376 /* Draw a rectangle outline, using the drawing API's draw_line. */
377 void draw_rect_outline(drawing *dr, int x, int y, int w, int h,
378                        int colour);
379
380 /* Draw a set of rectangle corners (e.g. for a cursor display). */
381 void draw_rect_corners(drawing *dr, int cx, int cy, int r, int col);
382
383 void move_cursor(int button, int *x, int *y, int maxw, int maxh, int wrap);
384
385 /* Used in netslide.c and sixteen.c for cursor movement around edge. */
386 int c2pos(int w, int h, int cx, int cy);
387 int c2diff(int w, int h, int cx, int cy, int button);
388 void pos2c(int w, int h, int pos, int *cx, int *cy);
389
390 /* Draws text with an 'outline' formed by offsetting the text
391  * by one pixel; useful for highlighting. Outline is omitted if -1. */
392 void draw_text_outline(drawing *dr, int x, int y, int fonttype,
393                        int fontsize, int align,
394                        int text_colour, int outline_colour, char *text);
395
396 /* Copies text left-justified with spaces. Length of string must be
397  * less than buffer size. */
398 void copy_left_justified(char *buf, size_t sz, const char *str);
399
400 /*
401  * dsf.c
402  */
403 int *snew_dsf(int size);
404
405 void print_dsf(int *dsf, int size);
406
407 /* Return the canonical element of the equivalence class containing element
408  * val.  If 'inverse' is non-NULL, this function will put into it a flag
409  * indicating whether the canonical element is inverse to val. */
410 int edsf_canonify(int *dsf, int val, int *inverse);
411 int dsf_canonify(int *dsf, int val);
412 int dsf_size(int *dsf, int val);
413
414 /* Allow the caller to specify that two elements should be in the same
415  * equivalence class.  If 'inverse' is TRUE, the elements are actually opposite
416  * to one another in some sense.  This function will fail an assertion if the
417  * caller gives it self-contradictory data, ie if two elements are claimed to
418  * be both opposite and non-opposite. */
419 void edsf_merge(int *dsf, int v1, int v2, int inverse);
420 void dsf_merge(int *dsf, int v1, int v2);
421 void dsf_init(int *dsf, int len);
422
423 /*
424  * tdq.c
425  */
426
427 /*
428  * Data structure implementing a 'to-do queue', a simple
429  * de-duplicating to-do list mechanism.
430  *
431  * Specification: a tdq is a queue which can hold integers from 0 to
432  * n-1, where n was some constant specified at tdq creation time. No
433  * integer may appear in the queue's current contents more than once;
434  * an attempt to add an already-present integer again will do nothing,
435  * so that that integer is removed from the queue at the position
436  * where it was _first_ inserted. The add and remove operations take
437  * constant time.
438  *
439  * The idea is that you might use this in applications like solvers:
440  * keep a tdq listing the indices of grid squares that you currently
441  * need to process in some way. Whenever you modify a square in a way
442  * that will require you to re-scan its neighbours, add them to the
443  * list with tdq_add; meanwhile you're constantly taking elements off
444  * the list when you need another square to process. In solvers where
445  * deductions are mostly localised, this should prevent repeated
446  * O(N^2) loops over the whole grid looking for something to do. (But
447  * if only _most_ of the deductions are localised, then you should
448  * respond to an empty to-do list by re-adding everything using
449  * tdq_fill, so _then_ you rescan the whole grid looking for newly
450  * enabled non-local deductions. Only if you've done that and emptied
451  * the list again finding nothing new to do are you actually done.)
452  */
453 typedef struct tdq tdq;
454 tdq *tdq_new(int n);
455 void tdq_free(tdq *tdq);
456 void tdq_add(tdq *tdq, int k);
457 int tdq_remove(tdq *tdq);        /* returns -1 if nothing available */
458 void tdq_fill(tdq *tdq);         /* add everything to the tdq at once */
459
460 /*
461  * laydomino.c
462  */
463 int *domino_layout(int w, int h, random_state *rs);
464 void domino_layout_prealloc(int w, int h, random_state *rs,
465                             int *grid, int *grid2, int *list);
466 /*
467  * version.c
468  */
469 extern char ver[];
470
471 /*
472  * random.c
473  */
474 random_state *random_new(const char *seed, int len);
475 random_state *random_copy(random_state *tocopy);
476 unsigned long random_bits(random_state *state, int bits);
477 unsigned long random_upto(random_state *state, unsigned long limit);
478 void random_free(random_state *state);
479 char *random_state_encode(random_state *state);
480 random_state *random_state_decode(const char *input);
481 /* random.c also exports SHA, which occasionally comes in useful. */
482 #if __STDC_VERSION__ >= 199901L
483 #include <stdint.h>
484 typedef uint32_t uint32;
485 #elif UINT_MAX >= 4294967295L
486 typedef unsigned int uint32;
487 #else
488 typedef unsigned long uint32;
489 #endif
490 typedef struct {
491     uint32 h[5];
492     unsigned char block[64];
493     int blkused;
494     uint32 lenhi, lenlo;
495 } SHA_State;
496 void SHA_Init(SHA_State *s);
497 void SHA_Bytes(SHA_State *s, const void *p, int len);
498 void SHA_Final(SHA_State *s, unsigned char *output);
499 void SHA_Simple(const void *p, int len, unsigned char *output);
500
501 /*
502  * printing.c
503  */
504 document *document_new(int pw, int ph, float userscale);
505 void document_free(document *doc);
506 void document_add_puzzle(document *doc, const game *game, game_params *par,
507                          game_state *st, game_state *st2);
508 void document_print(document *doc, drawing *dr);
509
510 /*
511  * ps.c
512  */
513 psdata *ps_init(FILE *outfile, int colour);
514 void ps_free(psdata *ps);
515 drawing *ps_drawing_api(psdata *ps);
516
517 /*
518  * combi.c: provides a structure and functions for iterating over
519  * combinations (i.e. choosing r things out of n).
520  */
521 typedef struct _combi_ctx {
522   int r, n, nleft, total;
523   int *a;
524 } combi_ctx;
525
526 combi_ctx *new_combi(int r, int n);
527 void reset_combi(combi_ctx *combi);
528 combi_ctx *next_combi(combi_ctx *combi); /* returns NULL for end */
529 void free_combi(combi_ctx *combi);
530
531 /*
532  * divvy.c
533  */
534 /* divides w*h rectangle into pieces of size k. Returns w*h dsf. */
535 int *divvy_rectangle(int w, int h, int k, random_state *rs);
536
537 /*
538  * findloop.c
539  */
540 struct findloopstate;
541 struct findloopstate *findloop_new_state(int nvertices);
542 void findloop_free_state(struct findloopstate *);
543 /*
544  * Callback provided by the client code to enumerate the graph
545  * vertices joined directly to a given vertex.
546  *
547  * Semantics: if vertex >= 0, return one of its neighbours; if vertex
548  * < 0, return a previously unmentioned neighbour of whatever vertex
549  * was last passed as input. Write to 'ctx' as necessary to store
550  * state. In either case, return < 0 if no such vertex can be found.
551  */
552 typedef int (*neighbour_fn_t)(int vertex, void *ctx);
553 /*
554  * Actual function to find loops. 'ctx' will be passed unchanged to
555  * the 'neighbour' function to query graph edges. Returns FALSE if no
556  * loop was found, or TRUE if one was.
557  */
558 int findloop_run(struct findloopstate *state, int nvertices,
559                  neighbour_fn_t neighbour, void *ctx);
560 /*
561  * Query whether an edge is part of a loop, in the output of
562  * find_loops.
563  *
564  * Due to the internal storage format, if you pass u,v which are not
565  * connected at all, the output will be TRUE. (The algorithm actually
566  * stores an exhaustive list of *non*-loop edges, because there are
567  * fewer of those, so really it's querying whether the edge is on that
568  * list.)
569  */
570 int findloop_is_loop_edge(struct findloopstate *state, int u, int v);
571
572 /*
573  * Data structure containing the function calls and data specific
574  * to a particular game. This is enclosed in a data structure so
575  * that a particular platform can choose, if it wishes, to compile
576  * all the games into a single combined executable rather than
577  * having lots of little ones.
578  */
579 struct game {
580     const char *name;
581     const char *winhelp_topic, *htmlhelp_topic;
582     game_params *(*default_params)(void);
583     int (*fetch_preset)(int i, char **name, game_params **params);
584     struct preset_menu *(*preset_menu)(void);
585     void (*decode_params)(game_params *, char const *string);
586     char *(*encode_params)(const game_params *, int full);
587     void (*free_params)(game_params *params);
588     game_params *(*dup_params)(const game_params *params);
589     int can_configure;
590     config_item *(*configure)(const game_params *params);
591     game_params *(*custom_params)(const config_item *cfg);
592     char *(*validate_params)(const game_params *params, int full);
593     char *(*new_desc)(const game_params *params, random_state *rs,
594                       char **aux, int interactive);
595     char *(*validate_desc)(const game_params *params, const char *desc);
596     game_state *(*new_game)(midend *me, const game_params *params,
597                             const char *desc);
598     game_state *(*dup_game)(const game_state *state);
599     void (*free_game)(game_state *state);
600     int can_solve;
601     char *(*solve)(const game_state *orig, const game_state *curr,
602                    const char *aux, char **error);
603     int can_format_as_text_ever;
604     int (*can_format_as_text_now)(const game_params *params);
605     char *(*text_format)(const game_state *state);
606     game_ui *(*new_ui)(const game_state *state);
607     void (*free_ui)(game_ui *ui);
608     char *(*encode_ui)(const game_ui *ui);
609     void (*decode_ui)(game_ui *ui, const char *encoding);
610     void (*changed_state)(game_ui *ui, const game_state *oldstate,
611                           const game_state *newstate);
612     char *(*interpret_move)(const game_state *state, game_ui *ui,
613                             const game_drawstate *ds, int x, int y, int button);
614     game_state *(*execute_move)(const game_state *state, const char *move);
615     int preferred_tilesize;
616     void (*compute_size)(const game_params *params, int tilesize,
617                          int *x, int *y);
618     void (*set_size)(drawing *dr, game_drawstate *ds,
619                      const game_params *params, int tilesize);
620     float *(*colours)(frontend *fe, int *ncolours);
621     game_drawstate *(*new_drawstate)(drawing *dr, const game_state *state);
622     void (*free_drawstate)(drawing *dr, game_drawstate *ds);
623     void (*redraw)(drawing *dr, game_drawstate *ds, const game_state *oldstate,
624                    const game_state *newstate, int dir, const game_ui *ui,
625                    float anim_time, float flash_time);
626     float (*anim_length)(const game_state *oldstate,
627                          const game_state *newstate, int dir, game_ui *ui);
628     float (*flash_length)(const game_state *oldstate,
629                           const game_state *newstate, int dir, game_ui *ui);
630     int (*status)(const game_state *state);
631     int can_print, can_print_in_colour;
632     void (*print_size)(const game_params *params, float *x, float *y);
633     void (*print)(drawing *dr, const game_state *state, int tilesize);
634     int wants_statusbar;
635     int is_timed;
636     int (*timing_state)(const game_state *state, game_ui *ui);
637     int flags;
638 };
639
640 /*
641  * Data structure containing the drawing API implemented by the
642  * front end and also by cross-platform printing modules such as
643  * PostScript.
644  */
645 struct drawing_api {
646     void (*draw_text)(void *handle, int x, int y, int fonttype, int fontsize,
647                       int align, int colour, char *text);
648     void (*draw_rect)(void *handle, int x, int y, int w, int h, int colour);
649     void (*draw_line)(void *handle, int x1, int y1, int x2, int y2,
650                       int colour);
651     void (*draw_polygon)(void *handle, int *coords, int npoints,
652                          int fillcolour, int outlinecolour);
653     void (*draw_circle)(void *handle, int cx, int cy, int radius,
654                         int fillcolour, int outlinecolour);
655     void (*draw_update)(void *handle, int x, int y, int w, int h);
656     void (*clip)(void *handle, int x, int y, int w, int h);
657     void (*unclip)(void *handle);
658     void (*start_draw)(void *handle);
659     void (*end_draw)(void *handle);
660     void (*status_bar)(void *handle, char *text);
661     blitter *(*blitter_new)(void *handle, int w, int h);
662     void (*blitter_free)(void *handle, blitter *bl);
663     void (*blitter_save)(void *handle, blitter *bl, int x, int y);
664     void (*blitter_load)(void *handle, blitter *bl, int x, int y);
665     void (*begin_doc)(void *handle, int pages);
666     void (*begin_page)(void *handle, int number);
667     void (*begin_puzzle)(void *handle, float xm, float xc,
668                          float ym, float yc, int pw, int ph, float wmm);
669     void (*end_puzzle)(void *handle);
670     void (*end_page)(void *handle, int number);
671     void (*end_doc)(void *handle);
672     void (*line_width)(void *handle, float width);
673     void (*line_dotted)(void *handle, int dotted);
674     char *(*text_fallback)(void *handle, const char *const *strings,
675                            int nstrings);
676     void (*draw_thick_line)(void *handle, float thickness,
677                             float x1, float y1, float x2, float y2,
678                             int colour);
679 };
680
681 /*
682  * For one-game-at-a-time platforms, there's a single structure
683  * like the above, under a fixed name. For all-at-once platforms,
684  * there's a list of all available puzzles in array form.
685  */
686 #ifdef COMBINED
687 extern const game *gamelist[];
688 extern const int gamecount;
689 #else
690 extern const game thegame;
691 #endif
692
693 /*
694  * Special string value to return from interpret_move in the case
695  * where the game UI has been updated but no actual move is being
696  * appended to the undo chain. Must be declared as a non-const char,
697  * but should never actually be modified by anyone.
698  */
699 extern char UI_UPDATE[];
700
701 /* A little bit of help to lazy developers */
702 #define DEFAULT_STATUSBAR_TEXT "Use status_bar() to fill this in."
703
704 #endif /* PUZZLES_PUZZLES_H */