aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Harris <bjh21@bjh21.me.uk>2022-12-30 00:00:17 +0000
committerBen Harris <bjh21@bjh21.me.uk>2022-12-30 00:01:02 +0000
commit72495304292e9ef71c996c571269557c2a299fdf (patch)
treefde4a9e9655616bbed4107867c7c9c6b6efeb926
parent3cb919f4f7eb8a0785ace3c750a4a33987a6eb49 (diff)
downloadpuzzles-72495304292e9ef71c996c571269557c2a299fdf.zip
puzzles-72495304292e9ef71c996c571269557c2a299fdf.tar.gz
puzzles-72495304292e9ef71c996c571269557c2a299fdf.tar.bz2
puzzles-72495304292e9ef71c996c571269557c2a299fdf.tar.xz
Clear any existing Tracks flash data when generating it
Simon points out that if you have an ambiguous puzzle then it might need different flash data for different solutions, so if you solve it one way, than manually unsolve it and solve it another way, the old flash data in the game state need to be cleared out when the new flash data are written. Tested by solving the hugely ambiguous "5x5:CwC,5,5,5,5,S5,S5,5,5,5,5".
-rw-r--r--tracks.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/tracks.c b/tracks.c
index 2fad011..00a2b31 100644
--- a/tracks.c
+++ b/tracks.c
@@ -242,7 +242,8 @@ static const int nbits[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4 };
#define S_CLUE 8
#define S_MARK 16
-#define S_FLASH_SHIFT 8 /* Position of tile in solved track, 8 bits */
+#define S_FLASH_SHIFT 8 /* Position of tile in solved track */
+#define S_FLASH_WIDTH 8 /* Width of above sub-field */
#define S_TRACK_SHIFT 16 /* U/D/L/R flags for edge track indicators */
#define S_NOTRACK_SHIFT 20 /* U/D/L/R flags for edge no-track indicators */
@@ -1836,8 +1837,9 @@ static void set_flash_data(game_state *state)
ntrack += state->numbers->numbers[x];
n = 0; x = 0; y = state->numbers->row_s; d = R;
do {
- /* Don't bother clearing; this only runs at completion. */
- state->sflags[y*w + x] |= (n++ * 255 / (ntrack - 1)) << S_FLASH_SHIFT;
+ state->sflags[y*w + x] &= ~(((1<<S_FLASH_WIDTH) - 1) << S_FLASH_SHIFT);
+ state->sflags[y*w + x] |=
+ (n++ * ((1<<S_FLASH_WIDTH) - 1) / (ntrack - 1)) << S_FLASH_SHIFT;
d = F(d); /* Find the direction we just arrived from. */
d = S_E_DIRS(state, x, y, E_TRACK) & ~d; /* Other track from here. */
x += DX(d); y += DY(d); /* Move to the next tile. */