X-Git-Url: https://git.distorted.org.uk/~mdw/sgt/puzzles/blobdiff_plain/ac9f41c4c8ccbf9364a5d351e4cb134812a9926b..d3fc6146c0fd38562c28eac50bc932b2992b97a5:/bridges.c diff --git a/bridges.c b/bridges.c index a3d342c..1829681 100644 --- a/bridges.c +++ b/bridges.c @@ -147,6 +147,11 @@ static void fixup_islands_for_realloc(game_state *state) } } +static int game_can_format_as_text_now(game_params *params) +{ + return TRUE; +} + static char *game_text_format(game_state *state) { int x, y, len, nl; @@ -1012,7 +1017,7 @@ static int grid_degree(game_state *state, int x, int y, int *nx_r, int *ny_r) static int map_hasloops(game_state *state, int mark) { - int x, y, ox, oy, nx, ny, loop = 0; + int x, y, ox, oy, nx = 0, ny = 0, loop = 0; memcpy(state->scratch, state->grid, GRIDSZ(state)); @@ -1064,8 +1069,7 @@ static void map_group(game_state *state) struct island *is, *is_join; /* Initialise dsf. */ - for (i = 0; i < wh; i++) - dsf[i] = i; + dsf_init(dsf, wh); /* For each island, find connected islands right or down * and merge the dsf for the island squares as well as the @@ -1602,9 +1606,8 @@ static game_state *new_state(game_params *params) ret->solved = ret->completed = 0; ret->solver = snew(struct solver_state); - ret->solver->dsf = snewn(wh, int); + ret->solver->dsf = snew_dsf(wh); ret->solver->tmpdsf = snewn(wh, int); - for (i = 0; i < wh; i++) ret->solver->dsf[i] = i; ret->solver->refcount = 1; @@ -1800,11 +1803,11 @@ generated: echeck = 0; for (x = 0; x < params->w; x++) { if (INDEX(tobuild, gridi, x, 0)) echeck |= 1; - if (INDEX(tobuild, gridi, x, params->w-1)) echeck |= 2; + if (INDEX(tobuild, gridi, x, params->h-1)) echeck |= 2; } for (y = 0; y < params->h; y++) { if (INDEX(tobuild, gridi, 0, y)) echeck |= 4; - if (INDEX(tobuild, gridi, params->h-1, y)) echeck |= 8; + if (INDEX(tobuild, gridi, params->w-1, y)) echeck |= 8; } if (echeck != 15) { debug(("Generated grid doesn't fill to sides, retrying.\n")); @@ -2288,22 +2291,30 @@ static void game_free_drawstate(drawing *dr, game_drawstate *ds) #define OFFSET(thing) ((TILE_SIZE/2) - ((thing)/2)) -static void line_vert(drawing *dr, game_drawstate *ds, - int ox, int oy, int col, grid_type v) +static void lines_vert(drawing *dr, game_drawstate *ds, + int ox, int oy, int lv, int col, grid_type v) { - int lw = LINE_WIDTH; + int lw = LINE_WIDTH, gw = LINE_WIDTH, bw, i, loff; + while ((bw = lw * lv + gw * (lv+1)) > TILE_SIZE) + gw--; + loff = OFFSET(bw); if (v & G_MARKV) - draw_rect(dr, ox-lw, oy, lw*3, TILE_SIZE, COL_MARK); - draw_rect(dr, ox, oy, lw, TILE_SIZE, col); + draw_rect(dr, ox + loff, oy, bw, TILE_SIZE, COL_MARK); + for (i = 0; i < lv; i++, loff += lw + gw) + draw_rect(dr, ox + loff + gw, oy, lw, TILE_SIZE, col); } -static void line_horiz(drawing *dr, game_drawstate *ds, - int ox, int oy, int col, grid_type v) +static void lines_horiz(drawing *dr, game_drawstate *ds, + int ox, int oy, int lh, int col, grid_type v) { - int lw = LINE_WIDTH; + int lw = LINE_WIDTH, gw = LINE_WIDTH, bw, i, loff; + while ((bw = lw * lh + gw * (lh+1)) > TILE_SIZE) + gw--; + loff = OFFSET(bw); if (v & G_MARKH) - draw_rect(dr, ox, oy-lw, TILE_SIZE, lw*3, COL_MARK); - draw_rect(dr, ox, oy, TILE_SIZE, lw, col); + draw_rect(dr, ox, oy + loff, TILE_SIZE, bw, COL_MARK); + for (i = 0; i < lh; i++, loff += lw + gw) + draw_rect(dr, ox, oy + loff + gw, TILE_SIZE, lw, col); } static void line_cross(drawing *dr, game_drawstate *ds, @@ -2353,8 +2364,7 @@ static void lines_redraw(drawing *dr, game_state *state, game_drawstate *ds, game_ui *ui, int x, int y, grid_type v, int lv, int lh) { - int lw = LINE_WIDTH, bw; - int ox = COORD(x), oy = COORD(y), loff, i; + int ox = COORD(x), oy = COORD(y); int vcol = (v & G_FLASH) ? COL_HIGHLIGHT : (v & G_WARN) ? COL_WARNING : COL_FOREGROUND, hcol = vcol; grid_type todraw = v & G_NOLINE; @@ -2385,24 +2395,18 @@ static void lines_redraw(drawing *dr, line_cross(dr, ds, ox + TS8(1), oy + TS8(3), hcol, todraw); line_cross(dr, ds, ox + TS8(5), oy + TS8(3), hcol, todraw); } - if (lv) { - bw = (lv*2-1) * lw; - for (i = 0, loff = OFFSET(bw); i < lv; i++, loff += lw*2) - line_vert(dr, ds, ox + loff, oy, vcol, v); - } - if (lh) { - bw = (lh*2-1) * lw; - for (i = 0, loff = OFFSET(bw); i < lh; i++, loff += lw*2) - line_horiz(dr, ds, ox, oy + loff, hcol, v); - } + if (lv) + lines_vert(dr, ds, ox, oy, lv, vcol, v); + if (lh) + lines_horiz(dr, ds, ox, oy, lh, hcol, v); dsf_debug_draw(dr, state, ds, x, y); draw_update(dr, ox, oy, TILE_SIZE, TILE_SIZE); } -#define ISLAND_RADIUS ((TILE_SIZE*13)/20) +#define ISLAND_RADIUS ((TILE_SIZE*12)/20) #define ISLAND_NUMSIZE(is) \ - (((is)->count < 10) ? TILE_SIZE : (TILE_SIZE*8)/10) + (((is)->count < 10) ? (TILE_SIZE*7)/10 : (TILE_SIZE*5)/10) static void island_redraw(drawing *dr, game_state *state, game_drawstate *ds, @@ -2630,7 +2634,7 @@ static void game_print(drawing *dr, game_state *state, int ts) #endif const struct game thegame = { - "Bridges", "games.bridges", + "Bridges", "games.bridges", "bridges", default_params, game_fetch_preset, decode_params, @@ -2645,7 +2649,7 @@ const struct game thegame = { dup_game, free_game, TRUE, solve_game, - TRUE, game_text_format, + TRUE, game_can_format_as_text_now, game_text_format, new_ui, free_ui, encode_ui, @@ -2663,7 +2667,7 @@ const struct game thegame = { TRUE, FALSE, game_print_size, game_print, FALSE, /* wants_statusbar */ FALSE, game_timing_state, - 0, /* flags */ + REQUIRE_RBUTTON, /* flags */ }; /* vim: set shiftwidth=4 tabstop=8: */