diff --git a/engines/sherlock/journal.cpp b/engines/sherlock/journal.cpp index be76756bddc..67cff152180 100644 --- a/engines/sherlock/journal.cpp +++ b/engines/sherlock/journal.cpp @@ -237,10 +237,10 @@ int Journal::loadJournalFile(bool alreadyLoaded) { bool ctrlSpace = false; bool commentFlag = false; bool commentJustPrinted = false; - const char *replyP = statement._reply.c_str(); + const byte *replyP = (const byte *)statement._reply.c_str(); while (*replyP) { - byte c = (byte)*replyP++; + byte c = *replyP++; // Is it a control character? if (c < 128) { @@ -286,10 +286,10 @@ int Journal::loadJournalFile(bool alreadyLoaded) { else journalString += NAMES[talk._talkTo]; - const char *strP = replyP + 1; + const byte *strP = replyP + 1; char v; do { - v = (byte)*strP++; + v = *strP++; } while (v && v < 128 && v != '.' && v != '!' && v != '?'); if (v == '?') @@ -306,7 +306,7 @@ int Journal::loadJournalFile(bool alreadyLoaded) { journalString += c; do { journalString += *replyP++; - } while (*replyP && (byte)*replyP < 128 && *replyP != '{' && *replyP != '}'); + } while (*replyP && *replyP < 128 && *replyP != '{' && *replyP != '}'); commentJustPrinted = false; } @@ -333,10 +333,10 @@ int Journal::loadJournalFile(bool alreadyLoaded) { else journalString += NAMES[c]; - const char *strP = replyP; + const byte *strP = replyP; byte v; do { - v = (byte)*strP++; + v = *strP++; } while (v && v < 128 && v != '.' && v != '!' && v != '?'); if (v == '?') @@ -356,7 +356,7 @@ int Journal::loadJournalFile(bool alreadyLoaded) { break; case ADJUST_OBJ_SEQUENCE: - replyP += ((byte)replyP[0] & 127) + (byte)replyP[1] + 2; + replyP += (replyP[0] & 127) + replyP[1] + 2; break; case WALK_TO_COORDS: @@ -380,7 +380,7 @@ int Journal::loadJournalFile(bool alreadyLoaded) { case SET_OBJECT: case DISPLAY_INFO_LINE: case REMOVE_ITEM_FROM_INVENTORY: - replyP += ((byte)*replyP & 127) + 1; + replyP += (*replyP & 127) + 1; break; case GOTO_SCENE: diff --git a/engines/sherlock/talk.cpp b/engines/sherlock/talk.cpp index fb16995d2b5..9e75f4ecc8e 100644 --- a/engines/sherlock/talk.cpp +++ b/engines/sherlock/talk.cpp @@ -993,14 +993,16 @@ void Talk::doScript(const Common::String &script) { _saveSeqNum = 0; - const char *str = script.c_str(); + const byte *scriptStart = (const byte *)script.c_str(); + const byte *str = scriptStart; + if (_scriptMoreFlag) { _scriptMoreFlag = 0; - str = script.c_str() + _scriptSaveIndex; + str = scriptStart + _scriptSaveIndex; } // Check if the script begins with a Stealh Mode Active command - if ((byte)str[0] == STEALTH_MODE_ACTIVE || _talkStealth) { + if (str[0] == STEALTH_MODE_ACTIVE || _talkStealth) { _talkStealth = 2; _speaker |= 128; } else { @@ -1008,7 +1010,7 @@ void Talk::doScript(const Common::String &script) { ui.clearWindow(); // Need to switch speakers? - if ((byte)str[0] == SWITCH_SPEAKER) { + if (str[0] == SWITCH_SPEAKER) { _speaker = str[1] - 1; str += 2; pullSequence(); @@ -1019,7 +1021,7 @@ void Talk::doScript(const Common::String &script) { } // Assign portrait location? - if ((byte)str[0] == ASSIGN_PORTRAIT_LOCATION) { + if (str[0] == ASSIGN_PORTRAIT_LOCATION) { switch (str[1] & 15) { case 1: people._portraitSide = 20; @@ -1041,7 +1043,7 @@ void Talk::doScript(const Common::String &script) { } // Remove portrait? - if ((byte)str[0] == REMOVE_PORTRAIT) { + if (str[0] == REMOVE_PORTRAIT) { _speaker = 255; } else { // Nope, so set the first speaker @@ -1053,7 +1055,7 @@ void Talk::doScript(const Common::String &script) { Common::String tempString; wait = 0; - byte c = (byte)str[0]; + byte c = str[0]; if (!c) { endStr = true; } else if (c == '{') { @@ -1066,7 +1068,7 @@ void Talk::doScript(const Common::String &script) { case SWITCH_SPEAKER: // Save the current point in the script, since it might be intterupted by // doing bg anims in the next call, so we need to know where to return to - _scriptCurrentIndex = str - script.c_str(); + _scriptCurrentIndex = str - scriptStart; if (!(_speaker & 128)) people.clearTalking(); @@ -1088,13 +1090,13 @@ void Talk::doScript(const Common::String &script) { // Save the current point in the script, since it might be intterupted by // doing bg anims in the next call, so we need to know where to return to ++str; - _scriptCurrentIndex = (str + 1) - script.c_str(); - scene.startCAnim(((byte)str[0] - 1) & 127, ((byte)str[0] & 128) ? -1 : 1); + _scriptCurrentIndex = (str + 1) - scriptStart; + scene.startCAnim((str[0] - 1) & 127, (str[0] & 128) ? -1 : 1); if (_talkToAbort) return; // Check if next character is changing side or changing portrait - if (charCount && ((byte)str[1] == SWITCH_SPEAKER || (byte)str[1] == ASSIGN_PORTRAIT_LOCATION)) + if (charCount && (str[1] == SWITCH_SPEAKER || str[1] == ASSIGN_PORTRAIT_LOCATION)) wait = 1; break; @@ -1120,14 +1122,14 @@ void Talk::doScript(const Common::String &script) { case PAUSE: // Pause - charCount = (byte)*++str; + charCount = *++str; wait = pauseFlag = true; break; case REMOVE_PORTRAIT: // Save the current point in the script, since it might be intterupted by // doing bg anims in the next call, so we need to know where to return to - _scriptCurrentIndex = str - script.c_str(); + _scriptCurrentIndex = str - scriptStart; if (_speaker >= 0 && _speaker < 128) people.clearTalking(); @@ -1186,10 +1188,10 @@ void Talk::doScript(const Common::String &script) { // Save the current point in the script, since it might be intterupted by // doing bg anims in the next call, so we need to know where to return to ++str; - _scriptCurrentIndex = str - script.c_str(); + _scriptCurrentIndex = str - scriptStart; - people.walkToCoords(Common::Point((((byte)str[0] - 1) * 256 + (byte)str[1] - 1) * 100, - (byte)str[2] * 100), str[3] - 1); + people.walkToCoords(Common::Point(((str[0] - 1) * 256 + str[1] - 1) * 100, + str[2] * 100), str[3] - 1); if (_talkToAbort) return; @@ -1200,7 +1202,7 @@ void Talk::doScript(const Common::String &script) { // Save the current point in the script, since it might be intterupted by // doing bg anims in the next call, so we need to know where to return to ++str; - _scriptCurrentIndex = str - script.c_str(); + _scriptCurrentIndex = str - scriptStart; for (int idx = 0; idx < (str[0] - 1); ++idx) { scene.doBgAnim(); @@ -1216,7 +1218,7 @@ void Talk::doScript(const Common::String &script) { case BANISH_WINDOW: // Save the current point in the script, since it might be intterupted by // doing bg anims in the next call, so we need to know where to return to - _scriptCurrentIndex = str - script.c_str(); + _scriptCurrentIndex = str - scriptStart; if (!(_speaker & 128)) people.clearTalking(); @@ -1246,7 +1248,7 @@ void Talk::doScript(const Common::String &script) { case SET_FLAG: { ++str; - int flag1 = ((byte)str[0] - 1) * 256 + (byte)str[1] - 1 - (str[1] == 1 ? 1 : 0); + int flag1 = (str[0] - 1) * 256 + str[1] - 1 - (str[1] == 1 ? 1 : 0); int flag = (flag1 & 0x3fff) * (flag1 >= 0x4000 ? -1 : 1); _vm->setFlags(flag); ++str; @@ -1284,7 +1286,7 @@ void Talk::doScript(const Common::String &script) { case IF_STATEMENT: { ++str; - int flag = ((byte)str[0] - 1) * 256 + (byte)str[1] - 1 - (str[1] == 1 ? 1 : 0); + int flag = (str[0] - 1) * 256 + str[1] - 1 - (str[1] == 1 ? 1 : 0); ++str; wait = 0; @@ -1334,14 +1336,14 @@ void Talk::doScript(const Common::String &script) { // Run a canimation? if (str[2] > 100) { - people._hSavedFacing = (byte)str[2]; + people._hSavedFacing = str[2]; people._hSavedPos = Common::Point(160, 100); } } str += 6; _scriptMoreFlag = (scene._goToScene == 100) ? 2 : 1; - _scriptSaveIndex = str - script.c_str(); + _scriptSaveIndex = str - scriptStart; endStr = true; wait = 0; break; @@ -1369,7 +1371,7 @@ void Talk::doScript(const Common::String &script) { tempString += str[idx + 1]; // Set comparison state according to if we want to hide or unhide - bool state = ((byte)str[0] >= 128); + bool state = (str[0] >= 128); str += str[0] & 127; for (uint idx = 0; idx < scene._bgShapes.size(); ++idx) { @@ -1389,7 +1391,7 @@ void Talk::doScript(const Common::String &script) { tempString += str[idx]; str += 8; - _scriptCurrentIndex = str - script.c_str(); + _scriptCurrentIndex = str - scriptStart; // Save the current script position and new talk file if (_scriptStack.size() < 9) { @@ -1418,8 +1420,8 @@ void Talk::doScript(const Common::String &script) { // Save the current point in the script, since it might be intterupted by // doing bg anims in the next call, so we need to know where to return to ++str; - _scriptCurrentIndex = str - script.c_str(); - events.moveMouse(Common::Point(((byte)str[0] - 1) * 256 + (byte)str[1] - 1, str[2])); + _scriptCurrentIndex = str - scriptStart; + events.moveMouse(Common::Point((str[0] - 1) * 256 + str[1] - 1, str[2])); if (_talkToAbort) return; str += 3; @@ -1446,7 +1448,7 @@ void Talk::doScript(const Common::String &script) { // Save the current point in the script, since it might be intterupted by // doing bg anims in the next call, so we need to know where to return to - _scriptCurrentIndex = (str + 1) - script.c_str(); + _scriptCurrentIndex = (str + 1) - scriptStart; people.walkToCoords(anim._goto, anim._gotoDir); if (_talkToAbort) @@ -1509,10 +1511,10 @@ void Talk::doScript(const Common::String &script) { width += screen.charWidth(str[idx]); ++idx; ++charCount; - } while (width < 298 && str[idx] && str[idx] != '{' && (byte)str[idx] < 128); + } while (width < 298 && str[idx] && str[idx] != '{' && str[idx] < 128); if (str[idx] || width >= 298) { - if ((byte)str[idx] < 128 && str[idx] != '{') { + if (str[idx] < 128 && str[idx] != '{') { --idx; --charCount; } @@ -1529,7 +1531,7 @@ void Talk::doScript(const Common::String &script) { } // Print the line - Common::String lineStr(str, str + idx); + Common::String lineStr((const char *)str, (const char *)str + idx); // If the speaker indicates a description file, print it in yellow if (_speaker != -1) { @@ -1552,20 +1554,20 @@ void Talk::doScript(const Common::String &script) { str += idx; // If line wrap occurred, then move to after the separating space between the words - if ((byte)str[0] < 128 && str[0] != '{') + if (str[0] < 128 && str[0] != '{') ++str; yp += 9; ++line; // Certain different conditions require a wait - if ((line == 4 && (byte)str[0] != SFX_COMMAND && (byte)str[0] != PAUSE && _speaker != -1) || - (line == 5 && (byte)str[0] != PAUSE && _speaker != -1) || + if ((line == 4 && str[0] != SFX_COMMAND && str[0] != PAUSE && _speaker != -1) || + (line == 5 && str[0] != PAUSE && _speaker != -1) || endStr) { wait = 1; } - switch ((byte)str[0]) { + switch (str[0]) { case SWITCH_SPEAKER: case ASSIGN_PORTRAIT_LOCATION: case BANISH_WINDOW: @@ -1582,7 +1584,7 @@ void Talk::doScript(const Common::String &script) { } // Open window if it wasn't already open, and text has already been printed - if ((openTalkWindow && wait) || (openTalkWindow && (byte)str[0] >= 128 && (byte)str[0] != CARRIAGE_RETURN)) { + if ((openTalkWindow && wait) || (openTalkWindow && str[0] >= 128 && str[0] != CARRIAGE_RETURN)) { if (!ui._windowStyle) { screen.slamRect(Common::Rect(0, CONTROLS_Y, SHERLOCK_SCREEN_WIDTH, SHERLOCK_SCREEN_HEIGHT)); } else { @@ -1596,7 +1598,7 @@ void Talk::doScript(const Common::String &script) { if (wait) { // Save the current point in the script, since it might be intterupted by // doing bg anims in the next call, so we need to know where to return to - _scriptCurrentIndex = str - script.c_str(); + _scriptCurrentIndex = str - scriptStart; // Handling pausing if (!pauseFlag && charCount < 160) @@ -1608,12 +1610,12 @@ void Talk::doScript(const Common::String &script) { // If a key was pressed to finish the window, see if further voice files should be skipped if (wait >= 0 && wait < 254) { - if ((byte)str[0] == SFX_COMMAND) + if (str[0] == SFX_COMMAND) str += 9; } // Clear the window unless the wait was due to a PAUSE command - if (!pauseFlag && wait != -1 && (byte)str[0] != SFX_COMMAND) { + if (!pauseFlag && wait != -1 && str[0] != SFX_COMMAND) { if (!_talkStealth) ui.clearWindow(); yp = CONTROLS_Y + 12;