diff options
Diffstat (limited to 'apps/plugins/puzzles/src/map.c')
-rw-r--r-- | apps/plugins/puzzles/src/map.c | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/apps/plugins/puzzles/src/map.c b/apps/plugins/puzzles/src/map.c index 54073bad0d..cdcd5861a8 100644 --- a/apps/plugins/puzzles/src/map.c +++ b/apps/plugins/puzzles/src/map.c | |||
@@ -213,30 +213,25 @@ static config_item *game_configure(const game_params *params) | |||
213 | ret[0].name = "Width"; | 213 | ret[0].name = "Width"; |
214 | ret[0].type = C_STRING; | 214 | ret[0].type = C_STRING; |
215 | sprintf(buf, "%d", params->w); | 215 | sprintf(buf, "%d", params->w); |
216 | ret[0].sval = dupstr(buf); | 216 | ret[0].u.string.sval = dupstr(buf); |
217 | ret[0].ival = 0; | ||
218 | 217 | ||
219 | ret[1].name = "Height"; | 218 | ret[1].name = "Height"; |
220 | ret[1].type = C_STRING; | 219 | ret[1].type = C_STRING; |
221 | sprintf(buf, "%d", params->h); | 220 | sprintf(buf, "%d", params->h); |
222 | ret[1].sval = dupstr(buf); | 221 | ret[1].u.string.sval = dupstr(buf); |
223 | ret[1].ival = 0; | ||
224 | 222 | ||
225 | ret[2].name = "Regions"; | 223 | ret[2].name = "Regions"; |
226 | ret[2].type = C_STRING; | 224 | ret[2].type = C_STRING; |
227 | sprintf(buf, "%d", params->n); | 225 | sprintf(buf, "%d", params->n); |
228 | ret[2].sval = dupstr(buf); | 226 | ret[2].u.string.sval = dupstr(buf); |
229 | ret[2].ival = 0; | ||
230 | 227 | ||
231 | ret[3].name = "Difficulty"; | 228 | ret[3].name = "Difficulty"; |
232 | ret[3].type = C_CHOICES; | 229 | ret[3].type = C_CHOICES; |
233 | ret[3].sval = DIFFCONFIG; | 230 | ret[3].u.choices.choicenames = DIFFCONFIG; |
234 | ret[3].ival = params->diff; | 231 | ret[3].u.choices.selected = params->diff; |
235 | 232 | ||
236 | ret[4].name = NULL; | 233 | ret[4].name = NULL; |
237 | ret[4].type = C_END; | 234 | ret[4].type = C_END; |
238 | ret[4].sval = NULL; | ||
239 | ret[4].ival = 0; | ||
240 | 235 | ||
241 | return ret; | 236 | return ret; |
242 | } | 237 | } |
@@ -245,15 +240,15 @@ static game_params *custom_params(const config_item *cfg) | |||
245 | { | 240 | { |
246 | game_params *ret = snew(game_params); | 241 | game_params *ret = snew(game_params); |
247 | 242 | ||
248 | ret->w = atoi(cfg[0].sval); | 243 | ret->w = atoi(cfg[0].u.string.sval); |
249 | ret->h = atoi(cfg[1].sval); | 244 | ret->h = atoi(cfg[1].u.string.sval); |
250 | ret->n = atoi(cfg[2].sval); | 245 | ret->n = atoi(cfg[2].u.string.sval); |
251 | ret->diff = cfg[3].ival; | 246 | ret->diff = cfg[3].u.choices.selected; |
252 | 247 | ||
253 | return ret; | 248 | return ret; |
254 | } | 249 | } |
255 | 250 | ||
256 | static char *validate_params(const game_params *params, int full) | 251 | static const char *validate_params(const game_params *params, int full) |
257 | { | 252 | { |
258 | if (params->w < 2 || params->h < 2) | 253 | if (params->w < 2 || params->h < 2) |
259 | return "Width and height must be at least two"; | 254 | return "Width and height must be at least two"; |
@@ -878,7 +873,7 @@ static const char colnames[FOUR] = { 'R', 'Y', 'G', 'B' }; | |||
878 | static int place_colour(struct solver_scratch *sc, | 873 | static int place_colour(struct solver_scratch *sc, |
879 | int *colouring, int index, int colour | 874 | int *colouring, int index, int colour |
880 | #ifdef SOLVER_DIAGNOSTICS | 875 | #ifdef SOLVER_DIAGNOSTICS |
881 | , char *verb | 876 | , const char *verb |
882 | #endif | 877 | #endif |
883 | ) | 878 | ) |
884 | { | 879 | { |
@@ -925,7 +920,7 @@ static char *colourset(char *buf, int set) | |||
925 | { | 920 | { |
926 | int i; | 921 | int i; |
927 | char *p = buf; | 922 | char *p = buf; |
928 | char *sep = ""; | 923 | const char *sep = ""; |
929 | 924 | ||
930 | for (i = 0; i < FOUR; i++) | 925 | for (i = 0; i < FOUR; i++) |
931 | if (set & (1 << i)) { | 926 | if (set & (1 << i)) { |
@@ -1219,7 +1214,8 @@ static int map_solver(struct solver_scratch *sc, | |||
1219 | (sc->possible[k] & currc)) { | 1214 | (sc->possible[k] & currc)) { |
1220 | #ifdef SOLVER_DIAGNOSTICS | 1215 | #ifdef SOLVER_DIAGNOSTICS |
1221 | if (verbose) { | 1216 | if (verbose) { |
1222 | char buf[80], *sep = ""; | 1217 | char buf[80]; |
1218 | const char *sep = ""; | ||
1223 | int r; | 1219 | int r; |
1224 | 1220 | ||
1225 | printf("%*sforcing chain, colour %s, ", | 1221 | printf("%*sforcing chain, colour %s, ", |
@@ -1704,8 +1700,8 @@ static char *new_game_desc(const game_params *params, random_state *rs, | |||
1704 | return ret; | 1700 | return ret; |
1705 | } | 1701 | } |
1706 | 1702 | ||
1707 | static char *parse_edge_list(const game_params *params, const char **desc, | 1703 | static const char *parse_edge_list(const game_params *params, |
1708 | int *map) | 1704 | const char **desc, int *map) |
1709 | { | 1705 | { |
1710 | int w = params->w, h = params->h, wh = w*h, n = params->n; | 1706 | int w = params->w, h = params->h, wh = w*h, n = params->n; |
1711 | int i, k, pos, state; | 1707 | int i, k, pos, state; |
@@ -1781,12 +1777,12 @@ static char *parse_edge_list(const game_params *params, const char **desc, | |||
1781 | return NULL; | 1777 | return NULL; |
1782 | } | 1778 | } |
1783 | 1779 | ||
1784 | static char *validate_desc(const game_params *params, const char *desc) | 1780 | static const char *validate_desc(const game_params *params, const char *desc) |
1785 | { | 1781 | { |
1786 | int w = params->w, h = params->h, wh = w*h, n = params->n; | 1782 | int w = params->w, h = params->h, wh = w*h, n = params->n; |
1787 | int area; | 1783 | int area; |
1788 | int *map; | 1784 | int *map; |
1789 | char *ret; | 1785 | const char *ret; |
1790 | 1786 | ||
1791 | map = snewn(2*wh, int); | 1787 | map = snewn(2*wh, int); |
1792 | ret = parse_edge_list(params, &desc, map); | 1788 | ret = parse_edge_list(params, &desc, map); |
@@ -1846,7 +1842,7 @@ static game_state *new_game(midend *me, const game_params *params, | |||
1846 | p = desc; | 1842 | p = desc; |
1847 | 1843 | ||
1848 | { | 1844 | { |
1849 | char *ret; | 1845 | const char *ret; |
1850 | ret = parse_edge_list(params, &p, state->map->map); | 1846 | ret = parse_edge_list(params, &p, state->map->map); |
1851 | assert(!ret); | 1847 | assert(!ret); |
1852 | } | 1848 | } |
@@ -2191,7 +2187,7 @@ static void free_game(game_state *state) | |||
2191 | } | 2187 | } |
2192 | 2188 | ||
2193 | static char *solve_game(const game_state *state, const game_state *currstate, | 2189 | static char *solve_game(const game_state *state, const game_state *currstate, |
2194 | const char *aux, char **error) | 2190 | const char *aux, const char **error) |
2195 | { | 2191 | { |
2196 | if (!aux) { | 2192 | if (!aux) { |
2197 | /* | 2193 | /* |
@@ -2375,7 +2371,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
2375 | */ | 2371 | */ |
2376 | if (button == 'l' || button == 'L') { | 2372 | if (button == 'l' || button == 'L') { |
2377 | ui->show_numbers = !ui->show_numbers; | 2373 | ui->show_numbers = !ui->show_numbers; |
2378 | return ""; | 2374 | return UI_UPDATE; |
2379 | } | 2375 | } |
2380 | 2376 | ||
2381 | if (IS_CURSOR_MOVE(button)) { | 2377 | if (IS_CURSOR_MOVE(button)) { |
@@ -2385,14 +2381,14 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
2385 | ui->cur_lastmove = button; | 2381 | ui->cur_lastmove = button; |
2386 | ui->dragx = COORD(ui->cur_x) + TILESIZE/2 + EPSILON_X(button); | 2382 | ui->dragx = COORD(ui->cur_x) + TILESIZE/2 + EPSILON_X(button); |
2387 | ui->dragy = COORD(ui->cur_y) + TILESIZE/2 + EPSILON_Y(button); | 2383 | ui->dragy = COORD(ui->cur_y) + TILESIZE/2 + EPSILON_Y(button); |
2388 | return ""; | 2384 | return UI_UPDATE; |
2389 | } | 2385 | } |
2390 | if (IS_CURSOR_SELECT(button)) { | 2386 | if (IS_CURSOR_SELECT(button)) { |
2391 | if (!ui->cur_visible) { | 2387 | if (!ui->cur_visible) { |
2392 | ui->dragx = COORD(ui->cur_x) + TILESIZE/2 + EPSILON_X(ui->cur_lastmove); | 2388 | ui->dragx = COORD(ui->cur_x) + TILESIZE/2 + EPSILON_X(ui->cur_lastmove); |
2393 | ui->dragy = COORD(ui->cur_y) + TILESIZE/2 + EPSILON_Y(ui->cur_lastmove); | 2389 | ui->dragy = COORD(ui->cur_y) + TILESIZE/2 + EPSILON_Y(ui->cur_lastmove); |
2394 | ui->cur_visible = 1; | 2390 | ui->cur_visible = 1; |
2395 | return ""; | 2391 | return UI_UPDATE; |
2396 | } | 2392 | } |
2397 | if (ui->drag_colour == -2) { /* not currently cursor-dragging, start. */ | 2393 | if (ui->drag_colour == -2) { /* not currently cursor-dragging, start. */ |
2398 | int r = region_from_coords(state, ds, ui->dragx, ui->dragy); | 2394 | int r = region_from_coords(state, ds, ui->dragx, ui->dragy); |
@@ -2404,7 +2400,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
2404 | ui->drag_pencil = 0; | 2400 | ui->drag_pencil = 0; |
2405 | } | 2401 | } |
2406 | ui->cur_moved = 0; | 2402 | ui->cur_moved = 0; |
2407 | return ""; | 2403 | return UI_UPDATE; |
2408 | } else { /* currently cursor-dragging; drop the colour in the new region. */ | 2404 | } else { /* currently cursor-dragging; drop the colour in the new region. */ |
2409 | x = COORD(ui->cur_x) + TILESIZE/2 + EPSILON_X(ui->cur_lastmove); | 2405 | x = COORD(ui->cur_x) + TILESIZE/2 + EPSILON_X(ui->cur_lastmove); |
2410 | y = COORD(ui->cur_y) + TILESIZE/2 + EPSILON_Y(ui->cur_lastmove); | 2406 | y = COORD(ui->cur_y) + TILESIZE/2 + EPSILON_Y(ui->cur_lastmove); |
@@ -2430,14 +2426,14 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
2430 | ui->dragx = x; | 2426 | ui->dragx = x; |
2431 | ui->dragy = y; | 2427 | ui->dragy = y; |
2432 | ui->cur_visible = 0; | 2428 | ui->cur_visible = 0; |
2433 | return ""; | 2429 | return UI_UPDATE; |
2434 | } | 2430 | } |
2435 | 2431 | ||
2436 | if ((button == LEFT_DRAG || button == RIGHT_DRAG) && | 2432 | if ((button == LEFT_DRAG || button == RIGHT_DRAG) && |
2437 | ui->drag_colour > -2) { | 2433 | ui->drag_colour > -2) { |
2438 | ui->dragx = x; | 2434 | ui->dragx = x; |
2439 | ui->dragy = y; | 2435 | ui->dragy = y; |
2440 | return ""; | 2436 | return UI_UPDATE; |
2441 | } | 2437 | } |
2442 | 2438 | ||
2443 | if ((button == LEFT_RELEASE || button == RIGHT_RELEASE) && | 2439 | if ((button == LEFT_RELEASE || button == RIGHT_RELEASE) && |
@@ -2461,18 +2457,18 @@ drag_dropped: | |||
2461 | ui->drag_colour = -2; | 2457 | ui->drag_colour = -2; |
2462 | 2458 | ||
2463 | if (r < 0) | 2459 | if (r < 0) |
2464 | return ""; /* drag into border; do nothing else */ | 2460 | return UI_UPDATE; /* drag into border; do nothing else */ |
2465 | 2461 | ||
2466 | if (state->map->immutable[r]) | 2462 | if (state->map->immutable[r]) |
2467 | return ""; /* can't change this region */ | 2463 | return UI_UPDATE; /* can't change this region */ |
2468 | 2464 | ||
2469 | if (state->colouring[r] == c && state->pencil[r] == p) | 2465 | if (state->colouring[r] == c && state->pencil[r] == p) |
2470 | return ""; /* don't _need_ to change this region */ | 2466 | return UI_UPDATE; /* don't _need_ to change this region */ |
2471 | 2467 | ||
2472 | if (alt_button) { | 2468 | if (alt_button) { |
2473 | if (state->colouring[r] >= 0) { | 2469 | if (state->colouring[r] >= 0) { |
2474 | /* Can't pencil on a coloured region */ | 2470 | /* Can't pencil on a coloured region */ |
2475 | return ""; | 2471 | return UI_UPDATE; |
2476 | } else if (c >= 0) { | 2472 | } else if (c >= 0) { |
2477 | /* Right-dragging from colour to blank toggles one pencil */ | 2473 | /* Right-dragging from colour to blank toggles one pencil */ |
2478 | p = state->pencil[r] ^ (1 << c); | 2474 | p = state->pencil[r] ^ (1 << c); |
@@ -3240,7 +3236,8 @@ int main(int argc, char **argv) | |||
3240 | { | 3236 | { |
3241 | game_params *p; | 3237 | game_params *p; |
3242 | game_state *s; | 3238 | game_state *s; |
3243 | char *id = NULL, *desc, *err; | 3239 | char *id = NULL, *desc; |
3240 | const char *err; | ||
3244 | int grade = FALSE; | 3241 | int grade = FALSE; |
3245 | int ret, diff, really_verbose = FALSE; | 3242 | int ret, diff, really_verbose = FALSE; |
3246 | struct solver_scratch *sc; | 3243 | struct solver_scratch *sc; |