Correction to pickVarRandom

Add HE80+ version too.

svn-id: r15138
This commit is contained in:
Travis Howell 2004-09-16 12:30:54 +00:00
parent 9bc8383cee
commit 49cd965411
5 changed files with 65 additions and 15 deletions

View File

@ -563,6 +563,7 @@ protected:
virtual void executeOpcode(byte i);
virtual const char *getOpcodeDesc(byte i);
void localizeArray(int slot, int script);
void redimArray(int arrayId, int newX, int newY, int d);
int readFileToArray(int slot, int32 size);
void writeFileFromArray(int slot, int resID);
@ -801,6 +802,7 @@ protected:
void o80_cursorCommand();
void o80_setState();
void o80_drawWizPolygon();
void o80_pickVarRandom();
};
class ScummEngine_v90he : public ScummEngine_v80he {

View File

@ -3019,7 +3019,7 @@ void ScummEngine_v6::o6_pickVarRandom() {
num = readArray(value, 0, 0);
byte *ptr = getResourceAddress(rtString, readVar(value));
if (_version >= 7 || _heversion >= 72) {
if (_version >= 7) {
var_A = READ_LE_UINT32(ptr + 4);
var_C = READ_LE_UINT32(ptr + 8);
} else {
@ -3028,7 +3028,7 @@ void ScummEngine_v6::o6_pickVarRandom() {
}
if (var_A-1 <= num) {
int16 var_2 = readArray(value, 0, num - 1);
int16 var_2 = readArray(value, 0, var_A - 1);
shuffleArray(value, 1, num - 1);
if (readArray(value, 0, 1) == var_2) {
num = 2;

View File

@ -1153,15 +1153,18 @@ void ScummEngine_v6he::o6_soundOps() {
}
}
void ScummEngine_v6he::o6_localizeArray() {
int slot = pop();
void ScummEngine_v6he::localizeArray(int slot, int script) {
if (slot >= _numArray)
error("o6_localizeArray(%d): array slot out of range", slot);
_arraySlot[slot] = vm.slot[_currentScript].number;
}
void ScummEngine_v6he::o6_localizeArray() {
int slot = pop();
localizeArray(slot, vm.slot[_currentScript].number);
}
void ScummEngine_v6he::o6_seekFilePos() {
int mode, offset, slot;
mode = pop();

View File

@ -1693,7 +1693,7 @@ void ScummEngine_v72he::o72_getPixel() {
void ScummEngine_v72he::o72_pickVarRandom() {
int num;
int args[100];
int32 var_A;
int32 dim1end;
num = getStackList(args, ARRAYSIZE(args));
int value = fetchScriptWord();
@ -1716,11 +1716,11 @@ void ScummEngine_v72he::o72_pickVarRandom() {
num = readArray(value, 0, 0);
ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, readVar(value));
var_A = FROM_LE_32(ah->dim1end);
dim1end = FROM_LE_32(ah->dim1end);
if (var_A-1 <= num) {
if (dim1end <= num) {
int16 var_2 = readArray(value, 0, num - 1);
shuffleArray(value, 1, num - 1);
shuffleArray(value, 1, dim1end);
if (readArray(value, 0, 1) == var_2) {
num = 2;
} else {

View File

@ -328,7 +328,7 @@ void ScummEngine_v80he::setupOpcodes() {
OPCODE(o6_soundOps),
OPCODE(o72_getPixel),
OPCODE(o6_localizeArray),
OPCODE(o72_pickVarRandom),
OPCODE(o80_pickVarRandom),
/* E4 */
OPCODE(o6_setBoxSet),
OPCODE(o6_invalid),
@ -424,11 +424,7 @@ void ScummEngine_v80he::o80_unknown49() {
void ScummEngine_v80he::o80_unknown4A() {
int slot = pop();
if (slot >= _numArray)
error("o80_unknown4A(%d): array slot out of range", slot);
_arraySlot[slot] = 0xFFFFFFFF;
localizeArray(slot, 0xFFFFFFFF);
}
void ScummEngine_v80he::o80_readConfigFile() {
@ -607,4 +603,53 @@ void ScummEngine_v80he::o80_drawWizPolygon() {
}
}
void ScummEngine_v80he::o80_pickVarRandom() {
int num;
int args[100];
int32 dim1end;
num = getStackList(args, ARRAYSIZE(args));
int value = fetchScriptWord();
if (readVar(value) == 0) {
defineArray(value, kDwordArray, 0, 0, 0, num + 1);
if (value & 0x8000)
localizeArray(readVar(value), 0xFFFFFFFF);
else if (value & 0x4000)
localizeArray(readVar(value), vm.slot[_currentScript].number);
if (num > 0) {
int16 counter = 0;
do {
writeArray(value, 0, counter + 1, args[counter]);
} while (++counter < num);
}
shuffleArray(value, 1, num-1);
writeArray(value, 0, 0, 2);
push(readArray(value, 0, 1));
return;
}
num = readArray(value, 0, 0);
ArrayHeader *ah = (ArrayHeader *)getResourceAddress(rtString, readVar(value));
dim1end = FROM_LE_32(ah->dim1end);
if (dim1end <= num) {
int16 var_2 = readArray(value, 0, num - 1);
shuffleArray(value, 1, dim1end);
if (readArray(value, 0, 1) == var_2 && var_2 >= 3) {
int tmp = readArray(value, 0, 2);
writeArray(value, 0, num, tmp);
writeArray(value, 0, 2, var_2);
}
}
writeArray(value, 0, 0, num + 1);
push(readArray(value, 0, num));
}
} // End of namespace Scumm