diff options
author | Bastien Bouclet | 2011-02-09 20:07:55 +0000 |
---|---|---|
committer | Bastien Bouclet | 2011-02-09 20:07:55 +0000 |
commit | d0a01c16891cdb362233022b7c62078b969729af (patch) | |
tree | df03e8a9ed7bdb1f1d4a0f08b7a223921c016e32 | |
parent | aac6bd518152571e8e119a733c76b9c2ade45cfb (diff) | |
download | scummvm-rg350-d0a01c16891cdb362233022b7c62078b969729af.tar.gz scummvm-rg350-d0a01c16891cdb362233022b7c62078b969729af.tar.bz2 scummvm-rg350-d0a01c16891cdb362233022b7c62078b969729af.zip |
MOHAWK: Implement Stoneship battery depletion
svn-id: r55860
-rw-r--r-- | engines/mohawk/myst_areas.h | 3 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/stoneship.cpp | 93 | ||||
-rw-r--r-- | engines/mohawk/myst_stacks/stoneship.h | 11 |
3 files changed, 86 insertions, 21 deletions
diff --git a/engines/mohawk/myst_areas.h b/engines/mohawk/myst_areas.h index c5cda6824f..66430f2068 100644 --- a/engines/mohawk/myst_areas.h +++ b/engines/mohawk/myst_areas.h @@ -70,7 +70,8 @@ public: bool contains(Common::Point point) { return _rect.contains(point); } virtual void drawDataToScreen() {} virtual void handleCardChange() {} - virtual Common::Rect getRect() { return _rect; } + Common::Rect getRect() { return _rect; } + void setRect(const Common::Rect &rect) { _rect = rect; } bool isEnabled(); void setEnabled(bool enabled); bool isDrawSubimages() { return _flags & kMystSubimageEnableFlag; } diff --git a/engines/mohawk/myst_stacks/stoneship.cpp b/engines/mohawk/myst_stacks/stoneship.cpp index 7a0e437f2c..fe82f99aab 100644 --- a/engines/mohawk/myst_stacks/stoneship.cpp +++ b/engines/mohawk/myst_stacks/stoneship.cpp @@ -93,9 +93,9 @@ void MystScriptParser_Stoneship::setupOpcodes() { // "Init" Opcodes OPCODE(200, o_hologramDisplay_init); OPCODE(201, o_hologramSelection_init); - OPCODE(202, opcode_202); + OPCODE(202, o_battery_init); OPCODE(203, opcode_203); - OPCODE(204, opcode_204); + OPCODE(204, o_batteryGauge_init); OPCODE(205, opcode_205); OPCODE(206, opcode_206); OPCODE(207, o_chest_init); @@ -111,6 +111,8 @@ void MystScriptParser_Stoneship::setupOpcodes() { void MystScriptParser_Stoneship::disablePersistentScripts() { _batteryCharging = false; + _batteryDepleting = false; + _batteryGaugeRunning = false; _telescopeRunning = false; } @@ -120,6 +122,12 @@ void MystScriptParser_Stoneship::runPersistentScripts() { if (_telescopeRunning) telescope_run(); + + if (_batteryGaugeRunning) + batteryGauge_run(); + + if (_batteryDepleting) + batteryDeplete_run(); } uint16 MystScriptParser_Stoneship::getVar(uint16 var) { @@ -481,6 +489,7 @@ void MystScriptParser_Stoneship::o_generatorStart(uint16 op, uint16 var, uint16 _state.generatorDuration -= _vm->_system->getMillis() - _state.generatorDepletionTime; // Start charging the battery + _batteryDepleting = false; _batteryCharging = true; _batteryNextTime = _vm->_system->getMillis() + 1000; @@ -507,6 +516,7 @@ void MystScriptParser_Stoneship::o_generatorStop(uint16 op, uint16 var, uint16 a _state.generatorDepletionTime = _vm->_system->getMillis() + _state.generatorDuration; _state.generatorPowerAvailable = 1; _batteryDepleting = true; + _batteryNextTime = _vm->_system->getMillis() + 60000; } // Pause handle movie @@ -529,13 +539,36 @@ void MystScriptParser_Stoneship::chargeBattery_run() { } uint16 MystScriptParser_Stoneship::batteryRemainingCharge() { - if (_state.generatorDepletionTime) { - return (_state.generatorDepletionTime - _vm->_system->getMillis()) / 7500; + uint32 time = _vm->_system->getMillis(); + + if (_state.generatorDepletionTime > time) { + return (_state.generatorDepletionTime - time) / 7500; } else { return 0; } } +void MystScriptParser_Stoneship::batteryDeplete_run() { + uint32 time = _vm->_system->getMillis(); + + if (time > _batteryNextTime) { + if (_state.generatorDuration > 60000) { + _state.generatorDuration -= 60000; + _batteryNextTime = time + 60000; + } else { // Battery depleted + _state.generatorDuration = 0; + _state.generatorDepletionTime = 0; + + if (_state.sideDoorOpened) + _state.generatorPowerAvailable = 2; + else + _state.generatorPowerAvailable = 0; + + _batteryDepleting = false; + } + } +} + void MystScriptParser_Stoneship::o_drawerOpenAchenar(uint16 op, uint16 var, uint16 argc, uint16 *argv) { debugC(kDebugScript, "Opcode %d: Open drawer", op); @@ -771,13 +804,27 @@ void MystScriptParser_Stoneship::o_hologramSelection_init(uint16 op, uint16 var, _hologramSelection = static_cast<MystResourceType6 *>(_invokingResource); } -void MystScriptParser_Stoneship::opcode_202(uint16 op, uint16 var, uint16 argc, uint16 *argv) { - varUnusedCheck(op, var); +void MystScriptParser_Stoneship::batteryGaugeUpdate() { + uint16 charge = 0; + + if (_state.generatorDepletionTime) { + charge = batteryRemainingCharge(); + } + + Common::Rect rect = _batteryGauge->getRect(); + + rect.top = rect.bottom - charge; + + _batteryGauge->setRect(rect); +} +void MystScriptParser_Stoneship::o_battery_init(uint16 op, uint16 var, uint16 argc, uint16 *argv) { // Used for Card 2160 (Lighthouse Battery Pack Closeup) - // TODO: Implement Code... - // Not Sure of Purpose - Update of Light / Discharge? - unknown(op, var, argc, argv); + debugC(kDebugScript, "Opcode %d: Battery init", op); + + _batteryGauge = static_cast<MystResourceType8 *>(_invokingResource); + + batteryGaugeUpdate(); } void MystScriptParser_Stoneship::opcode_203(uint16 op, uint16 var, uint16 argc, uint16 *argv) { @@ -813,16 +860,26 @@ void MystScriptParser_Stoneship::opcode_203(uint16 op, uint16 var, uint16 argc, unknown(op, var, argc, argv); } -void MystScriptParser_Stoneship::opcode_204(uint16 op, uint16 var, uint16 argc, uint16 *argv) { - varUnusedCheck(op, var); +void MystScriptParser_Stoneship::o_batteryGauge_init(uint16 op, uint16 var, uint16 argc, uint16 *argv) { + debugC(kDebugScript, "Opcode %d: Battery gauge init", op); + _batteryLastCharge = batteryRemainingCharge(); + _batteryGaugeRunning = true; +} - // Used for Card 2160 (Lighthouse Battery Pack Closeup) - if (argc == 0) { - // TODO: Implement Code For Battery Meter Level - // Overwrite _vm->_resources[1]->_subImages[0].rect.bottom 1 to 80 - // Add accessor functions for this... - } else - unknown(op, var, argc, argv); +void MystScriptParser_Stoneship::batteryGauge_run() { + uint16 batteryCharge = batteryRemainingCharge(); + + if (batteryCharge != _batteryLastCharge) { + batteryGaugeUpdate(); + + _batteryLastCharge = batteryCharge; + + // Redraw card + _vm->drawCardBackground(); + _vm->drawResourceImages(); + _vm->_gfx->copyBackBufferToScreen(Common::Rect(544, 333)); + _vm->_system->updateScreen(); + } } void MystScriptParser_Stoneship::opcode_205(uint16 op, uint16 var, uint16 argc, uint16 *argv) { diff --git a/engines/mohawk/myst_stacks/stoneship.h b/engines/mohawk/myst_stacks/stoneship.h index 7fa8e7a486..89f97415be 100644 --- a/engines/mohawk/myst_stacks/stoneship.h +++ b/engines/mohawk/myst_stacks/stoneship.h @@ -77,9 +77,9 @@ private: DECLARE_OPCODE(o_hologramDisplay_init); DECLARE_OPCODE(o_hologramSelection_init); - DECLARE_OPCODE(opcode_202); + DECLARE_OPCODE(o_battery_init); DECLARE_OPCODE(opcode_203); - DECLARE_OPCODE(opcode_204); + DECLARE_OPCODE(o_batteryGauge_init); DECLARE_OPCODE(opcode_205); DECLARE_OPCODE(opcode_206); DECLARE_OPCODE(o_chest_init); @@ -88,6 +88,7 @@ private: DECLARE_OPCODE(o_cloudOrb_init); void chargeBattery_run(); + void batteryDeplete_run(); MystGameState::Stoneship &_state; @@ -95,6 +96,12 @@ private: bool _batteryDepleting; uint32 _batteryNextTime; + bool _batteryGaugeRunning; + uint16 _batteryLastCharge; // 92 + MystResourceType8 *_batteryGauge; // 96 + void batteryGaugeUpdate(); + void batteryGauge_run(); + uint16 _cabinMystBookPresent; // 64 uint16 _siriusDrawerDrugsOpen; // 72 |