MOHAWK: Move card id remapping to RivenStack

This commit is contained in:
Bastien Bouclet 2016-08-07 10:49:00 +02:00 committed by Eugene Sandulenko
parent 3c8decec0a
commit 670a3c4558
7 changed files with 62 additions and 46 deletions

View File

@ -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;
}

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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;

View File

@ -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() {
}

View File

@ -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