aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk
diff options
context:
space:
mode:
authorBastien Bouclet2011-02-19 08:58:20 +0100
committerBastien Bouclet2011-02-22 20:38:54 +0100
commitbc39d327acd6fe5622848f7f98f4159c0e4afb4c (patch)
treeda51e0f9107c8a8a6400b3c3cced94ad15b6febe /engines/mohawk
parenta9620d938dc7031e47533f0dadf3295cd6488ca8 (diff)
downloadscummvm-rg350-bc39d327acd6fe5622848f7f98f4159c0e4afb4c.tar.gz
scummvm-rg350-bc39d327acd6fe5622848f7f98f4159c0e4afb4c.tar.bz2
scummvm-rg350-bc39d327acd6fe5622848f7f98f4159c0e4afb4c.zip
MOHAWK: Implement Mechanical elevator rotation
Diffstat (limited to 'engines/mohawk')
-rw-r--r--engines/mohawk/myst_areas.h1
-rw-r--r--engines/mohawk/myst_stacks/mechanical.cpp145
-rw-r--r--engines/mohawk/myst_stacks/mechanical.h13
3 files changed, 120 insertions, 39 deletions
diff --git a/engines/mohawk/myst_areas.h b/engines/mohawk/myst_areas.h
index 66430f2068..aa06d1a5b4 100644
--- a/engines/mohawk/myst_areas.h
+++ b/engines/mohawk/myst_areas.h
@@ -233,6 +233,7 @@ public:
void drawFrame(uint16 frame);
bool pullLeverV();
void releaseLeverV();
+ uint16 getNumFrames() { return _numFrames; }
protected:
uint16 _numFrames;
diff --git a/engines/mohawk/myst_stacks/mechanical.cpp b/engines/mohawk/myst_stacks/mechanical.cpp
index 0ae9078974..0596d29d88 100644
--- a/engines/mohawk/myst_stacks/mechanical.cpp
+++ b/engines/mohawk/myst_stacks/mechanical.cpp
@@ -23,6 +23,7 @@
*
*/
+#include "mohawk/cursors.h"
#include "mohawk/myst.h"
#include "mohawk/graphics.h"
#include "mohawk/myst_areas.h"
@@ -54,6 +55,9 @@ void Mechanical::setupOpcodes() {
OPCODE(100, o_throneEnablePassage);
OPCODE(104, o_snakeBoxTrigger);
OPCODE(105, o_fortressStaircaseMovie);
+ OPCODE(106, o_elevatorRotationStart);
+ OPCODE(107, o_elevatorRotationMove);
+ OPCODE(108, o_elevatorRotationStop);
OPCODE(121, opcode_121);
OPCODE(122, opcode_122);
OPCODE(123, opcode_123);
@@ -72,7 +76,7 @@ void Mechanical::setupOpcodes() {
OPCODE(201, o_fortressStaircase_init);
OPCODE(202, opcode_202);
OPCODE(203, o_snakeBox_init);
- OPCODE(204, opcode_204);
+ OPCODE(204, o_elevatorRotation_init);
OPCODE(205, opcode_205);
OPCODE(206, opcode_206);
OPCODE(209, opcode_209);
@@ -85,7 +89,6 @@ void Mechanical::setupOpcodes() {
void Mechanical::disablePersistentScripts() {
opcode_202_disable();
- opcode_204_disable();
opcode_205_disable();
opcode_206_disable();
opcode_209_disable();
@@ -93,7 +96,10 @@ void Mechanical::disablePersistentScripts() {
void Mechanical::runPersistentScripts() {
opcode_202_run();
- opcode_204_run();
+
+ if (_elevatorRotationLeverMoving)
+ elevatorRotation_run();
+
opcode_205_run();
opcode_206_run();
opcode_209_run();
@@ -131,13 +137,8 @@ uint16 Mechanical::getVar(uint16 var) {
return _state.staircaseState;
case 11: // Fortress Elevator Rotation Position
return _state.elevatorRotation;
-// case 12: // Fortress Elevator Rotation Cog Position
-// return 0;
-// return 1;
-// return 2;
-// return 3;
-// return 4;
-// return 5;
+ case 12: // Fortress Elevator Rotation Cog Position
+ return 5 - (uint16)(_elevatorRotationGearPosition + 0.5) % 6;
case 15: // Code Lock Execute Button Script
if (_mystStaircaseState)
return 0;
@@ -245,6 +246,85 @@ void Mechanical::o_fortressStaircaseMovie(uint16 op, uint16 var, uint16 argc, ui
_vm->_video->waitUntilMovieEnds(staircase);
}
+void Mechanical::o_elevatorRotationStart(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
+ debugC(kDebugScript, "Opcode %d: Elevator rotation lever start", op);
+
+ MystResourceType12 *lever = static_cast<MystResourceType12 *>(_invokingResource);
+ lever->drawFrame(0);
+
+ _elevatorRotationLeverMoving = true;
+ _elevatorRotationSpeed = 0;
+
+ _vm->_sound->stopBackgroundMyst();
+
+ _vm->_cursor->setCursor(700);
+}
+
+void Mechanical::o_elevatorRotationMove(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
+ debugC(kDebugScript, "Opcode %d: Elevator rotation lever move", op);
+
+ const Common::Point &mouse = _vm->_system->getEventManager()->getMousePos();
+ MystResourceType12 *lever = static_cast<MystResourceType12 *>(_invokingResource);
+
+ // Make the handle follow the mouse
+ int16 maxStep = lever->getNumFrames() - 1;
+ Common::Rect rect = lever->getRect();
+ int16 step = ((rect.bottom - mouse.y) * lever->getNumFrames()) / rect.height();
+ step = CLIP<int16>(step, 0, maxStep);
+
+ _elevatorRotationSpeed = step * 0.1;
+
+ // Draw current frame
+ lever->drawFrame(step);
+}
+
+void Mechanical::o_elevatorRotationStop(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
+ debugC(kDebugScript, "Opcode %d: Elevator rotation lever stop", op);
+
+ const Common::Point &mouse = _vm->_system->getEventManager()->getMousePos();
+ MystResourceType12 *lever = static_cast<MystResourceType12 *>(_invokingResource);
+
+ // Get current lever frame
+ int16 maxStep = lever->getNumFrames() - 1;
+ Common::Rect rect = lever->getRect();
+ int16 step = ((rect.bottom - mouse.y) * lever->getNumFrames()) / rect.height();
+ step = CLIP<int16>(step, 0, maxStep);
+
+ // Release lever
+ for (int i = step; i >= 0; i--) {
+ lever->drawFrame(i);
+ _vm->_system->delayMillis(10);
+ }
+
+ // Stop persistent script
+ _elevatorRotationLeverMoving = false;
+
+ float speed = _elevatorRotationSpeed * 10;
+
+ if (speed > 0) {
+
+ // Decrease speed
+ while (speed > 2) {
+ speed -= 0.5;
+
+ _elevatorRotationGearPosition += speed * 0.1;
+
+ if (_elevatorRotationGearPosition > 12)
+ break;
+
+ _vm->redrawArea(12);
+ _vm->_system->delayMillis(100);
+ }
+
+ // Increment position
+ _state.elevatorRotation = (_state.elevatorRotation + 1) % 10;
+
+ _vm->_sound->replaceSoundMyst(_elevatorRotationSoundId);
+ _vm->redrawArea(11);
+ }
+
+ _vm->checkCursorHints();
+}
void Mechanical::opcode_121(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
varUnusedCheck(op, var);
@@ -403,36 +483,29 @@ void Mechanical::o_snakeBox_init(uint16 op, uint16 var, uint16 argc, uint16 *arg
_snakeBox = static_cast<MystResourceType6 *>(_invokingResource);
}
-static struct {
- bool enabled;
- uint16 soundId;
-} g_opcode204Parameters;
-
-void Mechanical::opcode_204_run() {
- if (g_opcode204Parameters.enabled) {
- // TODO: Fill in Logic.
- // Var 12 holds Large Cog Position in range 0 to 5
- // - For animation
- // Var 11 holds C position in range 0 to 9
- // - 4 for Correct Answer
- // C Movement Sound
- //_vm->_sound->playSound(g_opcode204Parameters.soundId);
- }
-}
+void Mechanical::elevatorRotation_run() {
+ _vm->redrawArea(12);
+
+ _elevatorRotationGearPosition += _elevatorRotationSpeed;
+
+ if (_elevatorRotationGearPosition > 12) {
+ uint16 position = (uint16)_elevatorRotationGearPosition;
+ _elevatorRotationGearPosition = _elevatorRotationGearPosition - position + position % 6;
-void Mechanical::opcode_204_disable() {
- g_opcode204Parameters.enabled = false;
+ _state.elevatorRotation = (_state.elevatorRotation + 1) % 10;
+
+ _vm->_sound->replaceSoundMyst(_elevatorRotationSoundId);
+ _vm->redrawArea(11);
+ _vm->_system->delayMillis(100);
+ }
}
-void Mechanical::opcode_204(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
- varUnusedCheck(op, var);
+void Mechanical::o_elevatorRotation_init(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
+ debugC(kDebugScript, "Opcode %d: Elevator rotation init", op);
- // Used for Card 6180 (Lower Elevator Puzzle)
- if (argc == 1) {
- g_opcode204Parameters.soundId = argv[0];
- g_opcode204Parameters.enabled = true;
- } else
- unknown(op, var, argc, argv);
+ _elevatorRotationSoundId = argv[0];
+ _elevatorRotationGearPosition = 0;
+ _elevatorRotationLeverMoving = false;
}
static struct {
diff --git a/engines/mohawk/myst_stacks/mechanical.h b/engines/mohawk/myst_stacks/mechanical.h
index 7142425eb4..0e20b8e57a 100644
--- a/engines/mohawk/myst_stacks/mechanical.h
+++ b/engines/mohawk/myst_stacks/mechanical.h
@@ -54,8 +54,7 @@ private:
void opcode_202_run();
void opcode_202_disable();
- void opcode_204_run();
- void opcode_204_disable();
+ void elevatorRotation_run();
void opcode_205_run();
void opcode_205_disable();
void opcode_206_run();
@@ -66,6 +65,9 @@ private:
DECLARE_OPCODE(o_throneEnablePassage);
DECLARE_OPCODE(o_snakeBoxTrigger);
DECLARE_OPCODE(o_fortressStaircaseMovie);
+ DECLARE_OPCODE(o_elevatorRotationStart);
+ DECLARE_OPCODE(o_elevatorRotationMove);
+ DECLARE_OPCODE(o_elevatorRotationStop);
DECLARE_OPCODE(opcode_121);
DECLARE_OPCODE(opcode_122);
DECLARE_OPCODE(opcode_123);
@@ -83,7 +85,7 @@ private:
DECLARE_OPCODE(o_fortressStaircase_init);
DECLARE_OPCODE(opcode_202);
DECLARE_OPCODE(o_snakeBox_init);
- DECLARE_OPCODE(opcode_204);
+ DECLARE_OPCODE(o_elevatorRotation_init);
DECLARE_OPCODE(opcode_205);
DECLARE_OPCODE(opcode_206);
DECLARE_OPCODE(opcode_209);
@@ -96,6 +98,11 @@ private:
uint16 _fortressPosition; // 82
+ float _elevatorRotationSpeed; // 120
+ float _elevatorRotationGearPosition; // 124
+ uint16 _elevatorRotationSoundId; // 128
+ bool _elevatorRotationLeverMoving; // 184
+
uint16 _crystalLit; // 130
MystResourceType6 *_snakeBox; // 156