Fix problems with arrow UI with non-square grid.
[sgt/puzzles] / mines.c
diff --git a/mines.c b/mines.c
index 49702ff..3c4dc13 100644 (file)
--- a/mines.c
+++ b/mines.c
@@ -22,12 +22,17 @@ enum {
     COL_1, COL_2, COL_3, COL_4, COL_5, COL_6, COL_7, COL_8,
     COL_MINE, COL_BANG, COL_CROSS, COL_FLAG, COL_FLAGBASE, COL_QUERY,
     COL_HIGHLIGHT, COL_LOWLIGHT,
+    COL_WRONGNUMBER,
     NCOLOURS
 };
 
 #define PREFERRED_TILE_SIZE 20
 #define TILE_SIZE (ds->tilesize)
+#ifdef SMALL_SCREEN
+#define BORDER 8
+#else
 #define BORDER (TILE_SIZE * 3 / 2)
+#endif
 #define HIGHLIGHT_WIDTH (TILE_SIZE / 10)
 #define OUTER_HIGHLIGHT_WIDTH (BORDER / 10)
 #define COORD(x)  ( (x) * TILE_SIZE + BORDER )
@@ -58,7 +63,7 @@ struct mine_layout {
 
 struct game_state {
     int w, h, n, dead, won;
-    int used_solve, just_used_solve;
+    int used_solve;
     struct mine_layout *layout;               /* real mine positions */
     signed char *grid;                        /* player knowledge */
     /*
@@ -101,8 +106,10 @@ static const struct game_params mines_presets[] = {
   {9, 9, 35, TRUE},
   {16, 16, 40, TRUE},
   {16, 16, 99, TRUE},
+#ifndef SMALL_SCREEN
   {30, 16, 99, TRUE},
   {30, 16, 170, TRUE},
+#endif
 };
 
 static int game_fetch_preset(int i, char **name, game_params **params)
@@ -2169,7 +2176,7 @@ static game_state *new_game(midend *me, game_params *params, char *desc)
     state->h = params->h;
     state->n = params->n;
     state->dead = state->won = FALSE;
-    state->used_solve = state->just_used_solve = FALSE;
+    state->used_solve = FALSE;
 
     wh = state->w * state->h;
 
@@ -2274,7 +2281,6 @@ static game_state *dup_game(game_state *state)
     ret->dead = state->dead;
     ret->won = state->won;
     ret->used_solve = state->used_solve;
-    ret->just_used_solve = state->just_used_solve;
     ret->layout = state->layout;
     ret->layout->refcount++;
     ret->grid = snewn(ret->w * ret->h, signed char);
@@ -2575,13 +2581,12 @@ static game_state *execute_move(game_state *from, char *move)
                    ret->grid[yy*ret->w+xx] = v;
                }
            }
-       ret->used_solve = ret->just_used_solve = TRUE;
+       ret->used_solve = TRUE;
        ret->won = TRUE;
 
        return ret;
     } else {
        ret = dup_game(from);
-       ret->just_used_solve = FALSE;
 
        while (*move) {
            if (move[0] == 'F' &&
@@ -2712,6 +2717,10 @@ static float *game_colours(frontend *fe, int *ncolours)
     ret[COL_LOWLIGHT * 3 + 1] = ret[COL_BACKGROUND * 3 + 1] * 2.0 / 3.0;
     ret[COL_LOWLIGHT * 3 + 2] = ret[COL_BACKGROUND * 3 + 2] * 2.0 / 3.0;
 
+    ret[COL_WRONGNUMBER * 3 + 0] = 1.0F;
+    ret[COL_WRONGNUMBER * 3 + 1] = 0.6F;
+    ret[COL_WRONGNUMBER * 3 + 2] = 0.6F;
+
     *ncolours = NCOLOURS;
     return ret;
 }
@@ -2816,6 +2825,10 @@ static void draw_tile(drawing *dr, game_drawstate *ds,
         * Exception is that for value 65 (mine we've just trodden
         * on), we clear the square to COL_BANG.
         */
+        if (v & 32) {
+            bg = COL_WRONGNUMBER;
+            v &= ~32;
+        }
         draw_rect(dr, x, y, TILE_SIZE, TILE_SIZE,
                  (v == 65 ? COL_BANG :
                    bg == COL_BACKGROUND ? COL_BACKGROUND2 : bg));
@@ -2962,6 +2975,26 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
            if (state->layout->mines && state->layout->mines[y*ds->w+x])
                mines++;
 
+            if (v >= 0 && v <= 8) {
+                /*
+                 * Count up the flags around this tile, and if
+                 * there are too _many_, highlight the tile.
+                 */
+                int dx, dy, flags = 0;
+
+                for (dy = -1; dy <= +1; dy++)
+                    for (dx = -1; dx <= +1; dx++) {
+                        int nx = x+dx, ny = y+dy;
+                        if (nx >= 0 && nx < ds->w &&
+                            ny >= 0 && ny < ds->h &&
+                            state->grid[ny*ds->w+nx] == -1)
+                            flags++;
+                    }
+
+                if (flags > v)
+                    v |= 32;
+            }
+
            if ((v == -2 || v == -3) &&
                (abs(x-ui->hx) <= ui->hradius && abs(y-ui->hy) <= ui->hradius))
                v -= 20;
@@ -3043,7 +3076,7 @@ static void game_print(drawing *dr, game_state *state, int tilesize)
 #endif
 
 const struct game thegame = {
-    "Mines", "games.mines",
+    "Mines", "games.mines", "mines",
     default_params,
     game_fetch_preset,
     decode_params,
@@ -3076,7 +3109,7 @@ const struct game thegame = {
     FALSE, FALSE, game_print_size, game_print,
     TRUE,                             /* wants_statusbar */
     TRUE, game_timing_state,
-    BUTTON_BEATS(LEFT_BUTTON, RIGHT_BUTTON),
+    BUTTON_BEATS(LEFT_BUTTON, RIGHT_BUTTON) | REQUIRE_RBUTTON,
 };
 
 #ifdef STANDALONE_OBFUSCATOR