aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Bouclet2016-08-07 10:49:00 +0200
committerEugene Sandulenko2017-07-03 08:50:10 +0200
commit670a3c4558f3c2c7e7c0d84d95b906e6fe0ce804 (patch)
tree97d07cf30de54be748a20980b150d888ff8ffea8
parent3c8decec0a416d874ae6db93c7e4977ec36432fb (diff)
downloadscummvm-rg350-670a3c4558f3c2c7e7c0d84d95b906e6fe0ce804.tar.gz
scummvm-rg350-670a3c4558f3c2c7e7c0d84d95b906e6fe0ce804.tar.bz2
scummvm-rg350-670a3c4558f3c2c7e7c0d84d95b906e6fe0ce804.zip
MOHAWK: Move card id remapping to RivenStack
-rw-r--r--engines/mohawk/console.cpp2
-rw-r--r--engines/mohawk/riven.cpp35
-rw-r--r--engines/mohawk/riven.h2
-rw-r--r--engines/mohawk/riven_external.cpp20
-rw-r--r--engines/mohawk/riven_scripts.cpp7
-rw-r--r--engines/mohawk/riven_stack.cpp33
-rw-r--r--engines/mohawk/riven_stack.h9
7 files changed, 62 insertions, 46 deletions
diff --git a/engines/mohawk/console.cpp b/engines/mohawk/console.cpp
index fbf4c23474..e28babdba3 100644
--- a/engines/mohawk/console.cpp
+++ b/engines/mohawk/console.cpp
@@ -630,7 +630,7 @@ bool RivenConsole::Cmd_ListZipCards(int argc, const char **argv) {
}
bool RivenConsole::Cmd_GetRMAP(int argc, const char **argv) {
- uint32 rmapCode = _vm->getCurCardRMAP();
+ uint32 rmapCode = _vm->getCurStack()->getCurrentCardGlobalId();
debugPrintf("RMAP for %s %d = %08x\n", _vm->getStackName(_vm->getCurStack()->getId()).c_str(), _vm->getCurCard()->getId(), rmapCode);
return true;
}
diff --git a/engines/mohawk/riven.cpp b/engines/mohawk/riven.cpp
index 70f4ab5eb2..9a60384498 100644
--- a/engines/mohawk/riven.cpp
+++ b/engines/mohawk/riven.cpp
@@ -377,9 +377,10 @@ void MohawkEngine_Riven::changeToCard(uint16 dest) {
if (!(getFeatures() & GF_DEMO)) {
for (byte i = 0; i < 13; i++)
- if (_stack->getId() == rivenSpecialChange[i].startStack && dest == matchRMAPToCard(rivenSpecialChange[i].startCardRMAP)) {
+ if (_stack->getId() == rivenSpecialChange[i].startStack && dest == _stack->getCardStackId(
+ rivenSpecialChange[i].startCardRMAP)) {
changeToStack(rivenSpecialChange[i].targetStack);
- dest = matchRMAPToCard(rivenSpecialChange[i].targetCardRMAP);
+ dest = _stack->getCardStackId(rivenSpecialChange[i].targetCardRMAP);
}
}
@@ -486,32 +487,6 @@ Common::SeekableReadStream *MohawkEngine_Riven::getExtrasResource(uint32 tag, ui
return _extrasFile->getResource(tag, id);
}
-uint16 MohawkEngine_Riven::matchRMAPToCard(uint32 rmapCode) {
- uint16 index = 0;
- Common::SeekableReadStream *rmapStream = getResource(ID_RMAP, 1);
-
- for (uint16 i = 1; rmapStream->pos() < rmapStream->size(); i++) {
- uint32 code = rmapStream->readUint32BE();
- if (code == rmapCode)
- index = i;
- }
-
- delete rmapStream;
-
- if (!index)
- error ("Could not match RMAP code %08x", rmapCode);
-
- return index - 1;
-}
-
-uint32 MohawkEngine_Riven::getCurCardRMAP() {
- Common::SeekableReadStream *rmapStream = getResource(ID_RMAP, 1);
- rmapStream->seek(_card->getId() * 4);
- uint32 rmapCode = rmapStream->readUint32BE();
- delete rmapStream;
- return rmapCode;
-}
-
void MohawkEngine_Riven::delayAndUpdate(uint32 ms) {
uint32 startTime = _system->getMillis();
@@ -760,7 +735,7 @@ static void sunnersBeachTimer(MohawkEngine_Riven *vm) {
}
void MohawkEngine_Riven::installCardTimer() {
- switch (getCurCardRMAP()) {
+ switch (_stack->getCurrentCardGlobalId()) {
case 0x3a85: // Top of elevator on prison island
// Handle Catherine hardcoded videos
installTimer(&catherineIdleTimer, _rnd->getRandomNumberRng(1, 33) * 1000);
@@ -803,7 +778,7 @@ void MohawkEngine_Riven::checkSunnerAlertClick() {
if (sunners != 0)
return;
- uint32 rmapCode = getCurCardRMAP();
+ uint32 rmapCode = _stack->getCurrentCardGlobalId();
// This is only for the mid/lower staircase sections
if (rmapCode != 0x79bd && rmapCode != 0x7beb)
diff --git a/engines/mohawk/riven.h b/engines/mohawk/riven.h
index 3fd1905fd3..03788b5270 100644
--- a/engines/mohawk/riven.h
+++ b/engines/mohawk/riven.h
@@ -148,8 +148,6 @@ public:
Common::String getStackName(uint16 stack) const;
RivenCard *getCurCard() const { return _card; }
RivenStack *getCurStack() const { return _stack; }
- uint16 matchRMAPToCard(uint32);
- uint32 getCurCardRMAP();
// Hotspot functions/variables
Common::Array<ZipMode> _zipModeData;
diff --git a/engines/mohawk/riven_external.cpp b/engines/mohawk/riven_external.cpp
index 11f0b9623c..cf752d2f81 100644
--- a/engines/mohawk/riven_external.cpp
+++ b/engines/mohawk/riven_external.cpp
@@ -1734,12 +1734,12 @@ void RivenExternal::xvga1300_carriage(uint16 argc, uint16 *argv) {
_vm->_system->updateScreen(); // Update
_vm->_video->playMovieBlockingRiven(1); // Play handle movie
_vm->_gfx->scheduleTransition(15); // Set pan down transition
- _vm->changeToCard(_vm->matchRMAPToCard(0x18e77)); // Change to card facing up
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x18e77)); // Change to card facing up
_vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor (again)
_vm->_system->updateScreen(); // Update
_vm->_video->playMovieBlockingRiven(4); // Play carriage beginning to drop
_vm->_gfx->scheduleTransition(14); // Set pan up transition
- _vm->changeToCard(_vm->matchRMAPToCard(0x183a9)); // Change to card looking straight again
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x183a9)); // Change to card looking straight again
_vm->_video->playMovieBlockingRiven(2);
if (_vm->_vars["jgallows"] == 1) {
@@ -1774,16 +1774,16 @@ void RivenExternal::xvga1300_carriage(uint16 argc, uint16 *argv) {
if (gotClick) {
_vm->_gfx->scheduleTransition(16); // Schedule dissolve transition
- _vm->changeToCard(_vm->matchRMAPToCard(0x18d4d)); // Move forward
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x18d4d)); // Move forward
_vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor
_vm->_system->updateScreen(); // Update
_vm->_system->delayMillis(500); // Delay a half second before changing again
_vm->_gfx->scheduleTransition(12); // Schedule pan left transition
- _vm->changeToCard(_vm->matchRMAPToCard(0x18ab5)); // Turn right
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x18ab5)); // Turn right
_vm->_cursor->setCursor(kRivenHideCursor); // Hide the cursor
_vm->_system->updateScreen(); // Update
_vm->_video->playMovieBlockingRiven(1); // Play carriage ride movie
- _vm->changeToCard(_vm->matchRMAPToCard(0x17167)); // We have arrived at the top
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x17167)); // We have arrived at the top
} else
_vm->_video->playMovieBlockingRiven(3); // Too slow!
}
@@ -1849,7 +1849,7 @@ void RivenExternal::xhandlecontrolup(uint16 argc, uint16 *argv) {
if (changeLevel == -1) {
_vm->_video->playMovieBlockingRiven(1);
_vm->_video->playMovieBlockingRiven(2);
- _vm->changeToCard(_vm->matchRMAPToCard(0x1e374));
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x1e374));
}
}
@@ -1860,7 +1860,7 @@ void RivenExternal::xhandlecontroldown(uint16 argc, uint16 *argv) {
if (changeLevel == 1) {
_vm->_video->playMovieBlockingRiven(1);
_vm->_video->playMovieBlockingRiven(2);
- _vm->changeToCard(_vm->matchRMAPToCard(0x1e374));
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x1e374));
}
}
@@ -1887,10 +1887,10 @@ void RivenExternal::xhandlecontrolmid(uint16 argc, uint16 *argv) {
// Play the elevator video and then change the card
if (changeLevel == 1) {
_vm->_video->playMovieBlockingRiven(5);
- _vm->changeToCard(_vm->matchRMAPToCard(0x1e597));
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x1e597));
} else {
_vm->_video->playMovieBlockingRiven(4);
- _vm->changeToCard(_vm->matchRMAPToCard(0x1e29c));
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x1e29c));
}
}
@@ -2143,7 +2143,7 @@ void RivenExternal::xbookclick(uint16 argc, uint16 *argv) {
_vm->_vars["agehn"] = 4; // Set Gehn to the trapped state
_vm->_vars["atrapbook"] = 1; // We've got the trap book again
_vm->_sound->playSound(0); // Play the link sound again
- _vm->changeToCard(_vm->matchRMAPToCard(0x2885)); // Link out!
+ _vm->changeToCard(_vm->getCurStack()->getCardStackId(0x2885)); // Link out!
return;
}
break;
diff --git a/engines/mohawk/riven_scripts.cpp b/engines/mohawk/riven_scripts.cpp
index cfc97bfe59..3155c4347c 100644
--- a/engines/mohawk/riven_scripts.cpp
+++ b/engines/mohawk/riven_scripts.cpp
@@ -394,7 +394,8 @@ void RivenSimpleCommand::stopSound(uint16 op, uint16 argc, uint16 *argv) {
// would cause all ambient sounds not to play. An alternative
// fix would be to stop all scripts on a stack change, but this
// does fine for now.
- if (_vm->getCurStack()->getId() == kStackTspit && (_vm->getCurCardRMAP() == 0x6e9a || _vm->getCurCardRMAP() == 0xfeeb))
+ if (_vm->getCurStack()->getId() == kStackTspit && (_vm->getCurStack()->getCurrentCardGlobalId() == 0x6e9a ||
+ _vm->getCurStack()->getCurrentCardGlobalId() == 0xfeeb))
return;
// The argument is a bitflag for the setting.
@@ -477,7 +478,7 @@ void RivenSimpleCommand::changeStack(uint16 op, uint16 argc, uint16 *argv) {
_vm->changeToStack(index);
uint32 rmapCode = (argv[1] << 16) + argv[2];
- uint16 cardID = _vm->matchRMAPToCard(rmapCode);
+ uint16 cardID = _vm->getCurStack()->getCardStackId(rmapCode);
_vm->changeToCard(cardID);
}
@@ -580,7 +581,7 @@ void RivenSimpleCommand::activatePLST(uint16 op, uint16 argc, uint16 *argv) {
void RivenSimpleCommand::activateSLST(uint16 op, uint16 argc, uint16 *argv) {
// WORKAROUND: Disable the SLST that is played during Riven's intro.
// Riven X does this too (spoke this over with Jeff)
- if (_vm->getCurStack()->getId() == kStackTspit && _vm->getCurCardRMAP() == 0x6e9a && argv[0] == 2)
+ if (_vm->getCurStack()->getId() == kStackTspit && _vm->getCurStack()->getCurrentCardGlobalId() == 0x6e9a && argv[0] == 2)
return;
_vm->_activatedSLST = true;
diff --git a/engines/mohawk/riven_stack.cpp b/engines/mohawk/riven_stack.cpp
index b66ca834f4..54846f1139 100644
--- a/engines/mohawk/riven_stack.cpp
+++ b/engines/mohawk/riven_stack.cpp
@@ -23,6 +23,7 @@
#include "mohawk/riven_stack.h"
#include "mohawk/riven.h"
+#include "mohawk/riven_card.h"
#include "mohawk/resource.h"
namespace Mohawk {
@@ -31,6 +32,7 @@ RivenStack::RivenStack(MohawkEngine_Riven *vm, uint16 id) :
_vm(vm),
_id(id) {
loadResourceNames();
+ loadCardIdMap();
}
RivenStack::~RivenStack() {
@@ -83,6 +85,37 @@ int16 RivenStack::getIdFromName(RivenNameResource nameResource, const Common::St
}
}
+void RivenStack::loadCardIdMap() {
+ Common::SeekableReadStream *rmapStream = _vm->getResource(ID_RMAP, 1);
+
+ uint count = rmapStream->size() / sizeof(uint32);
+ _cardIdMap.resize(count);
+
+ for (uint i = 0; i < count; i++) {
+ _cardIdMap[i] = rmapStream->readUint32BE();
+ }
+
+ delete rmapStream;
+}
+
+uint16 RivenStack::getCardStackId(uint32 globalId) const {
+ int16 index = -1;
+
+ for (uint16 i = 0; i < _cardIdMap.size(); i++) {
+ if (_cardIdMap[i] == globalId)
+ index = i;
+ }
+
+ if (index < 0)
+ error ("Could not match RMAP code %08x", globalId);
+
+ return index;
+}
+
+uint32 RivenStack::getCurrentCardGlobalId() const {
+ return _cardIdMap[_vm->getCurCard()->getId()];
+}
+
RivenNameList::RivenNameList() {
}
diff --git a/engines/mohawk/riven_stack.h b/engines/mohawk/riven_stack.h
index 36d6fb0b06..02fb58cff2 100644
--- a/engines/mohawk/riven_stack.h
+++ b/engines/mohawk/riven_stack.h
@@ -89,8 +89,15 @@ public:
* The search is case insensitive.
*/
int16 getIdFromName(RivenNameResource nameResource, const Common::String &name) const;
+
+ /** Get the id of a card in the card from its global identifier */
+ uint16 getCardStackId(uint32 globalId) const;
+
+ /** Get the global id of the currently active card */
+ uint32 getCurrentCardGlobalId() const;
private:
void loadResourceNames();
+ void loadCardIdMap();
MohawkEngine_Riven *_vm;
@@ -102,6 +109,8 @@ private:
RivenNameList _hotspotNames;
RivenNameList _cardNames;
RivenNameList _stackNames;
+
+ Common::Array<uint32> _cardIdMap;
};
} // End of namespace Mohawk