summaryrefslogtreecommitdiff
path: root/apps/plugins/puzzles/src/bridges.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/puzzles/src/bridges.c')
-rw-r--r--apps/plugins/puzzles/src/bridges.c72
1 files changed, 34 insertions, 38 deletions
diff --git a/apps/plugins/puzzles/src/bridges.c b/apps/plugins/puzzles/src/bridges.c
index 6975208fd6..0a326f2a42 100644
--- a/apps/plugins/puzzles/src/bridges.c
+++ b/apps/plugins/puzzles/src/bridges.c
@@ -742,44 +742,40 @@ static config_item *game_configure(const game_params *params)
742 ret[0].name = "Width"; 742 ret[0].name = "Width";
743 ret[0].type = C_STRING; 743 ret[0].type = C_STRING;
744 sprintf(buf, "%d", params->w); 744 sprintf(buf, "%d", params->w);
745 ret[0].sval = dupstr(buf); 745 ret[0].u.string.sval = dupstr(buf);
746 ret[0].ival = 0;
747 746
748 ret[1].name = "Height"; 747 ret[1].name = "Height";
749 ret[1].type = C_STRING; 748 ret[1].type = C_STRING;
750 sprintf(buf, "%d", params->h); 749 sprintf(buf, "%d", params->h);
751 ret[1].sval = dupstr(buf); 750 ret[1].u.string.sval = dupstr(buf);
752 ret[1].ival = 0;
753 751
754 ret[2].name = "Difficulty"; 752 ret[2].name = "Difficulty";
755 ret[2].type = C_CHOICES; 753 ret[2].type = C_CHOICES;
756 ret[2].sval = ":Easy:Medium:Hard"; 754 ret[2].u.choices.choicenames = ":Easy:Medium:Hard";
757 ret[2].ival = params->difficulty; 755 ret[2].u.choices.selected = params->difficulty;
758 756
759 ret[3].name = "Allow loops"; 757 ret[3].name = "Allow loops";
760 ret[3].type = C_BOOLEAN; 758 ret[3].type = C_BOOLEAN;
761 ret[3].sval = NULL; 759 ret[3].u.boolean.bval = params->allowloops;
762 ret[3].ival = params->allowloops;
763 760
764 ret[4].name = "Max. bridges per direction"; 761 ret[4].name = "Max. bridges per direction";
765 ret[4].type = C_CHOICES; 762 ret[4].type = C_CHOICES;
766 ret[4].sval = ":1:2:3:4"; /* keep up-to-date with MAX_BRIDGES */ 763 ret[4].u.choices.choicenames = ":1:2:3:4"; /* keep up-to-date with
767 ret[4].ival = params->maxb - 1; 764 * MAX_BRIDGES */
765 ret[4].u.choices.selected = params->maxb - 1;
768 766
769 ret[5].name = "%age of island squares"; 767 ret[5].name = "%age of island squares";
770 ret[5].type = C_CHOICES; 768 ret[5].type = C_CHOICES;
771 ret[5].sval = ":5%:10%:15%:20%:25%:30%"; 769 ret[5].u.choices.choicenames = ":5%:10%:15%:20%:25%:30%";
772 ret[5].ival = (params->islands / 5)-1; 770 ret[5].u.choices.selected = (params->islands / 5)-1;
773 771
774 ret[6].name = "Expansion factor (%age)"; 772 ret[6].name = "Expansion factor (%age)";
775 ret[6].type = C_CHOICES; 773 ret[6].type = C_CHOICES;
776 ret[6].sval = ":0%:10%:20%:30%:40%:50%:60%:70%:80%:90%:100%"; 774 ret[6].u.choices.choicenames = ":0%:10%:20%:30%:40%:50%:60%:70%:80%:90%:100%";
777 ret[6].ival = params->expansion / 10; 775 ret[6].u.choices.selected = params->expansion / 10;
778 776
779 ret[7].name = NULL; 777 ret[7].name = NULL;
780 ret[7].type = C_END; 778 ret[7].type = C_END;
781 ret[7].sval = NULL;
782 ret[7].ival = 0;
783 779
784 return ret; 780 return ret;
785} 781}
@@ -788,18 +784,18 @@ static game_params *custom_params(const config_item *cfg)
788{ 784{
789 game_params *ret = snew(game_params); 785 game_params *ret = snew(game_params);
790 786
791 ret->w = atoi(cfg[0].sval); 787 ret->w = atoi(cfg[0].u.string.sval);
792 ret->h = atoi(cfg[1].sval); 788 ret->h = atoi(cfg[1].u.string.sval);
793 ret->difficulty = cfg[2].ival; 789 ret->difficulty = cfg[2].u.choices.selected;
794 ret->allowloops = cfg[3].ival; 790 ret->allowloops = cfg[3].u.boolean.bval;
795 ret->maxb = cfg[4].ival + 1; 791 ret->maxb = cfg[4].u.choices.selected + 1;
796 ret->islands = (cfg[5].ival + 1) * 5; 792 ret->islands = (cfg[5].u.choices.selected + 1) * 5;
797 ret->expansion = cfg[6].ival * 10; 793 ret->expansion = cfg[6].u.choices.selected * 10;
798 794
799 return ret; 795 return ret;
800} 796}
801 797
802static char *validate_params(const game_params *params, int full) 798static const char *validate_params(const game_params *params, int full)
803{ 799{
804 if (params->w < 3 || params->h < 3) 800 if (params->w < 3 || params->h < 3)
805 return "Width and height must be at least 3"; 801 return "Width and height must be at least 3";
@@ -1993,7 +1989,7 @@ generated:
1993 return ret; 1989 return ret;
1994} 1990}
1995 1991
1996static char *validate_desc(const game_params *params, const char *desc) 1992static const char *validate_desc(const game_params *params, const char *desc)
1997{ 1993{
1998 int i, wh = params->w * params->h; 1994 int i, wh = params->w * params->h;
1999 1995
@@ -2094,7 +2090,7 @@ static char *ui_cancel_drag(game_ui *ui)
2094 ui->dragx_src = ui->dragy_src = -1; 2090 ui->dragx_src = ui->dragy_src = -1;
2095 ui->dragx_dst = ui->dragy_dst = -1; 2091 ui->dragx_dst = ui->dragy_dst = -1;
2096 ui->dragging = 0; 2092 ui->dragging = 0;
2097 return ""; 2093 return UI_UPDATE;
2098} 2094}
2099 2095
2100static game_ui *new_ui(const game_state *state) 2096static game_ui *new_ui(const game_state *state)
@@ -2282,7 +2278,7 @@ static char *update_drag_dst(const game_state *state, game_ui *ui,
2282 /*debug(("update_drag src (%d,%d) d(%d,%d) dst (%d,%d)\n", 2278 /*debug(("update_drag src (%d,%d) d(%d,%d) dst (%d,%d)\n",
2283 ui->dragx_src, ui->dragy_src, dx, dy, 2279 ui->dragx_src, ui->dragy_src, dx, dy,
2284 ui->dragx_dst, ui->dragy_dst));*/ 2280 ui->dragx_dst, ui->dragy_dst));*/
2285 return ""; 2281 return UI_UPDATE;
2286} 2282}
2287 2283
2288static char *finish_drag(const game_state *state, game_ui *ui) 2284static char *finish_drag(const game_state *state, game_ui *ui)
@@ -2325,7 +2321,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
2325 if (ggrid & G_ISLAND) { 2321 if (ggrid & G_ISLAND) {
2326 ui->dragx_src = gx; 2322 ui->dragx_src = gx;
2327 ui->dragy_src = gy; 2323 ui->dragy_src = gy;
2328 return ""; 2324 return UI_UPDATE;
2329 } else 2325 } else
2330 return ui_cancel_drag(ui); 2326 return ui_cancel_drag(ui);
2331 } else if (button == LEFT_DRAG || button == RIGHT_DRAG) { 2327 } else if (button == LEFT_DRAG || button == RIGHT_DRAG) {
@@ -2339,7 +2335,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
2339 /* cancel a drag when we go back to the starting point */ 2335 /* cancel a drag when we go back to the starting point */
2340 ui->dragx_dst = -1; 2336 ui->dragx_dst = -1;
2341 ui->dragy_dst = -1; 2337 ui->dragy_dst = -1;
2342 return ""; 2338 return UI_UPDATE;
2343 } 2339 }
2344 } else if (button == LEFT_RELEASE || button == RIGHT_RELEASE) { 2340 } else if (button == LEFT_RELEASE || button == RIGHT_RELEASE) {
2345 if (ui->dragging) { 2341 if (ui->dragging) {
@@ -2424,19 +2420,19 @@ static char *interpret_move(const game_state *state, game_ui *ui,
2424 2420
2425 if (!dingrid) break; 2421 if (!dingrid) break;
2426 } 2422 }
2427 if (!oingrid) return ""; 2423 if (!oingrid) return UI_UPDATE;
2428 } 2424 }
2429 /* not reached */ 2425 /* not reached */
2430 2426
2431found: 2427found:
2432 ui->cur_x = nx; 2428 ui->cur_x = nx;
2433 ui->cur_y = ny; 2429 ui->cur_y = ny;
2434 return ""; 2430 return UI_UPDATE;
2435 } 2431 }
2436 } else if (IS_CURSOR_SELECT(button)) { 2432 } else if (IS_CURSOR_SELECT(button)) {
2437 if (!ui->cur_visible) { 2433 if (!ui->cur_visible) {
2438 ui->cur_visible = 1; 2434 ui->cur_visible = 1;
2439 return ""; 2435 return UI_UPDATE;
2440 } 2436 }
2441 if (ui->dragging || button == CURSOR_SELECT2) { 2437 if (ui->dragging || button == CURSOR_SELECT2) {
2442 ui_cancel_drag(ui); 2438 ui_cancel_drag(ui);
@@ -2444,7 +2440,7 @@ found:
2444 sprintf(buf, "M%d,%d", ui->cur_x, ui->cur_y); 2440 sprintf(buf, "M%d,%d", ui->cur_x, ui->cur_y);
2445 return dupstr(buf); 2441 return dupstr(buf);
2446 } else 2442 } else
2447 return ""; 2443 return UI_UPDATE;
2448 } else { 2444 } else {
2449 grid_type v = GRID(state, ui->cur_x, ui->cur_y); 2445 grid_type v = GRID(state, ui->cur_x, ui->cur_y);
2450 if (v & G_ISLAND) { 2446 if (v & G_ISLAND) {
@@ -2453,7 +2449,7 @@ found:
2453 ui->dragy_src = ui->cur_y; 2449 ui->dragy_src = ui->cur_y;
2454 ui->dragx_dst = ui->dragy_dst = -1; 2450 ui->dragx_dst = ui->dragy_dst = -1;
2455 ui->drag_is_noline = (button == CURSOR_SELECT2) ? 1 : 0; 2451 ui->drag_is_noline = (button == CURSOR_SELECT2) ? 1 : 0;
2456 return ""; 2452 return UI_UPDATE;
2457 } 2453 }
2458 } 2454 }
2459 } else if ((button >= '0' && button <= '9') || 2455 } else if ((button >= '0' && button <= '9') ||
@@ -2471,7 +2467,7 @@ found:
2471 2467
2472 if (!ui->cur_visible) { 2468 if (!ui->cur_visible) {
2473 ui->cur_visible = 1; 2469 ui->cur_visible = 1;
2474 return ""; 2470 return UI_UPDATE;
2475 } 2471 }
2476 2472
2477 for (i = 0; i < state->n_islands; ++i) { 2473 for (i = 0; i < state->n_islands; ++i) {
@@ -2498,12 +2494,12 @@ found:
2498 if (best_x != -1 && best_y != -1) { 2494 if (best_x != -1 && best_y != -1) {
2499 ui->cur_x = best_x; 2495 ui->cur_x = best_x;
2500 ui->cur_y = best_y; 2496 ui->cur_y = best_y;
2501 return ""; 2497 return UI_UPDATE;
2502 } else 2498 } else
2503 return NULL; 2499 return NULL;
2504 } else if (button == 'g' || button == 'G') { 2500 } else if (button == 'g' || button == 'G') {
2505 ui->show_hints = 1 - ui->show_hints; 2501 ui->show_hints = 1 - ui->show_hints;
2506 return ""; 2502 return UI_UPDATE;
2507 } 2503 }
2508 2504
2509 return NULL; 2505 return NULL;
@@ -2577,7 +2573,7 @@ badmove:
2577} 2573}
2578 2574
2579static char *solve_game(const game_state *state, const game_state *currstate, 2575static char *solve_game(const game_state *state, const game_state *currstate,
2580 const char *aux, char **error) 2576 const char *aux, const char **error)
2581{ 2577{
2582 char *ret; 2578 char *ret;
2583 game_state *solved; 2579 game_state *solved;