Skip to content

Commit

Permalink
MOHAWK: Implement Mechanical opcodes 101, 103 and 202. Singing Bird.
Browse files Browse the repository at this point in the history
  • Loading branch information
bgK committed May 12, 2011
1 parent 35086fe commit 4f5ecc4
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 21 deletions.
68 changes: 50 additions & 18 deletions engines/mohawk/myst_stacks/mechanical.cpp
Expand Up @@ -51,6 +51,9 @@ Mechanical::~Mechanical() {
void Mechanical::setupOpcodes() {
// "Stack-Specific" Opcodes
OPCODE(100, o_throneEnablePassage);
OPCODE(101, o_birdCrankStart);
OPCODE(102, NOP);
OPCODE(103, o_birdCrankStop);
OPCODE(104, o_snakeBoxTrigger);
OPCODE(105, o_fortressStaircaseMovie);
OPCODE(106, o_elevatorRotationStart);
Expand All @@ -72,7 +75,7 @@ void Mechanical::setupOpcodes() {
// "Init" Opcodes
OPCODE(200, o_throne_init);
OPCODE(201, o_fortressStaircase_init);
OPCODE(202, opcode_202);
OPCODE(202, o_bird_init);
OPCODE(203, o_snakeBox_init);
OPCODE(204, o_elevatorRotation_init);
OPCODE(205, opcode_205);
Expand All @@ -86,15 +89,16 @@ void Mechanical::setupOpcodes() {
#undef OPCODE

void Mechanical::disablePersistentScripts() {
opcode_202_disable();
opcode_205_disable();
opcode_206_disable();
opcode_209_disable();
_elevatorGoingMiddle = false;
_birdSinging = false;
}

void Mechanical::runPersistentScripts() {
opcode_202_run();
if (_birdSinging)
birdSing_run();

if (_elevatorRotationLeverMoving)
elevatorRotation_run();
Expand Down Expand Up @@ -242,6 +246,38 @@ void Mechanical::o_throneEnablePassage(uint16 op, uint16 var, uint16 argc, uint1
_vm->_resources[argv[0]]->setEnabled(getVar(var));
}

void Mechanical::o_birdCrankStart(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Mechanical bird crank start", op);

MystResourceType11 *crank = static_cast<MystResourceType11 *>(_invokingResource);

uint16 crankSoundId = crank->getList2(0);
_vm->_sound->replaceSoundMyst(crankSoundId, Audio::Mixer::kMaxChannelVolume, true);

_birdSingEndTime = 0;
_birdCrankStartTime = _vm->_system->getMillis();

MystResourceType6 *crankMovie = static_cast<MystResourceType6 *>(crank->getSubResource(0));
crankMovie->playMovie();
}

void Mechanical::o_birdCrankStop(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Mechanical bird crank stop", op);

MystResourceType11 *crank = static_cast<MystResourceType11 *>(_invokingResource);

MystResourceType6 *crankMovie = static_cast<MystResourceType6 *>(crank->getSubResource(0));
crankMovie->pauseMovie(true);

uint16 crankSoundId = crank->getList2(1);
_vm->_sound->replaceSoundMyst(crankSoundId);

_birdSingEndTime = 2 * _vm->_system->getMillis() - _birdCrankStartTime;
_birdSinging = true;

_bird->playMovie();
}

void Mechanical::o_snakeBoxTrigger(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Trigger Playing Of Snake Movie", op);

Expand Down Expand Up @@ -512,25 +548,21 @@ void Mechanical::o_fortressStaircase_init(uint16 op, uint16 var, uint16 argc, ui
_vm->_resources[argv[2]]->setEnabled(_state.staircaseState);
}

static struct {
bool enabled;
} g_opcode202Parameters;

void Mechanical::opcode_202_run() {
void Mechanical::birdSing_run() {
// Used for Card 6220 (Sirrus' Mechanical Bird)
// TODO: Fill in Function
uint32 time = _vm->_system->getMillis();
if (_birdSingEndTime < time) {
_bird->pauseMovie(true);
_birdSinging = false;
}
}

void Mechanical::opcode_202_disable() {
g_opcode202Parameters.enabled = false;
}
void Mechanical::o_bird_init(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
debugC(kDebugScript, "Opcode %d: Mechanical bird init", op);

void Mechanical::opcode_202(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
// Used for Card 6220 (Sirrus' Mechanical Bird)
if (argc == 0)
g_opcode202Parameters.enabled = true;
else
unknown(op, var, argc, argv);
_birdSinging = false;
_birdSingEndTime = 0;
_bird = static_cast<MystResourceType6 *>(_invokingResource);
}

void Mechanical::o_snakeBox_init(uint16 op, uint16 var, uint16 argc, uint16 *argv) {
Expand Down
13 changes: 10 additions & 3 deletions engines/mohawk/myst_stacks/mechanical.h
Expand Up @@ -49,8 +49,7 @@ class Mechanical : public MystScriptParser {
void toggleVar(uint16 var);
bool setVarValue(uint16 var, uint16 value);

void opcode_202_run();
void opcode_202_disable();
void birdSing_run();
void elevatorRotation_run();
void elevatorGoMiddle_run();
void opcode_205_run();
Expand All @@ -61,6 +60,8 @@ class Mechanical : public MystScriptParser {
void opcode_209_disable();

DECLARE_OPCODE(o_throneEnablePassage);
DECLARE_OPCODE(o_birdCrankStart);
DECLARE_OPCODE(o_birdCrankStop);
DECLARE_OPCODE(o_snakeBoxTrigger);
DECLARE_OPCODE(o_fortressStaircaseMovie);
DECLARE_OPCODE(o_elevatorRotationStart);
Expand All @@ -81,7 +82,7 @@ class Mechanical : public MystScriptParser {

DECLARE_OPCODE(o_throne_init);
DECLARE_OPCODE(o_fortressStaircase_init);
DECLARE_OPCODE(opcode_202);
DECLARE_OPCODE(o_bird_init);
DECLARE_OPCODE(o_snakeBox_init);
DECLARE_OPCODE(o_elevatorRotation_init);
DECLARE_OPCODE(opcode_205);
Expand Down Expand Up @@ -110,6 +111,12 @@ class Mechanical : public MystScriptParser {

uint16 _crystalLit; // 130

bool _birdSinging; // 144
uint32 _birdCrankStartTime; // 136
uint32 _birdSingEndTime; // 140
MystResourceType6 *_bird; // 152


MystResourceType6 *_snakeBox; // 156
};

Expand Down

0 comments on commit 4f5ecc4

Please sign in to comment.