summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/signpost.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/signpost.c')
-rw-r--r--apps/plugins/puzzles/src/signpost.c66
1 files changed, 34 insertions, 32 deletions
diff --git a/apps/plugins/puzzles/src/signpost.c b/apps/plugins/puzzles/src/signpost.c
index a61ec8b536..edcf63a823 100644
--- a/apps/plugins/puzzles/src/signpost.c
+++ b/apps/plugins/puzzles/src/signpost.c
@@ -387,24 +387,19 @@ static config_item *game_configure(const game_params *params)
387 ret[0].name = "Width"; 387 ret[0].name = "Width";
388 ret[0].type = C_STRING; 388 ret[0].type = C_STRING;
389 sprintf(buf, "%d", params->w); 389 sprintf(buf, "%d", params->w);
390 ret[0].sval = dupstr(buf); 390 ret[0].u.string.sval = dupstr(buf);
391 ret[0].ival = 0;
392 391
393 ret[1].name = "Height"; 392 ret[1].name = "Height";
394 ret[1].type = C_STRING; 393 ret[1].type = C_STRING;
395 sprintf(buf, "%d", params->h); 394 sprintf(buf, "%d", params->h);
396 ret[1].sval = dupstr(buf); 395 ret[1].u.string.sval = dupstr(buf);
397 ret[1].ival = 0;
398 396
399 ret[2].name = "Start and end in corners"; 397 ret[2].name = "Start and end in corners";
400 ret[2].type = C_BOOLEAN; 398 ret[2].type = C_BOOLEAN;
401 ret[2].sval = NULL; 399 ret[2].u.boolean.bval = params->force_corner_start;
402 ret[2].ival = params->force_corner_start;
403 400
404 ret[3].name = NULL; 401 ret[3].name = NULL;
405 ret[3].type = C_END; 402 ret[3].type = C_END;
406 ret[3].sval = NULL;
407 ret[3].ival = 0;
408 403
409 return ret; 404 return ret;
410} 405}
@@ -413,14 +408,14 @@ static game_params *custom_params(const config_item *cfg)
413{ 408{
414 game_params *ret = snew(game_params); 409 game_params *ret = snew(game_params);
415 410
416 ret->w = atoi(cfg[0].sval); 411 ret->w = atoi(cfg[0].u.string.sval);
417 ret->h = atoi(cfg[1].sval); 412 ret->h = atoi(cfg[1].u.string.sval);
418 ret->force_corner_start = cfg[2].ival; 413 ret->force_corner_start = cfg[2].u.boolean.bval;
419 414
420 return ret; 415 return ret;
421} 416}
422 417
423static char *validate_params(const game_params *params, int full) 418static const char *validate_params(const game_params *params, int full)
424{ 419{
425 if (params->w < 1) return "Width must be at least one"; 420 if (params->w < 1) return "Width must be at least one";
426 if (params->h < 1) return "Height must be at least one"; 421 if (params->h < 1) return "Height must be at least one";
@@ -502,10 +497,11 @@ static void free_game(game_state *state)
502} 497}
503 498
504static void unpick_desc(const game_params *params, const char *desc, 499static void unpick_desc(const game_params *params, const char *desc,
505 game_state **sout, char **mout) 500 game_state **sout, const char **mout)
506{ 501{
507 game_state *state = blank_game(params->w, params->h); 502 game_state *state = blank_game(params->w, params->h);
508 char *msg = NULL, c; 503 const char *msg = NULL;
504 char c;
509 int num = 0, i = 0; 505 int num = 0, i = 0;
510 506
511 while (*desc) { 507 while (*desc) {
@@ -848,9 +844,9 @@ generate:
848 return ret; 844 return ret;
849} 845}
850 846
851static char *validate_desc(const game_params *params, const char *desc) 847static const char *validate_desc(const game_params *params, const char *desc)
852{ 848{
853 char *ret = NULL; 849 const char *ret = NULL;
854 850
855 unpick_desc(params, desc, NULL, &ret); 851 unpick_desc(params, desc, NULL, &ret);
856 return ret; 852 return ret;
@@ -1342,7 +1338,7 @@ static int solve_state(game_state *state)
1342} 1338}
1343 1339
1344static char *solve_game(const game_state *state, const game_state *currstate, 1340static char *solve_game(const game_state *state, const game_state *currstate,
1345 const char *aux, char **error) 1341 const char *aux, const char **error)
1346{ 1342{
1347 game_state *tosolve; 1343 game_state *tosolve;
1348 char *ret = NULL; 1344 char *ret = NULL;
@@ -1441,18 +1437,20 @@ static char *interpret_move(const game_state *state, game_ui *ui,
1441 ui->dx = COORD(ui->cx) + TILE_SIZE/2; 1437 ui->dx = COORD(ui->cx) + TILE_SIZE/2;
1442 ui->dy = COORD(ui->cy) + TILE_SIZE/2; 1438 ui->dy = COORD(ui->cy) + TILE_SIZE/2;
1443 } 1439 }
1444 return ""; 1440 return UI_UPDATE;
1445 } else if (IS_CURSOR_SELECT(button)) { 1441 } else if (IS_CURSOR_SELECT(button)) {
1446 if (!ui->cshow) 1442 if (!ui->cshow)
1447 ui->cshow = 1; 1443 ui->cshow = 1;
1448 else if (ui->dragging) { 1444 else if (ui->dragging) {
1449 ui->dragging = FALSE; 1445 ui->dragging = FALSE;
1450 if (ui->sx == ui->cx && ui->sy == ui->cy) return ""; 1446 if (ui->sx == ui->cx && ui->sy == ui->cy) return UI_UPDATE;
1451 if (ui->drag_is_from) { 1447 if (ui->drag_is_from) {
1452 if (!isvalidmove(state, 0, ui->sx, ui->sy, ui->cx, ui->cy)) return ""; 1448 if (!isvalidmove(state, 0, ui->sx, ui->sy, ui->cx, ui->cy))
1449 return UI_UPDATE;
1453 sprintf(buf, "L%d,%d-%d,%d", ui->sx, ui->sy, ui->cx, ui->cy); 1450 sprintf(buf, "L%d,%d-%d,%d", ui->sx, ui->sy, ui->cx, ui->cy);
1454 } else { 1451 } else {
1455 if (!isvalidmove(state, 0, ui->cx, ui->cy, ui->sx, ui->sy)) return ""; 1452 if (!isvalidmove(state, 0, ui->cx, ui->cy, ui->sx, ui->sy))
1453 return UI_UPDATE;
1456 sprintf(buf, "L%d,%d-%d,%d", ui->cx, ui->cy, ui->sx, ui->sy); 1454 sprintf(buf, "L%d,%d-%d,%d", ui->cx, ui->cy, ui->sx, ui->sy);
1457 } 1455 }
1458 return dupstr(buf); 1456 return dupstr(buf);
@@ -1464,7 +1462,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
1464 ui->dy = COORD(ui->cy) + TILE_SIZE/2; 1462 ui->dy = COORD(ui->cy) + TILE_SIZE/2;
1465 ui->drag_is_from = (button == CURSOR_SELECT) ? 1 : 0; 1463 ui->drag_is_from = (button == CURSOR_SELECT) ? 1 : 0;
1466 } 1464 }
1467 return ""; 1465 return UI_UPDATE;
1468 } 1466 }
1469 if (IS_MOUSE_DOWN(button)) { 1467 if (IS_MOUSE_DOWN(button)) {
1470 if (ui->cshow) { 1468 if (ui->cshow) {
@@ -1492,29 +1490,31 @@ static char *interpret_move(const game_state *state, game_ui *ui,
1492 ui->dx = mx; 1490 ui->dx = mx;
1493 ui->dy = my; 1491 ui->dy = my;
1494 ui->cshow = 0; 1492 ui->cshow = 0;
1495 return ""; 1493 return UI_UPDATE;
1496 } else if (IS_MOUSE_DRAG(button) && ui->dragging) { 1494 } else if (IS_MOUSE_DRAG(button) && ui->dragging) {
1497 ui->dx = mx; 1495 ui->dx = mx;
1498 ui->dy = my; 1496 ui->dy = my;
1499 return ""; 1497 return UI_UPDATE;
1500 } else if (IS_MOUSE_RELEASE(button) && ui->dragging) { 1498 } else if (IS_MOUSE_RELEASE(button) && ui->dragging) {
1501 ui->dragging = FALSE; 1499 ui->dragging = FALSE;
1502 if (ui->sx == x && ui->sy == y) return ""; /* single click */ 1500 if (ui->sx == x && ui->sy == y) return UI_UPDATE; /* single click */
1503 1501
1504 if (!INGRID(state, x, y)) { 1502 if (!INGRID(state, x, y)) {
1505 int si = ui->sy*w+ui->sx; 1503 int si = ui->sy*w+ui->sx;
1506 if (state->prev[si] == -1 && state->next[si] == -1) 1504 if (state->prev[si] == -1 && state->next[si] == -1)
1507 return ""; 1505 return UI_UPDATE;
1508 sprintf(buf, "%c%d,%d", 1506 sprintf(buf, "%c%d,%d",
1509 (int)(ui->drag_is_from ? 'C' : 'X'), ui->sx, ui->sy); 1507 (int)(ui->drag_is_from ? 'C' : 'X'), ui->sx, ui->sy);
1510 return dupstr(buf); 1508 return dupstr(buf);
1511 } 1509 }
1512 1510
1513 if (ui->drag_is_from) { 1511 if (ui->drag_is_from) {
1514 if (!isvalidmove(state, 0, ui->sx, ui->sy, x, y)) return ""; 1512 if (!isvalidmove(state, 0, ui->sx, ui->sy, x, y))
1513 return UI_UPDATE;
1515 sprintf(buf, "L%d,%d-%d,%d", ui->sx, ui->sy, x, y); 1514 sprintf(buf, "L%d,%d-%d,%d", ui->sx, ui->sy, x, y);
1516 } else { 1515 } else {
1517 if (!isvalidmove(state, 0, x, y, ui->sx, ui->sy)) return ""; 1516 if (!isvalidmove(state, 0, x, y, ui->sx, ui->sy))
1517 return UI_UPDATE;
1518 sprintf(buf, "L%d,%d-%d,%d", x, y, ui->sx, ui->sy); 1518 sprintf(buf, "L%d,%d-%d,%d", x, y, ui->sx, ui->sy);
1519 } 1519 }
1520 return dupstr(buf); 1520 return dupstr(buf);
@@ -1523,7 +1523,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
1523 else if ((button == 'x' || button == 'X') && ui->cshow) { 1523 else if ((button == 'x' || button == 'X') && ui->cshow) {
1524 int si = ui->cy*w + ui->cx; 1524 int si = ui->cy*w + ui->cx;
1525 if (state->prev[si] == -1 && state->next[si] == -1) 1525 if (state->prev[si] == -1 && state->next[si] == -1)
1526 return ""; 1526 return UI_UPDATE;
1527 sprintf(buf, "%c%d,%d", 1527 sprintf(buf, "%c%d,%d",
1528 (int)((button == 'x') ? 'C' : 'X'), ui->cx, ui->cy); 1528 (int)((button == 'x') ? 'C' : 'X'), ui->cx, ui->cy);
1529 return dupstr(buf); 1529 return dupstr(buf);
@@ -1560,7 +1560,7 @@ static game_state *execute_move(const game_state *state, const char *move)
1560 if (move[0] == 'S') { 1560 if (move[0] == 'S') {
1561 game_params p; 1561 game_params p;
1562 game_state *tmp; 1562 game_state *tmp;
1563 char *valid; 1563 const char *valid;
1564 int i; 1564 int i;
1565 1565
1566 p.w = state->w; p.h = state->h; 1566 p.w = state->w; p.h = state->h;
@@ -2330,7 +2330,8 @@ static void start_soak(game_params *p, char *seedstr)
2330 2330
2331static void process_desc(char *id) 2331static void process_desc(char *id)
2332{ 2332{
2333 char *desc, *err, *solvestr; 2333 char *desc, *solvestr;
2334 const char *err;
2334 game_params *p; 2335 game_params *p;
2335 game_state *s; 2336 game_state *s;
2336 2337
@@ -2374,7 +2375,8 @@ static void process_desc(char *id)
2374 2375
2375int main(int argc, const char *argv[]) 2376int main(int argc, const char *argv[])
2376{ 2377{
2377 char *id = NULL, *desc, *err, *aux = NULL; 2378 char *id = NULL, *desc, *aux = NULL;
2379 const char *err;
2378 int soak = 0, verbose = 0, stdin_desc = 0, n = 1, i; 2380 int soak = 0, verbose = 0, stdin_desc = 0, n = 1, i;
2379 char *seedstr = NULL, newseed[16]; 2381 char *seedstr = NULL, newseed[16];
2380 2382