diff options
author | Travis Howell | 2007-03-24 00:41:38 +0000 |
---|---|---|
committer | Travis Howell | 2007-03-24 00:41:38 +0000 |
commit | de98304a3ee37f5a2cb70bf2036f1aea896f7429 (patch) | |
tree | 70d95861f40ddff683348a4433ded518b622440f /engines | |
parent | 8d326d1e28eef8e9e8eea9745bdd93ee19580eff (diff) | |
download | scummvm-rg350-de98304a3ee37f5a2cb70bf2036f1aea896f7429.tar.gz scummvm-rg350-de98304a3ee37f5a2cb70bf2036f1aea896f7429.tar.bz2 scummvm-rg350-de98304a3ee37f5a2cb70bf2036f1aea896f7429.zip |
Add patch #1687026 - Indy3: Series IQ-Points.
svn-id: r26289
Diffstat (limited to 'engines')
-rw-r--r-- | engines/scumm/intern.h | 2 | ||||
-rw-r--r-- | engines/scumm/script_v5.cpp | 116 | ||||
-rw-r--r-- | engines/scumm/scumm.h | 4 |
3 files changed, 103 insertions, 19 deletions
diff --git a/engines/scumm/intern.h b/engines/scumm/intern.h index 7cecc612fc..7aa7f39e7e 100644 --- a/engines/scumm/intern.h +++ b/engines/scumm/intern.h @@ -82,6 +82,8 @@ protected: int getWordVararg(int *ptr); void saveVars(); void loadVars(); + void saveIQPoints(); + void loadIQPoints(); virtual int getVar(); virtual int getVarOrDirectByte(byte mask); diff --git a/engines/scumm/script_v5.cpp b/engines/scumm/script_v5.cpp index 79caf4ac14..d6907680c0 100644 --- a/engines/scumm/script_v5.cpp +++ b/engines/scumm/script_v5.cpp @@ -870,15 +870,7 @@ void ScummEngine_v5::o5_saveLoadVars() { void ScummEngine_v5::saveVars() { int a, b; - - // FIXME: This opcode is currently a stub. It is needed for at least two things: - // * storing save game names in Indy 3 (and maybe others) - // * storing the global IQ (Indy Quotient) in Indy 3 - // The former is not so important as we have our own save system, but the - // latter one of course is a desirable feature. - // So implementing this would be nice indeed. Not sure what the filename - // should be -- either base it on the target name, or base it on the gameid. - // Both approaches have their merits, though. + static char filename[256]; while ((_opcode = fetchScriptByte()) != 0) { switch (_opcode & 0x1F) { @@ -892,17 +884,25 @@ void ScummEngine_v5::saveVars() { case 0x02: // write a range of string variables a = getVarOrDirectByte(PARAM_1); b = getVarOrDirectByte(PARAM_2); - debug(0, "stub saveVars: strings %d -> %d", a, b); + + if (a == RESID_IQ_EPISODE && b == RESID_IQ_EPISODE) { + if (_game.id == GID_INDY3) { + saveIQPoints(); + } + break; + } + // FIXME: changing savegame-names not supported break; case 0x03: // open file a = resStrLen(_scriptPointer); - debug(0, "stub saveVars to %s", _scriptPointer); + strncpy(filename, (const char *)_scriptPointer, a); + filename[a] = '\0'; _scriptPointer += a + 1; break; case 0x04: return; case 0x1F: // close file - debug(0, "stub saveVars close file"); + filename[0] = '\0'; return; } } @@ -910,10 +910,8 @@ void ScummEngine_v5::saveVars() { void ScummEngine_v5::loadVars() { int a, b; + static char filename[256]; - // FIXME: See ScummEngine_v5::saveVars - -// Common::hexdump(_scriptPointer, 64); while ((_opcode = fetchScriptByte()) != 0) { switch (_opcode & 0x1F) { case 0x01: // read a range of variables @@ -926,22 +924,98 @@ void ScummEngine_v5::loadVars() { case 0x02: // read a range of string variables a = getVarOrDirectByte(PARAM_1); b = getVarOrDirectByte(PARAM_2); - debug(0, "stub loadVars: strings %d -> %d", a, b); + + int slot; + int slotSize; + byte* slotContent; + int savegameId; + char name[32]; + bool avail_saves[100]; + + if (a == RESID_IQ_SERIES && b == RESID_IQ_SERIES) { + // Zak256 loads the IQ script-slot but does not use it -> ignore it + if(_game.id == GID_INDY3) { + loadIQPoints(); + } + break; + } + + listSavegames(avail_saves, ARRAYSIZE(avail_saves)); + for (slot = a; slot <= b; ++slot) { + slotSize = getResourceSize(rtString, slot); + slotContent = getResourceAddress(rtString, slot); + + // load savegame names + savegameId = slot - a + 1; + if (avail_saves[savegameId] && getSavegameName(savegameId, name)) { + int pos; + char *ptr = name; + // slotContent ends with {'\0','@'} -> max. length = slotSize-2 + for (pos = 0; pos < slotSize - 2; ++pos) { + if (!ptr[pos]) + break; + // replace special characters + if(ptr[pos] >= 32 && ptr[pos] <= 122 && ptr[pos] != 64) + slotContent[pos] = ptr[pos]; + else + slotContent[pos] = '_'; + } + slotContent[pos] = '\0'; + } else { + slotContent[0] = '\0'; + } + } break; case 0x03: // open file a = resStrLen(_scriptPointer); - debug(0, "stub loadVars from %s", _scriptPointer); + strncpy(filename, (const char *)_scriptPointer, a); + filename[a] = '\0'; _scriptPointer += a + 1; break; case 0x04: return; case 0x1F: // close file - debug(0, "stub loadVars close file"); + filename[0] = '\0'; return; } } } +void ScummEngine_v5::saveIQPoints() { + // save series IQ-points + Common::OutSaveFile *file; + char filename[256]; + + sprintf(filename, "%s.iq", _targetName.c_str()); + file = _saveFileMan->openForSaving(filename); + if (file != NULL) { + int size = getResourceSize(rtString, RESID_IQ_EPISODE); + byte *ptr = getResourceAddress(rtString, RESID_IQ_EPISODE); + file->write(ptr, size); + delete file; + } +} + +void ScummEngine_v5::loadIQPoints() { + // load series IQ-points + Common::InSaveFile *file; + char filename[256]; + + sprintf(filename, "%s.iq", _targetName.c_str()); + file = _saveFileMan->openForLoading(filename); + if (file != NULL) { + int size = getResourceSize(rtString, RESID_IQ_SERIES); + byte *ptr = getResourceAddress(rtString, RESID_IQ_SERIES); + byte *tmp = (byte*)malloc(size); + int nread = file->read(tmp, size); + if (nread == size) { + memcpy(ptr, tmp, size); + } + free(tmp); + delete file; + } +} + void ScummEngine_v5::o5_expression() { int dst, i; @@ -1124,9 +1198,13 @@ void ScummEngine_v5::o5_getActorY() { void ScummEngine_v5::o5_saveLoadGame() { getResultPos(); byte a = getVarOrDirectByte(PARAM_1); - byte slot = (a & 0x1F) + 1; + byte slot = a & 0x1F; byte result = 0; + // Slot numbers in older games start with 0, in newer games with 1 + if (_game.version <= 2) + slot++; + if ((_game.id == GID_MANIAC) && (_game.version <= 1)) { // Convert older load/save screen // 1 Load diff --git a/engines/scumm/scumm.h b/engines/scumm/scumm.h index d31ea1a2fb..bfaf780d5b 100644 --- a/engines/scumm/scumm.h +++ b/engines/scumm/scumm.h @@ -328,6 +328,10 @@ enum ResTypes { rtNumTypes = 22 }; +enum ResIds { + RESID_IQ_EPISODE = 7, + RESID_IQ_SERIES = 9 +}; /** |