Patch from James H: tinker with the presets on SLOW_SYSTEMs.
[sgt/puzzles] / midend.c
index b5efda6..f7d1aca 100644 (file)
--- a/midend.c
+++ b/midend.c
@@ -237,7 +237,8 @@ void midend_set_params(midend_data *me, game_params *params)
 static void midend_set_timer(midend_data *me)
 {
     me->timing = (me->ourgame->is_timed &&
-                 me->ourgame->timing_state(me->states[me->statepos-1].state));
+                 me->ourgame->timing_state(me->states[me->statepos-1].state,
+                                           me->ui));
     if (me->timing || me->flash_time || me->anim_time)
        activate_timer(me->frontend);
     else
@@ -311,10 +312,10 @@ void midend_new_game(midend_data *me)
     me->drawstate = me->ourgame->new_drawstate(me->states[0].state);
     midend_size_new_drawstate(me);
     me->elapsed = 0.0F;
-    midend_set_timer(me);
     if (me->ui)
         me->ourgame->free_ui(me->ui);
     me->ui = me->ourgame->new_ui(me->states[0].state);
+    midend_set_timer(me);
     me->pressed_mouse_button = 0;
 }
 
@@ -381,7 +382,7 @@ static void midend_finish_move(midend_data *me)
 
 void midend_stop_anim(midend_data *me)
 {
-    if (me->oldstate || me->anim_time) {
+    if (me->oldstate || me->anim_time != 0) {
        midend_finish_move(me);
         midend_redraw(me);
     }
@@ -431,7 +432,7 @@ static int midend_really_process_key(midend_data *me, int x, int y, int button)
 {
     game_state *oldstate =
         me->ourgame->dup_game(me->states[me->statepos - 1].state);
-    int special = FALSE, gotspecial = FALSE, ret = 1;
+    int type = MOVE, gottype = FALSE, ret = 1;
     float anim_time;
     game_state *s;
     char *movestr;
@@ -449,8 +450,8 @@ static int midend_really_process_key(midend_data *me, int x, int y, int button)
        } else if (button == 'u' || button == 'u' ||
                   button == '\x1A' || button == '\x1F') {
            midend_stop_anim(me);
-           special = special(me->states[me->statepos-1].movetype);
-           gotspecial = TRUE;
+           type = me->states[me->statepos-1].movetype;
+           gottype = TRUE;
            if (!midend_undo(me))
                goto done;
        } else if (button == 'r' || button == 'R' ||
@@ -491,18 +492,23 @@ static int midend_really_process_key(midend_data *me, int x, int y, int button)
             me->states[me->nstates].movetype = MOVE;
             me->statepos = ++me->nstates;
             me->dir = +1;
+           if (me->ui)
+               me->ourgame->changed_state(me->ui,
+                                          me->states[me->statepos-2].state,
+                                          me->states[me->statepos-1].state);
         } else {
             goto done;
         }
     }
 
-    if (!gotspecial)
-        special = special(me->states[me->statepos-1].movetype);
+    if (!gottype)
+        type = me->states[me->statepos-1].movetype;
 
     /*
      * See if this move requires an animation.
      */
-    if (special) {
+    if (special(type) && !(type == SOLVE &&
+                          (me->ourgame->mouse_priorities & SOLVE_ANIMATES))) {
         anim_time = 0;
     } else {
         anim_time = me->ourgame->anim_length(oldstate,
@@ -789,7 +795,7 @@ int midend_num_presets(midend_data *me)
                 preset = me->ourgame->default_params();
                 me->ourgame->decode_params(preset, val);
 
-               if (me->ourgame->validate_params(preset)) {
+               if (me->ourgame->validate_params(preset, TRUE)) {
                    /* Drop this one from the list. */
                    me->ourgame->free_params(preset);
                    continue;
@@ -955,7 +961,7 @@ static char *midend_game_id_int(midend_data *me, char *id, int defmode)
     if (par) {
         newcurparams = me->ourgame->dup_params(me->params);
         me->ourgame->decode_params(newcurparams, par);
-        error = me->ourgame->validate_params(newcurparams);
+        error = me->ourgame->validate_params(newcurparams, desc == NULL);
         if (error) {
             me->ourgame->free_params(newcurparams);
             return error;
@@ -1046,7 +1052,7 @@ char *midend_set_config(midend_data *me, int which, config_item *cfg)
     switch (which) {
       case CFG_SETTINGS:
        params = me->ourgame->custom_params(cfg);
-       error = me->ourgame->validate_params(params);
+       error = me->ourgame->validate_params(params, TRUE);
 
        if (error) {
            me->ourgame->free_params(params);
@@ -1112,8 +1118,18 @@ char *midend_solve(midend_data *me)
         me->ourgame->changed_state(me->ui,
                                    me->states[me->statepos-2].state,
                                    me->states[me->statepos-1].state);
-    me->anim_time = 0.0;
-    midend_finish_move(me);
+    me->dir = +1;
+    if (me->ourgame->mouse_priorities & SOLVE_ANIMATES) {
+       me->oldstate = me->ourgame->dup_game(me->states[me->statepos-2].state);
+        me->anim_time =
+           me->ourgame->anim_length(me->states[me->statepos-2].state,
+                                    me->states[me->statepos-1].state,
+                                    +1, me->ui);
+        me->anim_pos = 0.0;
+    } else {
+       me->anim_time = 0.0;
+       midend_finish_move(me);
+    }
     midend_redraw(me);
     midend_set_timer(me);
     return NULL;
@@ -1350,6 +1366,7 @@ char *midend_deserialise(midend_data *me,
         if (key[8] != ':') {
             if (started)
                 ret = "Data was incorrectly formatted for a saved game file";
+           goto cleanup;
         }
         len = strcspn(key, ": ");
         assert(len <= 8);
@@ -1480,16 +1497,24 @@ char *midend_deserialise(midend_data *me,
 
     params = me->ourgame->default_params();
     me->ourgame->decode_params(params, parstr);
-    if (me->ourgame->validate_params(params)) {
+    if (me->ourgame->validate_params(params, TRUE)) {
         ret = "Long-term parameters in save file are invalid";
         goto cleanup;
     }
     cparams = me->ourgame->default_params();
     me->ourgame->decode_params(cparams, cparstr);
-    if (me->ourgame->validate_params(cparams)) {
+    if (me->ourgame->validate_params(cparams, FALSE)) {
         ret = "Short-term parameters in save file are invalid";
         goto cleanup;
     }
+    if (seed && me->ourgame->validate_params(cparams, TRUE)) {
+        /*
+         * The seed's no use with this version, but we can perfectly
+         * well use the rest of the data.
+         */
+        sfree(seed);
+        seed = NULL;
+    }
     if (!desc) {
         ret = "Game description in save file is missing";
         goto cleanup;