Skip to content

Commit

Permalink
MOHAWK: Check the Books external commands against the original
Browse files Browse the repository at this point in the history
  • Loading branch information
bgK authored and sev- committed Jul 3, 2017
1 parent d7b241a commit 08e6423
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 111 deletions.
7 changes: 5 additions & 2 deletions engines/mohawk/riven_graphics.cpp
Expand Up @@ -26,6 +26,7 @@
#include "mohawk/riven_graphics.h"
#include "mohawk/riven_sound.h"
#include "mohawk/riven_stack.h"
#include "mohawk/riven_video.h"

#include "common/system.h"
#include "engines/util.h"
Expand Down Expand Up @@ -324,11 +325,13 @@ void RivenGraphics::copyImageToScreen(uint16 image, uint32 left, uint32 top, uin
applyScreenUpdate();
}

void RivenGraphics::updateScreen(const Common::Rect &updateRect) {
void RivenGraphics::updateScreen() {
if (_dirtyScreen) {
// Copy to screen if there's no transition. Otherwise transition. ;)
// Copy to screen if there's no transition. Otherwise transition.
if (_scheduledTransition == kRivenTransitionNone
|| _transitionMode == kRivenTransitionModeDisabled) {
const Common::Rect updateRect = Common::Rect(0, 0, 608, 392);

// mainScreen -> effectScreen -> systemScreen
_effectScreen->copyRectToSurface(*_mainScreen, updateRect.left, updateRect.top, updateRect);
_vm->_system->copyRectToScreen(_effectScreen->getBasePtr(updateRect.left, updateRect.top), _effectScreen->pitch, updateRect.left, updateRect.top, updateRect.width(), updateRect.height());
Expand Down
2 changes: 1 addition & 1 deletion engines/mohawk/riven_graphics.h
Expand Up @@ -138,7 +138,7 @@ class RivenGraphics : public GraphicsManager {
bool _dirtyScreen;

Graphics::PixelFormat _pixelFormat;
void updateScreen(const Common::Rect &updateRect = Common::Rect(0, 0, 608, 392));
void updateScreen();
void clearMainScreen();

// Credits
Expand Down
25 changes: 25 additions & 0 deletions engines/mohawk/riven_stack.cpp
Expand Up @@ -350,6 +350,31 @@ void RivenStack::removeTimer() {
_timerTime = 0;
}

bool RivenStack::pageTurn(RivenTransition transition) {
// Wait until the previous page turn sound completes
while (_vm->_sound->isEffectPlaying() && !_vm->shouldQuit()) {
if (!mouseIsDown()) {
return false;
}

_vm->doFrame();
}

// Play the page turning sound
const char *soundName = nullptr;
if (_vm->_rnd->getRandomBit())
soundName = "aPage1";
else
soundName = "aPage2";

_vm->_sound->playCardSound(soundName, 51, true);

// Now update the screen :)
_vm->_gfx->scheduleTransition(transition);

return true;
}

RivenNameList::RivenNameList() {

}
Expand Down
5 changes: 4 additions & 1 deletion engines/mohawk/riven_stack.h
Expand Up @@ -29,6 +29,8 @@
#include "common/rect.h"
#include "common/str-array.h"

#include "mohawk/riven_graphics.h"

namespace Mohawk {

class MohawkEngine_Riven;
Expand Down Expand Up @@ -153,11 +155,12 @@ class RivenStack {
// Common external commands
void xflies(uint16 argc, uint16 *argv); // Start the "flies" effect

// TODO: Misc stuff move elsewhere
// Miscellaneous
uint16 getComboDigit(uint32 correctCombo, uint32 digit);
void runDemoBoundaryDialog();
void runEndGame(uint16 videoCode, uint32 delay);
void runCredits(uint16 video, uint32 delay);
bool pageTurn(RivenTransition transition);

protected:
typedef Common::Functor2<uint16, uint16 *, void> ExternalCommand;
Expand Down
149 changes: 75 additions & 74 deletions engines/mohawk/riven_stacks/aspit.cpp
Expand Up @@ -45,13 +45,13 @@ ASpit::ASpit(MohawkEngine_Riven *vm) :
REGISTER_COMMAND(ASpit, xaatrusbookback); // Done
REGISTER_COMMAND(ASpit, xaatrusbookprevpage); // Done
REGISTER_COMMAND(ASpit, xaatrusbooknextpage); // Done
// REGISTER_COMMAND(ASpit, xacathopenbook);
// REGISTER_COMMAND(ASpit, xacathbookback);
// REGISTER_COMMAND(ASpit, xacathbookprevpage);
// REGISTER_COMMAND(ASpit, xacathbooknextpage);
// REGISTER_COMMAND(ASpit, xtrapbookback);
// REGISTER_COMMAND(ASpit, xatrapbookclose);
// REGISTER_COMMAND(ASpit, xatrapbookopen);
REGISTER_COMMAND(ASpit, xacathopenbook);
REGISTER_COMMAND(ASpit, xacathbookback);
REGISTER_COMMAND(ASpit, xacathbookprevpage);
REGISTER_COMMAND(ASpit, xacathbooknextpage);
REGISTER_COMMAND(ASpit, xtrapbookback);
REGISTER_COMMAND(ASpit, xatrapbookclose);
REGISTER_COMMAND(ASpit, xatrapbookopen);
REGISTER_COMMAND(ASpit, xarestoregame); // Done
// REGISTER_COMMAND(ASpit, xadisablemenureturn);
// REGISTER_COMMAND(ASpit, xaenablemenureturn);
Expand All @@ -77,7 +77,7 @@ void ASpit::xasetupcomplete(uint16 argc, uint16 *argv) {

void ASpit::xaatrusopenbook(uint16 argc, uint16 *argv) {
// Get the variable
uint32 &page = _vm->_vars["aatruspage"];
uint32 &page = _vm->_vars["aatrusbook"];

// Set hotspots depending on the page
RivenHotspot *openBook = _vm->getCard()->getHotspotByName("openBook");
Expand All @@ -101,34 +101,9 @@ void ASpit::xaatrusbookback(uint16 argc, uint16 *argv) {
_vm->_inventory->backFromItemScript();
}

bool ASpit::pageTurn(RivenTransition transition) {
// Wait until the previous page turn sound completes
while (_vm->_sound->isEffectPlaying() && !_vm->shouldQuit()) {
if (!mouseIsDown()) {
return false;
}

_vm->doFrame();
}

// Play the page turning sound
const char *soundName = nullptr;
if (_vm->_rnd->getRandomBit())
soundName = "aPage1";
else
soundName = "aPage2";

_vm->_sound->playCardSound(soundName, 51, true);

// Now update the screen :)
_vm->_gfx->scheduleTransition(transition);

return true;
}

void ASpit::xaatrusbookprevpage(uint16 argc, uint16 *argv) {
// Get the page variable
uint32 &page = _vm->_vars["aatruspage"];
uint32 &page = _vm->_vars["aatrusbook"];

// Keep turning pages while the mouse is pressed
bool firstPageTurn = true;
Expand All @@ -152,7 +127,7 @@ void ASpit::xaatrusbookprevpage(uint16 argc, uint16 *argv) {

void ASpit::xaatrusbooknextpage(uint16 argc, uint16 *argv) {
// Get the page variable
uint32 &page = _vm->_vars["aatruspage"];
uint32 &page = _vm->_vars["aatrusbook"];

// Keep turning pages while the mouse is pressed
bool firstPageTurn = true;
Expand All @@ -176,7 +151,7 @@ void ASpit::xaatrusbooknextpage(uint16 argc, uint16 *argv) {

void ASpit::xacathopenbook(uint16 argc, uint16 *argv) {
// Get the variable
uint32 page = _vm->_vars["acathpage"];
uint32 page = _vm->_vars["acathbook"];

// Set hotspots depending on the page
RivenHotspot *openBook = _vm->getCard()->getHotspotByName("openBook");
Expand All @@ -192,7 +167,10 @@ void ASpit::xacathopenbook(uint16 argc, uint16 *argv) {
openBook->enable(false);
}

// Draw the image of the page
cathBookDrawPage(page);
}

void ASpit::cathBookDrawPage(uint32 page) {// Draw the image of the page
_vm->getCard()->drawPicture(page);

// Draw the white page edges
Expand All @@ -202,22 +180,25 @@ void ASpit::xacathopenbook(uint16 argc, uint16 *argv) {
_vm->getCard()->drawPicture(51);

if (page == 28) {
// Draw the telescope combination
// The images for the numbers are tBMP's 13 through 17.
// The start point is at (156, 247)
uint32 teleCombo = _vm->_vars["tcorrectorder"];
static const uint16 kNumberWidth = 32;
static const uint16 kNumberHeight = 25;
static const uint16 kDstX = 156;
static const uint16 kDstY = 247;

for (byte i = 0; i < 5; i++) {
cathBookDrawTelescopeCombination();
}
}

void ASpit::cathBookDrawTelescopeCombination() {// Draw the telescope combination
// The images for the numbers are tBMP's 13 through 17.
// The start point is at (156, 247)
uint32 teleCombo = _vm->_vars["tcorrectorder"];
static const uint16 kNumberWidth = 32;
static const uint16 kNumberHeight = 25;
static const uint16 kDstX = 156;
static const uint16 kDstY = 247;

for (byte i = 0; i < 5; i++) {
uint16 offset = (getComboDigit(teleCombo, i) - 1) * kNumberWidth;
Common::Rect srcRect = Common::Rect(offset, 0, offset + kNumberWidth, kNumberHeight);
Common::Rect dstRect = Common::Rect(i * kNumberWidth + kDstX, kDstY, (i + 1) * kNumberWidth + kDstX, kDstY + kNumberHeight);
_vm->_gfx->drawImageRect(i + 13, srcRect, dstRect);
}
}
}

void ASpit::xacathbookback(uint16 argc, uint16 *argv) {
Expand All @@ -226,36 +207,52 @@ void ASpit::xacathbookback(uint16 argc, uint16 *argv) {

void ASpit::xacathbookprevpage(uint16 argc, uint16 *argv) {
// Get the variable
uint32 &page = _vm->_vars["acathpage"];
uint32 &page = _vm->_vars["acathbook"];

// Keep turning pages while the mouse is pressed
bool firstPageTurn = true;
while (mouseIsDown() || firstPageTurn) {
// Check for the first page
if (page == 1)
return;

// Increment the page if it's not the first page
if (page == 1)
return;
page--;
if (!pageTurn(kRivenTransitionWipeDown)) {
return;
}

// Play the page turning sound
_vm->_sound->playSound(5);
// Update the page number
page--;
firstPageTurn = false;

// Now update the screen :)
_vm->_gfx->scheduleTransition(kRivenTransitionWipeDown);
_vm->getCard()->drawPicture(page);
cathBookDrawPage(page);

_vm->doFrame();
}
}

void ASpit::xacathbooknextpage(uint16 argc, uint16 *argv) {
// Get the variable
uint32 &page = _vm->_vars["acathpage"];
uint32 &page = _vm->_vars["acathbook"];

// Increment the page if it's not the last page
if (page == 49)
return;
page++;
// Keep turning pages while the mouse is pressed
bool firstPageTurn = true;
while ((mouseIsDown() || firstPageTurn) && !_vm->shouldQuit()) {
// Check for the last page
if (page == 49)
return;

// Play the page turning sound
_vm->_sound->playSound(6);
if (!pageTurn(kRivenTransitionWipeUp)) {
return;
}

// Now update the screen :)
_vm->_gfx->scheduleTransition(kRivenTransitionWipeUp);
_vm->getCard()->drawPicture(page);
// Update the page number
page++;
firstPageTurn = false;

cathBookDrawPage(page);

_vm->doFrame();
}
}

void ASpit::xtrapbookback(uint16 argc, uint16 *argv) {
Expand All @@ -268,20 +265,24 @@ void ASpit::xatrapbookclose(uint16 argc, uint16 *argv) {
// Close the trap book
_vm->_vars["atrap"] = 0;

// Play the page turning sound
_vm->_sound->playSound(8);
pageTurn(kRivenTransitionWipeRight);

// Stop the flyby movie to prevent a glitch where the book does not actually
// close because the movie continues to draw over the closed book picture.
// This glitch also happened in the original engine with transitions disabled.
RivenVideo *flyby = _vm->_video->getSlot(1);
flyby->close();

_vm->refreshCard();
_vm->getCard()->enter(false);
}

void ASpit::xatrapbookopen(uint16 argc, uint16 *argv) {
// Open the trap book
_vm->_vars["atrap"] = 1;

// Play the page turning sound
_vm->_sound->playSound(9);
pageTurn(kRivenTransitionWipeLeft);

_vm->refreshCard();
_vm->getCard()->enter(false);
}

void ASpit::xarestoregame(uint16 argc, uint16 *argv) {
Expand Down
6 changes: 3 additions & 3 deletions engines/mohawk/riven_stacks/aspit.h
Expand Up @@ -25,8 +25,6 @@

#include "mohawk/riven_stack.h"

#include "mohawk/riven_graphics.h"

namespace Mohawk {
namespace RivenStacks {

Expand Down Expand Up @@ -71,7 +69,9 @@ class ASpit : public RivenStack {
void xaexittomain(uint16 argc, uint16 *argv);

private:
bool pageTurn(RivenTransition transition);
void cathBookDrawTelescopeCombination();

void cathBookDrawPage(uint32 page);
};

} // End of namespace RivenStacks
Expand Down
25 changes: 0 additions & 25 deletions engines/mohawk/riven_stacks/bspit.cpp
Expand Up @@ -149,31 +149,6 @@ void BSpit::xblabbooknextpage(uint16 argc, uint16 *argv) {
}
}

bool BSpit::pageTurn(RivenTransition transition) {
// Wait until the previous page turn sound completes
while (_vm->_sound->isEffectPlaying() && !_vm->shouldQuit()) {
if (!mouseIsDown()) {
return false;
}

_vm->doFrame();
}

// Play the page turning sound
const char *soundName = nullptr;
if (_vm->_rnd->getRandomBit())
soundName = "aPage1";
else
soundName = "aPage2";

_vm->_sound->playCardSound(soundName, 51, true);

// Now update the screen :)
_vm->_gfx->scheduleTransition(transition);

return true;
}

void BSpit::xsoundplug(uint16 argc, uint16 *argv) {
if (_vm->_vars["bcratergg"] == 0) {
if (_vm->_vars["bblrwtr"] == 0) {
Expand Down
3 changes: 0 additions & 3 deletions engines/mohawk/riven_stacks/bspit.h
Expand Up @@ -23,7 +23,6 @@
#ifndef RIVEN_STACKS_BSPIT_H
#define RIVEN_STACKS_BSPIT_H

#include <engines/mohawk/riven_graphics.h>
#include "mohawk/riven_stacks/domespit.h"

namespace Mohawk {
Expand Down Expand Up @@ -74,8 +73,6 @@ class BSpit : public DomeSpit {
void valveChangePosition(uint32 valvePosition, uint16 videoId, uint16 pictureId);

void labBookDrawDomeCombination() const;

bool pageTurn(Mohawk::RivenTransition transition);
};

} // End of namespace RivenStacks
Expand Down

0 comments on commit 08e6423

Please sign in to comment.