diff options
author | Johannes Schickel | 2008-04-24 21:11:55 +0000 |
---|---|---|
committer | Johannes Schickel | 2008-04-24 21:11:55 +0000 |
commit | 1c660c452436fbcf2e5d06f1e10cc7c236ee11b5 (patch) | |
tree | 60124fbdd03054f471d35e58c274f01912e83127 | |
parent | 604ce476e46732b94e71f1963018cf285125d82c (diff) | |
download | scummvm-rg350-1c660c452436fbcf2e5d06f1e10cc7c236ee11b5.tar.gz scummvm-rg350-1c660c452436fbcf2e5d06f1e10cc7c236ee11b5.tar.bz2 scummvm-rg350-1c660c452436fbcf2e5d06f1e10cc7c236ee11b5.zip |
Implemented opcode 56: o3_updateScore.
svn-id: r31704
-rw-r--r-- | engines/kyra/gui_v3.cpp | 66 | ||||
-rw-r--r-- | engines/kyra/kyra_v3.cpp | 74 | ||||
-rw-r--r-- | engines/kyra/kyra_v3.h | 14 | ||||
-rw-r--r-- | engines/kyra/script_v3.cpp | 7 | ||||
-rw-r--r-- | engines/kyra/staticres.cpp | 30 |
5 files changed, 185 insertions, 6 deletions
diff --git a/engines/kyra/gui_v3.cpp b/engines/kyra/gui_v3.cpp index c797ca0812..9371f3dca2 100644 --- a/engines/kyra/gui_v3.cpp +++ b/engines/kyra/gui_v3.cpp @@ -110,7 +110,7 @@ void KyraEngine_v3::showInventory() { redrawInventory(30); drawMalcolmsMoodPointer(-1, 30); - //XXX + drawScore(30, 215, 191); if (queryGameFlag(0x97)) drawJestersStaff(1, 30); @@ -312,6 +312,70 @@ void KyraEngine_v3::drawJestersStaff(int type, int page) { _screen->drawShape(page, getShapePtr(shape), 217, y, 0, 0); } +void KyraEngine_v3::drawScore(int page, int x, int y) { + debugC(9, kDebugLevelMain, "KyraEngine_v3::drawScore(%d, %d, %d)", page, x, y); + if (page == 30) { + page = 2; + y -= 144; + } + + int shape1 = _score / 100; + int shape2 = (_score - shape1*100) / 10; + int shape3 = _score % 10; + + _screen->drawShape(page, getShapePtr(shape1+433), x, y, 0, 0); + x += 8; + _screen->drawShape(page, getShapePtr(shape2+433), x, y, 0, 0); + x += 8; + _screen->drawShape(page, getShapePtr(shape3+433), x, y, 0, 0); +} + +void KyraEngine_v3::drawScoreCounting(int oldScore, int newScore, int drawOld, const int x) { + debugC(9, kDebugLevelMain, "KyraEngine_v3::drawScoreCounting(%d, %d, %d, %d)", oldScore, newScore, drawOld, x); + int y = 189; + if (_inventoryState) + y -= 44; + + int old100 = oldScore / 100; + int old010 = (oldScore - old100*100) / 10; + int old001 = oldScore % 10; + + int new100 = newScore / 100; + int new010 = (newScore - new100*100) / 10; + int new001 = newScore % 10; + + if (drawOld) { + _screen->drawShape(0, getShapePtr(old100+433), x + 0, y, 0, 0); + _screen->drawShape(0, getShapePtr(old010+433), x + 8, y, 0, 0); + _screen->drawShape(0, getShapePtr(old001+433), x + 16, y, 0, 0); + } + + if (old100 != new100) + _screen->drawShape(0, getShapePtr(old100+443), x + 0, y, 0, 0); + + if (old010 != new010) + _screen->drawShape(0, getShapePtr(old010+443), x + 8, y, 0, 0); + + _screen->drawShape(0, getShapePtr(old001+443), x + 16, y, 0, 0); + + _screen->drawShape(0, getShapePtr(new100+433), x + 0, y, 0, 0); + _screen->drawShape(0, getShapePtr(new010+433), x + 8, y, 0, 0); + _screen->drawShape(0, getShapePtr(new001+433), x + 16, y, 0, 0); +} + +int KyraEngine_v3::getScoreX(const char *str) { + debugC(9, kDebugLevelMain, "KyraEngine_v3::getScoreX('%s')", str); + Screen::FontId oldFont = _screen->setFont(Screen::FID_8_FNT); + _screen->_charWidth = -2; + + int width = _screen->getTextWidth(str); + int x = 160 + (width / 2) - 32; + + _screen->setFont(oldFont); + _screen->_charWidth = 0; + return x; +} + void KyraEngine_v3::redrawInventory(int page) { debugC(9, kDebugLevelMain, "KyraEngine_v3::redrawInventory(%d)", page); int yOffset = 0; diff --git a/engines/kyra/kyra_v3.cpp b/engines/kyra/kyra_v3.cpp index 0fbe3de456..0cabfc36f6 100644 --- a/engines/kyra/kyra_v3.cpp +++ b/engines/kyra/kyra_v3.cpp @@ -128,6 +128,8 @@ KyraEngine_v3::KyraEngine_v3(OSystem *system, const GameFlags &flags) : KyraEngi _inventoryScrollSpeed = -1; _invWsa = 0; _invWsaFrame = -1; + _score = 0; + memset(_scoreFlagTable, 0, sizeof(_scoreFlagTable)); } KyraEngine_v3::~KyraEngine_v3() { @@ -544,11 +546,13 @@ void KyraEngine_v3::startup() { musicUpdate(0); if (!loadLanguageFile("ITEMS.", _itemFile)) - error("couldn't load ITEMS"); + error("Couldn't load ITEMS"); + if (!loadLanguageFile("SCORE.", _scoreFile)) + error("Couldn't load SCORE"); if (!loadLanguageFile("C_CODE.", _cCodeFile)) - error("couldn't load C_CODE"); + error("Couldn't load C_CODE"); if (!loadLanguageFile("SCENES.", _scenesFile)) - error("couldn't load SCENES"); + error("Couldn't load SCENES"); //XXX @@ -605,7 +609,11 @@ void KyraEngine_v3::startup() { clearAnimObjects(); - //XXX + _scoreMax = 0; + for (int i = 0; i < _scoreTableSize; ++i) { + if (_scoreTable[i] > 0) + _scoreMax += _scoreTable[i]; + } musicUpdate(0); memset(_hiddenItems, -1, sizeof(_hiddenItems)); @@ -1594,6 +1602,64 @@ void KyraEngine_v3::runTemporaryScript(const char *filename, int allowSkip, int _scriptInterpreter->unloadScript(&_temporaryScriptData); } +#pragma mark - + +bool KyraEngine_v3::updateScore(int scoreId, int strId) { + debugC(9, kDebugLevelMain, "KyraEngine_v3::updateScore(%d, %d)", scoreId, strId); + + int scoreIndex = (scoreId >> 3); + int scoreBit = scoreId & 7; + if ((_scoreFlagTable[scoreIndex] & (1 << scoreBit)) != 0) + return false; + + setNextIdleAnimTimer(); + _scoreFlagTable[scoreIndex] |= (1 << scoreBit); + + _screen->hideMouse(); + strcpy(_stringBuffer, (const char*)getTableEntry(_scoreFile, strId)); + strcat(_stringBuffer, ": "); + + assert(scoreId < _scoreTableSize); + + int count = _scoreTable[scoreId]; + if (count > 0) + scoreIncrease(count, _stringBuffer); + + _screen->showMouse(); + setNextIdleAnimTimer(); + return true; +} + +void KyraEngine_v3::scoreIncrease(int count, const char *str) { + debugC(9, kDebugLevelMain, "KyraEngine_v3::scoreIncrease(%d, '%s')", count, str); + int drawOld = 1; + _screen->hideMouse(); + + showMessage(str, 0xFF, 0xF0); + const int x = getScoreX(str); + + for (int i = 0; i < count; ++i) { + int oldScore = _score; + int newScore = ++_score; + + if (newScore > _scoreMax) { + _score = _scoreMax; + break; + } + + drawScoreCounting(oldScore, newScore, drawOld, x); + if (_inventoryState) + drawScore(0, 215, 191); + _screen->updateScreen(); + delay(20, true); + + playSoundEffect(0x0E, 0xC8); + drawOld = 0; + } + + _screen->showMouse(); +} + #pragma mark - Movie *KyraEngine_v3::createWSAMovie() { diff --git a/engines/kyra/kyra_v3.h b/engines/kyra/kyra_v3.h index 440596cb58..2762b80e2b 100644 --- a/engines/kyra/kyra_v3.h +++ b/engines/kyra/kyra_v3.h @@ -266,6 +266,10 @@ private: void drawMalcolmsMoodText(); void drawMalcolmsMoodPointer(int frame, int page); void drawJestersStaff(int type, int page); + + void drawScore(int page, int x, int y); + void drawScoreCounting(int oldScore, int newScore, int drawOld, const int x); + int getScoreX(const char *str); static const uint8 _inventoryX[]; static const uint8 _inventoryY[]; @@ -650,6 +654,15 @@ private: char *_stringBuffer; + int _score; + int _scoreMax; + + static const int8 _scoreTable[]; + static const int _scoreTableSize; + int8 _scoreFlagTable[26]; + bool updateScore(int scoreId, int strId); + void scoreIncrease(int count, const char *str); + // opcodes int o3_getMalcolmShapes(ScriptState *script); int o3_setCharacterPos(ScriptState *script); @@ -684,6 +697,7 @@ private: int o3_wipeDownMouseItem(ScriptState *script); int o3_setMalcolmsMood(ScriptState *script); int o3_delay(ScriptState *script); + int o3_updateScore(ScriptState *script); int o3_setSceneFilename(ScriptState *script); int o3_drawSceneShape(ScriptState *script); int o3_checkInRect(ScriptState *script); diff --git a/engines/kyra/script_v3.cpp b/engines/kyra/script_v3.cpp index 09af5b169e..172645eaad 100644 --- a/engines/kyra/script_v3.cpp +++ b/engines/kyra/script_v3.cpp @@ -317,6 +317,11 @@ int KyraEngine_v3::o3_delay(ScriptState *script) { return 0; } +int KyraEngine_v3::o3_updateScore(ScriptState *script) { + debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_updateScore(%p) (%d, %d)", (const void *)script, stackPos(0), stackPos(1)); + return updateScore(stackPos(0), stackPos(1)) ? 1 : 0; +} + int KyraEngine_v3::o3_setSceneFilename(ScriptState *script) { debugC(3, kDebugLevelScriptFuncs, "KyraEngine_v3::o3_setSceneFilename(%p) (%d, '%s')", (const void *)script, stackPos(0), stackPosString(1)); strcpy(_sceneList[stackPos(0)].filename1, stackPosString(1)); @@ -1093,7 +1098,7 @@ void KyraEngine_v3::setupOpcodeTable() { Opcode(o3_dummy); Opcode(o3_delay); // 0x38 - OpcodeUnImpl(); + Opcode(o3_updateScore); OpcodeUnImpl(); Opcode(o3_setSceneFilename); OpcodeUnImpl(); diff --git a/engines/kyra/staticres.cpp b/engines/kyra/staticres.cpp index abafeceeb4..0ab1deb9bf 100644 --- a/engines/kyra/staticres.cpp +++ b/engines/kyra/staticres.cpp @@ -2400,5 +2400,35 @@ const uint8 KyraEngine_v3::_itemStringInv[] = { 0x6, 0x9, 0x2, 0xC }; +const int8 KyraEngine_v3::_scoreTable[] = { + 10, 8, 5, 9, 10, 10, 7, 8, + 9, 9, 8, 8, 7, 8, 5, 9, + 6, 10, 7, 8, 5, 9, 6, 6, + 7, 8, 5, 9, 6, 8, 7, 8, + 5, 9, 6, 10, 7, 8, 5, 5, + 5, 7, 5, 7, 10, 5, 10, 5, + 5, 8, 6, 8, 7, 5, 5, 8, + 6, 9, 5, 7, 6, 5, 5, 7, + 7, 7, 6, 5, 8, 6, 10, 5, + 7, 5, 10, 5, 5, 5, 5, 7, + 5, 8, 9, 7, 7, 6, 10, 6, + 5, 10, 8, 5, 8, 6, 10, 5, + 5, 8, 8, 5, 7, 7, 7, 6, + 8, 9, 8, 8, 6, 5, 7, 6, + 5, 8, 15, 7, 9, 6, 6, 8, + 5, 8, 15, 15, 5, 15, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + +const int KyraEngine_v3::_scoreTableSize = ARRAYSIZE(KyraEngine_v3::_scoreTable); + } // End of namespace Kyra |