chiark / gitweb /
Fix a decoding bug in Solo block-structure descriptions.
[sgt-puzzles.git] / galaxies.c
index 45d183599135799f88923f0637a95c911225f312..4ed913c03519bf9eb3645f7d1d9a4d1d31c486fe 100644 (file)
@@ -81,6 +81,7 @@ enum {
     COL_GRID,
     COL_EDGE,
     COL_ARROW,
+    COL_CURSOR,
     NCOLOURS
 };
 
@@ -193,7 +194,7 @@ static void free_params(game_params *params)
     sfree(params);
 }
 
-static game_params *dup_params(game_params *params)
+static game_params *dup_params(const game_params *params)
 {
     game_params *ret = snew(game_params);
     *ret = *params;                   /* structure copy */
@@ -220,7 +221,7 @@ static void decode_params(game_params *params, char const *string)
     }
 }
 
-static char *encode_params(game_params *params, int full)
+static char *encode_params(const game_params *params, int full)
 {
     char str[80];
     sprintf(str, "%dx%d", params->w, params->h);
@@ -229,7 +230,7 @@ static char *encode_params(game_params *params, int full)
     return dupstr(str);
 }
 
-static config_item *game_configure(game_params *params)
+static config_item *game_configure(const game_params *params)
 {
     config_item *ret;
     char buf[80];
@@ -261,7 +262,7 @@ static config_item *game_configure(game_params *params)
     return ret;
 }
 
-static game_params *custom_params(config_item *cfg)
+static game_params *custom_params(const config_item *cfg)
 {
     game_params *ret = snew(game_params);
 
@@ -272,7 +273,7 @@ static game_params *custom_params(config_item *cfg)
     return ret;
 }
 
-static char *validate_params(game_params *params, int full)
+static char *validate_params(const game_params *params, int full)
 {
     if (params->w < 3 || params->h < 3)
         return "Width and height must both be at least 3";
@@ -301,7 +302,7 @@ static void remove_dot(space *space) {
     space->flags &= ~F_DOT;
 }
 
-static void remove_assoc(game_state *state, space *tile) {
+static void remove_assoc(const game_state *state, space *tile) {
     if (tile->flags & F_TILE_ASSOC) {
         SPACE(state, tile->dotx, tile->doty).nassoc--;
         tile->flags &= ~F_TILE_ASSOC;
@@ -310,7 +311,7 @@ static void remove_assoc(game_state *state, space *tile) {
     }
 }
 
-static void add_assoc(game_state *state, space *tile, space *dot) {
+static void add_assoc(const game_state *state, space *tile, space *dot) {
     remove_assoc(state, tile);
 
 #ifdef STANDALONE_PICTURE_GENERATOR
@@ -326,7 +327,7 @@ static void add_assoc(game_state *state, space *tile, space *dot) {
            tile->x, tile->y, dot->x, dot->y, dot->nassoc));*/
 }
 
-static struct space *sp2dot(game_state *state, int x, int y)
+static struct space *sp2dot(const game_state *state, int x, int y)
 {
     struct space *sp = &SPACE(state, x, y);
     if (!(sp->flags & F_TILE_ASSOC)) return NULL;
@@ -335,7 +336,12 @@ static struct space *sp2dot(game_state *state, int x, int y)
 
 #define IS_VERTICAL_EDGE(x) ((x % 2) == 0)
 
-static char *game_text_format(game_state *state)
+static int game_can_format_as_text_now(const game_params *params)
+{
+    return TRUE;
+}
+
+static char *game_text_format(const game_state *state)
 {
     int maxlen = (state->sx+1)*state->sy, x, y;
     char *ret, *p;
@@ -359,7 +365,7 @@ static char *game_text_format(game_state *state)
                 case s_tile:
                     if (sp->flags & F_TILE_ASSOC) {
                         space *dot = sp2dot(state, sp->x, sp->y);
-                        if (dot->flags & F_DOT)
+                        if (dot && dot->flags & F_DOT)
                             *p++ = (dot->flags & F_DOT_BLACK) ? 'B' : 'W';
                         else
                             *p++ = '?'; /* association with not-a-dot. */
@@ -392,7 +398,7 @@ static char *game_text_format(game_state *state)
     return ret;
 }
 
-static void dbg_state(game_state *state)
+static void dbg_state(const game_state *state)
 {
 #ifdef DEBUGGING
     char *temp = game_text_format(state);
@@ -611,7 +617,8 @@ static void tiles_from_edge(struct game_state *state,
 
 /* Returns a move string for use by 'solve', including the initial
  * 'S' if issolve is true. */
-static char *diff_game(game_state *src, game_state *dest, int issolve)
+static char *diff_game(const game_state *src, const game_state *dest,
+                       int issolve)
 {
     int movelen = 0, movesize = 256, x, y, len;
     char *move = snewn(movesize, char), buf[80], *sep = "";
@@ -813,7 +820,7 @@ static void clear_game(game_state *state, int cleardots)
     if (cleardots) game_update_dots(state);
 }
 
-static game_state *dup_game(game_state *state)
+static game_state *dup_game(const game_state *state)
 {
     game_state *ret = blank_game(state->w, state->h);
 
@@ -1224,10 +1231,10 @@ static void generate_pass(game_state *state, random_state *rs, int *scratch,
     dbg_state(state);
 }
 
-static int check_complete(game_state *state, int *dsf, int *colours);
+static int check_complete(const game_state *state, int *dsf, int *colours);
 static int solver_state(game_state *state, int maxdiff);
 
-static char *new_game_desc(game_params *params, random_state *rs,
+static char *new_game_desc(const game_params *params, random_state *rs,
                           char **aux, int interactive)
 {
     game_state *state = blank_game(params->w, params->h), *copy;
@@ -1444,6 +1451,7 @@ generate:
                state = copy2;
            }
        }
+        sfree(posns);
     }
 #endif
 
@@ -1473,7 +1481,7 @@ static int dots_too_close(game_state *state)
     return (ret == -1) ? 1 : 0;
 }
 
-static game_state *load_game(game_params *params, char *desc,
+static game_state *load_game(const game_params *params, const char *desc,
                              char **why_r)
 {
     game_state *state = blank_game(params->w, params->h);
@@ -1521,7 +1529,7 @@ fail:
     return NULL;
 }
 
-static char *validate_desc(game_params *params, char *desc)
+static char *validate_desc(const game_params *params, const char *desc)
 {
     char *why = NULL;
     game_state *dummy = load_game(params, desc, &why);
@@ -1533,7 +1541,8 @@ static char *validate_desc(game_params *params, char *desc)
     return why;
 }
 
-static game_state *new_game(midend *me, game_params *params, char *desc)
+static game_state *new_game(midend *me, const game_params *params,
+                            const char *desc)
 {
     game_state *state = load_game(params, desc, NULL);
     if (!state) {
@@ -2205,8 +2214,8 @@ got_result:
 }
 
 #ifndef EDITOR
-static char *solve_game(game_state *state, game_state *currstate,
-                       char *aux, char **error)
+static char *solve_game(const game_state *state, const game_state *currstate,
+                        const char *aux, char **error)
 {
     game_state *tosolve;
     char *ret;
@@ -2253,12 +2262,15 @@ struct game_ui {
     int dx, dy;         /* pixel coords of drag pos. */
     int dotx, doty;     /* grid coords of dot we're dragging from. */
     int srcx, srcy;     /* grid coords of drag start */
+    int cur_x, cur_y, cur_visible;
 };
 
-static game_ui *new_ui(game_state *state)
+static game_ui *new_ui(const game_state *state)
 {
     game_ui *ui = snew(game_ui);
     ui->dragging = FALSE;
+    ui->cur_x = ui->cur_y = 1;
+    ui->cur_visible = 0;
     return ui;
 }
 
@@ -2267,17 +2279,17 @@ static void free_ui(game_ui *ui)
     sfree(ui);
 }
 
-static char *encode_ui(game_ui *ui)
+static char *encode_ui(const game_ui *ui)
 {
     return NULL;
 }
 
-static void decode_ui(game_ui *ui, char *encoding)
+static void decode_ui(game_ui *ui, const char *encoding)
 {
 }
 
-static void game_changed_state(game_ui *ui, game_state *oldstate,
-                               game_state *newstate)
+static void game_changed_state(game_ui *ui, const game_state *oldstate,
+                               const game_state *newstate)
 {
 }
 
@@ -2296,6 +2308,8 @@ static void game_changed_state(game_ui *ui, game_state *oldstate,
 #define DRAW_WIDTH      (BORDER * 2 + ds->w * TILE_SIZE)
 #define DRAW_HEIGHT     (BORDER * 2 + ds->h * TILE_SIZE)
 
+#define CURSOR_SIZE DOT_SIZE
+
 struct game_drawstate {
     int started;
     int w, h;
@@ -2307,6 +2321,9 @@ struct game_drawstate {
     int dragging, dragx, dragy;
 
     int *colour_scratch;
+
+    int cx, cy, cur_visible;
+    blitter *cur_bl;
 };
 
 #define CORNER_TOLERANCE 0.15F
@@ -2354,8 +2371,9 @@ static void coord_round_to_edge(float x, float y, int *xr, int *yr)
 #endif
 
 #ifdef EDITOR
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
-                           int x, int y, int button)
+static char *interpret_move(const game_state *state, game_ui *ui,
+                            const game_drawstate *ds,
+                            int x, int y, int button)
 {
     char buf[80];
     int px, py;
@@ -2389,8 +2407,9 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
     return NULL;
 }
 #else
-static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
-                           int x, int y, int button)
+static char *interpret_move(const game_state *state, game_ui *ui,
+                            const game_drawstate *ds,
+                            int x, int y, int button)
 {
     /* UI operations (play mode):
      *
@@ -2404,10 +2423,12 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
      * Add or remove dot (left-click)
      */
     char buf[80];
-    const char *sep;
+    const char *sep = "";
     int px, py;
     struct space *sp, *dot;
 
+    buf[0] = '\0';
+
     if (button == 'H' || button == 'h') {
         char *ret;
         game_state *tmp = dup_game(state);
@@ -2418,6 +2439,7 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
     }
 
     if (button == LEFT_BUTTON) {
+        ui->cur_visible = 0;
         coord_round_to_edge(FROMCOORD((float)x), FROMCOORD((float)y),
                             &px, &py);
 
@@ -2432,6 +2454,8 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
     } else if (button == RIGHT_BUTTON) {
         int px1, py1;
 
+        ui->cur_visible = 0;
+
         px = (int)(2*FROMCOORD((float)x) + 0.5);
         py = (int)(2*FROMCOORD((float)y) + 0.5);
 
@@ -2508,9 +2532,6 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
        if (px == ui->srcx && py == ui->srcy)
            return "";
 
-       sep = "";
-       buf[0] = '\0';
-
        /*
         * Otherwise, we remove the arrow from its starting
         * square if we didn't start from a dot...
@@ -2537,13 +2558,63 @@ static char *interpret_move(game_state *state, game_ui *ui, game_drawstate *ds,
            return dupstr(buf);
        else
            return "";
+    } else if (IS_CURSOR_MOVE(button)) {
+        move_cursor(button, &ui->cur_x, &ui->cur_y, state->sx-1, state->sy-1, 0);
+        if (ui->cur_x < 1) ui->cur_x = 1;
+        if (ui->cur_y < 1) ui->cur_y = 1;
+        ui->cur_visible = 1;
+        if (ui->dragging) {
+            ui->dx = SCOORD(ui->cur_x);
+            ui->dy = SCOORD(ui->cur_y);
+        }
+        return "";
+    } else if (IS_CURSOR_SELECT(button)) {
+        if (!ui->cur_visible) {
+            ui->cur_visible = 1;
+            return "";
+        }
+        sp = &SPACE(state, ui->cur_x, ui->cur_y);
+        if (ui->dragging) {
+            ui->dragging = FALSE;
+
+            if ((ui->srcx != ui->dotx || ui->srcy != ui->doty) &&
+                SPACE(state, ui->srcx, ui->srcy).flags & F_TILE_ASSOC) {
+                sprintf(buf, "%sU%d,%d", sep, ui->srcx, ui->srcy);
+                sep = ";";
+            }
+            if (sp->type == s_tile && !(sp->flags & F_DOT) && !(sp->flags & F_TILE_ASSOC)) {
+                sprintf(buf + strlen(buf), "%sA%d,%d,%d,%d",
+                        sep, ui->cur_x, ui->cur_y, ui->dotx, ui->doty);
+            }
+            return dupstr(buf);
+        } else if (sp->flags & F_DOT) {
+            ui->dragging = TRUE;
+            ui->dx = SCOORD(ui->cur_x);
+            ui->dy = SCOORD(ui->cur_y);
+            ui->dotx = ui->srcx = ui->cur_x;
+            ui->doty = ui->srcy = ui->cur_y;
+            return "";
+        } else if (sp->flags & F_TILE_ASSOC) {
+            assert(sp->type == s_tile);
+            ui->dragging = TRUE;
+            ui->dx = SCOORD(ui->cur_x);
+            ui->dy = SCOORD(ui->cur_y);
+            ui->dotx = sp->dotx;
+            ui->doty = sp->doty;
+            ui->srcx = ui->cur_x;
+            ui->srcy = ui->cur_y;
+            return "";
+        } else if (sp->type == s_edge) {
+            sprintf(buf, "E%d,%d", ui->cur_x, ui->cur_y);
+            return dupstr(buf);
+        }
     }
 
     return NULL;
 }
 #endif
 
-static int check_complete(game_state *state, int *dsf, int *colours)
+static int check_complete(const game_state *state, int *dsf, int *colours)
 {
     int w = state->w, h = state->h;
     int x, y, i, ret;
@@ -2720,7 +2791,7 @@ static int check_complete(game_state *state, int *dsf, int *colours)
     return ret;
 }
 
-static game_state *execute_move(game_state *state, char *move)
+static game_state *execute_move(const game_state *state, const char *move)
 {
     int x, y, ax, ay, n, dx, dy;
     game_state *ret = dup_game(state);
@@ -2840,8 +2911,8 @@ badmove:
  * we may want to drag from them, for example.
  */
 
-static void game_compute_size(game_params *params, int sz,
-                             int *x, int *y)
+static void game_compute_size(const game_params *params, int sz,
+                              int *x, int *y)
 {
     struct { int tilesize, w, h; } ads, *ds = &ads;
 
@@ -2854,7 +2925,7 @@ static void game_compute_size(game_params *params, int sz,
 }
 
 static void game_set_size(drawing *dr, game_drawstate *ds,
-                         game_params *params, int sz)
+                          const game_params *params, int sz)
 {
     ds->tilesize = sz;
 
@@ -2862,6 +2933,9 @@ static void game_set_size(drawing *dr, game_drawstate *ds,
 
     assert(!ds->bl);
     ds->bl = blitter_new(dr, TILE_SIZE, TILE_SIZE);
+
+    assert(!ds->cur_bl);
+    ds->cur_bl = blitter_new(dr, TILE_SIZE, TILE_SIZE);
 }
 
 static float *game_colours(frontend *fe, int *ncolours)
@@ -2907,15 +2981,18 @@ static float *game_colours(frontend *fe, int *ncolours)
     /* tinge the edit background to bluey */
     ret[COL_BACKGROUND * 3 + 0] = ret[COL_BACKGROUND * 3 + 0] * 0.8F;
     ret[COL_BACKGROUND * 3 + 1] = ret[COL_BACKGROUND * 3 + 0] * 0.8F;
-    ret[COL_BACKGROUND * 3 + 2] = ret[COL_BACKGROUND * 3 + 0] * 1.4F;
-    if (ret[COL_BACKGROUND * 3 + 2] > 1.0F) ret[COL_BACKGROUND * 3 + 2] = 1.0F;
+    ret[COL_BACKGROUND * 3 + 2] = min(ret[COL_BACKGROUND * 3 + 0] * 1.4F, 1.0F);
 #endif
 
+    ret[COL_CURSOR * 3 + 0] = min(ret[COL_BACKGROUND * 3 + 0] * 1.4F, 1.0F);
+    ret[COL_CURSOR * 3 + 1] = ret[COL_BACKGROUND * 3 + 0] * 0.8F;
+    ret[COL_CURSOR * 3 + 2] = ret[COL_BACKGROUND * 3 + 0] * 0.8F;
+
     *ncolours = NCOLOURS;
     return ret;
 }
 
-static game_drawstate *game_new_drawstate(drawing *dr, game_state *state)
+static game_drawstate *game_new_drawstate(drawing *dr, const game_state *state)
 {
     struct game_drawstate *ds = snew(struct game_drawstate);
     int i;
@@ -2936,11 +3013,16 @@ static game_drawstate *game_new_drawstate(drawing *dr, game_state *state)
 
     ds->colour_scratch = snewn(ds->w * ds->h, int);
 
+    ds->cur_bl = NULL;
+    ds->cx = ds->cy = 0;
+    ds->cur_visible = 0;
+
     return ds;
 }
 
 static void game_free_drawstate(drawing *dr, game_drawstate *ds)
 {
+    if (ds->cur_bl) blitter_free(dr, ds->cur_bl);
     sfree(ds->colour_scratch);
     if (ds->bl) blitter_free(dr, ds->bl);
     sfree(ds->dx);
@@ -2960,7 +3042,8 @@ static void game_free_drawstate(drawing *dr, game_drawstate *ds)
 #define DRAW_WHITE     0x0100
 #define DRAW_BLACK     0x0200
 #define DRAW_ARROW     0x0400
-#define DOT_SHIFT_C    11
+#define DRAW_CURSOR    0x0800
+#define DOT_SHIFT_C    12
 #define DOT_SHIFT_M    2
 #define DOT_WHITE      1UL
 #define DOT_BLACK      2UL
@@ -2970,7 +3053,7 @@ static void game_free_drawstate(drawing *dr, game_drawstate *ds)
  * (ddx,ddy). (I.e. pointing at the point (cx+ddx, cy+ddy).
  */
 static void draw_arrow(drawing *dr, game_drawstate *ds,
-                       int cx, int cy, int ddx, int ddy)
+                       int cx, int cy, int ddx, int ddy, int col)
 {
     float vlen = (float)sqrt(ddx*ddx+ddy*ddy);
     float xdx = ddx/vlen, xdy = ddy/vlen;
@@ -2980,9 +3063,9 @@ static void draw_arrow(drawing *dr, game_drawstate *ds,
     int adx = (int)((ydx-xdx)*TILE_SIZE/8), ady = (int)((ydy-xdy)*TILE_SIZE/8);
     int adx2 = (int)((-ydx-xdx)*TILE_SIZE/8), ady2 = (int)((-ydy-xdy)*TILE_SIZE/8);
 
-    draw_line(dr, e1x, e1y, e2x, e2y, COL_ARROW);
-    draw_line(dr, e1x, e1y, e1x+adx, e1y+ady, COL_ARROW);
-    draw_line(dr, e1x, e1y, e1x+adx2, e1y+ady2, COL_ARROW);
+    draw_line(dr, e1x, e1y, e2x, e2y, col);
+    draw_line(dr, e1x, e1y, e1x+adx, e1y+ady, col);
+    draw_line(dr, e1x, e1y, e1x+adx2, e1y+ady2, col);
 }
 
 static void draw_square(drawing *dr, game_drawstate *ds, int x, int y,
@@ -3009,10 +3092,17 @@ static void draw_square(drawing *dr, game_drawstate *ds, int x, int y,
     draw_rect(dr, lx, ly, TILE_SIZE, 1, gridcol);
 
     /*
-     * Draw the arrow.
+     * Draw the arrow, if present, or the cursor, if here.
      */
     if (flags & DRAW_ARROW)
-        draw_arrow(dr, ds, lx + TILE_SIZE/2, ly + TILE_SIZE/2, ddx, ddy);
+        draw_arrow(dr, ds, lx + TILE_SIZE/2, ly + TILE_SIZE/2, ddx, ddy,
+                   (flags & DRAW_CURSOR) ? COL_CURSOR : COL_ARROW);
+    else if (flags & DRAW_CURSOR)
+        draw_rect_outline(dr,
+                          lx + TILE_SIZE/2 - CURSOR_SIZE,
+                          ly + TILE_SIZE/2 - CURSOR_SIZE,
+                          2*CURSOR_SIZE+1, 2*CURSOR_SIZE+1,
+                          COL_CURSOR);
 
     /*
      * Draw the edges.
@@ -3059,9 +3149,10 @@ static void draw_square(drawing *dr, game_drawstate *ds, int x, int y,
     draw_update(dr, lx, ly, TILE_SIZE, TILE_SIZE);
 }
 
-static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
-                       game_state *state, int dir, game_ui *ui,
-                       float animtime, float flashtime)
+static void game_redraw(drawing *dr, game_drawstate *ds,
+                        const game_state *oldstate, const game_state *state,
+                        int dir, const game_ui *ui,
+                        float animtime, float flashtime)
 {
     int w = ds->w, h = ds->h;
     int x, y, flashing = FALSE;
@@ -3077,6 +3168,12 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
         draw_update(dr, ds->dragx, ds->dragy, TILE_SIZE, TILE_SIZE);
         ds->dragging = FALSE;
     }
+    if (ds->cur_visible) {
+        assert(ds->cur_bl);
+        blitter_load(dr, ds->cur_bl, ds->cx, ds->cy);
+        draw_update(dr, ds->cx, ds->cy, CURSOR_SIZE*2+1, CURSOR_SIZE*2+1);
+        ds->cur_visible = FALSE;
+    }
 
     if (!ds->started) {
         draw_rect(dr, 0, 0, DRAW_WIDTH, DRAW_HEIGHT, COL_BACKGROUND);
@@ -3169,6 +3266,15 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
                     }
                 }
 
+            /*
+             * Now work out if we have to draw a cursor for this square;
+             * cursors-on-lines are taken care of below.
+             */
+            if (ui->cur_visible &&
+                ui->cur_x == x*2+1 && ui->cur_y == y*2+1 &&
+                !(SPACE(state, x*2+1, y*2+1).flags & F_DOT))
+                flags |= DRAW_CURSOR;
+
             /*
              * Now we have everything we're going to need. Draw the
              * square.
@@ -3183,6 +3289,33 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
             }
         }
 
+    /*
+     * Draw a cursor. This secondary blitter is much less invasive than trying
+     * to fix up all of the rest of the code with sufficient flags to be able to
+     * display this sensibly.
+     */
+    if (ui->cur_visible) {
+        space *sp = &SPACE(state, ui->cur_x, ui->cur_y);
+        ds->cur_visible = TRUE;
+        ds->cx = SCOORD(ui->cur_x) - CURSOR_SIZE;
+        ds->cy = SCOORD(ui->cur_y) - CURSOR_SIZE;
+        blitter_save(dr, ds->cur_bl, ds->cx, ds->cy);
+        if (sp->flags & F_DOT) {
+            /* draw a red dot (over the top of whatever would be there already) */
+            draw_circle(dr, SCOORD(ui->cur_x), SCOORD(ui->cur_y), DOT_SIZE,
+                        COL_CURSOR, COL_BLACKDOT);
+        } else if (sp->type != s_tile) {
+            /* draw an edge/vertex square; tile cursors are dealt with above. */
+            int dx = (ui->cur_x % 2) ? CURSOR_SIZE : CURSOR_SIZE/3;
+            int dy = (ui->cur_y % 2) ? CURSOR_SIZE : CURSOR_SIZE/3;
+            int x1 = SCOORD(ui->cur_x)-dx, y1 = SCOORD(ui->cur_y)-dy;
+            int xs = dx*2+1, ys = dy*2+1;
+
+            draw_rect(dr, x1, y1, xs, ys, COL_CURSOR);
+        }
+        draw_update(dr, ds->cx, ds->cy, CURSOR_SIZE*2+1, CURSOR_SIZE*2+1);
+    }
+
     if (ui->dragging) {
         ds->dragging = TRUE;
         ds->dragx = ui->dx - TILE_SIZE/2;
@@ -3190,7 +3323,7 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
         blitter_save(dr, ds->bl, ds->dragx, ds->dragy);
         draw_arrow(dr, ds, ui->dx, ui->dy,
                    SCOORD(ui->dotx) - ui->dx,
-                   SCOORD(ui->doty) - ui->dy);
+                   SCOORD(ui->doty) - ui->dy, COL_ARROW);
     }
 #ifdef EDITOR
     {
@@ -3204,14 +3337,14 @@ static void game_redraw(drawing *dr, game_drawstate *ds, game_state *oldstate,
 #endif
 }
 
-static float game_anim_length(game_state *oldstate, game_state *newstate,
-                             int dir, game_ui *ui)
+static float game_anim_length(const game_state *oldstate,
+                              const game_state *newstate, int dir, game_ui *ui)
 {
     return 0.0F;
 }
 
-static float game_flash_length(game_state *oldstate, game_state *newstate,
-                              int dir, game_ui *ui)
+static float game_flash_length(const game_state *oldstate,
+                               const game_state *newstate, int dir, game_ui *ui)
 {
     if ((!oldstate->completed && newstate->completed) &&
         !(newstate->used_solve))
@@ -3220,13 +3353,18 @@ static float game_flash_length(game_state *oldstate, game_state *newstate,
         return 0.0F;
 }
 
-static int game_timing_state(game_state *state, game_ui *ui)
+static int game_status(const game_state *state)
+{
+    return state->completed ? +1 : 0;
+}
+
+static int game_timing_state(const game_state *state, game_ui *ui)
 {
     return TRUE;
 }
 
 #ifndef EDITOR
-static void game_print_size(game_params *params, float *x, float *y)
+static void game_print_size(const game_params *params, float *x, float *y)
 {
    int pw, ph;
 
@@ -3239,7 +3377,7 @@ static void game_print_size(game_params *params, float *x, float *y)
    *y = ph / 100.0F;
 }
 
-static void game_print(drawing *dr, game_state *state, int sz)
+static void game_print(drawing *dr, const game_state *state, int sz)
 {
     int w = state->w, h = state->h;
     int white, black, blackish;
@@ -3425,7 +3563,7 @@ const struct game thegame = {
 #else
     TRUE, solve_game,
 #endif
-    TRUE, game_text_format,
+    TRUE, game_can_format_as_text_now, game_text_format,
     new_ui,
     free_ui,
     encode_ui,
@@ -3440,6 +3578,7 @@ const struct game thegame = {
     game_redraw,
     game_anim_length,
     game_flash_length,
+    game_status,
 #ifdef EDITOR
     FALSE, FALSE, NULL, NULL,
     TRUE,                              /* wants_statusbar */