diff options
Diffstat (limited to 'apps/plugins/puzzles/src/galaxies.c')
-rw-r--r-- | apps/plugins/puzzles/src/galaxies.c | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/apps/plugins/puzzles/src/galaxies.c b/apps/plugins/puzzles/src/galaxies.c index 0cc3198ae0..fe7cd24ecf 100644 --- a/apps/plugins/puzzles/src/galaxies.c +++ b/apps/plugins/puzzles/src/galaxies.c | |||
@@ -346,29 +346,44 @@ static void add_assoc(const game_state *state, space *tile, space *dot) { | |||
346 | tile->x, tile->y, dot->x, dot->y, dot->nassoc));*/ | 346 | tile->x, tile->y, dot->x, dot->y, dot->nassoc));*/ |
347 | } | 347 | } |
348 | 348 | ||
349 | static void add_assoc_with_opposite(game_state *state, space *tile, space *dot) { | 349 | static bool ok_to_add_assoc_with_opposite_internal( |
350 | const game_state *state, space *tile, space *opposite) | ||
351 | { | ||
350 | int *colors; | 352 | int *colors; |
351 | space *opposite = space_opposite_dot(state, tile, dot); | 353 | bool toret; |
352 | 354 | ||
353 | if (opposite == NULL) { | 355 | if (tile->flags & F_DOT) |
354 | return; | 356 | return false; |
355 | } | 357 | if (opposite == NULL) |
356 | if (opposite->flags & F_DOT) { | 358 | return false; |
357 | return; | 359 | if (opposite->flags & F_DOT) |
358 | } | 360 | return false; |
359 | 361 | ||
362 | toret = true; | ||
360 | colors = snewn(state->w * state->h, int); | 363 | colors = snewn(state->w * state->h, int); |
361 | check_complete(state, NULL, colors); | 364 | check_complete(state, NULL, colors); |
362 | if (colors[(tile->y - 1)/2 * state->w + (tile->x - 1)/2]) { | 365 | |
363 | sfree(colors); | 366 | if (colors[(tile->y - 1)/2 * state->w + (tile->x - 1)/2]) |
364 | return; | 367 | toret = false; |
365 | } | 368 | if (colors[(opposite->y - 1)/2 * state->w + (opposite->x - 1)/2]) |
366 | if (colors[(opposite->y - 1)/2 * state->w + (opposite->x - 1)/2]) { | 369 | toret = false; |
367 | sfree(colors); | ||
368 | return; | ||
369 | } | ||
370 | 370 | ||
371 | sfree(colors); | 371 | sfree(colors); |
372 | return toret; | ||
373 | } | ||
374 | |||
375 | static bool ok_to_add_assoc_with_opposite( | ||
376 | const game_state *state, space *tile, space *dot) | ||
377 | { | ||
378 | space *opposite = space_opposite_dot(state, tile, dot); | ||
379 | return ok_to_add_assoc_with_opposite_internal(state, tile, opposite); | ||
380 | } | ||
381 | |||
382 | static void add_assoc_with_opposite(game_state *state, space *tile, space *dot) { | ||
383 | space *opposite = space_opposite_dot(state, tile, dot); | ||
384 | |||
385 | assert(ok_to_add_assoc_with_opposite_internal(state, tile, opposite)); | ||
386 | |||
372 | remove_assoc_with_opposite(state, tile); | 387 | remove_assoc_with_opposite(state, tile); |
373 | add_assoc(state, tile, dot); | 388 | add_assoc(state, tile, dot); |
374 | remove_assoc_with_opposite(state, opposite); | 389 | remove_assoc_with_opposite(state, opposite); |
@@ -2596,8 +2611,15 @@ static char *interpret_move(const game_state *state, game_ui *ui, | |||
2596 | */ | 2611 | */ |
2597 | if (INUI(state, px, py)) { | 2612 | if (INUI(state, px, py)) { |
2598 | sp = &SPACE(state, px, py); | 2613 | sp = &SPACE(state, px, py); |
2614 | dot = &SPACE(state, ui->dotx, ui->doty); | ||
2599 | 2615 | ||
2600 | if (!(sp->flags & F_DOT)) | 2616 | /* |
2617 | * Exception: if it's not actually legal to add an arrow | ||
2618 | * and its opposite at this position, we don't try, | ||
2619 | * because otherwise we'd append an empty entry to the | ||
2620 | * undo chain. | ||
2621 | */ | ||
2622 | if (ok_to_add_assoc_with_opposite(state, sp, dot)) | ||
2601 | sprintf(buf + strlen(buf), "%sA%d,%d,%d,%d", | 2623 | sprintf(buf + strlen(buf), "%sA%d,%d,%d,%d", |
2602 | sep, px, py, ui->dotx, ui->doty); | 2624 | sep, px, py, ui->dotx, ui->doty); |
2603 | } | 2625 | } |