diff options
Diffstat (limited to 'apps/plugins/puzzles/src/tracks.c')
-rw-r--r-- | apps/plugins/puzzles/src/tracks.c | 71 |
1 files changed, 35 insertions, 36 deletions
diff --git a/apps/plugins/puzzles/src/tracks.c b/apps/plugins/puzzles/src/tracks.c index 578813b1a3..3899007c94 100644 --- a/apps/plugins/puzzles/src/tracks.c +++ b/apps/plugins/puzzles/src/tracks.c | |||
@@ -148,28 +148,24 @@ static config_item *game_configure(const game_params *params) | |||
148 | ret[0].name = "Width"; | 148 | ret[0].name = "Width"; |
149 | ret[0].type = C_STRING; | 149 | ret[0].type = C_STRING; |
150 | sprintf(buf, "%d", params->w); | 150 | sprintf(buf, "%d", params->w); |
151 | ret[0].sval = dupstr(buf); | 151 | ret[0].u.string.sval = dupstr(buf); |
152 | ret[0].ival = 0; | ||
153 | 152 | ||
154 | ret[1].name = "Height"; | 153 | ret[1].name = "Height"; |
155 | ret[1].type = C_STRING; | 154 | ret[1].type = C_STRING; |
156 | sprintf(buf, "%d", params->h); | 155 | sprintf(buf, "%d", params->h); |
157 | ret[1].sval = dupstr(buf); | 156 | ret[1].u.string.sval = dupstr(buf); |
158 | ret[1].ival = 0; | ||
159 | 157 | ||
160 | ret[2].name = "Difficulty"; | 158 | ret[2].name = "Difficulty"; |
161 | ret[2].type = C_CHOICES; | 159 | ret[2].type = C_CHOICES; |
162 | ret[2].sval = DIFFCONFIG; | 160 | ret[2].u.choices.choicenames = DIFFCONFIG; |
163 | ret[2].ival = params->diff; | 161 | ret[2].u.choices.selected = params->diff; |
164 | 162 | ||
165 | ret[3].name = "Disallow consecutive 1 clues"; | 163 | ret[3].name = "Disallow consecutive 1 clues"; |
166 | ret[3].type = C_BOOLEAN; | 164 | ret[3].type = C_BOOLEAN; |
167 | ret[3].ival = params->single_ones; | 165 | ret[3].u.boolean.bval = params->single_ones; |
168 | 166 | ||
169 | ret[4].name = NULL; | 167 | ret[4].name = NULL; |
170 | ret[4].type = C_END; | 168 | ret[4].type = C_END; |
171 | ret[4].sval = NULL; | ||
172 | ret[4].ival = 0; | ||
173 | 169 | ||
174 | return ret; | 170 | return ret; |
175 | } | 171 | } |
@@ -178,15 +174,15 @@ static game_params *custom_params(const config_item *cfg) | |||
178 | { | 174 | { |
179 | game_params *ret = snew(game_params); | 175 | game_params *ret = snew(game_params); |
180 | 176 | ||
181 | ret->w = atoi(cfg[0].sval); | 177 | ret->w = atoi(cfg[0].u.string.sval); |
182 | ret->h = atoi(cfg[1].sval); | 178 | ret->h = atoi(cfg[1].u.string.sval); |
183 | ret->diff = cfg[2].ival; | 179 | ret->diff = cfg[2].u.choices.selected; |
184 | ret->single_ones = cfg[3].ival; | 180 | ret->single_ones = cfg[3].u.boolean.bval; |
185 | 181 | ||
186 | return ret; | 182 | return ret; |
187 | } | 183 | } |
188 | 184 | ||
189 | static char *validate_params(const game_params *params, int full) | 185 | static const char *validate_params(const game_params *params, int full) |
190 | { | 186 | { |
191 | /* | 187 | /* |
192 | * Generating anything under 4x4 runs into trouble of one kind | 188 | * Generating anything under 4x4 runs into trouble of one kind |
@@ -786,7 +782,7 @@ newpath: | |||
786 | return desc; | 782 | return desc; |
787 | } | 783 | } |
788 | 784 | ||
789 | static char *validate_desc(const game_params *params, const char *desc) | 785 | static const char *validate_desc(const game_params *params, const char *desc) |
790 | { | 786 | { |
791 | int i = 0, w = params->w, h = params->h, in = 0, out = 0; | 787 | int i = 0, w = params->w, h = params->h, in = 0, out = 0; |
792 | 788 | ||
@@ -1368,7 +1364,7 @@ static char *move_string_diff(const game_state *before, const game_state *after, | |||
1368 | } | 1364 | } |
1369 | 1365 | ||
1370 | static char *solve_game(const game_state *state, const game_state *currstate, | 1366 | static char *solve_game(const game_state *state, const game_state *currstate, |
1371 | const char *aux, char **error) | 1367 | const char *aux, const char **error) |
1372 | { | 1368 | { |
1373 | game_state *solved; | 1369 | game_state *solved; |
1374 | int ret; | 1370 | int ret; |
@@ -1922,13 +1918,13 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
1922 | ui->drag_sx = ui->drag_ex = gx; | 1918 | ui->drag_sx = ui->drag_ex = gx; |
1923 | ui->drag_sy = ui->drag_ey = gy; | 1919 | ui->drag_sy = ui->drag_ey = gy; |
1924 | 1920 | ||
1925 | return ""; | 1921 | return UI_UPDATE; |
1926 | } | 1922 | } |
1927 | 1923 | ||
1928 | if (IS_MOUSE_DRAG(button)) { | 1924 | if (IS_MOUSE_DRAG(button)) { |
1929 | ui->cursor_active = FALSE; | 1925 | ui->cursor_active = FALSE; |
1930 | update_ui_drag(state, ui, gx, gy); | 1926 | update_ui_drag(state, ui, gx, gy); |
1931 | return ""; | 1927 | return UI_UPDATE; |
1932 | } | 1928 | } |
1933 | 1929 | ||
1934 | if (IS_MOUSE_RELEASE(button)) { | 1930 | if (IS_MOUSE_RELEASE(button)) { |
@@ -1965,12 +1961,12 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
1965 | cy = CENTERED_COORD(gy); | 1961 | cy = CENTERED_COORD(gy); |
1966 | 1962 | ||
1967 | if (!INGRID(state, gx, gy) || FROMCOORD(x) != gx || FROMCOORD(y) != gy) | 1963 | if (!INGRID(state, gx, gy) || FROMCOORD(x) != gx || FROMCOORD(y) != gy) |
1968 | return ""; | 1964 | return UI_UPDATE; |
1969 | 1965 | ||
1970 | if (max(abs(x-cx),abs(y-cy)) < TILE_SIZE/4) { | 1966 | if (max(abs(x-cx),abs(y-cy)) < TILE_SIZE/4) { |
1971 | if (ui_can_flip_square(state, gx, gy, button == RIGHT_RELEASE)) | 1967 | if (ui_can_flip_square(state, gx, gy, button == RIGHT_RELEASE)) |
1972 | return square_flip_str(state, gx, gy, button == RIGHT_RELEASE, tmpbuf); | 1968 | return square_flip_str(state, gx, gy, button == RIGHT_RELEASE, tmpbuf); |
1973 | return ""; | 1969 | return UI_UPDATE; |
1974 | } else { | 1970 | } else { |
1975 | if (abs(x-cx) < abs(y-cy)) { | 1971 | if (abs(x-cx) < abs(y-cy)) { |
1976 | /* Closest to top/bottom edge. */ | 1972 | /* Closest to top/bottom edge. */ |
@@ -1984,7 +1980,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
1984 | return edge_flip_str(state, gx, gy, direction, | 1980 | return edge_flip_str(state, gx, gy, direction, |
1985 | button == RIGHT_RELEASE, tmpbuf); | 1981 | button == RIGHT_RELEASE, tmpbuf); |
1986 | else | 1982 | else |
1987 | return ""; | 1983 | return UI_UPDATE; |
1988 | } | 1984 | } |
1989 | } | 1985 | } |
1990 | } | 1986 | } |
@@ -1997,7 +1993,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
1997 | 1993 | ||
1998 | if (!ui->cursor_active) { | 1994 | if (!ui->cursor_active) { |
1999 | ui->cursor_active = TRUE; | 1995 | ui->cursor_active = TRUE; |
2000 | return ""; | 1996 | return UI_UPDATE; |
2001 | } | 1997 | } |
2002 | 1998 | ||
2003 | ui->curx = ui->curx + dx; | 1999 | ui->curx = ui->curx + dx; |
@@ -2008,17 +2004,17 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
2008 | } | 2004 | } |
2009 | ui->curx = min(max(ui->curx, 1), 2*w-1); | 2005 | ui->curx = min(max(ui->curx, 1), 2*w-1); |
2010 | ui->cury = min(max(ui->cury, 1), 2*h-1); | 2006 | ui->cury = min(max(ui->cury, 1), 2*h-1); |
2011 | return ""; | 2007 | return UI_UPDATE; |
2012 | } | 2008 | } |
2013 | 2009 | ||
2014 | if (IS_CURSOR_SELECT(button)) { | 2010 | if (IS_CURSOR_SELECT(button)) { |
2015 | if (!ui->cursor_active) { | 2011 | if (!ui->cursor_active) { |
2016 | ui->cursor_active = TRUE; | 2012 | ui->cursor_active = TRUE; |
2017 | return ""; | 2013 | return UI_UPDATE; |
2018 | } | 2014 | } |
2019 | /* click on square corner does nothing (shouldn't get here) */ | 2015 | /* click on square corner does nothing (shouldn't get here) */ |
2020 | if ((ui->curx % 2) == 0 && (ui->cury % 2 == 0)) | 2016 | if ((ui->curx % 2) == 0 && (ui->cury % 2 == 0)) |
2021 | return ""; | 2017 | return UI_UPDATE; |
2022 | 2018 | ||
2023 | gx = ui->curx / 2; | 2019 | gx = ui->curx / 2; |
2024 | gy = ui->cury / 2; | 2020 | gy = ui->cury / 2; |
@@ -2030,7 +2026,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
2030 | else if (!direction && | 2026 | else if (!direction && |
2031 | ui_can_flip_square(state, gx, gy, button == CURSOR_SELECT2)) | 2027 | ui_can_flip_square(state, gx, gy, button == CURSOR_SELECT2)) |
2032 | return square_flip_str(state, gx, gy, button == CURSOR_SELECT2, tmpbuf); | 2028 | return square_flip_str(state, gx, gy, button == CURSOR_SELECT2, tmpbuf); |
2033 | return ""; | 2029 | return UI_UPDATE; |
2034 | } | 2030 | } |
2035 | 2031 | ||
2036 | #if 0 | 2032 | #if 0 |
@@ -2140,7 +2136,7 @@ enum { | |||
2140 | COL_GRID, COL_CLUE, COL_CURSOR, | 2136 | COL_GRID, COL_CLUE, COL_CURSOR, |
2141 | COL_TRACK, COL_TRACK_CLUE, COL_SLEEPER, | 2137 | COL_TRACK, COL_TRACK_CLUE, COL_SLEEPER, |
2142 | COL_DRAGON, COL_DRAGOFF, | 2138 | COL_DRAGON, COL_DRAGOFF, |
2143 | COL_ERROR, COL_FLASH, | 2139 | COL_ERROR, COL_FLASH, COL_ERROR_BACKGROUND, |
2144 | NCOLOURS | 2140 | NCOLOURS |
2145 | }; | 2141 | }; |
2146 | 2142 | ||
@@ -2152,11 +2148,12 @@ static float *game_colours(frontend *fe, int *ncolours) | |||
2152 | game_mkhighlight(fe, ret, COL_BACKGROUND, COL_HIGHLIGHT, COL_LOWLIGHT); | 2148 | game_mkhighlight(fe, ret, COL_BACKGROUND, COL_HIGHLIGHT, COL_LOWLIGHT); |
2153 | 2149 | ||
2154 | for (i = 0; i < 3; i++) { | 2150 | for (i = 0; i < 3; i++) { |
2155 | ret[COL_TRACK_CLUE * 3 + i] = 0.0F; | 2151 | ret[COL_TRACK_CLUE * 3 + i] = 0.0F; |
2156 | ret[COL_TRACK * 3 + i] = 0.5F; | 2152 | ret[COL_TRACK * 3 + i] = 0.5F; |
2157 | ret[COL_CLUE * 3 + i] = 0.0F; | 2153 | ret[COL_CLUE * 3 + i] = 0.0F; |
2158 | ret[COL_GRID * 3 + i] = 0.75F; | 2154 | ret[COL_GRID * 3 + i] = 0.75F; |
2159 | ret[COL_CURSOR * 3 + i] = 0.6F; | 2155 | ret[COL_CURSOR * 3 + i] = 0.6F; |
2156 | ret[COL_ERROR_BACKGROUND * 3 + i] = 1.0F; | ||
2160 | } | 2157 | } |
2161 | 2158 | ||
2162 | ret[COL_SLEEPER * 3 + 0] = 0.5F; | 2159 | ret[COL_SLEEPER * 3 + 0] = 0.5F; |
@@ -2417,7 +2414,7 @@ static void draw_square(drawing *dr, game_drawstate *ds, | |||
2417 | draw_update(dr, ox, oy, TILE_SIZE, TILE_SIZE); | 2414 | draw_update(dr, ox, oy, TILE_SIZE, TILE_SIZE); |
2418 | } | 2415 | } |
2419 | 2416 | ||
2420 | static void draw_clue(drawing *dr, game_drawstate *ds, int w, int clue, int i, int col) | 2417 | static void draw_clue(drawing *dr, game_drawstate *ds, int w, int clue, int i, int col, int bg) |
2421 | { | 2418 | { |
2422 | int cx, cy, tsz = TILE_SIZE/2; | 2419 | int cx, cy, tsz = TILE_SIZE/2; |
2423 | char buf[20]; | 2420 | char buf[20]; |
@@ -2432,7 +2429,7 @@ static void draw_clue(drawing *dr, game_drawstate *ds, int w, int clue, int i, i | |||
2432 | 2429 | ||
2433 | draw_rect(dr, cx - tsz + GRID_LINE_TL, cy - tsz + GRID_LINE_TL, | 2430 | draw_rect(dr, cx - tsz + GRID_LINE_TL, cy - tsz + GRID_LINE_TL, |
2434 | TILE_SIZE - GRID_LINE_ALL, TILE_SIZE - GRID_LINE_ALL, | 2431 | TILE_SIZE - GRID_LINE_ALL, TILE_SIZE - GRID_LINE_ALL, |
2435 | COL_BACKGROUND); | 2432 | bg); |
2436 | sprintf(buf, "%d", clue); | 2433 | sprintf(buf, "%d", clue); |
2437 | draw_text(dr, cx, cy, FONT_VARIABLE, tsz, ALIGN_VCENTRE|ALIGN_HCENTRE, | 2434 | draw_text(dr, cx, cy, FONT_VARIABLE, tsz, ALIGN_VCENTRE|ALIGN_HCENTRE, |
2438 | col, buf); | 2435 | col, buf); |
@@ -2518,7 +2515,8 @@ static void game_redraw(drawing *dr, game_drawstate *ds, const game_state *oldst | |||
2518 | if (force || (state->num_errors[i] != ds->num_errors[i])) { | 2515 | if (force || (state->num_errors[i] != ds->num_errors[i])) { |
2519 | ds->num_errors[i] = state->num_errors[i]; | 2516 | ds->num_errors[i] = state->num_errors[i]; |
2520 | draw_clue(dr, ds, w, state->numbers->numbers[i], i, | 2517 | draw_clue(dr, ds, w, state->numbers->numbers[i], i, |
2521 | ds->num_errors[i] ? COL_ERROR : COL_CLUE); | 2518 | ds->num_errors[i] ? COL_ERROR : COL_CLUE, |
2519 | ds->num_errors[i] ? COL_ERROR_BACKGROUND : COL_BACKGROUND); | ||
2522 | } | 2520 | } |
2523 | } | 2521 | } |
2524 | 2522 | ||
@@ -2608,7 +2606,8 @@ static void game_print(drawing *dr, const game_state *state, int tilesize) | |||
2608 | 2606 | ||
2609 | /* clue numbers, and loop ends */ | 2607 | /* clue numbers, and loop ends */ |
2610 | for (i = 0; i < w+h; i++) | 2608 | for (i = 0; i < w+h; i++) |
2611 | draw_clue(dr, ds, w, state->numbers->numbers[i], i, black); | 2609 | draw_clue(dr, ds, w, state->numbers->numbers[i], i, |
2610 | black, COL_BACKGROUND); | ||
2612 | draw_loop_ends(dr, ds, state, black); | 2611 | draw_loop_ends(dr, ds, state, black); |
2613 | 2612 | ||
2614 | /* clue tracks / solution */ | 2613 | /* clue tracks / solution */ |