X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=pearl.c;h=f44365630d25ebbf4e4a80567c5522837ed099f5;hb=c5500926bf7458aabb0e11945bfd24038bfeedee;hp=83413a2b9ecdb9a647836a76265faa9914235cdf;hpb=8e35087e093876cd12b1a5800c16a068473e9bff;p=sgt-puzzles.git diff --git a/pearl.c b/pearl.c index 83413a2..f443656 100644 --- a/pearl.c +++ b/pearl.c @@ -1509,11 +1509,7 @@ static void dsf_update_completion(game_state *state, int *loopclass, assert(INGRID(state, bx, by)); /* should not have a link off grid */ bc = by*w+bx; -#if 0 assert(state->lines[bc] & F(dir)); /* should have reciprocal link */ -#endif - /* TODO put above assertion back in once we stop generating partially - * soluble puzzles. */ if (!(state->lines[bc] & F(dir))) return; ae = dsf_canonify(dsf, ac); @@ -1737,7 +1733,7 @@ static char *game_text_format(const game_state *state) for (r = 0; r < h; ++r) { for (c = 0; c < w; ++c) { int i = r*w + c, cell = r*ch*gw + c*cw; - board[cell] = state->shared->clues[i]["+BW"]; + board[cell] = "+BW"[(unsigned char)state->shared->clues[i]]; if (c < w - 1 && (state->lines[i] & R || state->lines[i+1] & L)) memset(board + cell + 1, '-', cw - 1); if (r < h - 1 && (state->lines[i] & D || state->lines[i+w] & U)) @@ -1963,23 +1959,20 @@ static void interpret_ui_drag(const game_state *state, const game_ui *ui, } static char *mark_in_direction(const game_state *state, int x, int y, int dir, - int ismark, char *buf) + int primary, char *buf) { int w = state->shared->w /*, h = state->shared->h, sz = state->shared->sz */; int x2 = x + DX(dir); int y2 = y + DY(dir); int dir2 = F(dir); - char ch = ismark ? 'M' : 'F'; + + char ch = primary ? 'F' : 'M', *other; if (!INGRID(state, x, y) || !INGRID(state, x2, y2)) return ""; + /* disallow laying a mark over a line, or vice versa. */ - if (ismark) { - if ((state->lines[y*w+x] & dir) || (state->lines[y2*w+x2] & dir2)) - return ""; - } else { - if ((state->marks[y*w+x] & dir) || (state->marks[y2*w+x2] & dir2)) - return ""; - } + other = primary ? state->marks : state->lines; + if (other[y*w+x] & dir || other[y2*w+x2] & dir2) return ""; sprintf(buf, "%c%d,%d,%d;%c%d,%d,%d", ch, dir, x, y, ch, dir2, x2, y2); return dupstr(buf); @@ -2027,11 +2020,14 @@ static char *interpret_move(const game_state *state, game_ui *ui, if (!ui->cursor_active) { ui->cursor_active = TRUE; } else if (control | shift) { + char *move; if (ui->ndragcoords > 0) return NULL; ui->ndragcoords = -1; - return mark_in_direction(state, ui->curx, ui->cury, - KEY_DIRECTION(button & ~MOD_MASK), - (button & MOD_SHFT), tmpbuf); + move = mark_in_direction(state, ui->curx, ui->cury, + KEY_DIRECTION(button), control, tmpbuf); + if (control && !shift && *move) + move_cursor(button, &ui->curx, &ui->cury, w, h, FALSE); + return move; } else { move_cursor(button, &ui->curx, &ui->cury, w, h, FALSE); if (ui->ndragcoords >= 0) @@ -2058,6 +2054,11 @@ static char *interpret_move(const game_state *state, game_ui *ui, } } + if (button == 27 || button == '\b') { + ui->ndragcoords = -1; + return ""; + } + if (release) { if (ui->ndragcoords > 0) { /* End of a drag: process the cached line data. */ @@ -2124,7 +2125,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, direction = (x < cx) ? L : R; } return mark_in_direction(state, gx, gy, direction, - (button == RIGHT_RELEASE), tmpbuf); + (button == LEFT_RELEASE), tmpbuf); } } }