aboutsummaryrefslogtreecommitdiff
path: root/scumm/script_v6.cpp
diff options
context:
space:
mode:
authorMax Horn2003-03-07 21:49:06 +0000
committerMax Horn2003-03-07 21:49:06 +0000
commit7ad611e710034bc4344b0cdcf50e401fa3fd0d42 (patch)
treeab2cff70aebc4e2d4a06ecff31f45a66d5888cb4 /scumm/script_v6.cpp
parent7ec34ab1a971a183ab68ff175d2b848a840b5266 (diff)
downloadscummvm-rg350-7ad611e710034bc4344b0cdcf50e401fa3fd0d42.tar.gz
scummvm-rg350-7ad611e710034bc4344b0cdcf50e401fa3fd0d42.tar.bz2
scummvm-rg350-7ad611e710034bc4344b0cdcf50e401fa3fd0d42.zip
replaced shuffleArray with a meaningful implementation, even if it differes from assembly
svn-id: r6752
Diffstat (limited to 'scumm/script_v6.cpp')
-rw-r--r--scumm/script_v6.cpp13
1 files changed, 7 insertions, 6 deletions
diff --git a/scumm/script_v6.cpp b/scumm/script_v6.cpp
index c58caacde6..427d21a8cc 100644
--- a/scumm/script_v6.cpp
+++ b/scumm/script_v6.cpp
@@ -2812,16 +2812,17 @@ void Scumm_v6::shuffleArray(int num, int minIdx, int maxIdx) {
int range = maxIdx - minIdx;
int count = range * 2;
+ // Shuffle the array 'num'
while (count--) {
+ // Determine two random elements...
int rand1 = _rnd.getRandomNumber(range) + minIdx;
int rand2 = _rnd.getRandomNumber(range) + minIdx;
- _vars[VAR_V6_RANDOM_NR] = rand2;
- // FIXME - uhm this seems wrong. It replaces item rand1 with itself
- // It would seem more logical if we first read elements rand1 and rand2,
- // then swapped them. Assembler analysis, anybody?
- writeArray(num, 0, rand1, readArray(num, 0, rand1));
- writeArray(num, 0, rand2, readArray(num, 0, rand2));
+ // ...and swap them
+ int val1 = readArray(num, 0, rand1);
+ int val2 = readArray(num, 0, rand2);
+ writeArray(num, 0, rand1, val2);
+ writeArray(num, 0, rand2, val1));
}
}