shithub: puzzles

Download patch

ref: b1c0d665bd0b3d62f060b8a7d0e27b92bd03d2c1
parent: 4670313f6fe1790165040910121481d16d5f062c
author: Simon Tatham <anakin@pobox.com>
date: Wed May 18 13:41:53 EDT 2005

If you paste in a random seed with different ephemeral parameters
from the currently configured ones, and then bring the Random Seed
box back up, the wrong parameters get shown, and the resulting
random seed is incorrect for the current game.

At least, it was, until this checkin.

[originally from svn r5808]

--- a/midend.c
+++ b/midend.c
@@ -34,7 +34,7 @@
     char **preset_names;
     int npresets, presetsize;
 
-    game_params *params, *tmpparams;
+    game_params *params, *curparams;
     struct midend_state_entry *states;
     game_drawstate *drawstate;
     game_state *oldstate;
@@ -68,7 +68,7 @@
     me->nstates = me->statesize = me->statepos = 0;
     me->states = NULL;
     me->params = ourgame->default_params();
-    me->tmpparams = NULL;
+    me->curparams = NULL;
     me->desc = NULL;
     me->seedstr = NULL;
     me->aux_info = NULL;
@@ -98,8 +98,8 @@
     if (me->aux_info)
 	me->ourgame->free_aux_info(me->aux_info);
     me->ourgame->free_params(me->params);
-    if (me->tmpparams)
-        me->ourgame->free_params(me->tmpparams);
+    if (me->curparams)
+        me->ourgame->free_params(me->curparams);
     sfree(me);
 }
 
@@ -143,6 +143,10 @@
                 newseed[i] = '0' + random_upto(me->random, 10);
             sfree(me->seedstr);
             me->seedstr = dupstr(newseed);
+
+	    if (me->curparams)
+		me->ourgame->free_params(me->curparams);
+	    me->curparams = me->ourgame->dup_params(me->params);
         }
 
 	sfree(me->desc);
@@ -151,14 +155,8 @@
 	me->aux_info = NULL;
 
         rs = random_init(me->seedstr, strlen(me->seedstr));
-        me->desc = me->ourgame->new_desc
-            (me->tmpparams ? me->tmpparams : me->params, rs, &me->aux_info);
+        me->desc = me->ourgame->new_desc(me->curparams, rs, &me->aux_info);
         random_free(rs);
-
-        if (me->tmpparams) {
-            me->ourgame->free_params(me->tmpparams);
-            me->tmpparams = NULL;
-        }
     }
 
     ensure(me);
@@ -657,7 +655,7 @@
          * the former is likely to persist across many code
          * changes).
          */
-        parstr = me->ourgame->encode_params(me->params, which == CFG_SEED);
+        parstr = me->ourgame->encode_params(me->curparams, which == CFG_SEED);
         if (which == CFG_DESC) {
             ret[0].sval = snewn(strlen(parstr) + strlen(me->desc) + 2, char);
             sprintf(ret[0].sval, "%s:%s", parstr, me->desc);
@@ -737,9 +735,9 @@
             me->ourgame->free_params(tmpparams);
             return error;
         }
-        if (me->tmpparams)
-            me->ourgame->free_params(me->tmpparams);
-        me->tmpparams = tmpparams;
+        if (me->curparams)
+            me->ourgame->free_params(me->curparams);
+        me->curparams = tmpparams;
 
         /*
          * Now filter only the persistent parts of this state into