From 79c42abf086911537400750fc356127669bf4c23 Mon Sep 17 00:00:00 2001 From: Denis Kasak Date: Mon, 6 Jul 2009 19:50:59 +0000 Subject: * Fixed extracting visibility and location of object from its status byte * Added Game::getRoomNum() which returns the current room number * Made Game::loadRoom() execute the room's startup script, load the room's objects and run their init scripts as well svn-id: r42194 --- engines/draci/game.cpp | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) (limited to 'engines/draci/game.cpp') diff --git a/engines/draci/game.cpp b/engines/draci/game.cpp index b2295d15b8..ab2302cae4 100644 --- a/engines/draci/game.cpp +++ b/engines/draci/game.cpp @@ -121,10 +121,10 @@ Game::Game(DraciEngine *vm) : _vm(vm) { byte tmp = objStatus.readByte(); // Set object visibility - _objects[i]._visible = tmp & 1; + _objects[i]._visible = tmp & (1 << 7); // Set object location - _objects[i]._location = tmp & ~1; + _objects[i]._location = (~(1 << 7) & tmp) - 1; } assert(numDialogs == _info->_numDialogs); @@ -172,6 +172,32 @@ void Game::loadRoom(uint roomNum) { _currentRoom._escRoom = roomReader.readByte() - 1; _currentRoom._numGates = roomReader.readByte(); + for (uint i = 0; i < _info->_numObjects; ++i) { + debugC(1, kDraciLogicDebugLevel, + "Checking if object %d (%d) is at the current location (%d)", i, + _objects[i]._location, roomNum); + + if (_objects[i]._location == roomNum) { + debugC(1, kDraciLogicDebugLevel, "Loading object %d from room %d", i, roomNum); + loadObject(i); + } + } + + // We can't do this in the above loop because some objects' scripts reference + // other objects that may not yet be loaded + for (uint i = 0; i < _info->_numObjects; ++i) { + if (_objects[i]._location == roomNum) { + _vm->_script->run(getObject(i)->_program, getObject(i)->_init); + } + } + + f = _vm->_roomsArchive->getFile(roomNum * 4 + 3); + _currentRoom._program._bytecode = new byte[f->_length]; + _currentRoom._program._length = f->_length; + memcpy(_currentRoom._program._bytecode, f->_data, f->_length); + + _vm->_script->run(_currentRoom._program, _currentRoom._init); + f = _vm->_paletteArchive->getFile(_currentRoom._palette); _vm->_screen->setPalette(f->_data, 0, kNumColours); } @@ -295,7 +321,13 @@ void Game::loadOverlays() { void Game::changeRoom(uint roomNum) { _currentRoom._roomNum = roomNum; loadRoom(roomNum); - loadOverlays(); + loadOverlays(); + + _vm->_script->run(_currentRoom._program, _currentRoom._init); +} + +int Game::getRoomNum() { + return _currentRoom._roomNum; } Game::~Game() { -- cgit v1.2.3