From 886cf189c66a9fa59f0317a25ccc5db9d75bf59a Mon Sep 17 00:00:00 2001 From: lukaslw Date: Fri, 8 Aug 2014 22:58:38 +0200 Subject: PRINCE: showPower(), O_EXIT - last mini-game and game ending --- engines/prince/prince.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++ engines/prince/prince.h | 12 +++++++++++ engines/prince/script.cpp | 16 +++++++++----- engines/prince/script.h | 1 + 4 files changed, 78 insertions(+), 5 deletions(-) (limited to 'engines/prince') diff --git a/engines/prince/prince.cpp b/engines/prince/prince.cpp index bac261e56f..d5796e203f 100644 --- a/engines/prince/prince.cpp +++ b/engines/prince/prince.cpp @@ -888,6 +888,16 @@ void PrinceEngine::keyHandler(Common::Event event) { getDebugger()->attach(); } break; + case Common::KEYCODE_z: + if (_flags->getFlagValue(Flags::POWERENABLED)) { + _flags->setFlagValue(Flags::MBFLAG, 1); + } + break; + case Common::KEYCODE_x: + if (_flags->getFlagValue(Flags::POWERENABLED)) { + _flags->setFlagValue(Flags::MBFLAG, 2); + } + break; case Common::KEYCODE_ESCAPE: _flags->setFlagValue(Flags::ESCAPED2, 1); break; @@ -1768,6 +1778,8 @@ void PrinceEngine::drawScreen() { _inventoryBackgroundRemember = false; } + showPower(); + getDebugger()->onFrame(); } else { @@ -2207,6 +2219,9 @@ void PrinceEngine::moveRunHero(int heroId, int x, int y, int dir, bool runHeroFl void PrinceEngine::leftMouseButton() { _flags->setFlagValue(Flags::LMOUSE, 1); + if (_flags->getFlagValue(Flags::POWERENABLED)) { + _flags->setFlagValue(Flags::MBFLAG, 1); + } if (_mouseFlag) { int option = 0; int optionEvent = -1; @@ -2285,6 +2300,9 @@ void PrinceEngine::leftMouseButton() { } void PrinceEngine::rightMouseButton() { + if (_flags->getFlagValue(Flags::POWERENABLED)) { + _flags->setFlagValue(Flags::MBFLAG, 2); + } if (_mouseFlag) { _mainHero->freeOldMove(); _secondHero->freeOldMove(); @@ -2920,6 +2938,42 @@ void PrinceEngine::mouseWeirdo() { } } +void PrinceEngine::showPower() { + if (_flags->getFlagValue(Flags::POWERENABLED)) { + int power = _flags->getFlagValue(Flags::POWER); + + byte *dst = (byte *)_graph->_frontScreen->getBasePtr(kPowerBarPosX, kPowerBarPosY); + for (int y = 0; y < kPowerBarHeight; y++) { + byte *dst2 = dst; + for (int x = 0; x < kPowerBarWidth; x++, dst2++) { + *dst2 = kPowerBarBackgroundColor; + } + dst += _graph->_frontScreen->pitch; + } + + if (power) { + byte *dst = (byte *)_graph->_frontScreen->getBasePtr(kPowerBarPosX, kPowerBarGreenPosY); + for (int y = 0; y < kPowerBarGreenHeight; y++) { + byte *dst2 = dst; + for (int x = 0; x < power + 1; x++, dst2++) { + if (x < 58) { + *dst2 = kPowerBarGreenColor1; + } else { + *dst2 = kPowerBarGreenColor2; + } + } + dst += _graph->_frontScreen->pitch; + } + } + + _graph->change(); + } +} + +// TODO +void PrinceEngine::showCredits() { +} + // Modified version of Graphics::drawLine() to allow breaking the loop and return value int PrinceEngine::drawLine(int x0, int y0, int x1, int y1, int (*plotProc)(int, int, void *), void *data) { // Bresenham's line algorithm, as described by Wikipedia diff --git a/engines/prince/prince.h b/engines/prince/prince.h index c8600e7828..4aeb4f99f4 100644 --- a/engines/prince/prince.h +++ b/engines/prince/prince.h @@ -262,6 +262,7 @@ public: void syncGame(Common::SeekableReadStream *readStream, Common::WriteStream *writeStream); bool loadGame(int slotNumber); void resetGame(); + void showCredits(); int getGameType() const; const char *getGameId() const; @@ -490,6 +491,17 @@ public: void getCurve(); void mouseWeirdo(); + static const uint16 kPowerBarPosX = 288; + static const uint16 kPowerBarPosY = 430; + static const uint8 kPowerBarWidth = 64; + static const uint8 kPowerBarHeight = 16; + static const uint8 kPowerBarBackgroundColor = 0; + static const uint16 kPowerBarGreenPosY = 434; + static const uint8 kPowerBarGreenColor1 = 202; + static const uint8 kPowerBarGreenColor2 = 235; + static const uint8 kPowerBarGreenHeight = 8; + void showPower(); + // Pathfinding static const int16 kPathGridStep = 2; static const int32 kPathBitmapLen = (kMaxPicHeight / kPathGridStep * kMaxPicWidth / kPathGridStep) / 8; diff --git a/engines/prince/script.cpp b/engines/prince/script.cpp index 4d00018a02..e6423144a7 100644 --- a/engines/prince/script.cpp +++ b/engines/prince/script.cpp @@ -406,7 +406,7 @@ int32 InterpreterFlags::getFlagValue(Flags::Id flagId) { Interpreter::Interpreter(PrinceEngine *vm, Script *script, InterpreterFlags *flags) : _vm(vm), _script(script), _flags(flags), - _stacktop(0), _opcodeNF(false), + _stacktop(0), _opcodeNF(false), _opcodeEnd(false), _waitFlag(0), _result(true) { // Initialize the script @@ -469,6 +469,10 @@ uint32 Interpreter::step(uint32 opcodePC) { } } + if (_opcodeEnd) { + _vm->quitGame(); + } + return _currentInstruction; } @@ -854,12 +858,14 @@ void Interpreter::O_JUMPNZ() { debugInterpreter("O_JUMPNZ result = %d, next %08x, offset 0x%08X", _result, _currentInstruction, offset); } -// TODO void Interpreter::O_EXIT() { int32 exitCode = readScriptFlagValue(); + _opcodeEnd = true; + _opcodeNF = 1; + if (exitCode == 0x2EAD) { + _vm->showCredits(); + } debugInterpreter("O_EXIT exitCode %d", exitCode); - // Set exit code and shows credits - // if exit code == 0x02EAD } void Interpreter::O_ADDFLAG() { @@ -1256,7 +1262,7 @@ void Interpreter::O_GETHERODATA() { debugInterpreter("O_GETHERODATA flag %04x - (%s), heroId %d, heroOffset %d", flagId, Flags::getFlagName(flagId), heroId, heroOffset); } -// TODO - for location 41 (prison in hell) +// No need of implementation here void Interpreter::O_GETMOUSEBUTTON() { debugInterpreter("O_GETMOUSEBUTTON"); } diff --git a/engines/prince/script.h b/engines/prince/script.h index 98f5000004..1c87fb3b23 100644 --- a/engines/prince/script.h +++ b/engines/prince/script.h @@ -222,6 +222,7 @@ private: byte _result; bool _opcodeNF; // break interpreter loop + bool _opcodeEnd; // end of a game flag static const uint32 _STACK_SIZE = 500; uint32 _stack[_STACK_SIZE]; -- cgit v1.2.3