summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/pearl.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/pearl.c')
-rw-r--r--apps/plugins/puzzles/src/pearl.c56
1 files changed, 26 insertions, 30 deletions
diff --git a/apps/plugins/puzzles/src/pearl.c b/apps/plugins/puzzles/src/pearl.c
index c6c305f3f2..4f3be50275 100644
--- a/apps/plugins/puzzles/src/pearl.c
+++ b/apps/plugins/puzzles/src/pearl.c
@@ -234,29 +234,24 @@ static config_item *game_configure(const game_params *params)
234 ret[0].name = "Width"; 234 ret[0].name = "Width";
235 ret[0].type = C_STRING; 235 ret[0].type = C_STRING;
236 sprintf(buf, "%d", params->w); 236 sprintf(buf, "%d", params->w);
237 ret[0].sval = dupstr(buf); 237 ret[0].u.string.sval = dupstr(buf);
238 ret[0].ival = 0;
239 238
240 ret[1].name = "Height"; 239 ret[1].name = "Height";
241 ret[1].type = C_STRING; 240 ret[1].type = C_STRING;
242 sprintf(buf, "%d", params->h); 241 sprintf(buf, "%d", params->h);
243 ret[1].sval = dupstr(buf); 242 ret[1].u.string.sval = dupstr(buf);
244 ret[1].ival = 0;
245 243
246 ret[2].name = "Difficulty"; 244 ret[2].name = "Difficulty";
247 ret[2].type = C_CHOICES; 245 ret[2].type = C_CHOICES;
248 ret[2].sval = DIFFCONFIG; 246 ret[2].u.choices.choicenames = DIFFCONFIG;
249 ret[2].ival = params->difficulty; 247 ret[2].u.choices.selected = params->difficulty;
250 248
251 ret[3].name = "Allow unsoluble"; 249 ret[3].name = "Allow unsoluble";
252 ret[3].type = C_BOOLEAN; 250 ret[3].type = C_BOOLEAN;
253 ret[3].sval = NULL; 251 ret[3].u.boolean.bval = params->nosolve;
254 ret[3].ival = params->nosolve;
255 252
256 ret[4].name = NULL; 253 ret[4].name = NULL;
257 ret[4].type = C_END; 254 ret[4].type = C_END;
258 ret[4].sval = NULL;
259 ret[4].ival = 0;
260 255
261 return ret; 256 return ret;
262} 257}
@@ -265,15 +260,15 @@ static game_params *custom_params(const config_item *cfg)
265{ 260{
266 game_params *ret = snew(game_params); 261 game_params *ret = snew(game_params);
267 262
268 ret->w = atoi(cfg[0].sval); 263 ret->w = atoi(cfg[0].u.string.sval);
269 ret->h = atoi(cfg[1].sval); 264 ret->h = atoi(cfg[1].u.string.sval);
270 ret->difficulty = cfg[2].ival; 265 ret->difficulty = cfg[2].u.choices.selected;
271 ret->nosolve = cfg[3].ival; 266 ret->nosolve = cfg[3].u.boolean.bval;
272 267
273 return ret; 268 return ret;
274} 269}
275 270
276static char *validate_params(const game_params *params, int full) 271static const char *validate_params(const game_params *params, int full)
277{ 272{
278 if (params->w < 5) return "Width must be at least five"; 273 if (params->w < 5) return "Width must be at least five";
279 if (params->h < 5) return "Height must be at least five"; 274 if (params->h < 5) return "Height must be at least five";
@@ -1392,7 +1387,7 @@ static char *new_game_desc(const game_params *params, random_state *rs,
1392 return desc; 1387 return desc;
1393} 1388}
1394 1389
1395static char *validate_desc(const game_params *params, const char *desc) 1390static const char *validate_desc(const game_params *params, const char *desc)
1396{ 1391{
1397 int i, sizesofar; 1392 int i, sizesofar;
1398 const int totalsize = params->w * params->h; 1393 const int totalsize = params->w * params->h;
@@ -1726,7 +1721,7 @@ static char *solve_for_diff(game_state *state, char *old_lines, char *new_lines)
1726} 1721}
1727 1722
1728static char *solve_game(const game_state *state, const game_state *currstate, 1723static char *solve_game(const game_state *state, const game_state *currstate,
1729 const char *aux, char **error) 1724 const char *aux, const char **error)
1730{ 1725{
1731 game_state *solved = dup_game(state); 1726 game_state *solved = dup_game(state);
1732 int i, ret, sz = state->shared->sz; 1727 int i, ret, sz = state->shared->sz;
@@ -2022,11 +2017,11 @@ static char *mark_in_direction(const game_state *state, int x, int y, int dir,
2022 2017
2023 char ch = primary ? 'F' : 'M', *other; 2018 char ch = primary ? 'F' : 'M', *other;
2024 2019
2025 if (!INGRID(state, x, y) || !INGRID(state, x2, y2)) return ""; 2020 if (!INGRID(state, x, y) || !INGRID(state, x2, y2)) return UI_UPDATE;
2026 2021
2027 /* disallow laying a mark over a line, or vice versa. */ 2022 /* disallow laying a mark over a line, or vice versa. */
2028 other = primary ? state->marks : state->lines; 2023 other = primary ? state->marks : state->lines;
2029 if (other[y*w+x] & dir || other[y2*w+x2] & dir2) return ""; 2024 if (other[y*w+x] & dir || other[y2*w+x2] & dir2) return UI_UPDATE;
2030 2025
2031 sprintf(buf, "%c%d,%d,%d;%c%d,%d,%d", ch, dir, x, y, ch, dir2, x2, y2); 2026 sprintf(buf, "%c%d,%d,%d;%c%d,%d,%d", ch, dir, x, y, ch, dir2, x2, y2);
2032 return dupstr(buf); 2027 return dupstr(buf);
@@ -2060,12 +2055,12 @@ static char *interpret_move(const game_state *state, game_ui *ui,
2060 ui->dragcoords[0] = gy * w + gx; 2055 ui->dragcoords[0] = gy * w + gx;
2061 ui->ndragcoords = 0; /* will be 1 once drag is confirmed */ 2056 ui->ndragcoords = 0; /* will be 1 once drag is confirmed */
2062 2057
2063 return ""; 2058 return UI_UPDATE;
2064 } 2059 }
2065 2060
2066 if (button == LEFT_DRAG && ui->ndragcoords >= 0) { 2061 if (button == LEFT_DRAG && ui->ndragcoords >= 0) {
2067 update_ui_drag(state, ui, gx, gy); 2062 update_ui_drag(state, ui, gx, gy);
2068 return ""; 2063 return UI_UPDATE;
2069 } 2064 }
2070 2065
2071 if (IS_MOUSE_RELEASE(button)) release = TRUE; 2066 if (IS_MOUSE_RELEASE(button)) release = TRUE;
@@ -2087,30 +2082,30 @@ static char *interpret_move(const game_state *state, game_ui *ui,
2087 if (ui->ndragcoords >= 0) 2082 if (ui->ndragcoords >= 0)
2088 update_ui_drag(state, ui, ui->curx, ui->cury); 2083 update_ui_drag(state, ui, ui->curx, ui->cury);
2089 } 2084 }
2090 return ""; 2085 return UI_UPDATE;
2091 } 2086 }
2092 2087
2093 if (IS_CURSOR_SELECT(button)) { 2088 if (IS_CURSOR_SELECT(button)) {
2094 if (!ui->cursor_active) { 2089 if (!ui->cursor_active) {
2095 ui->cursor_active = TRUE; 2090 ui->cursor_active = TRUE;
2096 return ""; 2091 return UI_UPDATE;
2097 } else if (button == CURSOR_SELECT) { 2092 } else if (button == CURSOR_SELECT) {
2098 if (ui->ndragcoords == -1) { 2093 if (ui->ndragcoords == -1) {
2099 ui->ndragcoords = 0; 2094 ui->ndragcoords = 0;
2100 ui->dragcoords[0] = ui->cury * w + ui->curx; 2095 ui->dragcoords[0] = ui->cury * w + ui->curx;
2101 ui->clickx = CENTERED_COORD(ui->curx); 2096 ui->clickx = CENTERED_COORD(ui->curx);
2102 ui->clicky = CENTERED_COORD(ui->cury); 2097 ui->clicky = CENTERED_COORD(ui->cury);
2103 return ""; 2098 return UI_UPDATE;
2104 } else release = TRUE; 2099 } else release = TRUE;
2105 } else if (button == CURSOR_SELECT2 && ui->ndragcoords >= 0) { 2100 } else if (button == CURSOR_SELECT2 && ui->ndragcoords >= 0) {
2106 ui->ndragcoords = -1; 2101 ui->ndragcoords = -1;
2107 return ""; 2102 return UI_UPDATE;
2108 } 2103 }
2109 } 2104 }
2110 2105
2111 if (button == 27 || button == '\b') { 2106 if (button == 27 || button == '\b') {
2112 ui->ndragcoords = -1; 2107 ui->ndragcoords = -1;
2113 return ""; 2108 return UI_UPDATE;
2114 } 2109 }
2115 2110
2116 if (release) { 2111 if (release) {
@@ -2142,7 +2137,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
2142 2137
2143 ui->ndragcoords = -1; 2138 ui->ndragcoords = -1;
2144 2139
2145 return buf ? buf : ""; 2140 return buf ? buf : UI_UPDATE;
2146 } else if (ui->ndragcoords == 0) { 2141 } else if (ui->ndragcoords == 0) {
2147 /* Click (or tiny drag). Work out which edge we were 2142 /* Click (or tiny drag). Work out which edge we were
2148 * closest to. */ 2143 * closest to. */
@@ -2163,12 +2158,12 @@ static char *interpret_move(const game_state *state, game_ui *ui,
2163 cx = CENTERED_COORD(gx); 2158 cx = CENTERED_COORD(gx);
2164 cy = CENTERED_COORD(gy); 2159 cy = CENTERED_COORD(gy);
2165 2160
2166 if (!INGRID(state, gx, gy)) return ""; 2161 if (!INGRID(state, gx, gy)) return UI_UPDATE;
2167 2162
2168 if (max(abs(x-cx),abs(y-cy)) < TILE_SIZE/4) { 2163 if (max(abs(x-cx),abs(y-cy)) < TILE_SIZE/4) {
2169 /* TODO closer to centre of grid: process as a cell click not an edge click. */ 2164 /* TODO closer to centre of grid: process as a cell click not an edge click. */
2170 2165
2171 return ""; 2166 return UI_UPDATE;
2172 } else { 2167 } else {
2173 int direction; 2168 int direction;
2174 if (abs(x-cx) < abs(y-cy)) { 2169 if (abs(x-cx) < abs(y-cy)) {
@@ -2712,7 +2707,8 @@ int main(int argc, const char *argv[])
2712 game_params *p = NULL; 2707 game_params *p = NULL;
2713 random_state *rs = NULL; 2708 random_state *rs = NULL;
2714 time_t seed = time(NULL); 2709 time_t seed = time(NULL);
2715 char *id = NULL, *err; 2710 char *id = NULL;
2711 const char *err;
2716 2712
2717 setvbuf(stdout, NULL, _IONBF, 0); 2713 setvbuf(stdout, NULL, _IONBF, 0);
2718 2714