- * Game-specific routines
- */
-extern const char *const game_name;
-const int game_can_configure;
-game_params *default_params(void);
-int game_fetch_preset(int i, char **name, game_params **params);
-game_params *decode_params(char const *string);
-char *encode_params(game_params *);
-void free_params(game_params *params);
-game_params *dup_params(game_params *params);
-config_item *game_configure(game_params *params);
-game_params *custom_params(config_item *cfg);
-char *validate_params(game_params *params);
-char *new_game_seed(game_params *params, random_state *rs);
-char *validate_seed(game_params *params, char *seed);
-game_state *new_game(game_params *params, char *seed);
-game_state *dup_game(game_state *state);
-void free_game(game_state *state);
-game_ui *new_ui(game_state *state);
-void free_ui(game_ui *ui);
-game_state *make_move(game_state *from, game_ui *ui, int x, int y, int button);
-void game_size(game_params *params, int *x, int *y);
-float *game_colours(frontend *fe, game_state *state, int *ncolours);
-game_drawstate *game_new_drawstate(game_state *state);
-void game_free_drawstate(game_drawstate *ds);
-void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate,
- game_state *newstate, game_ui *ui, float anim_time,
- float flash_time);
-float game_anim_length(game_state *oldstate, game_state *newstate);
-float game_flash_length(game_state *oldstate, game_state *newstate);
-int game_wants_statusbar(void);
+ * ps.c
+ */
+psdata *ps_init(FILE *outfile, int colour);
+void ps_free(psdata *ps);
+drawing *ps_drawing_api(psdata *ps);
+
+/*
+ * combi.c: provides a structure and functions for iterating over
+ * combinations (i.e. choosing r things out of n).
+ */
+typedef struct _combi_ctx {
+ int r, n, nleft, total;
+ int *a;
+} combi_ctx;
+
+combi_ctx *new_combi(int r, int n);
+void reset_combi(combi_ctx *combi);
+combi_ctx *next_combi(combi_ctx *combi); /* returns NULL for end */
+void free_combi(combi_ctx *combi);
+
+/*
+ * divvy.c
+ */
+/* divides w*h rectangle into pieces of size k. Returns w*h dsf. */
+int *divvy_rectangle(int w, int h, int k, random_state *rs);
+
+/*
+ * Data structure containing the function calls and data specific
+ * to a particular game. This is enclosed in a data structure so
+ * that a particular platform can choose, if it wishes, to compile
+ * all the games into a single combined executable rather than
+ * having lots of little ones.
+ */
+struct game {
+ const char *name;
+ const char *winhelp_topic, *htmlhelp_topic;
+ game_params *(*default_params)(void);
+ int (*fetch_preset)(int i, char **name, game_params **params);
+ void (*decode_params)(game_params *, char const *string);
+ char *(*encode_params)(game_params *, int full);
+ void (*free_params)(game_params *params);
+ game_params *(*dup_params)(game_params *params);
+ int can_configure;
+ config_item *(*configure)(game_params *params);
+ game_params *(*custom_params)(config_item *cfg);
+ char *(*validate_params)(game_params *params, int full);
+ char *(*new_desc)(game_params *params, random_state *rs,
+ char **aux, int interactive);
+ char *(*validate_desc)(game_params *params, char *desc);
+ game_state *(*new_game)(midend *me, game_params *params, char *desc);
+ game_state *(*dup_game)(game_state *state);
+ void (*free_game)(game_state *state);
+ int can_solve;
+ char *(*solve)(game_state *orig, game_state *curr,
+ char *aux, char **error);
+ int can_format_as_text_ever;
+ int (*can_format_as_text_now)(game_params *params);
+ char *(*text_format)(game_state *state);
+ game_ui *(*new_ui)(game_state *state);
+ void (*free_ui)(game_ui *ui);
+ char *(*encode_ui)(game_ui *ui);
+ void (*decode_ui)(game_ui *ui, char *encoding);
+ void (*changed_state)(game_ui *ui, game_state *oldstate,
+ game_state *newstate);
+ char *(*interpret_move)(game_state *state, game_ui *ui,
+ const game_drawstate *ds, int x, int y, int button);
+ game_state *(*execute_move)(game_state *state, char *move);
+ int preferred_tilesize;
+ void (*compute_size)(game_params *params, int tilesize, int *x, int *y);
+ void (*set_size)(drawing *dr, game_drawstate *ds,
+ game_params *params, int tilesize);
+ float *(*colours)(frontend *fe, int *ncolours);
+ game_drawstate *(*new_drawstate)(drawing *dr, game_state *state);
+ void (*free_drawstate)(drawing *dr, game_drawstate *ds);
+ void (*redraw)(drawing *dr, game_drawstate *ds, game_state *oldstate,
+ game_state *newstate, int dir, game_ui *ui, float anim_time,
+ float flash_time);
+ float (*anim_length)(game_state *oldstate, game_state *newstate, int dir,
+ game_ui *ui);
+ float (*flash_length)(game_state *oldstate, game_state *newstate, int dir,
+ game_ui *ui);
+ int (*status)(game_state *state);
+ int can_print, can_print_in_colour;
+ void (*print_size)(game_params *params, float *x, float *y);
+ void (*print)(drawing *dr, game_state *state, int tilesize);
+ int wants_statusbar;
+ int is_timed;
+ int (*timing_state)(game_state *state, game_ui *ui);
+ int flags;
+};
+
+/*
+ * Data structure containing the drawing API implemented by the
+ * front end and also by cross-platform printing modules such as
+ * PostScript.
+ */
+struct drawing_api {
+ void (*draw_text)(void *handle, int x, int y, int fonttype, int fontsize,
+ int align, int colour, char *text);
+ void (*draw_rect)(void *handle, int x, int y, int w, int h, int colour);
+ void (*draw_line)(void *handle, int x1, int y1, int x2, int y2,
+ int colour);
+ void (*draw_polygon)(void *handle, int *coords, int npoints,
+ int fillcolour, int outlinecolour);
+ void (*draw_circle)(void *handle, int cx, int cy, int radius,
+ int fillcolour, int outlinecolour);
+ void (*draw_update)(void *handle, int x, int y, int w, int h);
+ void (*clip)(void *handle, int x, int y, int w, int h);
+ void (*unclip)(void *handle);
+ void (*start_draw)(void *handle);
+ void (*end_draw)(void *handle);
+ void (*status_bar)(void *handle, char *text);
+ blitter *(*blitter_new)(void *handle, int w, int h);
+ void (*blitter_free)(void *handle, blitter *bl);
+ void (*blitter_save)(void *handle, blitter *bl, int x, int y);
+ void (*blitter_load)(void *handle, blitter *bl, int x, int y);
+ void (*begin_doc)(void *handle, int pages);
+ void (*begin_page)(void *handle, int number);
+ void (*begin_puzzle)(void *handle, float xm, float xc,
+ float ym, float yc, int pw, int ph, float wmm);
+ void (*end_puzzle)(void *handle);
+ void (*end_page)(void *handle, int number);
+ void (*end_doc)(void *handle);
+ void (*line_width)(void *handle, float width);
+ void (*line_dotted)(void *handle, int dotted);
+ char *(*text_fallback)(void *handle, const char *const *strings,
+ int nstrings);
+ void (*draw_thick_line)(void *handle, float thickness,
+ float x1, float y1, float x2, float y2,
+ int colour);
+};
+
+/*
+ * For one-game-at-a-time platforms, there's a single structure
+ * like the above, under a fixed name. For all-at-once platforms,
+ * there's a list of all available puzzles in array form.
+ */
+#ifdef COMBINED
+extern const game *gamelist[];
+extern const int gamecount;
+#else
+extern const game thegame;
+#endif