X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/8bba891059504d0c28eeaaa98af85cf24bc1a750..d3fc6146c0fd38562c28eac50bc932b2992b97a5:/dominosa.c diff --git a/dominosa.c b/dominosa.c index d1613b1..42a7a02 100644 --- a/dominosa.c +++ b/dominosa.c @@ -1027,7 +1027,7 @@ static char *validate_desc(game_params *params, char *desc) return ret; } -static game_state *new_game(midend_data *me, game_params *params, char *desc) +static game_state *new_game(midend *me, game_params *params, char *desc) { int n = params->n, w = n+2, h = n+1, wh = w*h; game_state *state = snew(game_state); @@ -1093,6 +1093,7 @@ static game_state *dup_game(game_state *state) static void free_game(game_state *state) { sfree(state->grid); + sfree(state->edges); if (--state->numbers->refcount <= 0) { sfree(state->numbers->numbers); sfree(state->numbers); @@ -1154,7 +1155,7 @@ static char *solve_game(game_state *state, game_state *currstate, int p2 = (i & 1) ? p1+1 : p1+w; extra = sprintf(buf, ";%c%d,%d", - v==-1 ? 'E' : 'D', p1, p2); + (int)(v==-1 ? 'E' : 'D'), p1, p2); if (retlen + extra + 1 >= retsize) { retsize = retlen + extra + 256; @@ -1170,6 +1171,11 @@ static char *solve_game(game_state *state, game_state *currstate, return ret; } +static int game_can_format_as_text_now(game_params *params) +{ + return TRUE; +} + static char *game_text_format(game_state *state) { return NULL; @@ -1257,7 +1263,7 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds, (state->grid[d1] != d1 || state->grid[d2] != d2)) return NULL; - sprintf(buf, "%c%d,%d", button == RIGHT_BUTTON ? 'E' : 'D', d1, d2); + sprintf(buf, "%c%d,%d", (int)(button == RIGHT_BUTTON ? 'E' : 'D'), d1, d2); return dupstr(buf); } @@ -1432,13 +1438,13 @@ static void game_compute_size(game_params *params, int tilesize, *y = h * TILESIZE + 2*BORDER; } -static void game_set_size(game_drawstate *ds, game_params *params, - int tilesize) +static void game_set_size(drawing *dr, game_drawstate *ds, + game_params *params, int tilesize) { ds->tilesize = tilesize; } -static float *game_colours(frontend *fe, game_state *state, int *ncolours) +static float *game_colours(frontend *fe, int *ncolours) { float *ret = snewn(3 * NCOLOURS, float); @@ -1468,7 +1474,7 @@ static float *game_colours(frontend *fe, game_state *state, int *ncolours) return ret; } -static game_drawstate *game_new_drawstate(game_state *state) +static game_drawstate *game_new_drawstate(drawing *dr, game_state *state) { struct game_drawstate *ds = snew(struct game_drawstate); int i; @@ -1484,7 +1490,7 @@ static game_drawstate *game_new_drawstate(game_state *state) return ds; } -static void game_free_drawstate(game_drawstate *ds) +static void game_free_drawstate(drawing *dr, game_drawstate *ds) { sfree(ds->visible); sfree(ds); @@ -1499,7 +1505,7 @@ enum { TYPE_MASK = 0x0F }; -static void draw_tile(frontend *fe, game_drawstate *ds, game_state *state, +static void draw_tile(drawing *dr, game_drawstate *ds, game_state *state, int x, int y, int type) { int w = state->w /*, h = state->h */; @@ -1508,7 +1514,7 @@ static void draw_tile(frontend *fe, game_drawstate *ds, game_state *state, char str[80]; int flags; - draw_rect(fe, cx, cy, TILESIZE, TILESIZE, COL_BACKGROUND); + draw_rect(dr, cx, cy, TILESIZE, TILESIZE, COL_BACKGROUND); flags = type &~ TYPE_MASK; type &= TYPE_MASK; @@ -1537,16 +1543,16 @@ static void draw_tile(frontend *fe, game_drawstate *ds, game_state *state, } if (type == TYPE_L || type == TYPE_T) - draw_circle(fe, cx+DOMINO_COFFSET, cy+DOMINO_COFFSET, + draw_circle(dr, cx+DOMINO_COFFSET, cy+DOMINO_COFFSET, DOMINO_RADIUS, bg, bg); if (type == TYPE_R || type == TYPE_T) - draw_circle(fe, cx+TILESIZE-1-DOMINO_COFFSET, cy+DOMINO_COFFSET, + draw_circle(dr, cx+TILESIZE-1-DOMINO_COFFSET, cy+DOMINO_COFFSET, DOMINO_RADIUS, bg, bg); if (type == TYPE_L || type == TYPE_B) - draw_circle(fe, cx+DOMINO_COFFSET, cy+TILESIZE-1-DOMINO_COFFSET, + draw_circle(dr, cx+DOMINO_COFFSET, cy+TILESIZE-1-DOMINO_COFFSET, DOMINO_RADIUS, bg, bg); if (type == TYPE_R || type == TYPE_B) - draw_circle(fe, cx+TILESIZE-1-DOMINO_COFFSET, + draw_circle(dr, cx+TILESIZE-1-DOMINO_COFFSET, cy+TILESIZE-1-DOMINO_COFFSET, DOMINO_RADIUS, bg, bg); @@ -1558,40 +1564,40 @@ static void draw_tile(frontend *fe, game_drawstate *ds, game_state *state, x2 = cx + TILESIZE-1 - (i ? DOMINO_GUTTER : DOMINO_COFFSET); y2 = cy + TILESIZE-1 - (i ? DOMINO_COFFSET : DOMINO_GUTTER); if (type == TYPE_L) - x2 = cx + TILESIZE-1; + x2 = cx + TILESIZE + TILESIZE/16; else if (type == TYPE_R) - x1 = cx; + x1 = cx - TILESIZE/16; else if (type == TYPE_T) - y2 = cy + TILESIZE-1; + y2 = cy + TILESIZE + TILESIZE/16; else if (type == TYPE_B) - y1 = cy; + y1 = cy - TILESIZE/16; - draw_rect(fe, x1, y1, x2-x1+1, y2-y1+1, bg); + draw_rect(dr, x1, y1, x2-x1+1, y2-y1+1, bg); } } else { if (flags & EDGE_T) - draw_rect(fe, cx+DOMINO_GUTTER, cy, + draw_rect(dr, cx+DOMINO_GUTTER, cy, TILESIZE-2*DOMINO_GUTTER, 1, COL_EDGE); if (flags & EDGE_B) - draw_rect(fe, cx+DOMINO_GUTTER, cy+TILESIZE-1, + draw_rect(dr, cx+DOMINO_GUTTER, cy+TILESIZE-1, TILESIZE-2*DOMINO_GUTTER, 1, COL_EDGE); if (flags & EDGE_L) - draw_rect(fe, cx, cy+DOMINO_GUTTER, + draw_rect(dr, cx, cy+DOMINO_GUTTER, 1, TILESIZE-2*DOMINO_GUTTER, COL_EDGE); if (flags & EDGE_R) - draw_rect(fe, cx+TILESIZE-1, cy+DOMINO_GUTTER, + draw_rect(dr, cx+TILESIZE-1, cy+DOMINO_GUTTER, 1, TILESIZE-2*DOMINO_GUTTER, COL_EDGE); nc = COL_TEXT; } sprintf(str, "%d", state->numbers->numbers[y*w+x]); - draw_text(fe, cx+TILESIZE/2, cy+TILESIZE/2, FONT_VARIABLE, TILESIZE/2, + draw_text(dr, cx+TILESIZE/2, cy+TILESIZE/2, FONT_VARIABLE, TILESIZE/2, ALIGN_HCENTRE | ALIGN_VCENTRE, nc, str); - draw_update(fe, cx, cy, TILESIZE, TILESIZE); + draw_update(dr, cx, cy, TILESIZE, TILESIZE); } -static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate, +static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate, game_state *state, int dir, game_ui *ui, float animtime, float flashtime) { @@ -1602,8 +1608,8 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate, if (!ds->started) { int pw, ph; game_compute_size(&state->params, TILESIZE, &pw, &ph); - draw_rect(fe, 0, 0, pw, ph, COL_BACKGROUND); - draw_update(fe, 0, 0, pw, ph); + draw_rect(dr, 0, 0, pw, ph, COL_BACKGROUND); + draw_update(dr, 0, 0, pw, ph); ds->started = TRUE; } @@ -1658,7 +1664,7 @@ static void game_redraw(frontend *fe, game_drawstate *ds, game_state *oldstate, c |= 0x40; /* we're flashing */ if (ds->visible[n] != c) { - draw_tile(fe, ds, state, x, y, c); + draw_tile(dr, ds, state, x, y, c); ds->visible[n] = c; } } @@ -1681,14 +1687,57 @@ static float game_flash_length(game_state *oldstate, game_state *newstate, return 0.0F; } -static int game_wants_statusbar(void) +static int game_timing_state(game_state *state, game_ui *ui) { - return FALSE; + return TRUE; } -static int game_timing_state(game_state *state, game_ui *ui) +static void game_print_size(game_params *params, float *x, float *y) { - return TRUE; + int pw, ph; + + /* + * I'll use 6mm squares by default. + */ + game_compute_size(params, 600, &pw, &ph); + *x = pw / 100.0; + *y = ph / 100.0; +} + +static void game_print(drawing *dr, game_state *state, int tilesize) +{ + int w = state->w, h = state->h; + int c, x, y; + + /* Ick: fake up `ds->tilesize' for macro expansion purposes */ + game_drawstate ads, *ds = &ads; + game_set_size(dr, ds, NULL, tilesize); + + c = print_mono_colour(dr, 1); assert(c == COL_BACKGROUND); + c = print_mono_colour(dr, 0); assert(c == COL_TEXT); + c = print_mono_colour(dr, 0); assert(c == COL_DOMINO); + c = print_mono_colour(dr, 0); assert(c == COL_DOMINOCLASH); + c = print_mono_colour(dr, 1); assert(c == COL_DOMINOTEXT); + c = print_mono_colour(dr, 0); assert(c == COL_EDGE); + + for (y = 0; y < h; y++) + for (x = 0; x < w; x++) { + int n = y*w+x; + unsigned long c; + + if (state->grid[n] == n-1) + c = TYPE_R; + else if (state->grid[n] == n+1) + c = TYPE_L; + else if (state->grid[n] == n-w) + c = TYPE_B; + else if (state->grid[n] == n+w) + c = TYPE_T; + else + c = TYPE_BLANK; + + draw_tile(dr, ds, state, x, y, c); + } } #ifdef COMBINED @@ -1696,7 +1745,7 @@ static int game_timing_state(game_state *state, game_ui *ui) #endif const struct game thegame = { - "Dominosa", "games.dominosa", + "Dominosa", "games.dominosa", "dominosa", default_params, game_fetch_preset, decode_params, @@ -1711,7 +1760,7 @@ const struct game thegame = { dup_game, free_game, TRUE, solve_game, - FALSE, game_text_format, + FALSE, game_can_format_as_text_now, game_text_format, new_ui, free_ui, encode_ui, @@ -1726,7 +1775,8 @@ const struct game thegame = { game_redraw, game_anim_length, game_flash_length, - game_wants_statusbar, + TRUE, FALSE, game_print_size, game_print, + FALSE, /* wants_statusbar */ FALSE, game_timing_state, - 0, /* mouse_priorities */ + 0, /* flags */ };