aboutsummaryrefslogtreecommitdiff
path: root/engines/mohawk
diff options
context:
space:
mode:
Diffstat (limited to 'engines/mohawk')
-rw-r--r--engines/mohawk/riven.cpp8
-rw-r--r--engines/mohawk/riven_card.cpp40
-rw-r--r--engines/mohawk/riven_card.h6
-rw-r--r--engines/mohawk/riven_scripts.cpp14
-rw-r--r--engines/mohawk/riven_scripts.h6
5 files changed, 54 insertions, 20 deletions
diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp
index 9ed7b22ac1..2e035005a1 100644
--- a/engines/mohawk/riven.cpp
+++ b/engines/mohawk/riven.cpp
@@ -387,9 +387,6 @@ void MohawkEngine_Riven::changeToCard(uint16 dest) {
}
}
- if (_card)
- _card->runScript(kCardLeaveScript);
-
delete _card;
_card = new RivenCard(this, dest);
@@ -400,9 +397,6 @@ void MohawkEngine_Riven::refreshCard() {
// Clear any timer still floating around
removeTimer();
- _gfx->clearWaterEffects();
- _video->stopVideos();
-
_card->open();
if (_showHotspots)
@@ -838,7 +832,7 @@ void MohawkEngine_Riven::addZipVisitedCard(uint16 cardId, uint16 cardNameId) {
ZipMode zip;
zip.name = cardName;
zip.id = cardId;
- if (!(Common::find(_zipModeData.begin(), _zipModeData.end(), zip) != _zipModeData.end()))
+ if (Common::find(_zipModeData.begin(), _zipModeData.end(), zip) == _zipModeData.end())
_zipModeData.push_back(zip);
}
diff --git a/engines/mohawk/riven_card.cpp b/engines/mohawk/riven_card.cpp
index 15271b71c0..402c10b7af 100644
--- a/engines/mohawk/riven_card.cpp
+++ b/engines/mohawk/riven_card.cpp
@@ -44,9 +44,14 @@ RivenCard::RivenCard(MohawkEngine_Riven *vm, uint16 id) :
}
RivenCard::~RivenCard() {
+ runLeaveScripts();
+
for (uint i = 0; i < _hotspots.size(); i++) {
delete _hotspots[i];
}
+
+ _vm->_gfx->clearWaterEffects();
+ _vm->_video->stopVideos();
}
void RivenCard::loadCardResource(uint16 id) {
@@ -93,13 +98,18 @@ void RivenCard::initializeZipMode() {
}
}
-void RivenCard::runScript(uint16 scriptType) {
+RivenScriptPtr RivenCard::getScript(uint16 scriptType) const {
for (uint16 i = 0; i < _scripts.size(); i++)
if (_scripts[i].type == scriptType) {
- RivenScriptPtr script = _scripts[i].script;
- _vm->_scriptMan->runScript(script, false);
- break;
+ return _scripts[i].script;
}
+
+ return RivenScriptPtr(new RivenScript());
+}
+
+void RivenCard::runScript(uint16 scriptType) {
+ RivenScriptPtr script = getScript(scriptType);
+ _vm->_scriptMan->runScript(script, false);
}
uint16 RivenCard::getId() const {
@@ -381,12 +391,12 @@ void RivenCard::onMouseDragUpdate() {
}
void RivenCard::onMouseUpdate() {
- RivenScriptPtr script;
+ RivenScriptPtr script(new RivenScript());
if (_hoveredHotspot) {
script = _hoveredHotspot->getScript(kMouseInsideScript);
}
- if (script && !script->empty()) {
+ if (!script->empty()) {
_vm->_scriptMan->runScript(script, false);
} else {
updateMouseCursor();
@@ -405,6 +415,22 @@ void RivenCard::updateMouseCursor() {
_vm->_system->updateScreen();
}
+void RivenCard::runLeaveScripts() {
+ RivenScriptPtr script(new RivenScript());
+
+ if (_pressedHotspot) {
+ script += _pressedHotspot->getScript(kMouseUpScript);
+ }
+
+ if (_hoveredHotspot) {
+ script += _hoveredHotspot->getScript(kMouseLeaveScript);
+ }
+
+ script += getScript(kCardLeaveScript);
+
+ _vm->_scriptMan->runScript(script, false);
+}
+
RivenHotspot::RivenHotspot(MohawkEngine_Riven *vm, Common::ReadStream *stream) :
_vm(vm) {
loadFromStream(stream);
@@ -448,7 +474,7 @@ RivenScriptPtr RivenHotspot::getScript(uint16 scriptType) const {
return _scripts[i].script;
}
- return RivenScriptPtr();
+ return RivenScriptPtr(new RivenScript());
}
bool RivenHotspot::isEnabled() const {
diff --git a/engines/mohawk/riven_card.h b/engines/mohawk/riven_card.h
index 98e65ae5ff..f387201ad4 100644
--- a/engines/mohawk/riven_card.h
+++ b/engines/mohawk/riven_card.h
@@ -125,7 +125,11 @@ private:
void loadCardHotspotEnableList(uint16 id);
void loadCardWaterEffectList(uint16 id);
+ RivenScriptPtr getScript(uint16 scriptType) const;
void defaultLoadScript();
+ void runLeaveScripts();
+
+ void updateMouseCursor();
struct HotspotEnableRecord {
uint16 index;
@@ -156,8 +160,6 @@ private:
Common::Array<SLSTRecord> _soundList;
Common::Array<HotspotEnableRecord> _hotspotEnableList;
Common::Array<WaterEffectRecord> _waterEffectList;
-
- void updateMouseCursor();
};
/**
diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp
index d220045779..18c666dbbb 100644
--- a/engines/mohawk/riven_scripts.cpp
+++ b/engines/mohawk/riven_scripts.cpp
@@ -114,10 +114,6 @@ void RivenScriptManager::clearStoredMovieOpcode() {
}
void RivenScriptManager::runScript(const RivenScriptPtr &script, bool queue) {
- if (!script || script->empty()) {
- return;
- }
-
if (!queue) {
script->run();
} else {
@@ -187,6 +183,16 @@ bool RivenScript::empty() const {
return _commands.empty();
}
+RivenScript &RivenScript::operator+=(const RivenScript &other) {
+ _commands.push_back(other._commands);
+ return *this;
+}
+
+RivenScriptPtr &operator+=(RivenScriptPtr &lhs, const RivenScriptPtr &rhs) {
+ *lhs += *rhs;
+ return lhs;
+}
+
RivenCommand::RivenCommand(MohawkEngine_Riven *vm) :
_vm(vm) {
diff --git a/engines/mohawk/riven_scripts.h b/engines/mohawk/riven_scripts.h
index 05cbd15f40..0d575d7adc 100644
--- a/engines/mohawk/riven_scripts.h
+++ b/engines/mohawk/riven_scripts.h
@@ -87,11 +87,17 @@ public:
/** Stop the script after the current command */
void stopRunning() { _continueRunning = false; }
+ /** Append the commands of the other script to this script */
+ RivenScript &operator+=(const RivenScript &other);
+
private:
Common::Array<RivenCommand *> _commands;
bool _continueRunning;
};
+/** Append the commands of the rhs Script to those of the lhs Script */
+RivenScriptPtr &operator+=(RivenScriptPtr &lhs, const RivenScriptPtr &rhs);
+
/**
* A script and its type
*