From 65bc46d3ab7ba1102c46c475bb145a4c64403109 Mon Sep 17 00:00:00 2001 From: Sven Hesse Date: Sat, 29 Jan 2011 22:47:53 +0000 Subject: GOB: Add Script::evalInt() and Script::evalString() svn-id: r55634 --- engines/gob/inter.h | 2 +- engines/gob/inter_playtoons.cpp | 82 ++++++++------------- engines/gob/inter_v1.cpp | 61 ++++++---------- engines/gob/inter_v2.cpp | 157 ++++++++++++++-------------------------- engines/gob/inter_v4.cpp | 27 +++---- engines/gob/inter_v5.cpp | 3 +- engines/gob/inter_v6.cpp | 72 +++++++----------- engines/gob/inter_v7.cpp | 134 ++++++++++++---------------------- engines/gob/script.cpp | 10 +++ engines/gob/script.h | 7 +- engines/gob/sound/sound.cpp | 12 +-- engines/gob/sound/sound.h | 4 +- 12 files changed, 218 insertions(+), 353 deletions(-) (limited to 'engines/gob') diff --git a/engines/gob/inter.h b/engines/gob/inter.h index a4f9c0748e..e69b010363 100644 --- a/engines/gob/inter.h +++ b/engines/gob/inter.h @@ -558,7 +558,7 @@ protected: void o6_removeHotspot(OpFuncParams ¶ms); void o6_fillRect(OpFuncParams ¶ms); - void probe16bitMusic(char *fileName); + void probe16bitMusic(Common::String &fileName); }; class Inter_Playtoons : public Inter_v6 { diff --git a/engines/gob/inter_playtoons.cpp b/engines/gob/inter_playtoons.cpp index 96f7de55e1..dfbf9ecdd5 100644 --- a/engines/gob/inter_playtoons.cpp +++ b/engines/gob/inter_playtoons.cpp @@ -210,19 +210,9 @@ void Inter_Playtoons::oPlaytoons_freeSprite(OpFuncParams ¶ms) { } void Inter_Playtoons::oPlaytoons_checkData(OpFuncParams ¶ms) { - int16 handle; - uint16 varOff; - int32 size; - char *backSlash; - SaveLoad::SaveMode mode; + const char *file = _vm->_game->_script->evalString(); - _vm->_game->_script->evalExpr(0); - varOff = _vm->_game->_script->readVarIndex(); - - size = -1; - handle = 1; - - char *file = _vm->_game->_script->getResultStr(); + uint16 varOff = _vm->_game->_script->readVarIndex(); // WORKAROUND: In Playtoons games, some files are read on CD (and only on CD). // In this case, "@:\" is replaced by the CD drive letter. @@ -245,12 +235,15 @@ void Inter_Playtoons::oPlaytoons_checkData(OpFuncParams ¶ms) { } // WORKAROUND: In the Playtoons stick files found in german Addy 4, some paths are hardcoded - if ((backSlash = strrchr(file, '\\'))) { + const char *backSlash = strrchr(file, '\\'); + if (backSlash) { debugC(2, kDebugFileIO, "oPlaytoons_checkData: \"%s\" instead of \"%s\"", backSlash + 1, file); file = backSlash + 1; } - mode = _vm->_saveLoad->getSaveMode(file); + int32 size = -1; + int16 handle = 1; + SaveLoad::SaveMode mode = _vm->_saveLoad->getSaveMode(file); if (mode == SaveLoad::kSaveModeNone) { size = _vm->_dataIO->fileSize(file); if (size == -1) @@ -272,21 +265,12 @@ void Inter_Playtoons::oPlaytoons_checkData(OpFuncParams ¶ms) { } void Inter_Playtoons::oPlaytoons_readData(OpFuncParams ¶ms) { - int32 retSize; - int32 size; - int32 offset; - uint16 dataVar; - byte *buf; - SaveLoad::SaveMode mode; + const char *file = _vm->_game->_script->evalString(); - _vm->_game->_script->evalExpr(0); - dataVar = _vm->_game->_script->readVarIndex(); - size = _vm->_game->_script->readValExpr(); - _vm->_game->_script->evalExpr(0); - offset = _vm->_game->_script->getResultInt(); - retSize = 0; - - char *file = _vm->_game->_script->getResultStr(); + uint16 dataVar = _vm->_game->_script->readVarIndex(); + int32 size = _vm->_game->_script->readValExpr(); + int32 offset = _vm->_game->_script->evalInt(); + int32 retSize = 0; // WORKAROUND: In Playtoons games, some files are read on CD (and only on CD). // In this case, "@:\" is replaced by the CD drive letter. @@ -299,7 +283,7 @@ void Inter_Playtoons::oPlaytoons_readData(OpFuncParams ¶ms) { debugC(2, kDebugFileIO, "Read from file \"%s\" (%d, %d bytes at %d)", file, dataVar, size, offset); - mode = _vm->_saveLoad->getSaveMode(file); + SaveLoad::SaveMode mode = _vm->_saveLoad->getSaveMode(file); if (mode == SaveLoad::kSaveModeSave) { WRITE_VAR(1, 1); @@ -324,7 +308,7 @@ void Inter_Playtoons::oPlaytoons_readData(OpFuncParams ¶ms) { size = _vm->_game->_script->getVariablesCount() * 4; } - buf = _variables->getAddressOff8(dataVar); + byte *buf = _variables->getAddressOff8(dataVar); if (file[0] == 0) { WRITE_VAR(1, size); @@ -417,36 +401,28 @@ void Inter_Playtoons::oPlaytoons_CD_25() { } void Inter_Playtoons::oPlaytoons_copyFile() { - char fileName1[128]; - char fileName2[128]; + Common::String file1 = _vm->_game->_script->evalString(); + Common::String file2 = _vm->_game->_script->evalString(); - _vm->_game->_script->evalExpr(0); - Common::strlcpy(fileName1, _vm->_game->_script->getResultStr(), 128); - _vm->_game->_script->evalExpr(0); - Common::strlcpy(fileName2, _vm->_game->_script->getResultStr(), 128); - - warning("Playtoons Stub: copy file from \"%s\" to \"%s\"", fileName1, fileName2); + warning("Playtoons Stub: copy file from \"%s\" to \"%s\"", file1.c_str(), file2.c_str()); } void Inter_Playtoons::oPlaytoons_openItk() { - char fileName[128]; - char *backSlash; + const char *fileName = _vm->_game->_script->evalString(); + const char *backSlash = strrchr(fileName, '\\'); - _vm->_game->_script->evalExpr(0); - Common::strlcpy(fileName, _vm->_game->_script->getResultStr(), 124); + Common::String file; + if (backSlash) { + debugC(2, kDebugFileIO, "Opening ITK file \"%s\" instead of \"%s\"", + backSlash + 1, fileName); + file = backSlash + 1; + } else + file = fileName; - if (!strchr(fileName, '.')) - strcat(fileName, ".ITK"); + if (!file.contains('.')) + file += ".ITK"; - // Workaround for Bambou : In the script, the path is hardcoded (!!) - if ((backSlash = strrchr(fileName, '\\'))) { - debugC(2, kDebugFileIO, "Opening ITK file \"%s\" instead of \"%s\"", backSlash + 1, fileName); - _vm->_dataIO->openArchive(backSlash + 1, false); - } else - _vm->_dataIO->openArchive(fileName, false); - // All the other checks are meant to verify (if not found at the first try) - // if the file is present on the CD or not. As everything is supposed to - // be copied, those checks are skipped + _vm->_dataIO->openArchive(file, false); } } // End of namespace Gob diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp index a908758500..b8fb90034e 100644 --- a/engines/gob/inter_v1.cpp +++ b/engines/gob/inter_v1.cpp @@ -612,9 +612,8 @@ void Inter_v1::o1_loadCurLayer() { } void Inter_v1::o1_playCDTrack() { - _vm->_game->_script->evalExpr(0); _vm->_sound->adlibPlayBgMusic(); // Mac version - _vm->_sound->cdPlay(_vm->_game->_script->getResultStr()); // PC CD version + _vm->_sound->cdPlay(_vm->_game->_script->evalString()); // PC CD version } void Inter_v1::o1_getCDTrackPos() { @@ -960,8 +959,7 @@ void Inter_v1::o1_printText(OpFuncParams ¶ms) { void Inter_v1::o1_loadTot(OpFuncParams ¶ms) { if ((_vm->_game->_script->peekByte() & 0x80) != 0) { _vm->_game->_script->skip(1); - _vm->_game->_script->evalExpr(0); - _vm->_game->_totToLoad = _vm->_game->_script->getResultStr(); + _vm->_game->_totToLoad = _vm->_game->_script->evalString(); } else { uint8 size = _vm->_game->_script->readInt8(); _vm->_game->_totToLoad = Common::String(_vm->_game->_script->readString(size), size); @@ -1585,13 +1583,11 @@ void Inter_v1::o1_getFreeMem(OpFuncParams ¶ms) { } void Inter_v1::o1_checkData(OpFuncParams ¶ms) { - int16 varOff; - - _vm->_game->_script->evalExpr(0); - varOff = _vm->_game->_script->readVarIndex(); + const char *file = _vm->_game->_script->evalString(); + int16 varOff = _vm->_game->_script->readVarIndex(); - if (!_vm->_dataIO->hasFile(_vm->_game->_script->getResultStr())) { - warning("File \"%s\" not found", _vm->_game->_script->getResultStr()); + if (!_vm->_dataIO->hasFile(file)) { + warning("File \"%s\" not found", file); WRITE_VAR_OFFSET(varOff, (uint32) -1); } else WRITE_VAR_OFFSET(varOff, 50); // "handle" between 50 and 128 = in archive @@ -1683,12 +1679,11 @@ void Inter_v1::o1_blitCursor(OpFuncParams ¶ms) { } void Inter_v1::o1_loadFont(OpFuncParams ¶ms) { - _vm->_game->_script->evalExpr(0); - uint16 index = _vm->_game->_script->readInt16(); + const char *font = _vm->_game->_script->evalString(); + uint16 index = _vm->_game->_script->readInt16(); _vm->_draw->animateCursor(4); - - _vm->_draw->loadFont(index, _vm->_game->_script->getResultStr()); + _vm->_draw->loadFont(index, font); } void Inter_v1::o1_freeFont(OpFuncParams ¶ms) { @@ -1706,20 +1701,15 @@ void Inter_v1::o1_freeFont(OpFuncParams ¶ms) { } void Inter_v1::o1_readData(OpFuncParams ¶ms) { - int16 retSize; - int16 size; - int16 dataVar; - int16 offset; - - _vm->_game->_script->evalExpr(0); - dataVar = _vm->_game->_script->readVarIndex(); - size = _vm->_game->_script->readValExpr(); - offset = _vm->_game->_script->readValExpr(); - retSize = 0; + const char *file = _vm->_game->_script->evalString(); + int16 dataVar = _vm->_game->_script->readVarIndex(); + int16 size = _vm->_game->_script->readValExpr(); + int16 offset = _vm->_game->_script->readValExpr(); + int16 retSize = 0; WRITE_VAR(1, 1); - Common::SeekableReadStream *stream = _vm->_dataIO->getFile(_vm->_game->_script->getResultStr()); + Common::SeekableReadStream *stream = _vm->_dataIO->getFile(file); if (!stream) return; @@ -1741,28 +1731,25 @@ void Inter_v1::o1_readData(OpFuncParams ¶ms) { } void Inter_v1::o1_writeData(OpFuncParams ¶ms) { - int16 offset; - int16 size; - int16 dataVar; - // This writes into a file. It's not portable and isn't needed anyway // (Gobliiins 1 doesn't use save file), so we just warn should it be // called regardless. - _vm->_game->_script->evalExpr(0); - dataVar = _vm->_game->_script->readVarIndex(); - size = _vm->_game->_script->readValExpr(); - offset = _vm->_game->_script->readValExpr(); + const char *file = _vm->_game->_script->evalString(); - warning("Attempted to write to file \"%s\"", _vm->_game->_script->getResultStr()); + int16 dataVar = _vm->_game->_script->readVarIndex(); + int16 size = _vm->_game->_script->readValExpr(); + int16 offset = _vm->_game->_script->readValExpr(); + + warning("Attempted to write to file \"%s\" (%d, %d, %d)", file, dataVar, size, offset); WRITE_VAR(1, 0); } void Inter_v1::o1_manageDataFile(OpFuncParams ¶ms) { - _vm->_game->_script->evalExpr(0); + Common::String file = _vm->_game->_script->evalString(); - if (_vm->_game->_script->getResultStr()[0] != 0) - _vm->_dataIO->openArchive(_vm->_game->_script->getResultStr(), true); + if (!file.empty()) + _vm->_dataIO->openArchive(file, true); else _vm->_dataIO->closeArchive(true); } diff --git a/engines/gob/inter_v2.cpp b/engines/gob/inter_v2.cpp index 7fe425b007..b56f001ac9 100644 --- a/engines/gob/inter_v2.cpp +++ b/engines/gob/inter_v2.cpp @@ -513,8 +513,7 @@ void Inter_v2::o2_playCDTrack() { if (!(_vm->_draw->_renderFlags & RENDERFLAG_NOBLITINVALIDATED)) _vm->_draw->blitInvalidated(); - _vm->_game->_script->evalExpr(0); - _vm->_sound->cdPlay(_vm->_game->_script->getResultStr()); + _vm->_sound->cdPlay(_vm->_game->_script->evalString()); } void Inter_v2::o2_waitCDTrackEnd() { @@ -529,13 +528,10 @@ void Inter_v2::o2_stopCD() { } void Inter_v2::o2_readLIC() { - char path[40]; + Common::String file = _vm->_game->_script->evalString(); + file += ".LIC"; - _vm->_game->_script->evalExpr(0); - Common::strlcpy(path, _vm->_game->_script->getResultStr(), 36); - strcat(path, ".LIC"); - - _vm->_sound->cdLoadLIC(path); + _vm->_sound->cdLoadLIC(file.c_str()); } void Inter_v2::o2_freeLIC() { @@ -569,34 +565,27 @@ void Inter_v2::o2_loadFontToSprite() { } void Inter_v2::o2_totSub() { - char totFile[14]; - byte length; - int flags; - int i; - - length = _vm->_game->_script->readByte(); + uint8 length = _vm->_game->_script->readByte(); if ((length & 0x7F) > 13) error("Length in o2_totSub is greater than 13 (%d)", length); - if (length & 0x80) { - _vm->_game->_script->evalExpr(0); - strcpy(totFile, _vm->_game->_script->getResultStr()); - } else { - for (i = 0; i < length; i++) - totFile[i] = _vm->_game->_script->readChar(); - totFile[i] = 0; - } + Common::String totFile; + if (length & 0x80) + totFile = _vm->_game->_script->evalString(); + else + for (uint8 i = 0; i < length; i++) + totFile += _vm->_game->_script->readChar(); // WORKAROUND: There is a race condition in the script when opening the notepad - if (!scumm_stricmp(totFile, "edit")) + if (!totFile.equalsIgnoreCase("edit")) _vm->_util->forceMouseUp(); // WORKAROUND: For some reason, the variable indicating which TOT to load next // is overwritten in the guard house card game in Woodruff - if ((_vm->getGameType() == kGameTypeWoodruff) && !scumm_stricmp(totFile, "6")) - strcpy(totFile, "EMAP2011"); + if ((_vm->getGameType() == kGameTypeWoodruff) && (totFile == "6")) + totFile = "EMAP2011"; - flags = _vm->_game->_script->readByte(); + uint8 flags = _vm->_game->_script->readByte(); _vm->_game->totSub(flags, totFile); } @@ -947,15 +936,10 @@ void Inter_v2::o2_setScrollOffset() { } void Inter_v2::o2_playImd() { - char imd[128]; - bool close; - - _vm->_game->_script->evalExpr(0); - _vm->_game->_script->getResultStr()[8] = 0; - Common::strlcpy(imd, _vm->_game->_script->getResultStr(), 128); - VideoPlayer::Properties props; + Common::String imd = Common::String(_vm->_game->_script->evalString(), 8); + props.x = _vm->_game->_script->readValExpr(); props.y = _vm->_game->_script->readValExpr(); props.startFrame = _vm->_game->_script->readValExpr(); @@ -967,12 +951,12 @@ void Inter_v2::o2_playImd() { props.palCmd = 1 << (props.flags & 0x3F); debugC(1, kDebugVideo, "Playing video \"%s\" @ %d+%d, frames %d - %d, " - "paletteCmd %d (%d - %d), flags %X", imd, + "paletteCmd %d (%d - %d), flags %X", imd.c_str(), props.x, props.y, props.startFrame, props.lastFrame, props.palCmd, props.palStart, props.palEnd, props.flags); int slot = 0; - if (imd[0] != 0) { + if (!imd.empty()) { _vm->_vidPlayer->evaluateFlags(props); if ((slot = _vm->_vidPlayer->openVideo(true, imd, props)) < 0) { WRITE_VAR(11, (uint32) -1); @@ -980,7 +964,7 @@ void Inter_v2::o2_playImd() { } } - close = (props.lastFrame == -1); + bool close = (props.lastFrame == -1); if (props.startFrame == -2) { props.startFrame = 0; props.lastFrame = 0; @@ -995,36 +979,29 @@ void Inter_v2::o2_playImd() { } void Inter_v2::o2_getImdInfo() { - int16 varX, varY; - int16 varFrames; - int16 varWidth, varHeight; + Common::String imd = _vm->_game->_script->evalString(); - _vm->_game->_script->evalExpr(0); - varX = _vm->_game->_script->readVarIndex(); - varY = _vm->_game->_script->readVarIndex(); - varFrames = _vm->_game->_script->readVarIndex(); - varWidth = _vm->_game->_script->readVarIndex(); - varHeight = _vm->_game->_script->readVarIndex(); + int16 varX = _vm->_game->_script->readVarIndex(); + int16 varY = _vm->_game->_script->readVarIndex(); + int16 varFrames = _vm->_game->_script->readVarIndex(); + int16 varWidth = _vm->_game->_script->readVarIndex(); + int16 varHeight = _vm->_game->_script->readVarIndex(); // WORKAROUND: The nut rolling animation in the administration center // in Woodruff is called "noixroul", but the scripts think it's "noixroule". if ((_vm->getGameType() == kGameTypeWoodruff) && - (!scumm_stricmp(_vm->_game->_script->getResultStr(), "noixroule"))) - strcpy(_vm->_game->_script->getResultStr(), "noixroul"); + imd.equalsIgnoreCase("noixroule")) + imd = "noixroul"; - _vm->_vidPlayer->writeVideoInfo(_vm->_game->_script->getResultStr(), varX, varY, - varFrames, varWidth, varHeight); + _vm->_vidPlayer->writeVideoInfo(imd, varX, varY, varFrames, varWidth, varHeight); } void Inter_v2::o2_openItk() { - char fileName[32]; + Common::String file = _vm->_game->_script->evalString(); + if (!file.contains('.')) + file += ".ITK"; - _vm->_game->_script->evalExpr(0); - Common::strlcpy(fileName, _vm->_game->_script->getResultStr(), 28); - if (!strchr(fileName, '.')) - strcat(fileName, ".ITK"); - - _vm->_dataIO->openArchive(fileName, false); + _vm->_dataIO->openArchive(file, false); } void Inter_v2::o2_closeItk() { @@ -1263,62 +1240,45 @@ void Inter_v2::o2_getFreeMem(OpFuncParams ¶ms) { } void Inter_v2::o2_checkData(OpFuncParams ¶ms) { - int16 varOff; - int32 size; - SaveLoad::SaveMode mode; - - _vm->_game->_script->evalExpr(0); - varOff = _vm->_game->_script->readVarIndex(); - - size = -1; - - char *file = _vm->_game->_script->getResultStr(); + Common::String file = _vm->_game->_script->evalString(); + int16 varOff = _vm->_game->_script->readVarIndex(); // WORKAROUND: For some reason, the variable indicating which TOT to load next // is overwritten in the guard house card game in Woodruff. - if ((_vm->getGameType() == kGameTypeWoodruff) && !scumm_stricmp(file, "6.TOT")) - strcpy(file, "EMAP2011.TOT"); + if ((_vm->getGameType() == kGameTypeWoodruff) && file.equalsIgnoreCase("6.tot")) + file = "EMAP2011.TOT"; - mode = _vm->_saveLoad->getSaveMode(file); + int32 size = -1; + SaveLoad::SaveMode mode = _vm->_saveLoad->getSaveMode(file.c_str()); if (mode == SaveLoad::kSaveModeNone) { size = _vm->_dataIO->fileSize(file); if (size == -1) - warning("File \"%s\" not found", file); + warning("File \"%s\" not found", file.c_str()); } else if (mode == SaveLoad::kSaveModeSave) - size = _vm->_saveLoad->getSize(file); + size = _vm->_saveLoad->getSize(file.c_str()); else if (mode == SaveLoad::kSaveModeExists) size = 23; - debugC(2, kDebugFileIO, "Requested size of file \"%s\": %d", - file, size); + debugC(2, kDebugFileIO, "Requested size of file \"%s\": %d", file.c_str(), size); WRITE_VAR_OFFSET(varOff, (size == -1) ? -1 : 50); WRITE_VAR(16, (uint32) size); } void Inter_v2::o2_readData(OpFuncParams ¶ms) { - int32 retSize; - int32 size; - int32 offset; - int16 dataVar; - byte *buf; - SaveLoad::SaveMode mode; - - _vm->_game->_script->evalExpr(0); - dataVar = _vm->_game->_script->readVarIndex(); - size = _vm->_game->_script->readValExpr(); - _vm->_game->_script->evalExpr(0); - offset = _vm->_game->_script->getResultInt(); - retSize = 0; - - char *file = _vm->_game->_script->getResultStr(); + const char *file = _vm->_game->_script->evalString(); + + uint16 dataVar = _vm->_game->_script->readVarIndex(); + int32 size = _vm->_game->_script->readValExpr(); + int32 offset = _vm->_game->_script->evalInt(); + int32 retSize = 0; debugC(2, kDebugFileIO, "Read from file \"%s\" (%d, %d bytes at %d)", file, dataVar, size, offset); - mode = _vm->_saveLoad->getSaveMode(file); + SaveLoad::SaveMode mode = _vm->_saveLoad->getSaveMode(file); if (mode == SaveLoad::kSaveModeSave) { WRITE_VAR(1, 1); @@ -1345,7 +1305,7 @@ void Inter_v2::o2_readData(OpFuncParams ¶ms) { size = _vm->_game->_script->getVariablesCount() * 4; } - buf = _variables->getAddressOff8(dataVar); + byte *buf = _variables->getAddressOff8(dataVar); if (file[0] == 0) { WRITE_VAR(1, size); @@ -1379,25 +1339,18 @@ void Inter_v2::o2_readData(OpFuncParams ¶ms) { } void Inter_v2::o2_writeData(OpFuncParams ¶ms) { - int32 offset; - int32 size; - int16 dataVar; - SaveLoad::SaveMode mode; - - _vm->_game->_script->evalExpr(0); - dataVar = _vm->_game->_script->readVarIndex(); - size = _vm->_game->_script->readValExpr(); - _vm->_game->_script->evalExpr(0); - offset = _vm->_game->_script->getResultInt(); + const char *file = _vm->_game->_script->evalString(); - char *file = _vm->_game->_script->getResultStr(); + int16 dataVar = _vm->_game->_script->readVarIndex(); + int32 size = _vm->_game->_script->readValExpr(); + int32 offset = _vm->_game->_script->evalInt(); debugC(2, kDebugFileIO, "Write to file \"%s\" (%d, %d bytes at %d)", file, dataVar, size, offset); WRITE_VAR(1, 1); - mode = _vm->_saveLoad->getSaveMode(file); + SaveLoad::SaveMode mode = _vm->_saveLoad->getSaveMode(file); if (mode == SaveLoad::kSaveModeSave) { if (!_vm->_saveLoad->save(file, dataVar, size, offset)) { diff --git a/engines/gob/inter_v4.cpp b/engines/gob/inter_v4.cpp index 033262ebbc..778387e52d 100644 --- a/engines/gob/inter_v4.cpp +++ b/engines/gob/inter_v4.cpp @@ -141,17 +141,12 @@ void Inter_v4::o4_initScreen() { } void Inter_v4::o4_playVmdOrMusic() { - char fileName[128]; - bool close; - - _vm->_game->_script->evalExpr(0); - Common::strlcpy(fileName, _vm->_game->_script->getResultStr(), 128); + Common::String file = _vm->_game->_script->evalString(); // WORKAROUND: The nut rolling animation in the administration center // in Woodruff is called "noixroul", but the scripts think it's "noixroule". - if ((_vm->getGameType() == kGameTypeWoodruff) && - (!scumm_stricmp(fileName, "noixroule"))) - strcpy(fileName, "noixroul"); + if ((_vm->getGameType() == kGameTypeWoodruff) && file.equalsIgnoreCase("noixroule")) + file = "noixroul"; VideoPlayer::Properties props; @@ -166,11 +161,11 @@ void Inter_v4::o4_playVmdOrMusic() { props.palCmd = 1 << (props.flags & 0x3F); debugC(1, kDebugVideo, "Playing video \"%s\" @ %d+%d, frames %d - %d, " - "paletteCmd %d (%d - %d), flags %X", fileName, + "paletteCmd %d (%d - %d), flags %X", file.c_str(), props.x, props.y, props.startFrame, props.lastFrame, props.palCmd, props.palStart, props.palEnd, props.flags); - close = false; + bool close = false; if (props.lastFrame == -1) { close = true; } else if (props.lastFrame == -2) { @@ -187,7 +182,7 @@ void Inter_v4::o4_playVmdOrMusic() { uint32 x = props.x; uint32 y = props.y; - int slot = _vm->_vidPlayer->openVideo(false, fileName, props); + int slot = _vm->_vidPlayer->openVideo(false, file, props); _vm->_mult->_objects[props.startFrame].videoSlot = slot + 1; @@ -201,7 +196,7 @@ void Inter_v4::o4_playVmdOrMusic() { return; } else if (props.lastFrame == -4) { - warning("Woodruff Stub: Video/Music command -4: Play background video %s", fileName); + warning("Woodruff Stub: Video/Music command -4: Play background video %s", file.c_str()); return; } else if (props.lastFrame == -5) { _vm->_sound->bgStop(); @@ -211,15 +206,15 @@ void Inter_v4::o4_playVmdOrMusic() { } else if (props.lastFrame == -7) { return; } else if (props.lastFrame == -8) { - warning("Woodruff Stub: Video/Music command -8: Play background video %s", fileName); + warning("Woodruff Stub: Video/Music command -8: Play background video %s", file.c_str()); return; } else if (props.lastFrame == -9) { _vm->_sound->bgStop(); _vm->_sound->bgSetPlayMode(BackgroundAtmosphere::kPlayModeRandom); - _vm->_sound->bgPlay(fileName, "SND", SOUND_SND, props.palStart); + _vm->_sound->bgPlay(file.c_str(), "SND", SOUND_SND, props.palStart); return; } else if (props.lastFrame < 0) { - warning("Unknown Video/Music command: %d, %s", props.lastFrame, fileName); + warning("Unknown Video/Music command: %d, %s", props.lastFrame, file.c_str()); return; } @@ -232,7 +227,7 @@ void Inter_v4::o4_playVmdOrMusic() { _vm->_vidPlayer->evaluateFlags(props); int slot = 0; - if ((fileName[0] != 0) && ((slot = _vm->_vidPlayer->openVideo(true, fileName, props)) < 0)) { + if (!file.empty() && ((slot = _vm->_vidPlayer->openVideo(true, file, props)) < 0)) { WRITE_VAR(11, (uint32) -1); return; } diff --git a/engines/gob/inter_v5.cpp b/engines/gob/inter_v5.cpp index 87ecf14c8e..85b213ae66 100644 --- a/engines/gob/inter_v5.cpp +++ b/engines/gob/inter_v5.cpp @@ -100,8 +100,7 @@ void Inter_v5::setupOpcodesGob() { } void Inter_v5::o5_deleteFile() { - _vm->_game->_script->evalExpr(0); - char *file = _vm->_game->_script->getResultStr(); + const char *file =_vm->_game->_script->evalString(); debugC(2, kDebugFileIO, "Delete file \"%s\"", file); diff --git a/engines/gob/inter_v6.cpp b/engines/gob/inter_v6.cpp index 73fc5d18a0..6f2605468c 100644 --- a/engines/gob/inter_v6.cpp +++ b/engines/gob/inter_v6.cpp @@ -73,26 +73,18 @@ void Inter_v6::setupOpcodesGob() { } void Inter_v6::o6_totSub() { - char totFile[14]; - byte length; - int flags; - int i; - - length = _vm->_game->_script->readByte(); + uint8 length = _vm->_game->_script->readByte(); if ((length & 0x7F) > 13) error("Length in o6_totSub is greater than 13 (%d)", length); - if (length & 0x80) { - _vm->_game->_script->evalExpr(0); - strcpy(totFile, _vm->_game->_script->getResultStr()); - } else { - for (i = 0; i < length; i++) - totFile[i] = _vm->_game->_script->readChar(); - totFile[i] = 0; - } - - flags = _vm->_game->_script->readByte(); + Common::String totFile; + if (length & 0x80) + totFile = _vm->_game->_script->evalString(); + else + for (uint8 i = 0; i < length; i++) + totFile += _vm->_game->_script->readChar(); + uint8 flags = _vm->_game->_script->readByte(); if (flags & 0x40) warning("Urban Stub: o6_totSub(), flags & 0x40"); @@ -100,11 +92,7 @@ void Inter_v6::o6_totSub() { } void Inter_v6::o6_playVmdOrMusic() { - char fileName[128]; - bool close; - - _vm->_game->_script->evalExpr(0); - Common::strlcpy(fileName, _vm->_game->_script->getResultStr(), 128); + Common::String file = _vm->_game->_script->evalString(); VideoPlayer::Properties props; @@ -120,22 +108,22 @@ void Inter_v6::o6_playVmdOrMusic() { props.forceSeek = true; debugC(1, kDebugVideo, "Playing video \"%s\" @ %d+%d, frames %d - %d, " - "paletteCmd %d (%d - %d), flags %X", fileName, + "paletteCmd %d (%d - %d), flags %X", file.c_str(), props.x, props.y, props.startFrame, props.lastFrame, props.palCmd, props.palStart, props.palEnd, props.flags); // WORKAROUND: When taking the music sheet from Dr. Dramish's car, // the video that lets the sheet vanish is missing. We'll // play the one where the sheet is already gone instead. - if (!strcmp(fileName, "MXRAMPART") && _vm->isCurrentTot("avt005.tot")) - strcpy(fileName, "PLCOFDR2"); + if (_vm->isCurrentTot("avt005.tot") && file.equalsIgnoreCase("MXRAMPART")) + file = "PLCOFDR2"; - if (!strcmp(fileName, "RIEN")) { + if (file == "RIEN") { _vm->_vidPlayer->closeAll(); return; } - close = false; + bool close = false; if (props.lastFrame == -1) { close = true; } else if (props.lastFrame == -5) { @@ -149,16 +137,16 @@ void Inter_v6::o6_playVmdOrMusic() { // warning("Urban/Playtoons Stub: Video/Music command -6 (flush cache)"); return; } else if ((props.lastFrame == -8) || (props.lastFrame == -9)) { - if (!strchr(fileName, '.')) - strcat(fileName, ".WA8"); + if (!file.contains('.')) + file += ".WA8"; - probe16bitMusic(fileName); + probe16bitMusic(file); if (props.lastFrame == -9) debugC(0, kDebugVideo, "Urban/Playtoons Stub: Delayed music stop?"); _vm->_sound->bgStop(); - _vm->_sound->bgPlay(fileName, SOUND_WAV); + _vm->_sound->bgPlay(file.c_str(), SOUND_WAV); return; } else if (props.lastFrame <= -10) { _vm->_vidPlayer->closeVideo(); @@ -167,7 +155,7 @@ void Inter_v6::o6_playVmdOrMusic() { props.loop = true; } else if (props.lastFrame < 0) { - warning("Urban/Playtoons Stub: Unknown Video/Music command: %d, %s", props.lastFrame, fileName); + warning("Urban/Playtoons Stub: Unknown Video/Music command: %d, %s", props.lastFrame, file.c_str()); return; } @@ -184,7 +172,7 @@ void Inter_v6::o6_playVmdOrMusic() { primary = false; int slot = 0; - if ((fileName[0] != 0) && ((slot = _vm->_vidPlayer->openVideo(primary, fileName, props)) < 0)) { + if (!file.empty() && ((slot = _vm->_vidPlayer->openVideo(primary, file, props)) < 0)) { WRITE_VAR(11, (uint32) -1); return; } @@ -392,11 +380,10 @@ void Inter_v6::o6_fillRect(OpFuncParams ¶ms) { _vm->_draw->_spriteRight = _vm->_game->_script->readValExpr(); _vm->_draw->_spriteBottom = _vm->_game->_script->readValExpr(); - _vm->_game->_script->evalExpr(0); + uint32 patternColor = _vm->_game->_script->evalInt(); - _vm->_draw->_backColor = _vm->_game->_script->getResultInt() & 0xFFFF; - - _vm->_draw->_pattern = _vm->_game->_script->getResultInt() >> 16; + _vm->_draw->_backColor = patternColor & 0xFFFF; + _vm->_draw->_pattern = patternColor >> 16; if (_vm->_draw->_pattern != 0) warning("Urban Stub: o6_fillRect(), _pattern = %d", _vm->_draw->_pattern); @@ -421,21 +408,16 @@ void Inter_v6::o6_fillRect(OpFuncParams ¶ms) { _vm->_draw->spriteOperation(DRAW_FILLRECT); } -void Inter_v6::probe16bitMusic(char *fileName) { - int len = strlen(fileName); - - if (len < 4) - return; - - if (scumm_stricmp(fileName + len - 4, ".WA8")) +void Inter_v6::probe16bitMusic(Common::String &fileName) { + if (!fileName[fileName.size() - 1] != '8') return; - fileName[len - 1] = 'V'; + fileName.setChar('V', fileName.size() - 1); if (_vm->_dataIO->hasFile(fileName)) return; - fileName[len - 1] = '8'; + fileName.setChar('8', fileName.size() - 1); } } // End of namespace Gob diff --git a/engines/gob/inter_v7.cpp b/engines/gob/inter_v7.cpp index 4457da7ad4..7067969e91 100644 --- a/engines/gob/inter_v7.cpp +++ b/engines/gob/inter_v7.cpp @@ -84,10 +84,8 @@ void Inter_v7::o7_draw0x0C() { } void Inter_v7::o7_loadCursor() { - int16 cursorIndex = _vm->_game->_script->readValExpr(); - - _vm->_game->_script->evalExpr(0); - Common::String cursorFile = _vm->_game->_script->getResultStr(); + int16 cursorIndex = _vm->_game->_script->readValExpr(); + Common::String cursorFile = _vm->_game->_script->evalString(); warning("Addy Stub: Load cursor \"%s\" to %d", cursorFile.c_str(), cursorIndex); @@ -109,25 +107,18 @@ void Inter_v7::o7_loadCursor() { } void Inter_v7::o7_displayWarning() { - _vm->_game->_script->evalExpr(0); - Common::String caption = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String text = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String source = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String msg = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String param = _vm->_game->_script->getResultStr(); + Common::String caption = _vm->_game->_script->evalString(); + Common::String text = _vm->_game->_script->evalString(); + Common::String source = _vm->_game->_script->evalString(); + Common::String msg = _vm->_game->_script->evalString(); + Common::String param = _vm->_game->_script->evalString(); warning("%s: %s (%s)", source.c_str(), msg.c_str(), param.c_str()); } void Inter_v7::o7_draw0x45() { - _vm->_game->_script->evalExpr(0); - Common::String str0 = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String str1 = _vm->_game->_script->getResultStr(); + Common::String str0 = _vm->_game->_script->evalString(); + Common::String str1 = _vm->_game->_script->evalString(); warning("Addy Stub Draw 0x45: \"%s\", \"%s\"", str0.c_str(), str1.c_str()); } @@ -140,10 +131,8 @@ void Inter_v7::o7_intToString() { } void Inter_v7::o7_callGroup() { - _vm->_game->_script->evalExpr(0); - Common::String str0 = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String str1 = _vm->_game->_script->getResultStr(); + Common::String str0 = _vm->_game->_script->evalString(); + Common::String str1 = _vm->_game->_script->evalString(); int16 expr0 = _vm->_game->_script->readValExpr(); @@ -151,8 +140,7 @@ void Inter_v7::o7_callGroup() { } void Inter_v7::o7_loadGroups() { - _vm->_game->_script->evalExpr(0); - Common::String str0 = _vm->_game->_script->getResultStr(); + Common::String str0 = _vm->_game->_script->evalString(); int16 expr0 = _vm->_game->_script->readValExpr(); @@ -160,10 +148,8 @@ void Inter_v7::o7_loadGroups() { } void Inter_v7::o7_draw0x89() { - _vm->_game->_script->evalExpr(0); - Common::String str0 = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String str1 = _vm->_game->_script->getResultStr(); + Common::String str0 = _vm->_game->_script->evalString(); + Common::String str1 = _vm->_game->_script->evalString(); warning("Addy Stub Draw 0x89: \"%s\", \"%s\"", str0.c_str(), str1.c_str()); @@ -180,8 +166,7 @@ void Inter_v7::o7_draw0x89() { } void Inter_v7::o7_findFile() { - _vm->_game->_script->evalExpr(0); - const char *file = _vm->_game->_script->getResultStr(); + const char *file = _vm->_game->_script->evalString(); uint16 pathIndex = _vm->_game->_script->readVarIndex(); if (!strncmp(file, "", 4)) @@ -204,34 +189,31 @@ void Inter_v7::o7_findFile() { } void Inter_v7::o7_getSystemProperty() { - _vm->_game->_script->evalExpr(0); - - if (!scumm_stricmp(_vm->_game->_script->getResultStr(), "TotalPhys")) { + const char *property = _vm->_game->_script->evalString(); + if (!scumm_stricmp(property, "TotalPhys")) { // HACK storeValue(1000000); return; } - if (!scumm_stricmp(_vm->_game->_script->getResultStr(), "AvailPhys")) { + if (!scumm_stricmp(property, "AvailPhys")) { // HACK storeValue(1000000); return; } - if (!scumm_stricmp(_vm->_game->_script->getResultStr(), "TimeGMT")) { + if (!scumm_stricmp(property, "TimeGMT")) { renewTimeInVars(); storeValue(0); return; } - warning("Inter_v7::o7_getSystemProperty(): Unknown property \"%s\"", - _vm->_game->_script->getResultStr()); + warning("Inter_v7::o7_getSystemProperty(): Unknown property \"%s\"", property); storeValue(0); } void Inter_v7::o7_loadLBM() { - _vm->_game->_script->evalExpr(0); - Common::String file = _vm->_game->_script->getResultStr(); + Common::String file = _vm->_game->_script->evalString(); if (!file.contains('.')) file += ".LBM"; @@ -261,22 +243,15 @@ void Inter_v7::o7_zeroVar() { } void Inter_v7::o7_getINIValue() { - _vm->_game->_script->evalExpr(0); - - Common::String file; - if (!strncmp(_vm->_game->_script->getResultStr(), "", 4)) - file = _vm->_game->_script->getResultStr() + 4; - else if (!strncmp(_vm->_game->_script->getResultStr(), "", 7)) - file = _vm->_game->_script->getResultStr() + 7; - else - file = _vm->_game->_script->getResultStr(); - - _vm->_game->_script->evalExpr(0); - Common::String section = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String key = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String def = _vm->_game->_script->getResultStr(); + const char *file = _vm->_game->_script->evalString(); + if (!strncmp(file, "", 4)) + file += 4; + else if (!strncmp(file, "", 7)) + file += 7; + + Common::String section = _vm->_game->_script->evalString(); + Common::String key = _vm->_game->_script->evalString(); + Common::String def = _vm->_game->_script->evalString(); Common::String value; _inis.getValue(value, file, section, key, def); @@ -285,29 +260,21 @@ void Inter_v7::o7_getINIValue() { } void Inter_v7::o7_setINIValue() { - _vm->_game->_script->evalExpr(0); - - Common::String file; - if (!strncmp(_vm->_game->_script->getResultStr(), "", 4)) - file = _vm->_game->_script->getResultStr() + 4; - else if (!strncmp(_vm->_game->_script->getResultStr(), "", 7)) - file = _vm->_game->_script->getResultStr() + 7; - else - file = _vm->_game->_script->getResultStr(); - - _vm->_game->_script->evalExpr(0); - Common::String section = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String key = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String value = _vm->_game->_script->getResultStr(); + const char *file = _vm->_game->_script->evalString(); + if (!strncmp(file, "", 4)) + file += 4; + else if (!strncmp(file, "", 7)) + file += 7; + + Common::String section = _vm->_game->_script->evalString(); + Common::String key = _vm->_game->_script->evalString(); + Common::String value = _vm->_game->_script->evalString(); _inis.setValue(file, section, key, value); } void Inter_v7::o7_draw0xA4() { - _vm->_game->_script->evalExpr(0); - Common::String str0 = _vm->_game->_script->getResultStr(); + Common::String str0 = _vm->_game->_script->evalString(); int16 expr0 = _vm->_game->_script->readValExpr(); int16 expr1 = _vm->_game->_script->readValExpr(); @@ -316,30 +283,23 @@ void Inter_v7::o7_draw0xA4() { } void Inter_v7::o7_opendBase() { - _vm->_game->_script->evalExpr(0); - Common::String str0 = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String str1 = _vm->_game->_script->getResultStr(); + Common::String str0 = _vm->_game->_script->evalString(); + Common::String str1 = _vm->_game->_script->evalString(); warning("Addy Stub: Open dBase file \"%s.dbf\" (%s)", str0.c_str(), str1.c_str()); } void Inter_v7::o7_draw0xC5() { - _vm->_game->_script->evalExpr(0); - Common::String str0 = _vm->_game->_script->getResultStr(); + Common::String str0 = _vm->_game->_script->evalString(); warning("Addy Stub Draw 0xC5: \"%s\"", str0.c_str()); } void Inter_v7::o7_draw0xC6() { - _vm->_game->_script->evalExpr(0); - Common::String str0 = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String str1 = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String str2 = _vm->_game->_script->getResultStr(); - _vm->_game->_script->evalExpr(0); - Common::String str3 = _vm->_game->_script->getResultStr(); + Common::String str0 = _vm->_game->_script->evalString(); + Common::String str1 = _vm->_game->_script->evalString(); + Common::String str2 = _vm->_game->_script->evalString(); + Common::String str3 = _vm->_game->_script->evalString(); int16 index0 = _vm->_game->_script->readVarIndex(); diff --git a/engines/gob/script.cpp b/engines/gob/script.cpp index fd67a70cba..eb37451229 100644 --- a/engines/gob/script.cpp +++ b/engines/gob/script.cpp @@ -321,6 +321,16 @@ bool Script::evalBool() { return false; } +int32 Script::evalInt() { + evalExpr(0); + return getResultInt(); +} + +const char *Script::evalString() { + evalExpr(0); + return getResultStr(); +} + int32 Script::getResultInt() const { return _expression->getResultInt(); } diff --git a/engines/gob/script.h b/engines/gob/script.h index ffdb4d6340..0e8ac0d69f 100644 --- a/engines/gob/script.h +++ b/engines/gob/script.h @@ -84,8 +84,11 @@ public: void skipExpr(char stopToken); // Higher-level expression parsing functions - char evalExpr(int16 *pRes); - bool evalBool(); + char evalExpr(int16 *pRes); + bool evalBool(); + int32 evalInt(); + + const char *evalString(); // Accessing the result of expressions int32 getResultInt() const; diff --git a/engines/gob/sound/sound.cpp b/engines/gob/sound/sound.cpp index 30bbb94fd4..219c6b84e8 100644 --- a/engines/gob/sound/sound.cpp +++ b/engines/gob/sound/sound.cpp @@ -508,11 +508,11 @@ void Sound::blasterWaitEndPlay(bool interruptible, bool stopComp) { _blaster->stopSound(0); } -void Sound::cdLoadLIC(const char *fname) { +void Sound::cdLoadLIC(const Common::String &fname) { if (!_cdrom) return; - debugC(1, kDebugSound, "CDROM: Loading LIC \"%s\"", fname); + debugC(1, kDebugSound, "CDROM: Loading LIC \"%s\"", fname.c_str()); Common::SeekableReadStream *stream = _vm->_dataIO->getFile(fname); if (!stream) @@ -592,17 +592,17 @@ void Sound::cdPlayMultMusic() { } } -void Sound::cdPlay(const char *trackName) { +void Sound::cdPlay(const Common::String &trackName) { if (!_cdrom) return; - debugC(1, kDebugSound, "CDROM: Playing track \"%s\"", trackName); + debugC(1, kDebugSound, "CDROM: Playing track \"%s\"", trackName.c_str()); // WORKAROUND - In Fascination CD, in the storage room, a track has the wrong // name in the scripts, and therefore doesn't play. This fixes the problem. - if ((_vm->getGameType() == kGameTypeFascination) && !scumm_stricmp(trackName, "boscle")) + if ((_vm->getGameType() == kGameTypeFascination) && trackName.equalsIgnoreCase("boscle")) _cdrom->startTrack("bosscle"); else - _cdrom->startTrack(trackName); + _cdrom->startTrack(trackName.c_str()); } void Sound::cdStop() { diff --git a/engines/gob/sound/sound.h b/engines/gob/sound/sound.h index 516fed5c78..24e161154b 100644 --- a/engines/gob/sound/sound.h +++ b/engines/gob/sound/sound.h @@ -114,13 +114,13 @@ public: // CD-ROM - void cdLoadLIC(const char *fname); + void cdLoadLIC(const Common::String &fname); void cdUnloadLIC(); void cdPlayBgMusic(); void cdPlayMultMusic(); - void cdPlay(const char *trackName); + void cdPlay(const Common::String &); void cdStop(); bool cdIsPlaying() const; -- cgit v1.2.3