2014-08-05 22:17:30 -04:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/scummsys.h"
|
2014-08-06 22:43:40 -04:00
|
|
|
#include "common/memstream.h"
|
2014-08-05 22:17:30 -04:00
|
|
|
#include "access/access.h"
|
2014-08-06 08:55:56 -04:00
|
|
|
#include "access/resources.h"
|
2014-08-05 22:17:30 -04:00
|
|
|
#include "access/room.h"
|
|
|
|
|
2014-08-07 21:54:22 -04:00
|
|
|
#define TILE_WIDTH 16
|
|
|
|
#define TILE_HEIGHT 16
|
|
|
|
|
2014-08-05 22:17:30 -04:00
|
|
|
namespace Access {
|
|
|
|
|
2014-08-07 21:54:22 -04:00
|
|
|
Room::Room(AccessEngine *vm) : Manager(vm) {
|
2014-08-05 22:17:30 -04:00
|
|
|
_function = 0;
|
2014-08-05 23:23:49 -04:00
|
|
|
_roomFlag = 0;
|
2014-08-07 21:59:45 -04:00
|
|
|
_playField = nullptr;
|
|
|
|
_tile = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
Room::~Room() {
|
|
|
|
delete[] _playField;
|
|
|
|
delete[] _tile;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::freePlayField() {
|
|
|
|
delete[] _playField;
|
|
|
|
_playField = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::freeTileData() {
|
|
|
|
delete[] _tile;
|
|
|
|
_tile = nullptr;
|
2014-08-05 22:17:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void Room::doRoom() {
|
|
|
|
bool reloadFlag = false;
|
|
|
|
|
|
|
|
while (!_vm->shouldQuit()) {
|
|
|
|
if (!reloadFlag) {
|
|
|
|
_vm->_numImages = 0;
|
|
|
|
_vm->_newRect.clear();
|
|
|
|
_vm->_oldRect.clear();
|
|
|
|
_vm->_nextImage = 0;
|
|
|
|
_vm->_numAnimTimers = 0;
|
2014-08-05 23:23:49 -04:00
|
|
|
|
|
|
|
reloadRoom();
|
2014-08-05 22:17:30 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
reloadFlag = false;
|
|
|
|
_vm->_startup = 0;
|
|
|
|
_function = 0;
|
|
|
|
|
|
|
|
while (!_vm->shouldQuit()) {
|
|
|
|
_vm->_numImages = 0;
|
|
|
|
if (_vm->_startup != -1 && --_vm->_startup != 0) {
|
|
|
|
--_vm->_startup;
|
|
|
|
_vm->_events->showCursor();
|
|
|
|
_vm->_screen->fadeIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_events->pollEvents();
|
|
|
|
_vm->_nextImage = 0;
|
|
|
|
_vm->_player->walk();
|
|
|
|
_vm->_sound->midiRepeat();
|
|
|
|
_vm->_screen->checkScroll();
|
|
|
|
doCommands();
|
|
|
|
|
|
|
|
// DOROOMFLASHBACK jump point
|
|
|
|
if (_function == 1) {
|
|
|
|
clearRoom();
|
|
|
|
break;
|
|
|
|
} else if (_function == 2) {
|
|
|
|
clearRoom();
|
|
|
|
return;
|
|
|
|
} else if (_function == 3) {
|
|
|
|
reloadRoom1();
|
|
|
|
reloadFlag = true;
|
|
|
|
break;
|
|
|
|
} else if (_function == 4) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_vm->_screen->_scrollFlag) {
|
|
|
|
_vm->_screen->copyBF1BF2();
|
|
|
|
_vm->_newRect.clear();
|
|
|
|
_function = 0;
|
|
|
|
roomLoop();
|
|
|
|
|
|
|
|
if (_function == 1) {
|
|
|
|
clearRoom();
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
_vm->_screen->plotList();
|
|
|
|
_vm->_screen->copyRects();
|
|
|
|
|
|
|
|
_vm->_screen->copyBF2Vid();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
_vm->_screen->copyBF1BF2();
|
|
|
|
_vm->_newRect.clear();
|
|
|
|
_function = 0;
|
|
|
|
roomLoop();
|
|
|
|
|
|
|
|
if (_function == 1) {
|
|
|
|
clearRoom();
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
_vm->_screen->plotList();
|
|
|
|
_vm->_screen->copyBlocks();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::clearRoom() {
|
2014-08-06 08:28:20 -04:00
|
|
|
if (_vm->_sound->_music) {
|
|
|
|
_vm->_sound->stopSong();
|
|
|
|
delete[] _vm->_sound->_music;
|
|
|
|
_vm->_sound->_music = nullptr;
|
2014-08-05 23:23:49 -04:00
|
|
|
}
|
|
|
|
|
2014-08-06 08:28:20 -04:00
|
|
|
_vm->_sound->freeSounds();
|
|
|
|
_vm->_numAnimTimers = 0;
|
2014-08-05 23:23:49 -04:00
|
|
|
|
2014-08-06 08:28:20 -04:00
|
|
|
_vm->freeAnimationData();
|
|
|
|
_vm->_scripts->freeScriptData();
|
|
|
|
_vm->freeCells();
|
2014-08-07 21:59:45 -04:00
|
|
|
freePlayField();
|
2014-08-06 08:28:20 -04:00
|
|
|
_vm->freeInactiveData();
|
|
|
|
_vm->freeManData();
|
2014-08-05 22:17:30 -04:00
|
|
|
}
|
|
|
|
|
2014-08-06 22:43:40 -04:00
|
|
|
void Room::loadRoomData(const byte *roomData) {
|
|
|
|
RoomInfo roomInfo(roomData);
|
|
|
|
|
|
|
|
_roomFlag = roomInfo._roomFlag;
|
|
|
|
|
|
|
|
_vm->_establishFlag = false;
|
|
|
|
if (roomInfo._estIndex != -1) {
|
|
|
|
_vm->_establishFlag = true;
|
|
|
|
if (_vm->_establishTable[roomInfo._estIndex] != 1) {
|
|
|
|
_vm->_establishTable[roomInfo._estIndex] = 1;
|
|
|
|
_vm->establish(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_sound->freeMusic();
|
|
|
|
if (roomInfo._musicFile._fileNum != -1) {
|
|
|
|
_vm->_sound->_music = _vm->_files->loadFile(roomInfo._musicFile._fileNum,
|
|
|
|
roomInfo._musicFile._subfile);
|
|
|
|
_vm->_sound->_midiSize = _vm->_files->_filesize;
|
|
|
|
_vm->_sound->midiPlay();
|
|
|
|
_vm->_sound->_musicRepeat = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_scaleH1 = roomInfo._scaleH1;
|
|
|
|
_vm->_scaleH2 = roomInfo._scaleH2;
|
|
|
|
_vm->_scaleN1 = roomInfo._scaleN1;
|
|
|
|
_vm->_scaleT1 = ((_vm->_scaleH2 - _vm->_scaleH1) << 8) / _vm->_scaleN1;
|
|
|
|
|
|
|
|
if (roomInfo._playFieldFile._fileNum != -1) {
|
|
|
|
_vm->loadPlayField(roomInfo._playFieldFile._fileNum,
|
|
|
|
roomInfo._playFieldFile._subfile);
|
|
|
|
setupRoom();
|
|
|
|
|
|
|
|
_vm->_scaleMaxY = _vm->_playFieldHeight << 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load cells
|
|
|
|
_vm->loadCells(roomInfo._cells);
|
|
|
|
|
|
|
|
// Load script data
|
|
|
|
_vm->_scripts->freeScriptData();
|
|
|
|
if (roomInfo._scriptFile._fileNum != -1)
|
|
|
|
_vm->_scripts->_script = _vm->_files->loadFile(roomInfo._scriptFile._fileNum,
|
|
|
|
roomInfo._scriptFile._subfile);
|
|
|
|
|
|
|
|
// Load animation data
|
|
|
|
_vm->freeAnimationData();
|
|
|
|
if (roomInfo._animFile._fileNum != -1)
|
|
|
|
_vm->_anim = _vm->_files->loadFile(roomInfo._animFile._fileNum,
|
|
|
|
roomInfo._animFile._subfile);
|
|
|
|
|
|
|
|
_vm->_scaleI = roomInfo._scaleI;
|
|
|
|
_vm->_screen->_scrollThreshold = roomInfo._scrollThreshold;
|
|
|
|
|
2014-08-07 20:31:42 -04:00
|
|
|
// Handle loading scene palette data
|
|
|
|
if (roomInfo._paletteFile._fileNum != -1) {
|
|
|
|
_vm->_screen->_startColor = roomInfo._startColor;
|
|
|
|
_vm->_screen->_numColors = roomInfo._numColors;
|
|
|
|
_vm->_screen->loadPalette(roomInfo._paletteFile._fileNum,
|
|
|
|
roomInfo._paletteFile._subfile);
|
|
|
|
}
|
2014-08-06 22:43:40 -04:00
|
|
|
|
|
|
|
// Load extra cells
|
|
|
|
_vm->_extraCells.clear();
|
|
|
|
for (uint i = 0; i < roomInfo._vidTable.size(); ++i) {
|
|
|
|
ExtraCell ec;
|
|
|
|
ec._vidTable = roomInfo._vidTable[i] & 0xffff;
|
|
|
|
ec._vidTable1 = roomInfo._vidTable[i] >> 16;
|
|
|
|
|
|
|
|
_vm->_extraCells.push_back(ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load sounds for the scene
|
|
|
|
_vm->_sound->loadSounds(roomInfo._sounds);
|
2014-08-05 23:23:49 -04:00
|
|
|
}
|
|
|
|
|
2014-08-05 22:17:30 -04:00
|
|
|
void Room::roomLoop() {
|
2014-08-07 09:23:31 -04:00
|
|
|
_vm->_scripts->_sequence = 2000;
|
|
|
|
_vm->_scripts->searchForSeq();
|
|
|
|
_vm->_scripts->executeCommand();
|
2014-08-05 22:17:30 -04:00
|
|
|
}
|
|
|
|
|
2014-08-05 23:23:49 -04:00
|
|
|
void Room::setupRoom() {
|
2014-08-07 09:23:31 -04:00
|
|
|
_vm->_screen->setScaleTable(_vm->_scale);
|
|
|
|
_vm->_screen->setBufferScan();
|
|
|
|
|
|
|
|
if (_roomFlag != 2)
|
|
|
|
setIconPalette();
|
|
|
|
|
2014-08-07 21:59:45 -04:00
|
|
|
if (_vm->_screen->_vWindowSize.x == _playFieldSize.x) {
|
2014-08-07 09:23:31 -04:00
|
|
|
_vm->_screen->_scrollX = 0;
|
|
|
|
_vm->_screen->_scrollCol = 0;
|
|
|
|
} else {
|
|
|
|
_vm->_screen->_scrollX = _vm->_player->_rawPlayer.x -
|
|
|
|
(_vm->_player->_rawPlayer.x >> 4);
|
|
|
|
int xp = MAX((_vm->_player->_rawPlayer.x >> 4) -
|
|
|
|
(_vm->_screen->_vWindowSize.x / 2), 0);
|
|
|
|
_vm->_screen->_scrollCol = xp;
|
|
|
|
|
2014-08-07 21:59:45 -04:00
|
|
|
xp = xp + _vm->_screen->_vWindowSize.x - _playFieldSize.x;
|
2014-08-07 09:23:31 -04:00
|
|
|
if (xp >= 0) {
|
|
|
|
_vm->_screen->_scrollCol = xp + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-07 21:59:45 -04:00
|
|
|
if (_vm->_screen->_vWindowSize.y == _playFieldSize.y) {
|
2014-08-07 09:23:31 -04:00
|
|
|
_vm->_screen->_scrollY = 0;
|
|
|
|
_vm->_screen->_scrollRow = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
_vm->_screen->_scrollY = _vm->_player->_rawPlayer.y -
|
|
|
|
(_vm->_player->_rawPlayer.y >> 4);
|
|
|
|
int yp = MAX((_vm->_player->_rawPlayer.y >> 4) -
|
|
|
|
(_vm->_screen->_vWindowSize.y / 2), 0);
|
|
|
|
_vm->_screen->_scrollRow = yp;
|
|
|
|
|
2014-08-07 21:59:45 -04:00
|
|
|
yp = yp + _vm->_screen->_vWindowSize.y - _playFieldSize.y;
|
2014-08-07 09:23:31 -04:00
|
|
|
if (yp >= 0) {
|
|
|
|
_vm->_screen->_scrollRow = yp + 1;
|
|
|
|
}
|
|
|
|
}
|
2014-08-05 23:23:49 -04:00
|
|
|
}
|
2014-08-05 22:17:30 -04:00
|
|
|
|
2014-08-05 23:23:49 -04:00
|
|
|
void Room::setWallCodes() {
|
2014-08-07 21:54:22 -04:00
|
|
|
_jetFrame.clear();
|
|
|
|
_jetFrame.resize(_plotter._walls.size());
|
|
|
|
|
|
|
|
_vm->_player->_rawXTemp = _vm->_player->_rawPlayer.x;
|
|
|
|
_vm->_player->_rawYTemp = _vm->_player->_rawPlayer.y;
|
2014-08-05 22:17:30 -04:00
|
|
|
}
|
|
|
|
|
2014-08-05 23:23:49 -04:00
|
|
|
void Room::buildScreen() {
|
2014-08-07 21:54:22 -04:00
|
|
|
int scrollCol = _vm->_screen->_scrollCol;
|
|
|
|
int cnt = _vm->_screen->_vWindowSize.x + 1;
|
|
|
|
int offset = 0;
|
|
|
|
|
|
|
|
for (int idx = 0; idx < cnt, offset += TILE_WIDTH; ++idx) {
|
|
|
|
buildColumn(_vm->_screen->_scrollCol, offset);
|
|
|
|
++_vm->_screen->_scrollCol;
|
|
|
|
}
|
|
|
|
|
|
|
|
_vm->_screen->_scrollCol = scrollCol;
|
|
|
|
_vm->_screen->copyBF1BF2();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Room::buildColumn(int playX, int screenX) {
|
2014-08-07 21:59:45 -04:00
|
|
|
const byte *pSrc = _playField + _vm->_screen->_scrollRow *
|
|
|
|
_playFieldSize.x + playX;
|
2014-08-07 21:54:22 -04:00
|
|
|
byte *pDest = (byte *)_vm->_buffer1.getPixels();
|
|
|
|
|
|
|
|
for (int y = 0; y <= _vm->_screen->_vWindowSize.y; ++y) {
|
2014-08-07 21:59:45 -04:00
|
|
|
byte *pTile = _tile + (*pSrc << 8);
|
2014-08-07 21:54:22 -04:00
|
|
|
|
|
|
|
for (int tileY = 0; tileY < TILE_HEIGHT; ++tileY) {
|
|
|
|
Common::copy(pTile, pTile + TILE_WIDTH, pDest);
|
|
|
|
pDest += _vm->_screen->_vWindowSize.x;
|
|
|
|
}
|
|
|
|
}
|
2014-08-05 23:23:49 -04:00
|
|
|
}
|
2014-08-05 22:17:30 -04:00
|
|
|
|
2014-08-06 22:43:40 -04:00
|
|
|
/*------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
RoomInfo::RoomInfo(const byte *data) {
|
|
|
|
Common::MemoryReadStream stream(data, 999);
|
|
|
|
|
2014-08-07 20:31:42 -04:00
|
|
|
_roomFlag = stream.readByte();
|
2014-08-06 22:43:40 -04:00
|
|
|
_estIndex = (int16)stream.readUint16LE();
|
|
|
|
_musicFile._fileNum = (int16)stream.readUint16LE();
|
|
|
|
_musicFile._subfile = stream.readUint16LE();
|
|
|
|
_scaleH1 = stream.readByte();
|
|
|
|
_scaleH2 = stream.readByte();
|
|
|
|
_scaleN1 = stream.readByte();
|
|
|
|
_playFieldFile._fileNum = (int16)stream.readUint16LE();
|
|
|
|
_playFieldFile._subfile = stream.readUint16LE();
|
|
|
|
|
|
|
|
for (byte cell = stream.readByte(); cell != 0xff; cell = stream.readByte()) {
|
|
|
|
CellIdent ci;
|
|
|
|
ci._cell = cell;
|
|
|
|
ci._fileNum = (int16)stream.readUint16LE();
|
|
|
|
ci._subfile = stream.readUint16LE();
|
|
|
|
|
|
|
|
_cells.push_back(ci);
|
|
|
|
}
|
|
|
|
|
|
|
|
_scriptFile._fileNum = (int16)stream.readUint16LE();
|
|
|
|
_scriptFile._subfile = stream.readUint16LE();
|
|
|
|
_animFile._fileNum = (int16)stream.readUint16LE();
|
|
|
|
_animFile._subfile = stream.readUint16LE();
|
|
|
|
_scaleI = stream.readByte();
|
|
|
|
_scrollThreshold = stream.readByte();
|
|
|
|
_paletteFile._fileNum = (int16)stream.readUint16LE();
|
|
|
|
_paletteFile._subfile = stream.readUint16LE();
|
2014-08-07 20:31:42 -04:00
|
|
|
if (_paletteFile._fileNum == -1) {
|
|
|
|
_startColor = _numColors = 0;
|
|
|
|
} else {
|
|
|
|
_startColor = stream.readUint16LE();
|
|
|
|
_numColors = stream.readUint16LE();
|
|
|
|
}
|
2014-08-06 22:43:40 -04:00
|
|
|
|
|
|
|
for (int16 v = (int16)stream.readUint16LE(); v != -1;
|
|
|
|
v = (int16)stream.readUint16LE()) {
|
|
|
|
uint16 v2 = stream.readUint16LE();
|
|
|
|
|
|
|
|
_vidTable.push_back(v | ((uint32)v2 << 16));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int16 fileNum = (int16)stream.readUint16LE(); fileNum != -1;
|
|
|
|
fileNum = (int16)stream.readUint16LE()) {
|
2014-08-07 20:31:42 -04:00
|
|
|
SoundIdent fi;
|
2014-08-06 22:43:40 -04:00
|
|
|
fi._fileNum = fileNum;
|
|
|
|
fi._subfile = stream.readUint16LE();
|
2014-08-07 20:31:42 -04:00
|
|
|
fi._priority = stream.readUint16LE();
|
2014-08-06 22:43:40 -04:00
|
|
|
|
|
|
|
_sounds.push_back(fi);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-08-05 22:17:30 -04:00
|
|
|
} // End of namespace Access
|