From dab5cd387dd10e7c75987bac97e974216806bba3 Mon Sep 17 00:00:00 2001 From: Strangerke Date: Mon, 14 Sep 2015 00:23:07 +0200 Subject: SHERLOCK: Reduce the scope of several variables. --- engines/sherlock/tattoo/tattoo_darts.cpp | 17 +++++++---------- engines/sherlock/tattoo/tattoo_inventory.cpp | 2 +- engines/sherlock/tattoo/tattoo_journal.cpp | 2 +- engines/sherlock/tattoo/tattoo_people.cpp | 4 +--- engines/sherlock/tattoo/tattoo_scene.cpp | 3 +-- engines/sherlock/tattoo/tattoo_user_interface.cpp | 5 ++--- engines/sherlock/tattoo/widget_files.cpp | 3 +-- engines/sherlock/tattoo/widget_lab.cpp | 2 +- engines/sherlock/tattoo/widget_talk.cpp | 8 ++++---- engines/sherlock/tattoo/widget_verbs.cpp | 2 +- 10 files changed, 20 insertions(+), 28 deletions(-) (limited to 'engines/sherlock/tattoo') diff --git a/engines/sherlock/tattoo/tattoo_darts.cpp b/engines/sherlock/tattoo/tattoo_darts.cpp index cb4b52b01a..6d6c74dcf6 100644 --- a/engines/sherlock/tattoo/tattoo_darts.cpp +++ b/engines/sherlock/tattoo/tattoo_darts.cpp @@ -77,7 +77,6 @@ void Darts::playDarts(GameType gameType) { Screen &screen = *_vm->_screen; int oldFontType = screen.fontNumber(); int playerNum = 0; - int roundStart, score; int lastDart; int numHits = 0; bool gameOver = false; @@ -92,6 +91,7 @@ void Darts::playDarts(GameType gameType) { initDarts(); while (!done && !_vm->shouldQuit()) { + int roundStart, score; roundStart = score = (playerNum == 0) ? _score1 : _score2; showNames(playerNum); @@ -143,7 +143,6 @@ void Darts::playDarts(GameType gameType) { } else { // check for cricket game over bool allClosed = true; - int nOtherScore; for (int y = 0; y < 7; y++) { if (_cricketScore[playerNum][y] < 3) @@ -151,7 +150,7 @@ void Darts::playDarts(GameType gameType) { } if (allClosed) { - nOtherScore = (playerNum == 0) ? _score2 : _score1; + int nOtherScore = (playerNum == 0) ? _score2 : _score1; if (score >= nOtherScore) gameOver = true; } @@ -561,11 +560,10 @@ void Darts::drawDartThrow(const Common::Point &dartPos, int computer) { Events &events = *_vm->_events; Screen &screen = *_vm->_screen; int cx, cy; - int handCy; int drawX = 0, drawY = 0, oldDrawX = 0, oldDrawY = 0; int xSize = 0, ySize = 0, oldxSize = 0, oldySize = 0; - int handOCx, handOCy; - int ocx, ocy; + int handOCx = 0, handOCy = 0; + int ocx = 0, ocy = 0; int handOldxSize, handOldySize; int delta = 9; int dartNum; @@ -576,7 +574,6 @@ void Darts::drawDartThrow(const Common::Point &dartPos, int computer) { ImageFile &hands = !computer ? *_hand1 : *_hand2; int numFrames = !computer ? 14 : 13; - ocx = ocy = handOCx = handOCy = 0; oldxSize = oldySize = handOldxSize = handOldySize = 1; cx = dartPos.x; cy = SHERLOCK_SCREEN_HEIGHT - _handSize.y - 20; @@ -590,7 +587,7 @@ void Darts::drawDartThrow(const Common::Point &dartPos, int computer) { for (int idx = 0; idx < numFrames; ++idx) { _handSize.x = hands[idx]._offset.x + hands[idx]._width; _handSize.y = hands[idx]._offset.y + hands[idx]._height; - handCy = SHERLOCK_SCREEN_HEIGHT - _handSize.y; + int handCy = SHERLOCK_SCREEN_HEIGHT - _handSize.y; screen._backBuffer1.transBlitFrom(hands[idx], Common::Point(_handX, handCy)); screen.slamArea(_handX, handCy, _handSize.x + 1, _handSize.y); @@ -787,8 +784,6 @@ void Darts::getComputerNumber(int playerNum, Common::Point &targetPos) { int score; int aim = 0; Common::Point pt; - bool done = false; - int cricketaimset = false; bool shootBull = false; score = (playerNum == 0) ? _score1 : _score2; @@ -799,6 +794,7 @@ void Darts::getComputerNumber(int playerNum, Common::Point &targetPos) { if(score > 60) shootBull = true; } else { + bool cricketaimset = false; if (_cricketScore[playerNum][6] < 3) { // shoot at bull first aim = CRICKET_VALUE[6]; @@ -842,6 +838,7 @@ void Darts::getComputerNumber(int playerNum, Common::Point &targetPos) { } } else { // Loop in case number does not exist on board + bool done = false; do { done = findNumberOnBoard(aim, pt); --aim; diff --git a/engines/sherlock/tattoo/tattoo_inventory.cpp b/engines/sherlock/tattoo/tattoo_inventory.cpp index 6bd1822c10..14e79e9f33 100644 --- a/engines/sherlock/tattoo/tattoo_inventory.cpp +++ b/engines/sherlock/tattoo/tattoo_inventory.cpp @@ -43,10 +43,10 @@ void TattooInventory::loadInv() { Common::SeekableReadStream *stream = _vm->_res->load("invent.txt"); int count = stream->readByte(); - char c; for (int idx = 0; idx < count; ++idx) { Common::String name; + char c; while ((c = stream->readByte()) != 0) name += c; diff --git a/engines/sherlock/tattoo/tattoo_journal.cpp b/engines/sherlock/tattoo/tattoo_journal.cpp index b45d669c34..abe3e5420e 100644 --- a/engines/sherlock/tattoo/tattoo_journal.cpp +++ b/engines/sherlock/tattoo/tattoo_journal.cpp @@ -345,9 +345,9 @@ void TattooJournal::handleButtons() { disableControls(); bool notFound = false; - int dir; do { + int dir; if ((dir = getFindName(notFound)) != 0) { _savedIndex = _index; _savedSub = _sub; diff --git a/engines/sherlock/tattoo/tattoo_people.cpp b/engines/sherlock/tattoo/tattoo_people.cpp index e3e957e35c..fe60189965 100644 --- a/engines/sherlock/tattoo/tattoo_people.cpp +++ b/engines/sherlock/tattoo/tattoo_people.cpp @@ -1010,7 +1010,6 @@ void TattooPerson::walkHolmesToNPC() { Screen &screen = *_vm->_screen; Talk &talk = *_vm->_talk; TattooPerson &holmes = people[HOLMES]; - int facing; // Save the character's details pushNPCPath(); @@ -1073,9 +1072,8 @@ void TattooPerson::walkHolmesToNPC() { if (!talk._talkToAbort) { // Setup correct direction for Holmes to face - // See where Holmes is with respect to the NPC (x coords) - facing = (holmes._position.x < _position.x) ? STOP_RIGHT : STOP_LEFT; + int facing = (holmes._position.x < _position.x) ? STOP_RIGHT : STOP_LEFT; // See where Holmes is with respect to the NPC (y coords) if (holmes._position.y < (_position.y - (10 * FIXED_INT_MULTIPLIER))) { diff --git a/engines/sherlock/tattoo/tattoo_scene.cpp b/engines/sherlock/tattoo/tattoo_scene.cpp index f13d0588df..816220361b 100644 --- a/engines/sherlock/tattoo/tattoo_scene.cpp +++ b/engines/sherlock/tattoo/tattoo_scene.cpp @@ -809,13 +809,12 @@ void TattooScene::synchronize(Serializer &s) { int TattooScene::closestZone(const Common::Point &pt) { int zone = -1; int dist = 9999; - int d; for (uint idx = 0; idx < _zones.size(); ++idx) { Common::Rect &r = _zones[idx]; // Check the distance from the point to the center of the zone - d = ABS(r.left + (r.width() / 2) - pt.x) + ABS(r.top + (r.height() / 2) - pt.y); + int d = ABS(r.left + (r.width() / 2) - pt.x) + ABS(r.top + (r.height() / 2) - pt.y); if (d < dist) { dist = d; zone = idx; diff --git a/engines/sherlock/tattoo/tattoo_user_interface.cpp b/engines/sherlock/tattoo/tattoo_user_interface.cpp index 6ed0bf66db..da4a277ba3 100644 --- a/engines/sherlock/tattoo/tattoo_user_interface.cpp +++ b/engines/sherlock/tattoo/tattoo_user_interface.cpp @@ -85,7 +85,6 @@ void TattooUserInterface::lookAtObject() { Talk &talk = *_vm->_talk; Common::Point mousePos = events.mousePos(); Common::String desc; - int cAnimSpeed = 0; _lookPos = mousePos; _menuMode = LOOK_MODE; @@ -95,7 +94,7 @@ void TattooUserInterface::lookAtObject() { } else { // Check if there is a Look animation if (_bgShape->_lookcAnim != 0) { - cAnimSpeed = _bgShape->_lookcAnim & 0xe0; + int cAnimSpeed = _bgShape->_lookcAnim & 0xe0; cAnimSpeed >>= 5; ++cAnimSpeed; @@ -377,7 +376,6 @@ void TattooUserInterface::doStandardControl() { TattooScene &scene = *(TattooScene *)_vm->_scene; Talk &talk = *_vm->_talk; Common::Point mousePos = events.mousePos(); - bool noDesc = false; // Don't do any input processing whilst the prolog is running if (vm._runningProlog) @@ -458,6 +456,7 @@ void TattooUserInterface::doStandardControl() { if (_arrowZone == -1 || events._rightReleased) freeMenu(); + bool noDesc = false; if (_personFound) { if (people[_bgFound - 1000]._description.empty() || people[_bgFound - 1000]._description.hasPrefix(" ")) noDesc = true; diff --git a/engines/sherlock/tattoo/widget_files.cpp b/engines/sherlock/tattoo/widget_files.cpp index c9a20b0f8a..0f5e6793c4 100644 --- a/engines/sherlock/tattoo/widget_files.cpp +++ b/engines/sherlock/tattoo/widget_files.cpp @@ -253,7 +253,6 @@ bool WidgetFiles::getFilename() { int done = 0; bool blinkFlag = false; int blinkCountdown = 0; - int width; int cursorColor = 192; byte color, textColor; bool insert = true; @@ -285,7 +284,7 @@ bool WidgetFiles::getFilename() { char currentChar = (index == (int)filename.size()) ? ' ' : filename[index]; Common::String charString = Common::String::format("%c", currentChar); - width = screen.charWidth(currentChar); + int width = screen.charWidth(currentChar); // Wait for keypress while (!events.kbHit()) { diff --git a/engines/sherlock/tattoo/widget_lab.cpp b/engines/sherlock/tattoo/widget_lab.cpp index 2873b12f22..eb32e2e22c 100644 --- a/engines/sherlock/tattoo/widget_lab.cpp +++ b/engines/sherlock/tattoo/widget_lab.cpp @@ -45,7 +45,6 @@ void WidgetLab::handleEvents() { Common::Point mousePos = events.mousePos(); WidgetBase::handleEvents(); - bool noDesc = false; // Handle drawing tooltips. If the user is dragging a lab item, display a tooltip for using the item // on another. Otherwise, fall back on showing standard tooltips @@ -65,6 +64,7 @@ void WidgetLab::handleEvents() { if (ui._arrowZone == -1 || events._rightReleased) ui._tooltipWidget.setText(""); + bool noDesc = false; if (ui._bgFound != -1) { if (ui._bgShape->_description.hasPrefix(" ") || ui._bgShape->_description.empty()) noDesc = true; diff --git a/engines/sherlock/tattoo/widget_talk.cpp b/engines/sherlock/tattoo/widget_talk.cpp index 00e8233a95..6e7bde292f 100644 --- a/engines/sherlock/tattoo/widget_talk.cpp +++ b/engines/sherlock/tattoo/widget_talk.cpp @@ -369,11 +369,11 @@ void WidgetTalk::handleEvents() { void WidgetTalk::render(Highlight highlightMode) { TattooTalk &talk = *(TattooTalk *)_vm->_talk; - int yp = 5; - int statementNum = 1; - byte color; if (highlightMode != HL_SCROLLBAR_ONLY) { + int yp = 5; + int statementNum = 1; + // Draw all the statements // Check whether scrolling has occurred, and if so, figure out what the starting // number for the first visible statement will be @@ -392,7 +392,7 @@ void WidgetTalk::render(Highlight highlightMode) { _surface.fillRect(Common::Rect(3, yp, _surface.w() - BUTTON_SIZE - 3, yp + _surface.fontHeight()), TRANSPARENCY); // Different coloring based on whether the option has been previously chosen or not - color = (!talk._talkHistory[talk._converseNum][_statementLines[idx]._num]) ? + byte color = (!talk._talkHistory[talk._converseNum][_statementLines[idx]._num]) ? INFO_TOP : INFO_BOTTOM; if (_statementLines[idx]._num == _selector && highlightMode == HL_CHANGED_HIGHLIGHTS) diff --git a/engines/sherlock/tattoo/widget_verbs.cpp b/engines/sherlock/tattoo/widget_verbs.cpp index 0b523a93e9..09d2795a7b 100644 --- a/engines/sherlock/tattoo/widget_verbs.cpp +++ b/engines/sherlock/tattoo/widget_verbs.cpp @@ -158,7 +158,6 @@ void WidgetVerbs::handleEvents() { Talk &talk = *_vm->_talk; TattooUserInterface &ui = *(TattooUserInterface *)_vm->_ui; Common::Point mousePos = events.mousePos(); - bool noDesc = false; Common::String strLook = fixedText.getText(kFixedText_Look); Common::String strTalk = fixedText.getText(kFixedText_Talk); @@ -184,6 +183,7 @@ void WidgetVerbs::handleEvents() { ui._personFound = ui._bgFound >= 1000; ui._bgShape = ui._personFound || ui._bgFound == -1 ? nullptr : &scene._bgShapes[ui._bgFound]; + bool noDesc = false; if (ui._personFound) { if (people[ui._bgFound - 1000]._description.empty() || people[ui._bgFound - 1000]._description.hasPrefix(" ")) noDesc = true; -- cgit v1.2.3