X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=blobdiff_plain;f=towers.c;h=a3a7e55a45f01166932ad7ca0b5f42df06ca20a7;hb=db313b3948d27244dd7c34c2609c66d6204d8931;hp=9c2cdd8e75ab0edfc7ddcf3e21d5797b777e8292;hpb=486d2c8a76e325d7a145e236a8c8b21d159fa412;p=sgt-puzzles.git diff --git a/towers.c b/towers.c index 9c2cdd8..a3a7e55 100644 --- a/towers.c +++ b/towers.c @@ -114,7 +114,7 @@ static const char *const cluepos[] = { struct game_state { game_params par; struct clues *clues; - int *cluesdone; + unsigned char *clues_done; digit *grid; int *pencil; /* bitmaps using bits 1<<1..1<clues->clues = snewn(4*w, int); state->clues->immutable = snewn(a, digit); state->grid = snewn(a, digit); - state->cluesdone = snewn(4*w, int); + state->clues_done = snewn(4*w, unsigned char); state->pencil = snewn(a, int); for (i = 0; i < a; i++) { @@ -891,7 +891,7 @@ static game_state *new_game(midend *me, const game_params *params, } memset(state->clues->immutable, 0, a); - memset(state->cluesdone, 0, 4*w*sizeof(int)); + memset(state->clues_done, 0, 4*w*sizeof(unsigned char)); for (i = 0; i < 4*w; i++) { if (i > 0) { @@ -945,10 +945,10 @@ static game_state *dup_game(const game_state *state) ret->grid = snewn(a, digit); ret->pencil = snewn(a, int); - ret->cluesdone = snewn(4*w, int); + ret->clues_done = snewn(4*w, unsigned char); memcpy(ret->grid, state->grid, a*sizeof(digit)); memcpy(ret->pencil, state->pencil, a*sizeof(int)); - memcpy(ret->cluesdone, state->cluesdone, 4*w*sizeof(int)); + memcpy(ret->clues_done, state->clues_done, 4*w*sizeof(unsigned char)); ret->completed = state->completed; ret->cheated = state->cheated; @@ -960,7 +960,7 @@ static void free_game(game_state *state) { sfree(state->grid); sfree(state->pencil); - sfree(state->cluesdone); + sfree(state->clues_done); if (--state->clues->refcount <= 0) { sfree(state->clues->immutable); sfree(state->clues->clues); @@ -1248,7 +1248,8 @@ static int check_errors(const game_state *state, int *errors) } } - if (n > clues[i] || (j == w && n < clues[i])) { + if (n > clues[i] || (best == w && n < clues[i]) || + (best < w && n == clues[i])) { if (errors) { int x, y; CLUEPOS(x, y, i, w); @@ -1292,6 +1293,7 @@ static char *interpret_move(const game_state *state, game_ui *ui, int x, int y, int button) { int w = state->par.w; + int shift_or_control = button & (MOD_SHFT | MOD_CTRL); int tx, ty; char buf[80]; @@ -1376,6 +1378,20 @@ static char *interpret_move(const game_state *state, game_ui *ui, } } if (IS_CURSOR_MOVE(button)) { + if (shift_or_control) { + int x = ui->hx, y = ui->hy; + switch (button) { + case CURSOR_LEFT: x = -1; break; + case CURSOR_RIGHT: x = w; break; + case CURSOR_UP: y = -1; break; + case CURSOR_DOWN: y = w; break; + } + if (is_clue(state, x, y)) { + sprintf(buf, "%c%d,%d", 'D', x, y); + return dupstr(buf); + } + return NULL; + } move_cursor(button, &ui->hx, &ui->hy, w, w, 0); ui->hshow = ui->hcursor = 1; return ""; @@ -1472,7 +1488,7 @@ static game_state *execute_move(const game_state *from, const char *move) } else if (move[0] == 'D' && sscanf(move+1, "%d,%d", &x, &y) == 2 && is_clue(from, x, y)) { int index = clue_index(from, x, y); - ret->cluesdone[index] = !ret->cluesdone[index]; + ret->clues_done[index] = !ret->clues_done[index]; return ret; } @@ -1781,7 +1797,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, if (ds->errtmp[(y+1)*(w+2)+(x+1)]) tile |= DF_ERROR; - else if (state->cluesdone[i]) + else if (state->clues_done[i]) tile |= DF_CLUE_DONE; ds->tiles[(y+1)*(w+2)+(x+1)] = tile; @@ -1962,7 +1978,7 @@ static void game_print(drawing *dr, const game_state *state, int tilesize) const struct game thegame = { "Towers", "games.towers", "towers", default_params, - game_fetch_preset, + game_fetch_preset, NULL, decode_params, encode_params, free_params,