diff options
-rw-r--r-- | gob/anim.cpp | 12 | ||||
-rw-r--r-- | gob/anim.h | 15 | ||||
-rw-r--r-- | gob/cdrom.cpp | 119 | ||||
-rw-r--r-- | gob/cdrom.h | 39 | ||||
-rw-r--r-- | gob/dataio.cpp | 187 | ||||
-rw-r--r-- | gob/dataio.h | 56 | ||||
-rw-r--r-- | gob/draw.cpp | 981 | ||||
-rw-r--r-- | gob/draw.h | 164 | ||||
-rw-r--r-- | gob/driver_vga.cpp | 14 | ||||
-rw-r--r-- | gob/driver_vga.h | 14 | ||||
-rw-r--r-- | gob/game.cpp | 1491 | ||||
-rw-r--r-- | gob/game.h | 269 | ||||
-rw-r--r-- | gob/global.cpp | 255 | ||||
-rw-r--r-- | gob/global.h | 177 | ||||
-rw-r--r-- | gob/gob.cpp | 137 | ||||
-rw-r--r-- | gob/gob.h | 51 | ||||
-rw-r--r-- | gob/goblin.cpp | 2696 | ||||
-rw-r--r-- | gob/goblin.h | 354 | ||||
-rw-r--r-- | gob/init.cpp | 247 | ||||
-rw-r--r-- | gob/init.h | 18 | ||||
-rw-r--r-- | gob/inter.cpp | 1162 | ||||
-rw-r--r-- | gob/inter.h | 142 | ||||
-rw-r--r-- | gob/map.cpp | 522 | ||||
-rw-r--r-- | gob/map.h | 111 | ||||
-rw-r--r-- | gob/mult.cpp | 1188 | ||||
-rw-r--r-- | gob/mult.h | 327 | ||||
-rw-r--r-- | gob/pack.cpp | 2 | ||||
-rw-r--r-- | gob/pack.h | 7 | ||||
-rw-r--r-- | gob/palanim.cpp | 189 | ||||
-rw-r--r-- | gob/palanim.h | 19 | ||||
-rw-r--r-- | gob/parse.cpp | 373 | ||||
-rw-r--r-- | gob/parse.h | 29 | ||||
-rw-r--r-- | gob/scenery.cpp | 620 | ||||
-rw-r--r-- | gob/scenery.h | 214 | ||||
-rw-r--r-- | gob/sound.cpp | 107 | ||||
-rw-r--r-- | gob/sound.h | 109 | ||||
-rw-r--r-- | gob/timer.cpp | 10 | ||||
-rw-r--r-- | gob/timer.h | 19 | ||||
-rw-r--r-- | gob/util.cpp | 200 | ||||
-rw-r--r-- | gob/util.h | 125 | ||||
-rw-r--r-- | gob/video.cpp | 162 | ||||
-rw-r--r-- | gob/video.h | 166 |
42 files changed, 6743 insertions, 6356 deletions
diff --git a/gob/anim.cpp b/gob/anim.cpp index 7524ca91f8..3d3fd4ab74 100644 --- a/gob/anim.cpp +++ b/gob/anim.cpp @@ -25,10 +25,12 @@ namespace Gob { -int16 anim_animAreaLeft; -int16 anim_animAreaTop; -int16 anim_animAreaWidth; -int16 anim_animAreaHeight; -SurfaceDesc *anim_underAnimSurf = 0; +Anim::Anim() { + _areaLeft = 0; + _areaTop = 0; + _areaWidth = 0; + _areaHeight = 0; + _animSurf = 0; +} } // End of namespace Gob diff --git a/gob/anim.h b/gob/anim.h index 2557e7d0ba..741816a710 100644 --- a/gob/anim.h +++ b/gob/anim.h @@ -24,11 +24,16 @@ namespace Gob { -extern int16 anim_animAreaLeft; -extern int16 anim_animAreaTop; -extern int16 anim_animAreaWidth; -extern int16 anim_animAreaHeight; -extern SurfaceDesc *anim_underAnimSurf; +class Anim { +public: + int16 _areaLeft; + int16 _areaTop; + int16 _areaWidth; + int16 _areaHeight; + Video::SurfaceDesc *_animSurf; + + Anim(); +}; } // End of namespace Gob diff --git a/gob/cdrom.cpp b/gob/cdrom.cpp index 6a8ae1a4b7..ed05812c87 100644 --- a/gob/cdrom.cpp +++ b/gob/cdrom.cpp @@ -28,73 +28,76 @@ namespace Gob { -byte *cd_LICbuffer; -char cd_curTrack[16]; -uint16 cd_numTracks; -bool cd_globFlag; -uint32 cd_trackStop; -uint32 cd_startTime; - -void cd_readLIC(const char *fname) { +CDROM::CDROM(GobEngine *vm) : _vm(vm) { + _cdPlaying = false; + _LICbuffer = 0; + for (int i = 0; i < 16; i++) + _curTrack[i] = 0; + _numTracks = 0; + _trackStop = 0; + _startTime = 0; +} + +void CDROM::readLIC(const char *fname) { char tmp[80]; int handle; uint16 version, startChunk, pos; - cd_freeLICbuffer(); + freeLICbuffer(); - *cd_curTrack = 0; + *_curTrack = 0; strcpy(tmp, fname); - handle = data_openData(tmp); + handle = _vm->_dataio->openData(tmp); if (handle == -1) return; - data_closeData(handle); + _vm->_dataio->closeData(handle); - data_getUnpackedData(tmp); + _vm->_dataio->getUnpackedData(tmp); - handle = data_openData(tmp); + handle = _vm->_dataio->openData(tmp); - data_readData(handle, (char *)&version, 2); + _vm->_dataio->readData(handle, (char *)&version, 2); version = READ_LE_UINT16(&version); - data_readData(handle, (char *)&startChunk, 2); + _vm->_dataio->readData(handle, (char *)&startChunk, 2); startChunk = READ_LE_UINT16(&startChunk); - data_readData(handle, (char *)&cd_numTracks, 2); - cd_numTracks = READ_LE_UINT16(&cd_numTracks); + _vm->_dataio->readData(handle, (char *)&_numTracks, 2); + _numTracks = READ_LE_UINT16(&_numTracks); if (version != 3) { error("Wrong file %s (%d)", fname, version); return; } - data_seekData(handle, 50, SEEK_SET); + _vm->_dataio->seekData(handle, 50, SEEK_SET); for (int i = 0; i < startChunk; i++) { - data_readData(handle, (char *)&pos, 2); + _vm->_dataio->readData(handle, (char *)&pos, 2); pos = READ_LE_UINT16(&pos); if (!pos) break; - data_seekData(handle, pos, SEEK_CUR); + _vm->_dataio->seekData(handle, pos, SEEK_CUR); } - cd_LICbuffer = (byte *)malloc(cd_numTracks * 22); - data_readData(handle, (char *)cd_LICbuffer, cd_numTracks * 22); + _LICbuffer = (byte *)malloc(_numTracks * 22); + _vm->_dataio->readData(handle, (char *)_LICbuffer, _numTracks * 22); - data_closeData(handle); + _vm->_dataio->closeData(handle); } -void cd_freeLICbuffer(void) { - free(cd_LICbuffer); - cd_LICbuffer = 0; +void CDROM::freeLICbuffer(void) { + free(_LICbuffer); + _LICbuffer = 0; } -void cd_playBgMusic() { +void CDROM::playBgMusic() { static const char *tracks[][2] = { {"avt00.tot", "mine"}, {"avt001.tot", "nuit"}, @@ -121,13 +124,13 @@ void cd_playBgMusic() { }; for (int i = 0; i < ARRAYSIZE(tracks); i++) - if (!scumm_stricmp(game_curTotFile, tracks[i][0])) { - cd_startTrack(tracks[i][1]); + if (!scumm_stricmp(_vm->_game->curTotFile, tracks[i][0])) { + startTrack(tracks[i][1]); break; } } -void cd_playMultMusic() { +void CDROM::playMultMusic() { static const char *tracks[][6] = { {"avt005.tot", "fra1", "all1", "ang1", "esp1", "ita1"}, {"avt006.tot", "fra2", "all2", "ang2", "esp2", "ita2"}, @@ -138,25 +141,25 @@ void cd_playMultMusic() { }; for (int i = 0; i < ARRAYSIZE(tracks); i++) - if (!scumm_stricmp(game_curTotFile, tracks[i][0])) { - cd_globFlag = true; - cd_startTrack(tracks[i][language + 1]); + if (!scumm_stricmp(_vm->_game->curTotFile, tracks[i][0])) { + _cdPlaying = true; + startTrack(tracks[i][_vm->_global->language + 1]); break; } } -void cd_startTrack(const char *trackname) { +void CDROM::startTrack(const char *trackname) { byte *curPtr, *matchPtr; - if (!cd_LICbuffer) + if (!_LICbuffer) return; - debug(3, "cd_startTrack(%s)", trackname); + debug(3, "startTrack(%s)", trackname); matchPtr = 0; - curPtr = cd_LICbuffer; + curPtr = _LICbuffer; - for (int i = 0; i < cd_numTracks; i++) { + for (int i = 0; i < _numTracks; i++) { if (!scumm_stricmp((char *)curPtr, trackname)) { matchPtr = curPtr; break; @@ -169,64 +172,64 @@ void cd_startTrack(const char *trackname) { return; } - strcpy(cd_curTrack, trackname); + strcpy(_curTrack, trackname); - cd_stopPlaying(); + stopPlaying(); - while (cd_getTrackPos() != -1); + while (getTrackPos() != -1); uint32 start, end; start = READ_LE_UINT32(matchPtr + 12); end = READ_LE_UINT32(matchPtr + 16); - cd_play(start, end); + play(start, end); - cd_startTime = util_getTimeKey(); - cd_trackStop = cd_startTime + (end - start + 1 + 150) * 40 / 3; + _startTime = _vm->_util->getTimeKey(); + _trackStop = _startTime + (end - start + 1 + 150) * 40 / 3; } -void cd_play(uint32 from, uint32 to) { +void CDROM::play(uint32 from, uint32 to) { // play from sector [from] to sector [to] // // format is HSG: // HSG encodes frame information into a double word: // minute multiplied by 4500, plus second multiplied by 75, // plus frame, minus 150 - debug(3, "cd_play(%d, %d)", from, to); + debug(3, "play(%d, %d)", from, to); AudioCD.play(1, 0, from, to - from + 1); } -int32 cd_getTrackPos(void) { - uint32 curPos = util_getTimeKey() - cd_startTime; +int32 CDROM::getTrackPos(void) { + uint32 curPos = _vm->_util->getTimeKey() - _startTime; - if (AudioCD.isPlaying() && (util_getTimeKey() < cd_trackStop)) + if (AudioCD.isPlaying() && (_vm->_util->getTimeKey() < _trackStop)) return curPos * 3 / 40; else return -1; } -void cd_stopPlaying(void) { - cd_stop(); +void CDROM::stopPlaying(void) { + stop(); - while (cd_getTrackPos() != -1); + while (getTrackPos() != -1); } -void cd_stop(void) { - debug(3, "cd_stop()"); +void CDROM::stop(void) { + debug(3, "stop()"); AudioCD.stop(); } -void cd_testCD(int trySubst, const char *label) { +void CDROM::testCD(int trySubst, const char *label) { if (!trySubst) { error("CDROM track substitution is not supported"); return; } - cd_LICbuffer = 0; - cd_globFlag = false; + _LICbuffer = 0; + _cdPlaying = false; // Original checked CD label here // but will skip it as it will require OSystem extensions of direct diff --git a/gob/cdrom.h b/gob/cdrom.h index 48a693e135..110e053bd7 100644 --- a/gob/cdrom.h +++ b/gob/cdrom.h @@ -22,18 +22,31 @@ namespace Gob { -extern bool cd_globFlag; - -void cd_readLIC(const char *fname); -void cd_freeLICbuffer(void); - -void cd_startTrack(const char *s); -void cd_playBgMusic(); -void cd_playMultMusic(); -void cd_play(uint32 from, uint32 to); -int32 cd_getTrackPos(void); -void cd_stopPlaying(void); -void cd_stop(void); -void cd_testCD(int trySubst, const char *label); +class CDROM { +public: + bool _cdPlaying; + + void readLIC(const char *fname); + void freeLICbuffer(void); + + void startTrack(const char *s); + void playBgMusic(); + void playMultMusic(); + void play(uint32 from, uint32 to); + int32 getTrackPos(void); + void stopPlaying(void); + void stop(void); + void testCD(int trySubst, const char *label); + + CDROM(GobEngine *vm); + +protected: + byte *_LICbuffer; + char _curTrack[16]; + uint16 _numTracks; + uint32 _trackStop; + uint32 _startTime; + GobEngine *_vm; +}; } // End of namespace Gob diff --git a/gob/dataio.cpp b/gob/dataio.cpp index 809bce42e7..e0743566d4 100644 --- a/gob/dataio.cpp +++ b/gob/dataio.cpp @@ -26,11 +26,14 @@ namespace Gob { -Common::File *file_getHandle(int16 handle) { - return &filesHandles[handle]; +DataIO::DataIO(GobEngine *vm) : _vm(vm) { } -int16 file_open(const char *path, Common::File::AccessMode mode) { +Common::File *DataIO::file_getHandle(int16 handle) { + return &_vm->_global->filesHandles[handle]; +} + +int16 DataIO::file_open(const char *path, Common::File::AccessMode mode) { int16 i; for (i = 0; i < MAX_FILES; i++) { @@ -48,51 +51,51 @@ int16 file_open(const char *path, Common::File::AccessMode mode) { return -1; } -int16 data_getChunk(const char *chunkName) { +int16 DataIO::getChunk(const char *chunkName) { int16 file; int16 slot; int16 chunk; struct ChunkDesc *dataDesc; for (file = 0; file < MAX_DATA_FILES; file++) { - if (dataFiles[file] == 0) + if (_vm->_global->dataFiles[file] == 0) return -1; for (slot = 0; slot < MAX_SLOT_COUNT; slot++) - if (chunkPos[file * MAX_SLOT_COUNT + slot] == -1) + if (_vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] == -1) break; if (slot == MAX_SLOT_COUNT) return -1; - dataDesc = dataFiles[file]; - for (chunk = 0; chunk < numDataChunks[file]; + dataDesc = _vm->_global->dataFiles[file]; + for (chunk = 0; chunk < _vm->_global->numDataChunks[file]; chunk++, dataDesc++) { if (scumm_stricmp(chunkName, dataDesc->chunkName) != 0) continue; - isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 0; - chunkSize[file * MAX_SLOT_COUNT + slot] = + _vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 0; + _vm->_global->chunkSize[file * MAX_SLOT_COUNT + slot] = dataDesc->size; - chunkOffset[file * MAX_SLOT_COUNT + slot] = + _vm->_global->chunkOffset[file * MAX_SLOT_COUNT + slot] = dataDesc->offset; - chunkPos[file * MAX_SLOT_COUNT + slot] = 0; + _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] = 0; return file * 10 + slot + 50; } } return -1; } -char data_freeChunk(int16 handle) { +char DataIO::freeChunk(int16 handle) { if (handle >= 50 && handle < 100) { handle -= 50; - chunkPos[(handle / 10) * MAX_SLOT_COUNT + (handle % 10)] = -1; + _vm->_global->chunkPos[(handle / 10) * MAX_SLOT_COUNT + (handle % 10)] = -1; return 0; } return 1; } -int32 data_readChunk(int16 handle, char *buf, int16 size) { +int32 DataIO::readChunk(int16 handle, char *buf, int16 size) { int16 file; int16 slot; int16 i; @@ -103,30 +106,30 @@ int32 data_readChunk(int16 handle, char *buf, int16 size) { file = (handle - 50) / 10; slot = (handle - 50) % 10; - if (isCurrentSlot[file * MAX_SLOT_COUNT + slot] == 0) { + if (_vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + slot] == 0) { for (i = 0; i < MAX_SLOT_COUNT; i++) - isCurrentSlot[file * MAX_SLOT_COUNT + i] = 0; + _vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + i] = 0; offset = - chunkOffset[file * MAX_SLOT_COUNT + slot] + - chunkPos[file * MAX_SLOT_COUNT + slot]; - debug(7, "seek: %ld, %ld", chunkOffset[file * MAX_SLOT_COUNT + slot], chunkPos[file * MAX_SLOT_COUNT + slot]); - file_getHandle(dataFileHandles[file])->seek(offset, SEEK_SET); + _vm->_global->chunkOffset[file * MAX_SLOT_COUNT + slot] + + _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot]; + debug(7, "seek: %ld, %ld", _vm->_global->chunkOffset[file * MAX_SLOT_COUNT + slot], _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot]); + file_getHandle(_vm->_global->dataFileHandles[file])->seek(offset, SEEK_SET); } - isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 1; - if (chunkPos[file * MAX_SLOT_COUNT + slot] + size > - chunkSize[file * MAX_SLOT_COUNT + slot]) + _vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 1; + if (_vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] + size > + _vm->_global->chunkSize[file * MAX_SLOT_COUNT + slot]) size = - chunkSize[file * MAX_SLOT_COUNT + slot] - - chunkPos[file * MAX_SLOT_COUNT + slot]; + _vm->_global->chunkSize[file * MAX_SLOT_COUNT + slot] - + _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot]; - file_getHandle(dataFileHandles[file])->read(buf, size); - chunkPos[file * MAX_SLOT_COUNT + slot] += size; + file_getHandle(_vm->_global->dataFileHandles[file])->read(buf, size); + _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] += size; return size; } -int16 data_seekChunk(int16 handle, int32 pos, int16 from) { +int16 DataIO::seekChunk(int16 handle, int32 pos, int16 from) { int16 file; int16 slot; @@ -135,16 +138,16 @@ int16 data_seekChunk(int16 handle, int32 pos, int16 from) { file = (handle - 50) / 10; slot = (handle - 50) % 10; - isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 0; + _vm->_global->isCurrentSlot[file * MAX_SLOT_COUNT + slot] = 0; if (from == SEEK_SET) - chunkPos[file * MAX_SLOT_COUNT + slot] = pos; + _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] = pos; else - chunkPos[file * MAX_SLOT_COUNT + slot] += pos; + _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot] += pos; - return chunkPos[file * MAX_SLOT_COUNT + slot]; + return _vm->_global->chunkPos[file * MAX_SLOT_COUNT + slot]; } -int32 data_getChunkSize(const char *chunkName) { +int32 DataIO::getChunkSize(const char *chunkName) { int16 file; int16 chunk; struct ChunkDesc *dataDesc; @@ -152,33 +155,33 @@ int32 data_getChunkSize(const char *chunkName) { int32 realSize; for (file = 0; file < MAX_DATA_FILES; file++) { - if (dataFiles[file] == 0) + if (_vm->_global->dataFiles[file] == 0) return -1; - dataDesc = dataFiles[file]; - for (chunk = 0; chunk < numDataChunks[file]; + dataDesc = _vm->_global->dataFiles[file]; + for (chunk = 0; chunk < _vm->_global->numDataChunks[file]; chunk++, dataDesc++) { if (scumm_stricmp(chunkName, dataDesc->chunkName) != 0) continue; if (dataDesc->packed == 0) { - packedSize = -1; + _vm->_global->packedSize = -1; return dataDesc->size; } for (slot = 0; slot < MAX_SLOT_COUNT; slot++) - isCurrentSlot[slot] = 0; + _vm->_global->isCurrentSlot[slot] = 0; - file_getHandle(dataFileHandles[file])->seek(dataDesc->offset, SEEK_SET); - realSize = file_getHandle(dataFileHandles[file])->readUint32LE(); - packedSize = dataDesc->size; + file_getHandle(_vm->_global->dataFileHandles[file])->seek(dataDesc->offset, SEEK_SET); + realSize = file_getHandle(_vm->_global->dataFileHandles[file])->readUint32LE(); + _vm->_global->packedSize = dataDesc->size; return realSize; } } return -1; } -void data_openDataFile(const char *src) { +void DataIO::openDataFile(const char *src) { char path[128]; int16 i; int16 file; @@ -190,52 +193,52 @@ void data_openDataFile(const char *src) { strcat(path, ".stk"); for (file = 0; file < MAX_DATA_FILES; file++) - if (dataFiles[file] == 0) + if (_vm->_global->dataFiles[file] == 0) break; if (file == MAX_DATA_FILES) - error("data_dataFileOpen: Data file slots are full\n"); - dataFileHandles[file] = file_open(path); + error("dataFileOpen: Data file slots are full\n"); + _vm->_global->dataFileHandles[file] = file_open(path); - if (dataFileHandles[file] == -1) - error("data_dataFileOpen: Can't open %s data file\n", path); + if (_vm->_global->dataFileHandles[file] == -1) + error("dataFileOpen: Can't open %s data file\n", path); - numDataChunks[file] = file_getHandle(dataFileHandles[file])->readUint16LE(); + _vm->_global->numDataChunks[file] = file_getHandle(_vm->_global->dataFileHandles[file])->readUint16LE(); - debug(7, "DataChunks: %d [for %s]", numDataChunks[file], path); + debug(7, "DataChunks: %d [for %s]", _vm->_global->numDataChunks[file], path); - dataFiles[file] = dataDesc = + _vm->_global->dataFiles[file] = dataDesc = (struct ChunkDesc *)malloc(sizeof(struct ChunkDesc) * - numDataChunks[file]); + _vm->_global->numDataChunks[file]); - for (i = 0; i < numDataChunks[file]; i++) { - file_getHandle(dataFileHandles[file])->read(dataDesc[i].chunkName, 13); - dataDesc[i].size = file_getHandle(dataFileHandles[file])->readUint32LE(); - dataDesc[i].offset = file_getHandle(dataFileHandles[file])->readUint32LE(); - dataDesc[i].packed = file_getHandle(dataFileHandles[file])->readByte(); + for (i = 0; i < _vm->_global->numDataChunks[file]; i++) { + file_getHandle(_vm->_global->dataFileHandles[file])->read(dataDesc[i].chunkName, 13); + dataDesc[i].size = file_getHandle(_vm->_global->dataFileHandles[file])->readUint32LE(); + dataDesc[i].offset = file_getHandle(_vm->_global->dataFileHandles[file])->readUint32LE(); + dataDesc[i].packed = file_getHandle(_vm->_global->dataFileHandles[file])->readByte(); } - for (i = 0; i < numDataChunks[file]; i++) + for (i = 0; i < _vm->_global->numDataChunks[file]; i++) debug(7, "%d: %s %d", i, dataDesc[i].chunkName, dataDesc[i].size); for (i = 0; i < MAX_SLOT_COUNT; i++) - chunkPos[file * MAX_SLOT_COUNT + i] = -1; + _vm->_global->chunkPos[file * MAX_SLOT_COUNT + i] = -1; } -void data_closeDataFile() { +void DataIO::closeDataFile() { int16 file; for (file = MAX_DATA_FILES - 1; file >= 0; file--) { - if (dataFiles[file] != 0) { - free(dataFiles[file]); - dataFiles[file] = 0; - file_getHandle(dataFileHandles[file])->close(); + if (_vm->_global->dataFiles[file] != 0) { + free(_vm->_global->dataFiles[file]); + _vm->_global->dataFiles[file] = 0; + file_getHandle(_vm->_global->dataFileHandles[file])->close(); return; } } } -char *data_getUnpackedData(const char *name) { +char *DataIO::getUnpackedData(const char *name) { int32 realSize; int16 chunk; char *unpackBuf; @@ -243,11 +246,11 @@ char *data_getUnpackedData(const char *name) { char *ptr; int32 sizeLeft; - realSize = data_getChunkSize(name); - if (packedSize == -1 || realSize == -1) + realSize = getChunkSize(name); + if (_vm->_global->packedSize == -1 || realSize == -1) return 0; - chunk = data_getChunk(name); + chunk = getChunk(name); if (chunk == -1) return 0; @@ -255,76 +258,76 @@ char *data_getUnpackedData(const char *name) { if (unpackBuf == 0) return 0; - packBuf = (char *)malloc(packedSize); + packBuf = (char *)malloc(_vm->_global->packedSize); if (packBuf == 0) { free(unpackBuf); return 0; } - sizeLeft = packedSize; + sizeLeft = _vm->_global->packedSize; ptr = packBuf; while (sizeLeft > 0x4000) { - data_readChunk(chunk, ptr, 0x4000); + readChunk(chunk, ptr, 0x4000); sizeLeft -= 0x4000; ptr += 0x4000; } - data_readChunk(chunk, ptr, sizeLeft); - data_freeChunk(chunk); - unpackData(packBuf, unpackBuf); + readChunk(chunk, ptr, sizeLeft); + freeChunk(chunk); + _vm->_pack->unpackData(packBuf, unpackBuf); free(packBuf); return unpackBuf; } -void data_closeData(int16 handle) { - if (data_freeChunk(handle) != 0) +void DataIO::closeData(int16 handle) { + if (freeChunk(handle) != 0) file_getHandle(handle)->close(); } -int16 data_openData(const char *path, Common::File::AccessMode mode) { +int16 DataIO::openData(const char *path, Common::File::AccessMode mode) { int16 handle; if (mode != Common::File::kFileReadMode) return file_open(path, mode); - handle = data_getChunk(path); + handle = getChunk(path); if (handle >= 0) return handle; return file_open(path, mode); } -int32 data_readData(int16 handle, char *buf, int16 size) { +int32 DataIO::readData(int16 handle, char *buf, int16 size) { int32 res; - res = data_readChunk(handle, buf, size); + res = readChunk(handle, buf, size); if (res >= 0) return res; return file_getHandle(handle)->read(buf, size); } -void data_seekData(int16 handle, int32 pos, int16 from) { +void DataIO::seekData(int16 handle, int32 pos, int16 from) { int32 resPos; - resPos = data_seekChunk(handle, pos, from); + resPos = seekChunk(handle, pos, from); if (resPos != -1) return; file_getHandle(handle)->seek(pos, from); } -int32 data_getDataSize(const char *name) { +int32 DataIO::getDataSize(const char *name) { char buf[128]; int32 chunkSz; Common::File file; strcpy(buf, name); - chunkSz = data_getChunkSize(buf); + chunkSz = getChunkSize(buf); if (chunkSz >= 0) return chunkSz; if (!file.open(buf)) - error("data_getDataSize: Can't find data(%s)", name); + error("getDataSize: Can't find data(%s)", name); chunkSz = file.size(); file.close(); @@ -332,31 +335,31 @@ int32 data_getDataSize(const char *name) { return chunkSz; } -char *data_getData(const char *path) { +char *DataIO::getData(const char *path) { char *data; char *ptr; int32 size; int16 handle; - data = data_getUnpackedData(path); + data = getUnpackedData(path); if (data != 0) return data; - size = data_getDataSize(path); + size = getDataSize(path); data = (char *)malloc(size); if (data == 0) return 0; - handle = data_openData(path); + handle = openData(path); ptr = data; while (size > 0x4000) { - data_readData(handle, ptr, 0x4000); + readData(handle, ptr, 0x4000); size -= 0x4000; ptr += 0x4000; } - data_readData(handle, ptr, size); - data_closeData(handle); + readData(handle, ptr, size); + closeData(handle); return data; } diff --git a/gob/dataio.h b/gob/dataio.h index 15b33d55b8..48ac485c01 100644 --- a/gob/dataio.h +++ b/gob/dataio.h @@ -23,36 +23,46 @@ #define GOB_DATAIO_H #include "common/file.h" +#include "gob/gob.h" namespace Gob { #define MAX_DATA_FILES 3 #define MAX_SLOT_COUNT 4 -struct ChunkDesc { - char chunkName[13]; - uint32 size; - uint32 offset; - byte packed; -}; +class DataIO { +public: + struct ChunkDesc { + char chunkName[13]; + uint32 size; + uint32 offset; + byte packed; + ChunkDesc() : size(0), offset(0), packed(0) { chunkName[0] = 0; } + }; + + int16 file_open(const char *path, Common::File::AccessMode mode = Common::File::kFileReadMode); + Common::File *file_getHandle(int16 handle); + int16 getChunk(const char *chunkName); + char freeChunk(int16 handle); + int32 readChunk(int16 handle, char *buf, int16 size); + int16 seekChunk(int16 handle, int32 pos, int16 from); + int32 getChunkSize(const char *chunkName); + void openDataFile(const char *src); + void closeDataFile(void); + char *getUnpackedData(const char *name); + void closeData(int16 handle); + int16 openData(const char *path, Common::File::AccessMode mode = Common::File::kFileReadMode); + int32 readData(int16 handle, char *buf, int16 size); + void seekData(int16 handle, int32 pos, int16 from); + int32 getDataSize(const char *name); + char *getData(const char *path); + char *getSmallData(const char *path); -int16 file_open(const char *path, Common::File::AccessMode mode = Common::File::kFileReadMode); -Common::File *file_getHandle(int16 handle); -int16 data_getChunk(const char *chunkName); -char data_freeChunk(int16 handle); -int32 data_readChunk(int16 handle, char *buf, int16 size); -int16 data_seekChunk(int16 handle, int32 pos, int16 from); -int32 data_getChunkSize(const char *chunkName); -void data_openDataFile(const char *src); -void data_closeDataFile(void); -char *data_getUnpackedData(const char *name); -void data_closeData(int16 handle); -int16 data_openData(const char *path, Common::File::AccessMode mode = Common::File::kFileReadMode); -int32 data_readData(int16 handle, char *buf, int16 size); -void data_seekData(int16 handle, int32 pos, int16 from); -int32 data_getDataSize(const char *name); -char *data_getData(const char *path); -char *data_getSmallData(const char *path); + DataIO(class GobEngine *vm); + +protected: + class GobEngine *_vm; +}; } // End of namespace Gob diff --git a/gob/draw.cpp b/gob/draw.cpp index 4c7b592710..a894f8e1a7 100644 --- a/gob/draw.cpp +++ b/gob/draw.cpp @@ -33,72 +33,101 @@ namespace Gob { -int16 draw_fontIndex = 0; -int16 draw_spriteLeft = 0; -int16 draw_spriteTop = 0; -int16 draw_spriteRight = 0; -int16 draw_spriteBottom = 0; -int16 draw_destSpriteX = 0; -int16 draw_destSpriteY = 0; -int16 draw_backColor = 0; -int16 draw_frontColor = 0; -char draw_letterToPrint = 0; -Draw_FontToSprite draw_fontToSprite[4]; -int16 draw_destSurface = 0; -int16 draw_sourceSurface = 0; -int16 draw_renderFlags = 0; -int16 draw_backDeltaX = 0; -int16 draw_backDeltaY = 0; -FontDesc *draw_fonts[4]; -char *draw_textToPrint = 0; -int16 draw_transparency = 0; -SurfaceDesc *draw_spritesArray[50]; - -int16 draw_invalidatedCount; -int16 draw_invalidatedTops[30]; -int16 draw_invalidatedLefts[30]; -int16 draw_invalidatedRights[30]; -int16 draw_invalidatedBottoms[30]; - -int8 draw_noInvalidated = 0; -int8 draw_applyPal = 0; -int8 draw_paletteCleared = 0; - -SurfaceDesc *draw_backSurface = 0; -SurfaceDesc *draw_frontSurface = 0; - -int16 draw_unusedPalette1[18]; -int16 draw_unusedPalette2[16]; -Color draw_vgaPalette[256]; -Color draw_vgaSmallPalette[16]; - -int16 draw_cursorX = 0; -int16 draw_cursorY = 0; -int16 draw_cursorWidth = 0; -int16 draw_cursorHeight = 0; - -int16 draw_cursorXDeltaVar = -1; -int16 draw_cursorYDeltaVar = -1; - -int16 draw_cursorIndex = 0; -int16 draw_transparentCursor = 0; -SurfaceDesc *draw_cursorSprites = 0; -SurfaceDesc *draw_cursorBack = 0; -int16 draw_cursorAnim = 0; -int8 draw_cursorAnimLow[40]; -int8 draw_cursorAnimHigh[40]; -int8 draw_cursorAnimDelays[40]; -static uint32 draw_cursorTimeKey = 0; - -int16 draw_palLoadData1[] = { 0, 17, 34, 51 }; -int16 draw_palLoadData2[] = { 0, 68, 136, 204 }; - -void draw_invalidateRect(int16 left, int16 top, int16 right, int16 bottom) { +Draw::Draw(GobEngine *vm) : _vm(vm) { + fontIndex = 0; + spriteLeft = 0; + spriteTop = 0; + spriteRight = 0; + spriteBottom = 0; + destSpriteX = 0; + destSpriteY = 0; + backColor = 0; + frontColor = 0; + letterToPrint = 0; + + destSurface = 0; + sourceSurface = 0; + renderFlags = 0; + backDeltaX = 0; + backDeltaY = 0; + + for (int i = 0; i < 4; i++) + fonts[i] = 0; + + textToPrint = 0; + transparency = 0; + + for (int i = 0; i < 50; i++) + spritesArray[i] = 0; + + invalidatedCount = 0; + for (int i = 0; i < 30; i++) { + invalidatedTops[i] = 0; + invalidatedLefts[i] = 0; + invalidatedRights[i] = 0; + invalidatedBottoms[i] = 0; + } + + noInvalidated = 0; + applyPal = 0; + paletteCleared = 0; + + backSurface = 0; + frontSurface = 0; + + for (int i = 0; i < 18; i++) + unusedPalette1[i] = 0; + for (int i = 0; i < 16; i++) + unusedPalette2[i] = 0; + for (int i = 0; i < 256; i++) { + vgaPalette[i].red = 0; + vgaPalette[i].blue = 0; + vgaPalette[i].green = 0; + } + for (int i = 0; i < 16; i++) { + vgaSmallPalette[i].red = 0; + vgaSmallPalette[i].blue = 0; + vgaSmallPalette[i].green = 0; + } + + cursorX = 0; + cursorY = 0; + cursorWidth = 0; + cursorHeight = 0; + + cursorXDeltaVar = -1; + cursorYDeltaVar = -1; + + for (int i = 0; i < 40; i++) { + cursorAnimLow[i] = 0; + cursorAnimHigh[i] = 0; + cursorAnimDelays[i] = 0; + } + + gcursorIndex = 0; + transparentCursor = 0; + cursorSprites = 0; + cursorBack = 0; + cursorAnim = 0; + + palLoadData1[0] = 0; + palLoadData1[1] = 17; + palLoadData1[2] = 34; + palLoadData1[3] = 51; + palLoadData2[0] = 0; + palLoadData2[1] = 68; + palLoadData2[2] = 136; + palLoadData2[3] = 204; + + cursorTimeKey = 0; +} + +void Draw::invalidateRect(int16 left, int16 top, int16 right, int16 bottom) { int16 temp; int16 rect; int16 i; - if (draw_renderFlags & RENDERFLAG_NOINVALIDATE) + if (renderFlags & RENDERFLAG_NOINVALIDATE) return; if (left > right) { @@ -115,14 +144,14 @@ void draw_invalidateRect(int16 left, int16 top, int16 right, int16 bottom) { if (left > 319 || right < 0 || top > 199 || bottom < 0) return; - draw_noInvalidated = 0; + noInvalidated = 0; - if (draw_invalidatedCount >= 30) { - draw_invalidatedLefts[0] = 0; - draw_invalidatedTops[0] = 0; - draw_invalidatedRights[0] = 319; - draw_invalidatedBottoms[0] = 199; - draw_invalidatedCount = 1; + if (invalidatedCount >= 30) { + invalidatedLefts[0] = 0; + invalidatedTops[0] = 0; + invalidatedRights[0] = 319; + invalidatedBottoms[0] = 199; + invalidatedCount = 1; return; } @@ -141,154 +170,154 @@ void draw_invalidateRect(int16 left, int16 top, int16 right, int16 bottom) { left &= 0xfff0; right |= 0x000f; - for (rect = 0; rect < draw_invalidatedCount; rect++) { - - if (draw_invalidatedTops[rect] > top) { - if (draw_invalidatedTops[rect] > bottom) { - for (i = draw_invalidatedCount; i > rect; i--) { - draw_invalidatedLefts[i] = - draw_invalidatedLefts[i - 1]; - draw_invalidatedTops[i] = - draw_invalidatedTops[i - 1]; - draw_invalidatedRights[i] = - draw_invalidatedRights[i - 1]; - draw_invalidatedBottoms[i] = - draw_invalidatedBottoms[i - 1]; + for (rect = 0; rect < invalidatedCount; rect++) { + + if (invalidatedTops[rect] > top) { + if (invalidatedTops[rect] > bottom) { + for (i = invalidatedCount; i > rect; i--) { + invalidatedLefts[i] = + invalidatedLefts[i - 1]; + invalidatedTops[i] = + invalidatedTops[i - 1]; + invalidatedRights[i] = + invalidatedRights[i - 1]; + invalidatedBottoms[i] = + invalidatedBottoms[i - 1]; } - draw_invalidatedLefts[rect] = left; - draw_invalidatedTops[rect] = top; - draw_invalidatedRights[rect] = right; - draw_invalidatedBottoms[rect] = bottom; - draw_invalidatedCount++; + invalidatedLefts[rect] = left; + invalidatedTops[rect] = top; + invalidatedRights[rect] = right; + invalidatedBottoms[rect] = bottom; + invalidatedCount++; return; } - if (draw_invalidatedBottoms[rect] < bottom) - draw_invalidatedBottoms[rect] = bottom; + if (invalidatedBottoms[rect] < bottom) + invalidatedBottoms[rect] = bottom; - if (draw_invalidatedLefts[rect] > left) - draw_invalidatedLefts[rect] = left; + if (invalidatedLefts[rect] > left) + invalidatedLefts[rect] = left; - if (draw_invalidatedRights[rect] < right) - draw_invalidatedRights[rect] = right; + if (invalidatedRights[rect] < right) + invalidatedRights[rect] = right; - draw_invalidatedTops[rect] = top; + invalidatedTops[rect] = top; return; } - if (draw_invalidatedBottoms[rect] < top) + if (invalidatedBottoms[rect] < top) continue; - if (draw_invalidatedBottoms[rect] < bottom) - draw_invalidatedBottoms[rect] = bottom; + if (invalidatedBottoms[rect] < bottom) + invalidatedBottoms[rect] = bottom; - if (draw_invalidatedLefts[rect] > left) - draw_invalidatedLefts[rect] = left; + if (invalidatedLefts[rect] > left) + invalidatedLefts[rect] = left; - if (draw_invalidatedRights[rect] < right) - draw_invalidatedRights[rect] = right; + if (invalidatedRights[rect] < right) + invalidatedRights[rect] = right; return; } - draw_invalidatedLefts[draw_invalidatedCount] = left; - draw_invalidatedTops[draw_invalidatedCount] = top; - draw_invalidatedRights[draw_invalidatedCount] = right; - draw_invalidatedBottoms[draw_invalidatedCount] = bottom; - draw_invalidatedCount++; + invalidatedLefts[invalidatedCount] = left; + invalidatedTops[invalidatedCount] = top; + invalidatedRights[invalidatedCount] = right; + invalidatedBottoms[invalidatedCount] = bottom; + invalidatedCount++; return; } -void draw_blitInvalidated(void) { +void Draw::blitInvalidated(void) { int16 i; - if (draw_cursorIndex == 4) - draw_blitCursor(); + if (gcursorIndex == 4) + blitCursor(); - if (inter_terminate) + if (_vm->_inter->terminate) return; - if (draw_noInvalidated && draw_applyPal == 0) + if (noInvalidated && applyPal == 0) return; - if (draw_noInvalidated) { - draw_setPalette(); - draw_applyPal = 0; + if (noInvalidated) { + setPalette(); + applyPal = 0; return; } - if (draw_applyPal) { - draw_clearPalette(); + if (applyPal) { + clearPalette(); - vid_drawSprite(draw_backSurface, draw_frontSurface, 0, 0, 319, + _vm->_video->drawSprite(backSurface, frontSurface, 0, 0, 319, 199, 0, 0, 0); - draw_setPalette(); - draw_invalidatedCount = 0; - draw_noInvalidated = 1; - draw_applyPal = 0; + setPalette(); + invalidatedCount = 0; + noInvalidated = 1; + applyPal = 0; return; } - doRangeClamp = 0; - for (i = 0; i < draw_invalidatedCount; i++) { - vid_drawSprite(draw_backSurface, draw_frontSurface, - draw_invalidatedLefts[i], draw_invalidatedTops[i], - draw_invalidatedRights[i], draw_invalidatedBottoms[i], - draw_invalidatedLefts[i], draw_invalidatedTops[i], 0); + _vm->_global->doRangeClamp = 0; + for (i = 0; i < invalidatedCount; i++) { + _vm->_video->drawSprite(backSurface, frontSurface, + invalidatedLefts[i], invalidatedTops[i], + invalidatedRights[i], invalidatedBottoms[i], + invalidatedLefts[i], invalidatedTops[i], 0); } - doRangeClamp = 1; + _vm->_global->doRangeClamp = 1; - draw_invalidatedCount = 0; - draw_noInvalidated = 1; - draw_applyPal = 0; + invalidatedCount = 0; + noInvalidated = 1; + applyPal = 0; } -void draw_setPalette(void) { - if (videoMode != 0x13) - error("draw_setPalette: Video mode 0x%x is not supported!\n", - videoMode); +void Draw::setPalette(void) { + if (_vm->_global->videoMode != 0x13) + error("setPalette: Video mode 0x%x is not supported!\n", + _vm->_global->videoMode); - pPaletteDesc->unused1 = draw_unusedPalette1; - pPaletteDesc->unused2 = draw_unusedPalette2; - pPaletteDesc->vgaPal = draw_vgaPalette; - vid_setFullPalette(pPaletteDesc); - draw_paletteCleared = 0; + _vm->_global->pPaletteDesc->unused1 = unusedPalette1; + _vm->_global->pPaletteDesc->unused2 = unusedPalette2; + _vm->_global->pPaletteDesc->vgaPal = vgaPalette; + _vm->_video->setFullPalette(_vm->_global->pPaletteDesc); + paletteCleared = 0; } -void draw_clearPalette(void) { - if (draw_paletteCleared == 0) { - draw_paletteCleared = 1; - util_clearPalette(); +void Draw::clearPalette(void) { + if (paletteCleared == 0) { + paletteCleared = 1; + _vm->_util->clearPalette(); } } -void draw_blitCursor(void) { - if (draw_cursorIndex == -1) +void Draw::blitCursor(void) { + if (gcursorIndex == -1) return; - draw_cursorIndex = -1; - if (draw_cursorX + draw_cursorWidth > 320) - draw_cursorWidth = 320 - draw_cursorX; + gcursorIndex = -1; + if (cursorX + cursorWidth > 320) + cursorWidth = 320 - cursorX; - if (draw_cursorY + draw_cursorHeight > 200) - draw_cursorHeight = 200 - draw_cursorY; + if (cursorY + cursorHeight > 200) + cursorHeight = 200 - cursorY; - if (draw_noInvalidated) { - vid_drawSprite(draw_backSurface, draw_frontSurface, - draw_cursorX, draw_cursorY, - draw_cursorX + draw_cursorWidth - 1, - draw_cursorY + draw_cursorHeight - 1, draw_cursorX, - draw_cursorY, 0); + if (noInvalidated) { + _vm->_video->drawSprite(backSurface, frontSurface, + cursorX, cursorY, + cursorX + cursorWidth - 1, + cursorY + cursorHeight - 1, cursorX, + cursorY, 0); } else { - draw_invalidateRect(draw_cursorX, draw_cursorY, - draw_cursorX + draw_cursorWidth - 1, - draw_cursorY + draw_cursorHeight - 1); + invalidateRect(cursorX, cursorY, + cursorX + cursorWidth - 1, + cursorY + cursorHeight - 1); } } -void draw_spriteOperation(int16 operation) { +void Draw::spriteOperation(int16 operation) { uint16 id; char *dataBuf; - Game_TotResItem *itemPtr; + Game::TotResItem *itemPtr; int32 offset; int16 len; int16 i; @@ -296,270 +325,270 @@ void draw_spriteOperation(int16 operation) { int16 y; int16 perLine; - if (draw_sourceSurface >= 100) - draw_sourceSurface -= 80; + if (sourceSurface >= 100) + sourceSurface -= 80; - if (draw_destSurface >= 100) - draw_destSurface -= 80; + if (destSurface >= 100) + destSurface -= 80; - if (draw_renderFlags & RENDERFLAG_USEDELTAS) { - if (draw_sourceSurface == 21) { - draw_spriteLeft += draw_backDeltaX; - draw_spriteTop += draw_backDeltaY; + if (renderFlags & RENDERFLAG_USEDELTAS) { + if (sourceSurface == 21) { + spriteLeft += backDeltaX; + spriteTop += backDeltaY; } - if (draw_destSurface == 21) { - draw_destSpriteX += draw_backDeltaX; - draw_destSpriteY += draw_backDeltaY; + if (destSurface == 21) { + destSpriteX += backDeltaX; + destSpriteY += backDeltaY; if (operation == DRAW_DRAWLINE || (operation >= DRAW_DRAWBAR && operation <= DRAW_FILLRECTABS)) { - draw_spriteRight += draw_backDeltaX; - draw_spriteBottom += draw_backDeltaY; + spriteRight += backDeltaX; + spriteBottom += backDeltaY; } } } switch (operation) { case DRAW_BLITSURF: - vid_drawSprite(draw_spritesArray[draw_sourceSurface], - draw_spritesArray[draw_destSurface], - draw_spriteLeft, draw_spriteTop, - draw_spriteLeft + draw_spriteRight - 1, - draw_spriteTop + draw_spriteBottom - 1, - draw_destSpriteX, draw_destSpriteY, draw_transparency); - - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_destSpriteX + draw_spriteRight - 1, - draw_destSpriteY + draw_spriteBottom - 1); + _vm->_video->drawSprite(spritesArray[sourceSurface], + spritesArray[destSurface], + spriteLeft, spriteTop, + spriteLeft + spriteRight - 1, + spriteTop + spriteBottom - 1, + destSpriteX, destSpriteY, transparency); + + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + destSpriteX + spriteRight - 1, + destSpriteY + spriteBottom - 1); } break; case DRAW_PUTPIXEL: - vid_putPixel(draw_destSpriteX, draw_destSpriteY, - draw_frontColor, draw_spritesArray[draw_destSurface]); - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_destSpriteX, draw_destSpriteY); + _vm->_video->putPixel(destSpriteX, destSpriteY, + frontColor, spritesArray[destSurface]); + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + destSpriteX, destSpriteY); } break; case DRAW_FILLRECT: - vid_fillRect(draw_spritesArray[draw_destSurface], - draw_destSpriteX, draw_destSpriteY, - draw_destSpriteX + draw_spriteRight - 1, - draw_destSpriteY + draw_spriteBottom - 1, draw_backColor); - - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_destSpriteX + draw_spriteRight - 1, - draw_destSpriteY + draw_spriteBottom - 1); + _vm->_video->fillRect(spritesArray[destSurface], + destSpriteX, destSpriteY, + destSpriteX + spriteRight - 1, + destSpriteY + spriteBottom - 1, backColor); + + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + destSpriteX + spriteRight - 1, + destSpriteY + spriteBottom - 1); } break; case DRAW_DRAWLINE: - vid_drawLine(draw_spritesArray[draw_destSurface], - draw_destSpriteX, draw_destSpriteY, - draw_spriteRight, draw_spriteBottom, draw_frontColor); + _vm->_video->drawLine(spritesArray[destSurface], + destSpriteX, destSpriteY, + spriteRight, spriteBottom, frontColor); - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_spriteRight, draw_spriteBottom); + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + spriteRight, spriteBottom); } break; case DRAW_INVALIDATE: - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX - draw_spriteRight, draw_destSpriteY - draw_spriteBottom, // !! - draw_destSpriteX + draw_spriteRight, - draw_destSpriteY + draw_spriteBottom); + if (destSurface == 21) { + invalidateRect(destSpriteX - spriteRight, destSpriteY - spriteBottom, // !! + destSpriteX + spriteRight, + destSpriteY + spriteBottom); } break; case DRAW_LOADSPRITE: - id = draw_spriteLeft; + id = spriteLeft; if (id >= 30000) { dataBuf = - game_loadExtData(id, &draw_spriteRight, - &draw_spriteBottom); - vid_drawPackedSprite((byte *)dataBuf, draw_spriteRight, - draw_spriteBottom, draw_destSpriteX, - draw_destSpriteY, draw_transparency, - draw_spritesArray[draw_destSurface]); - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, - draw_destSpriteY, - draw_destSpriteX + draw_spriteRight - 1, - draw_destSpriteY + draw_spriteBottom - 1); + _vm->_game->loadExtData(id, &spriteRight, + &spriteBottom); + _vm->_video->drawPackedSprite((byte *)dataBuf, spriteRight, + spriteBottom, destSpriteX, + destSpriteY, transparency, + spritesArray[destSurface]); + if (destSurface == 21) { + invalidateRect(destSpriteX, + destSpriteY, + destSpriteX + spriteRight - 1, + destSpriteY + spriteBottom - 1); } free(dataBuf); break; } // Load from .TOT resources - itemPtr = &game_totResourceTable->items[id]; + itemPtr = &_vm->_game->totResourceTable->items[id]; offset = itemPtr->offset; if (offset >= 0) { dataBuf = - ((char *)game_totResourceTable) + + ((char *)_vm->_game->totResourceTable) + szGame_TotResTable + szGame_TotResItem * - game_totResourceTable->itemsCount + offset; + _vm->_game->totResourceTable->itemsCount + offset; } else { dataBuf = - game_imFileData + - (int32)READ_LE_UINT32(&((int32 *)game_imFileData)[-offset - 1]); + _vm->_game->imFileData + + (int32)READ_LE_UINT32(&((int32 *)_vm->_game->imFileData)[-offset - 1]); } - draw_spriteRight = itemPtr->width; - draw_spriteBottom = itemPtr->height; - vid_drawPackedSprite((byte *)dataBuf, - draw_spriteRight, draw_spriteBottom, - draw_destSpriteX, draw_destSpriteY, - draw_transparency, draw_spritesArray[draw_destSurface]); - - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_destSpriteX + draw_spriteRight - 1, - draw_destSpriteY + draw_spriteBottom - 1); + spriteRight = itemPtr->width; + spriteBottom = itemPtr->height; + _vm->_video->drawPackedSprite((byte *)dataBuf, + spriteRight, spriteBottom, + destSpriteX, destSpriteY, + transparency, spritesArray[destSurface]); + + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + destSpriteX + spriteRight - 1, + destSpriteY + spriteBottom - 1); } break; case DRAW_PRINTTEXT: - len = strlen(draw_textToPrint); - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_destSpriteX + - len * draw_fonts[draw_fontIndex]->itemWidth - 1, - draw_destSpriteY + - draw_fonts[draw_fontIndex]->itemHeight - 1); + len = strlen(textToPrint); + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + destSpriteX + + len * fonts[fontIndex]->itemWidth - 1, + destSpriteY + + fonts[fontIndex]->itemHeight - 1); } for (i = 0; i < len; i++) { - vid_drawLetter(draw_textToPrint[i], - draw_destSpriteX, draw_destSpriteY, - draw_fonts[draw_fontIndex], - draw_transparency, - draw_frontColor, draw_backColor, - draw_spritesArray[draw_destSurface]); - - draw_destSpriteX += draw_fonts[draw_fontIndex]->itemWidth; + _vm->_video->drawLetter(textToPrint[i], + destSpriteX, destSpriteY, + fonts[fontIndex], + transparency, + frontColor, backColor, + spritesArray[destSurface]); + + destSpriteX += fonts[fontIndex]->itemWidth; } break; case DRAW_DRAWBAR: - vid_drawLine(draw_spritesArray[draw_destSurface], - draw_destSpriteX, draw_spriteBottom, - draw_spriteRight, draw_spriteBottom, draw_frontColor); + _vm->_video->drawLine(spritesArray[destSurface], + destSpriteX, spriteBottom, + spriteRight, spriteBottom, frontColor); - vid_drawLine(draw_spritesArray[draw_destSurface], - draw_destSpriteX, draw_destSpriteY, - draw_destSpriteX, draw_spriteBottom, draw_frontColor); + _vm->_video->drawLine(spritesArray[destSurface], + destSpriteX, destSpriteY, + destSpriteX, spriteBottom, frontColor); - vid_drawLine(draw_spritesArray[draw_destSurface], - draw_spriteRight, draw_destSpriteY, - draw_spriteRight, draw_spriteBottom, draw_frontColor); + _vm->_video->drawLine(spritesArray[destSurface], + spriteRight, destSpriteY, + spriteRight, spriteBottom, frontColor); - vid_drawLine(draw_spritesArray[draw_destSurface], - draw_destSpriteX, draw_destSpriteY, - draw_spriteRight, draw_destSpriteY, draw_frontColor); + _vm->_video->drawLine(spritesArray[destSurface], + destSpriteX, destSpriteY, + spriteRight, destSpriteY, frontColor); - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_spriteRight, draw_spriteBottom); + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + spriteRight, spriteBottom); } break; case DRAW_CLEARRECT: - if (draw_backColor < 16) { - vid_fillRect(draw_spritesArray[draw_destSurface], - draw_destSpriteX, draw_destSpriteY, - draw_spriteRight, draw_spriteBottom, - draw_backColor); + if (backColor < 16) { + _vm->_video->fillRect(spritesArray[destSurface], + destSpriteX, destSpriteY, + spriteRight, spriteBottom, + backColor); } - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_spriteRight, draw_spriteBottom); + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + spriteRight, spriteBottom); } break; case DRAW_FILLRECTABS: - vid_fillRect(draw_spritesArray[draw_destSurface], - draw_destSpriteX, draw_destSpriteY, - draw_spriteRight, draw_spriteBottom, draw_backColor); + _vm->_video->fillRect(spritesArray[destSurface], + destSpriteX, destSpriteY, + spriteRight, spriteBottom, backColor); - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_spriteRight, draw_spriteBottom); + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + spriteRight, spriteBottom); } break; case DRAW_DRAWLETTER: - if (draw_fontToSprite[draw_fontIndex].sprite == -1) { - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, - draw_destSpriteY, - draw_destSpriteX + - draw_fonts[draw_fontIndex]->itemWidth - 1, - draw_destSpriteY + - draw_fonts[draw_fontIndex]->itemHeight - + if (fontToSprite[fontIndex].sprite == -1) { + if (destSurface == 21) { + invalidateRect(destSpriteX, + destSpriteY, + destSpriteX + + fonts[fontIndex]->itemWidth - 1, + destSpriteY + + fonts[fontIndex]->itemHeight - 1); } - vid_drawLetter(draw_letterToPrint, - draw_destSpriteX, draw_destSpriteY, - draw_fonts[draw_fontIndex], - draw_transparency, - draw_frontColor, draw_backColor, - draw_spritesArray[draw_destSurface]); + _vm->_video->drawLetter(letterToPrint, + destSpriteX, destSpriteY, + fonts[fontIndex], + transparency, + frontColor, backColor, + spritesArray[destSurface]); break; } perLine = - draw_spritesArray[(int16)draw_fontToSprite[draw_fontIndex]. - sprite]->width / draw_fontToSprite[draw_fontIndex].width; - - y = (draw_letterToPrint - - draw_fontToSprite[draw_fontIndex].base) / perLine * - draw_fontToSprite[draw_fontIndex].height; - - x = (draw_letterToPrint - - draw_fontToSprite[draw_fontIndex].base) % perLine * - draw_fontToSprite[draw_fontIndex].width; - - if (draw_destSurface == 21) { - draw_invalidateRect(draw_destSpriteX, draw_destSpriteY, - draw_destSpriteX + - draw_fontToSprite[draw_fontIndex].width, - draw_destSpriteY + - draw_fontToSprite[draw_fontIndex].height); + spritesArray[(int16)fontToSprite[fontIndex]. + sprite]->width / fontToSprite[fontIndex].width; + + y = (letterToPrint - + fontToSprite[fontIndex].base) / perLine * + fontToSprite[fontIndex].height; + + x = (letterToPrint - + fontToSprite[fontIndex].base) % perLine * + fontToSprite[fontIndex].width; + + if (destSurface == 21) { + invalidateRect(destSpriteX, destSpriteY, + destSpriteX + + fontToSprite[fontIndex].width, + destSpriteY + + fontToSprite[fontIndex].height); } - vid_drawSprite(draw_spritesArray[(int16)draw_fontToSprite - [draw_fontIndex].sprite], - draw_spritesArray[draw_destSurface], x, y, - x + draw_fontToSprite[draw_fontIndex].width, - y + draw_fontToSprite[draw_fontIndex].height, - draw_destSpriteX, draw_destSpriteY, draw_transparency); + _vm->_video->drawSprite(spritesArray[(int16)fontToSprite + [fontIndex].sprite], + spritesArray[destSurface], x, y, + x + fontToSprite[fontIndex].width, + y + fontToSprite[fontIndex].height, + destSpriteX, destSpriteY, transparency); break; } - if (draw_renderFlags & RENDERFLAG_USEDELTAS) { - if (draw_sourceSurface == 21) { - draw_spriteLeft -= draw_backDeltaX; - draw_spriteTop -= draw_backDeltaY; + if (renderFlags & RENDERFLAG_USEDELTAS) { + if (sourceSurface == 21) { + spriteLeft -= backDeltaX; + spriteTop -= backDeltaY; } - if (draw_destSurface == 21) { - draw_destSpriteX -= draw_backDeltaX; - draw_destSpriteY -= draw_backDeltaY; + if (destSurface == 21) { + destSpriteX -= backDeltaX; + destSpriteY -= backDeltaY; } } } -void draw_animateCursor(int16 cursor) { +void Draw::animateCursor(int16 cursor) { int16 newX = 0; int16 newY = 0; - Game_Collision *ptr; + Game::Collision *ptr; int16 minX; int16 minY; int16 maxX; @@ -570,20 +599,20 @@ void draw_animateCursor(int16 cursor) { if (cursorIndex == -1) { cursorIndex = 0; - for (ptr = game_collisionAreas; ptr->left != -1; ptr++) { + for (ptr = _vm->_game->collisionAreas; ptr->left != -1; ptr++) { if (ptr->flags & 0xfff0) continue; - if (ptr->left > inter_mouseX) + if (ptr->left > _vm->_global->inter_mouseX) continue; - if (ptr->right < inter_mouseX) + if (ptr->right < _vm->_global->inter_mouseX) continue; - if (ptr->top > inter_mouseY) + if (ptr->top > _vm->_global->inter_mouseY) continue; - if (ptr->bottom < inter_mouseY) + if (ptr->bottom < _vm->_global->inter_mouseY) continue; if ((ptr->flags & 0xf) < 3) @@ -592,161 +621,161 @@ void draw_animateCursor(int16 cursor) { cursorIndex = 3; break; } - if (draw_cursorAnimLow[cursorIndex] == -1) + if (cursorAnimLow[cursorIndex] == -1) cursorIndex = 1; } - if (draw_cursorAnimLow[cursorIndex] != -1) { - if (cursorIndex == draw_cursorIndex) { - if (draw_cursorAnimDelays[draw_cursorIndex] != 0 && - draw_cursorAnimDelays[draw_cursorIndex] * 10 + - draw_cursorTimeKey <= util_getTimeKey()) { - draw_cursorAnim++; - draw_cursorTimeKey = util_getTimeKey(); + if (cursorAnimLow[cursorIndex] != -1) { + if (cursorIndex == gcursorIndex) { + if (cursorAnimDelays[gcursorIndex] != 0 && + cursorAnimDelays[gcursorIndex] * 10 + + cursorTimeKey <= _vm->_util->getTimeKey()) { + cursorAnim++; + cursorTimeKey = _vm->_util->getTimeKey(); } else { -/* if (draw_noInvalidated && - inter_mouseX == draw_cursorX && inter_mouseY == draw_cursorY) +/* if (noInvalidated && + inter_mouseX == cursorX && inter_mouseY == cursorY) return;*/ } } else { - draw_cursorIndex = cursorIndex; - if (draw_cursorAnimDelays[draw_cursorIndex] != 0) { - draw_cursorAnim = - draw_cursorAnimLow[draw_cursorIndex]; - draw_cursorTimeKey = util_getTimeKey(); + gcursorIndex = cursorIndex; + if (cursorAnimDelays[gcursorIndex] != 0) { + cursorAnim = + cursorAnimLow[gcursorIndex]; + cursorTimeKey = _vm->_util->getTimeKey(); } else { - draw_cursorAnim = draw_cursorIndex; + cursorAnim = gcursorIndex; } } - if (draw_cursorAnimDelays[draw_cursorIndex] != 0 && - (draw_cursorAnimHigh[draw_cursorIndex] < draw_cursorAnim || - draw_cursorAnimLow[draw_cursorIndex] > - draw_cursorAnim)) { - draw_cursorAnim = draw_cursorAnimLow[draw_cursorIndex]; + if (cursorAnimDelays[gcursorIndex] != 0 && + (cursorAnimHigh[gcursorIndex] < cursorAnim || + cursorAnimLow[gcursorIndex] > + cursorAnim)) { + cursorAnim = cursorAnimLow[gcursorIndex]; } - newX = inter_mouseX; - newY = inter_mouseY; - if (draw_cursorXDeltaVar != -1) { - newX -= (uint16)VAR_OFFSET(draw_cursorIndex * 4 + (draw_cursorXDeltaVar / 4) * 4); - newY -= (uint16)VAR_OFFSET(draw_cursorIndex * 4 + (draw_cursorYDeltaVar / 4) * 4); + newX = _vm->_global->inter_mouseX; + newY = _vm->_global->inter_mouseY; + if (cursorXDeltaVar != -1) { + newX -= (uint16)VAR_OFFSET(gcursorIndex * 4 + (cursorXDeltaVar / 4) * 4); + newY -= (uint16)VAR_OFFSET(gcursorIndex * 4 + (cursorYDeltaVar / 4) * 4); } - minX = MIN(newX, draw_cursorX); - minY = MIN(newY, draw_cursorY); - maxX = MAX(draw_cursorX, newX) + draw_cursorWidth - 1; - maxY = MAX(draw_cursorY, newY) + draw_cursorHeight - 1; - vid_drawSprite(draw_backSurface, draw_cursorBack, - newX, newY, newX + draw_cursorWidth - 1, - newY + draw_cursorHeight - 1, 0, 0, 0); - - vid_drawSprite(draw_cursorSprites, draw_backSurface, - draw_cursorWidth * draw_cursorAnim, 0, - draw_cursorWidth * (draw_cursorAnim + 1) - 1, - draw_cursorHeight - 1, newX, newY, draw_transparentCursor); - - if (draw_noInvalidated == 0) { - cursorIndex = draw_cursorIndex; - draw_cursorIndex = -1; - draw_blitInvalidated(); - draw_cursorIndex = cursorIndex; + minX = MIN(newX, cursorX); + minY = MIN(newY, cursorY); + maxX = MAX(cursorX, newX) + cursorWidth - 1; + maxY = MAX(cursorY, newY) + cursorHeight - 1; + _vm->_video->drawSprite(backSurface, cursorBack, + newX, newY, newX + cursorWidth - 1, + newY + cursorHeight - 1, 0, 0, 0); + + _vm->_video->drawSprite(cursorSprites, backSurface, + cursorWidth * cursorAnim, 0, + cursorWidth * (cursorAnim + 1) - 1, + cursorHeight - 1, newX, newY, transparentCursor); + + if (noInvalidated == 0) { + cursorIndex = gcursorIndex; + gcursorIndex = -1; + blitInvalidated(); + gcursorIndex = cursorIndex; } else { - vid_waitRetrace(videoMode); + _vm->_video->waitRetrace(_vm->_global->videoMode); } - vid_drawSprite(draw_backSurface, draw_frontSurface, + _vm->_video->drawSprite(backSurface, frontSurface, minX, minY, maxX, maxY, minX, minY, 0); - vid_drawSprite(draw_cursorBack, draw_backSurface, - 0, 0, draw_cursorWidth - 1, draw_cursorHeight - 1, + _vm->_video->drawSprite(cursorBack, backSurface, + 0, 0, cursorWidth - 1, cursorHeight - 1, newX, newY, 0); } else { - draw_blitCursor(); + blitCursor(); } - draw_cursorX = newX; - draw_cursorY = newY; + cursorX = newX; + cursorY = newY; } -void draw_interPalLoad(void) { +void Draw::interPalLoad(void) { int16 i; int16 ind1; int16 ind2; byte cmd; char *palPtr; - cmd = *inter_execPtr++; - draw_applyPal = 0; + cmd = *_vm->_global->inter_execPtr++; + applyPal = 0; if (cmd & 0x80) cmd &= 0x7f; else - draw_applyPal = 1; + applyPal = 1; if (cmd == 49) { warning("inter_palLoad: cmd == 49 is not supported"); //var_B = 1; - for (i = 0; i < 18; i++, inter_execPtr++) { + for (i = 0; i < 18; i++, _vm->_global->inter_execPtr++) { if (i < 2) { - if (draw_applyPal == 0) + if (applyPal == 0) continue; - draw_unusedPalette1[i] = *inter_execPtr; + unusedPalette1[i] = *_vm->_global->inter_execPtr; continue; } //if (*inter_execPtr != 0) // var_B = 0; - ind1 = *inter_execPtr >> 4; - ind2 = (*inter_execPtr & 0xf); + ind1 = *_vm->_global->inter_execPtr >> 4; + ind2 = (*_vm->_global->inter_execPtr & 0xf); - draw_unusedPalette1[i] = - ((draw_palLoadData1[ind1] + draw_palLoadData2[ind2]) << 8) + - (draw_palLoadData2[ind1] + draw_palLoadData1[ind2]); + unusedPalette1[i] = + ((palLoadData1[ind1] + palLoadData2[ind2]) << 8) + + (palLoadData2[ind1] + palLoadData1[ind2]); } - pPaletteDesc->unused1 = draw_unusedPalette1; + _vm->_global->pPaletteDesc->unused1 = unusedPalette1; } switch (cmd) { case 52: - for (i = 0; i < 16; i++, inter_execPtr += 3) { - draw_vgaSmallPalette[i].red = inter_execPtr[0]; - draw_vgaSmallPalette[i].green = inter_execPtr[1]; - draw_vgaSmallPalette[i].blue = inter_execPtr[2]; + for (i = 0; i < 16; i++, _vm->_global->inter_execPtr += 3) { + vgaSmallPalette[i].red = _vm->_global->inter_execPtr[0]; + vgaSmallPalette[i].green = _vm->_global->inter_execPtr[1]; + vgaSmallPalette[i].blue = _vm->_global->inter_execPtr[2]; } break; case 50: - for (i = 0; i < 16; i++, inter_execPtr++) - draw_unusedPalette2[i] = *inter_execPtr; + for (i = 0; i < 16; i++, _vm->_global->inter_execPtr++) + unusedPalette2[i] = *_vm->_global->inter_execPtr; break; case 53: - palPtr = game_loadTotResource(inter_load16()); - memcpy((char *)draw_vgaPalette, palPtr, 768); + palPtr = _vm->_game->loadTotResource(_vm->_inter->load16()); + memcpy((char *)vgaPalette, palPtr, 768); break; case 54: - memset((char *)draw_vgaPalette, 0, 768); + memset((char *)vgaPalette, 0, 768); break; } - if (!draw_applyPal) { - pPaletteDesc->unused2 = draw_unusedPalette2; - pPaletteDesc->unused1 = draw_unusedPalette1; + if (!applyPal) { + _vm->_global->pPaletteDesc->unused2 = unusedPalette2; + _vm->_global->pPaletteDesc->unused1 = unusedPalette1; - if (videoMode != 0x13) - pPaletteDesc->vgaPal = (Color *)draw_vgaSmallPalette; + if (_vm->_global->videoMode != 0x13) + _vm->_global->pPaletteDesc->vgaPal = (Video::Color *)vgaSmallPalette; else - pPaletteDesc->vgaPal = (Color *)draw_vgaPalette; + _vm->_global->pPaletteDesc->vgaPal = (Video::Color *)vgaPalette; - pal_fade((PalDesc *) pPaletteDesc, 0, 0); + _vm->_palanim->fade((Video::PalDesc *) _vm->_global->pPaletteDesc, 0, 0); } } -void draw_printText(void) { +void Draw::printText(void) { int16 savedFlags; - int16 destSpriteX; + int16 ldestSpriteX; char *dataPtr; char *ptr; char *ptr2; @@ -757,59 +786,59 @@ void draw_printText(void) { int16 val; char buf[20]; - index = inter_load16(); + index = _vm->_inter->load16(); - cd_playMultMusic(); + _vm->_cdrom->playMultMusic(); - dataPtr = (char *)game_totTextData + game_totTextData->items[index].offset; + dataPtr = (char *)_vm->_game->totTextData + _vm->_game->totTextData->items[index].offset; ptr = dataPtr; - if (draw_renderFlags & RENDERFLAG_CAPTUREPUSH) { - draw_destSpriteX = READ_LE_UINT16(ptr); - draw_destSpriteY = READ_LE_UINT16(ptr + 2); - draw_spriteRight = READ_LE_UINT16(ptr + 4) - draw_destSpriteX + 1; - draw_spriteBottom = READ_LE_UINT16(ptr + 6) - draw_destSpriteY + 1; - game_capturePush(draw_destSpriteX, draw_destSpriteY, - draw_spriteRight, draw_spriteBottom); - (*scen_pCaptureCounter)++; + if (renderFlags & RENDERFLAG_CAPTUREPUSH) { + destSpriteX = READ_LE_UINT16(ptr); + destSpriteY = READ_LE_UINT16(ptr + 2); + spriteRight = READ_LE_UINT16(ptr + 4) - destSpriteX + 1; + spriteBottom = READ_LE_UINT16(ptr + 6) - destSpriteY + 1; + _vm->_game->capturePush(destSpriteX, destSpriteY, + spriteRight, spriteBottom); + (*_vm->_scenery->pCaptureCounter)++; } - draw_destSpriteX = READ_LE_UINT16(ptr); - destX = draw_destSpriteX; + destSpriteX = READ_LE_UINT16(ptr); + destX = destSpriteX; - draw_destSpriteY = READ_LE_UINT16(ptr + 2); - destY = draw_destSpriteY; + destSpriteY = READ_LE_UINT16(ptr + 2); + destY = destSpriteY; - draw_spriteRight = READ_LE_UINT16(ptr + 4); - draw_spriteBottom = READ_LE_UINT16(ptr + 6); - draw_destSurface = 21; + spriteRight = READ_LE_UINT16(ptr + 4); + spriteBottom = READ_LE_UINT16(ptr + 6); + destSurface = 21; ptr += 8; - draw_backColor = *ptr++; - draw_transparency = 1; - draw_spriteOperation(DRAW_CLEARRECT); + backColor = *ptr++; + transparency = 1; + spriteOperation(DRAW_CLEARRECT); - draw_backColor = 0; - savedFlags = draw_renderFlags; + backColor = 0; + savedFlags = renderFlags; - draw_renderFlags &= ~RENDERFLAG_NOINVALIDATE; - for (; (draw_destSpriteX = READ_LE_UINT16(ptr)) != -1; ptr++) { - draw_destSpriteX += destX; - draw_destSpriteY = READ_LE_UINT16(ptr + 2) + destY; - draw_spriteRight = READ_LE_UINT16(ptr + 4) + destX; - draw_spriteBottom = READ_LE_UINT16(ptr + 6) + destY; + renderFlags &= ~RENDERFLAG_NOINVALIDATE; + for (; (destSpriteX = READ_LE_UINT16(ptr)) != -1; ptr++) { + destSpriteX += destX; + destSpriteY = READ_LE_UINT16(ptr + 2) + destY; + spriteRight = READ_LE_UINT16(ptr + 4) + destX; + spriteBottom = READ_LE_UINT16(ptr + 6) + destY; ptr += 8; cmd = (*ptr & 0xf0) >> 4; if (cmd == 0) { - draw_frontColor = *ptr & 0xf; - draw_spriteOperation(DRAW_DRAWLINE); + frontColor = *ptr & 0xf; + spriteOperation(DRAW_DRAWLINE); } else if (cmd == 1) { - draw_frontColor = *ptr & 0xf; - draw_spriteOperation(DRAW_DRAWBAR); + frontColor = *ptr & 0xf; + spriteOperation(DRAW_DRAWBAR); } else if (cmd == 2) { - draw_backColor = *ptr & 0xf; - draw_spriteOperation(DRAW_FILLRECTABS); + backColor = *ptr & 0xf; + spriteOperation(DRAW_FILLRECTABS); } } ptr += 2; @@ -828,23 +857,23 @@ void draw_printText(void) { cmd = *ptr; if (cmd == 3) { ptr++; - draw_fontIndex = (*ptr & 0xf0) >> 4; - draw_frontColor = *ptr & 0xf; + fontIndex = (*ptr & 0xf0) >> 4; + frontColor = *ptr & 0xf; ptr++; continue; } else if (cmd == 2) { ptr++; - draw_destSpriteX = destX + READ_LE_UINT16(ptr); - draw_destSpriteY = destY + READ_LE_UINT16(ptr + 2); + destSpriteX = destX + READ_LE_UINT16(ptr); + destSpriteY = destY + READ_LE_UINT16(ptr + 2); ptr += 4; continue; } if ((byte)*ptr != 0xba) { - draw_letterToPrint = *ptr; - draw_spriteOperation(DRAW_DRAWLETTER); - draw_destSpriteX += - draw_fonts[draw_fontIndex]->itemWidth; + letterToPrint = *ptr; + spriteOperation(DRAW_DRAWLETTER); + destSpriteX += + fonts[fontIndex]->itemWidth; ptr++; } else { cmd = ptr2[17] & 0x7f; @@ -854,51 +883,51 @@ void draw_printText(void) { } else if (cmd == 1) { val = READ_LE_UINT16(ptr2 + 18) * 4; - strcpy(buf, inter_variables + val); + strcpy(buf, _vm->_global->inter_variables + val); } else { val = READ_LE_UINT16(ptr2 + 18) * 4; sprintf(buf, "%d", VAR_OFFSET(val)); if (buf[0] == '-') { while (strlen(buf) - 1 < (uint32)ptr2[17]) { - util_insertStr("0", buf, 1); + _vm->_util->insertStr("0", buf, 1); } } else { while (strlen(buf) - 1 < (uint32)ptr2[17]) { - util_insertStr("0", buf, 0); + _vm->_util->insertStr("0", buf, 0); } } - util_insertStr(",", buf, strlen(buf) + 1 - ptr2[17]); + _vm->_util->insertStr(",", buf, strlen(buf) + 1 - ptr2[17]); } - draw_textToPrint = buf; - destSpriteX = draw_destSpriteX; - draw_spriteOperation(DRAW_PRINTTEXT); + textToPrint = buf; + ldestSpriteX = destSpriteX; + spriteOperation(DRAW_PRINTTEXT); if (ptr2[17] & 0x80) { if (ptr[1] == ' ') { - draw_destSpriteX += draw_fonts[draw_fontIndex]->itemWidth; + destSpriteX += fonts[fontIndex]->itemWidth; while (ptr[1] == ' ') ptr++; if (ptr[1] == 2) { - if (READ_LE_UINT16(ptr + 4) == draw_destSpriteY) + if (READ_LE_UINT16(ptr + 4) == destSpriteY) ptr += 5; } - } else if (ptr[1] == 2 && READ_LE_UINT16(ptr + 4) == draw_destSpriteY) { + } else if (ptr[1] == 2 && READ_LE_UINT16(ptr + 4) == destSpriteY) { ptr += 5; - draw_destSpriteX += draw_fonts[draw_fontIndex]->itemWidth; + destSpriteX += fonts[fontIndex]->itemWidth; } } else { - draw_destSpriteX = destSpriteX + draw_fonts[draw_fontIndex]->itemWidth; + destSpriteX = ldestSpriteX + fonts[fontIndex]->itemWidth; } ptr2 += 23; ptr++; } } - draw_renderFlags = savedFlags; - if (draw_renderFlags & 4) { - warning("draw_printText: Input not supported!"); + renderFlags = savedFlags; + if (renderFlags & 4) { + warning("printText: Input not supported!"); // xor ax, ax // loc_436_1391: // xor dx, dx @@ -913,9 +942,9 @@ void draw_printText(void) { // add sp, 0Ch } - if ((draw_renderFlags & RENDERFLAG_CAPTUREPOP) && *scen_pCaptureCounter != 0) { - (*scen_pCaptureCounter)--; - game_capturePop(1); + if ((renderFlags & RENDERFLAG_CAPTUREPOP) && *_vm->_scenery->pCaptureCounter != 0) { + (*_vm->_scenery->pCaptureCounter)--; + _vm->_game->capturePop(1); } } diff --git a/gob/draw.h b/gob/draw.h index 6880881c51..2084aa1bf5 100644 --- a/gob/draw.h +++ b/gob/draw.h @@ -31,81 +31,95 @@ namespace Gob { #define RENDERFLAG_CAPTUREPOP 8 #define RENDERFLAG_USEDELTAS 0x10 -typedef struct Draw_FontToSprite { - int8 sprite; - int8 base; - int8 width; - int8 height; -} Draw_FontToSprite; - -extern int16 draw_fontIndex; -extern int16 draw_spriteLeft; -extern int16 draw_spriteTop; -extern int16 draw_spriteRight; -extern int16 draw_spriteBottom; -extern int16 draw_destSpriteX; -extern int16 draw_destSpriteY; -extern int16 draw_backColor; -extern int16 draw_frontColor; -extern char draw_letterToPrint; -extern Draw_FontToSprite draw_fontToSprite[4]; -extern int16 draw_destSurface; -extern int16 draw_sourceSurface; -extern int16 draw_renderFlags; -extern int16 draw_backDeltaX; -extern int16 draw_backDeltaY; -extern FontDesc *draw_fonts[4]; -extern char *draw_textToPrint; -extern int16 draw_transparency; -extern SurfaceDesc *draw_spritesArray[50]; - -extern int16 draw_invalidatedCount; -extern int16 draw_invalidatedTops[30]; -extern int16 draw_invalidatedLefts[30]; -extern int16 draw_invalidatedRights[30]; -extern int16 draw_invalidatedBottoms[30]; - -extern int8 draw_noInvalidated; -extern int8 draw_doFullFlip; -extern int8 draw_paletteCleared; - -extern int16 draw_cursorIndex; -extern int16 draw_transparentCursor; - -extern SurfaceDesc *draw_backSurface; -extern SurfaceDesc *draw_frontSurface; - -extern int16 draw_unusedPalette1[18]; -extern int16 draw_unusedPalette2[16]; -extern Color draw_vgaPalette[256]; -extern Color draw_vgaSmallPalette[16]; - -extern int16 draw_cursorX; -extern int16 draw_cursorY; -extern int16 draw_cursorWidth; -extern int16 draw_cursorHeight; - -extern int16 draw_cursorXDeltaVar; -extern int16 draw_cursorYDeltaVar; - -extern SurfaceDesc *draw_cursorSprites; -extern SurfaceDesc *draw_cursorBack; -extern int16 draw_cursorAnim; -extern int8 draw_cursorAnimLow[40]; -extern int8 draw_cursorAnimHigh[40]; -extern int8 draw_cursorAnimDelays[40]; -extern int8 draw_applyPal; - -void draw_invalidateRect(int16 left, int16 top, int16 right, int16 bottom); -void draw_blitInvalidated(void); -void draw_setPalette(void); -void draw_clearPalette(void); -void draw_blitCursor(void); - -void draw_spriteOperation(int16 operation); -void draw_animateCursor(int16 cursor); -void draw_interPalLoad(void); -void draw_printText(void); +class Draw { + public: + typedef struct FontToSprite { + int8 sprite; + int8 base; + int8 width; + int8 height; + FontToSprite() : sprite(0), base(0), width(0), height() {} + } FontToSprite; + + int16 fontIndex; + int16 spriteLeft; + int16 spriteTop; + int16 spriteRight; + int16 spriteBottom; + int16 destSpriteX; + int16 destSpriteY; + int16 backColor; + int16 frontColor; + char letterToPrint; + FontToSprite fontToSprite[4]; + int16 destSurface; + int16 sourceSurface; + int16 renderFlags; + int16 backDeltaX; + int16 backDeltaY; + Video::FontDesc *fonts[4]; + char *textToPrint; + int16 transparency; + Video::SurfaceDesc *spritesArray[50]; + + int16 invalidatedCount; + int16 invalidatedTops[30]; + int16 invalidatedLefts[30]; + int16 invalidatedRights[30]; + int16 invalidatedBottoms[30]; + + int8 noInvalidated; +// int8 doFullFlip; // Never used?!? + int8 paletteCleared; + + int16 gcursorIndex; + int16 transparentCursor; + uint32 cursorTimeKey; + + Video::SurfaceDesc *backSurface; + Video::SurfaceDesc *frontSurface; + + int16 unusedPalette1[18]; + int16 unusedPalette2[16]; + Video::Color vgaPalette[256]; + Video::Color vgaSmallPalette[16]; + + int16 cursorX; + int16 cursorY; + int16 cursorWidth; + int16 cursorHeight; + + int16 cursorXDeltaVar; + int16 cursorYDeltaVar; + + Video::SurfaceDesc *cursorSprites; + Video::SurfaceDesc *cursorBack; + int16 cursorAnim; + int8 cursorAnimLow[40]; + int8 cursorAnimHigh[40]; + int8 cursorAnimDelays[40]; + int8 applyPal; + + int16 palLoadData1[4]; + int16 palLoadData2[4]; + + void invalidateRect(int16 left, int16 top, int16 right, int16 bottom); + void blitInvalidated(void); + void setPalette(void); + void clearPalette(void); + void blitCursor(void); + + void spriteOperation(int16 operation); + void animateCursor(int16 cursor); + void interPalLoad(void); + void printText(void); + + Draw(GobEngine *vm); + + protected: + GobEngine *_vm; +}; + // Draw operations #define DRAW_BLITSURF 0 diff --git a/gob/driver_vga.cpp b/gob/driver_vga.cpp index eeaa9a10a6..15444f4bd9 100644 --- a/gob/driver_vga.cpp +++ b/gob/driver_vga.cpp @@ -30,7 +30,7 @@ namespace Gob { -void VGAVideoDriver::drawSprite(SurfaceDesc *source, SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) { +void VGAVideoDriver::drawSprite(Video::SurfaceDesc *source, Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) { if (x >= 0 && x < dest->width && y >= 0 && y < dest->height) { int16 width = (right - left) + 1; int16 height = (bottom - top) + 1; @@ -54,7 +54,7 @@ void VGAVideoDriver::drawSprite(SurfaceDesc *source, SurfaceDesc *dest, int16 le } } -void VGAVideoDriver::fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color) { +void VGAVideoDriver::fillRect(Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color) { if (left < dest->width && right < dest->width && top < dest->height && bottom < dest->height) { byte *pos = dest->vidPtr + (top * dest->width) + left; int16 width = (right - left) + 1; @@ -69,12 +69,12 @@ void VGAVideoDriver::fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 ri } } -void VGAVideoDriver::putPixel(int16 x, int16 y, byte color, SurfaceDesc *dest) { +void VGAVideoDriver::putPixel(int16 x, int16 y, byte color, Video::SurfaceDesc *dest) { if (x >= 0 && x < dest->width && y >= 0 && y < dest->height) dest->vidPtr[(y * dest->width) + x] = color; } -void VGAVideoDriver::drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, byte color1, byte color2, byte transp, SurfaceDesc *dest) { +void VGAVideoDriver::drawLetter(unsigned char item, int16 x, int16 y, Video::FontDesc *fontDesc, byte color1, byte color2, byte transp, Video::SurfaceDesc *dest) { byte *src, *dst; uint16 data; int i, j; @@ -103,16 +103,16 @@ void VGAVideoDriver::drawLetter(unsigned char item, int16 x, int16 y, FontDesc * } static void plotPixel(int x, int y, int color, void *data) { - SurfaceDesc *dest = (SurfaceDesc *)data; + Video::SurfaceDesc *dest = (Video::SurfaceDesc *)data; if (x >= 0 && x < dest->width && y >= 0 && y < dest->height) dest->vidPtr[(y * dest->width) + x] = color; } -void VGAVideoDriver::drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color) { +void VGAVideoDriver::drawLine(Video::SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color) { Graphics::drawLine(x0, y0, x1, y1, color, &plotPixel, dest); } -void VGAVideoDriver::drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, SurfaceDesc *dest) { +void VGAVideoDriver::drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, Video::SurfaceDesc *dest) { int destRight = x + width; int destBottom = y + height; diff --git a/gob/driver_vga.h b/gob/driver_vga.h index 1aab68e4f6..d146c70224 100644 --- a/gob/driver_vga.h +++ b/gob/driver_vga.h @@ -29,13 +29,13 @@ namespace Gob { class VGAVideoDriver : public VideoDriver { public: VGAVideoDriver() {} - virtual ~VGAVideoDriver() {} - void drawSprite(SurfaceDesc *source, SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp); - void fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color); - void putPixel(int16 x, int16 y, byte color, SurfaceDesc *dest); - void drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, byte color1, byte color2, byte transp, SurfaceDesc *dest); - void drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color); - void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, SurfaceDesc *dest); + virtual ~VGAVideoDriver() {} + void drawSprite(Video::SurfaceDesc *source, Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp); + void fillRect(Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color); + void putPixel(int16 x, int16 y, byte color, Video::SurfaceDesc *dest); + void drawLetter(unsigned char item, int16 x, int16 y, Video::FontDesc *fontDesc, byte color1, byte color2, byte transp, Video::SurfaceDesc *dest); + void drawLine(Video::SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color); + void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, Video::SurfaceDesc *dest); }; } diff --git a/gob/game.cpp b/gob/game.cpp index 5187cfd6ff..b664a69d92 100644 --- a/gob/game.cpp +++ b/gob/game.cpp @@ -36,57 +36,60 @@ namespace Gob { -Game_ExtTable *game_extTable = 0; - -char *game_totFileData = 0; -Game_TotTextTable *game_totTextData; -Game_TotResTable *game_totResourceTable = 0; -char *game_imFileData = 0; -int16 game_extHandle = 0; -char game_curExtFile[14]; -char game_curTotFile[14]; -char game_curImaFile[18]; - -Game_Collision *game_collisionAreas = 0; -char game_shouldPushColls = 0; -char game_collStr[256]; - -int16 game_lastCollKey; -int16 game_lastCollAreaIndex; -int16 game_lastCollId; - -char game_handleMouse; -char game_forceHandleMouse; +int16 Game::captureCount = 0; +Common::Rect Game::captureStack[20]; + +Game::Game(GobEngine *vm) : _vm(vm) { + extTable = 0; + totFileData = 0; + totResourceTable = 0; + imFileData = 0; + extHandle = 0; + collisionAreas = 0; + shouldPushColls = 0; + totTextData = 0; + + // Collisions stack + collStackSize = 0; + for (int i = 0; i < 3; i++) { + collStack[i] = 0; + collStackElemSizes[i] = 0; + } -char game_tempStr[256]; + for (int i = 0; i < 20; i++) + soundSamples[i] = 0; -int16 game_activeCollResId; -int16 game_activeCollIndex; + curTotFile[0] = 0; + curExtFile[0] = 0; + totToLoad[0] = 0; -// Collisions stack -int16 game_collStackSize = 0; -Game_Collision *game_collStack[3]; -int16 game_collStackElemSizes[3]; + startTimeKey = 0; + mouseButtons = 0; -int16 game_mouseButtons = 0; + lastCollKey = 0; + lastCollAreaIndex = 0; + lastCollId = 0; -// Capture -static Common::Rect game_captureStack[20]; -static int16 game_captureCount = 0; + activeCollResId = 0; + activeCollIndex = 0; + ghandleMouse = 0; + forceHandleMouse = 0; -Snd_SoundDesc *game_soundSamples[20]; + tempStr[0] = 0; + curImaFile[0] = 0; + soundFromExt[0] = 0; + collStr[0] = 0; -char game_soundFromExt[20]; -char game_totToLoad[20]; -int32 game_startTimeKey; + // Capture +} -char *game_loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) { +char *Game::loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) { int16 commonHandle; int16 itemsCount; int32 offset; uint32 size; - Game_ExtItem *item; + ExtItem *item; char isPacked; int16 handle; int32 tableSize; @@ -96,12 +99,12 @@ char *game_loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) { char *dataPtr; itemId -= 30000; - if (game_extTable == 0) + if (extTable == 0) return 0; commonHandle = -1; - itemsCount = game_extTable->itemsCount; - item = &game_extTable->items[itemId]; + itemsCount = extTable->itemsCount; + item = &extTable->items[itemId]; tableSize = szGame_ExtTable + szGame_ExtItem * itemsCount; offset = item->offset; @@ -114,29 +117,29 @@ char *game_loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) { if (pResWidth != 0) { *pResWidth = item->width & 0x7fff; *pResHeight = item->height; - debug(7, "game_loadExtData(%d, %d, %d)", itemId, *pResWidth, *pResHeight); + debug(7, "loadExtData(%d, %d, %d)", itemId, *pResWidth, *pResHeight); } - debug(7, "game_loadExtData(%d, 0, 0)", itemId); + debug(7, "loadExtData(%d, 0, 0)", itemId); if (item->height == 0) size += (item->width & 0x7fff) << 16; debug(7, "size: %d off: %d", size, offset); if (offset >= 0) { - handle = game_extHandle; + handle = extHandle; } else { offset = -(offset + 1); tableSize = 0; - data_closeData(game_extHandle); + _vm->_dataio->closeData(extHandle); strcpy(path, "commun.ex1"); - path[strlen(path) - 1] = *(game_totFileData + 0x3c) + '0'; - commonHandle = data_openData(path); + path[strlen(path) - 1] = *(totFileData + 0x3c) + '0'; + commonHandle = _vm->_dataio->openData(path); handle = commonHandle; } debug(7, "off: %ld size: %ld", offset, tableSize); - data_seekData(handle, offset + tableSize, SEEK_SET); + _vm->_dataio->seekData(handle, offset + tableSize, SEEK_SET); if (isPacked) dataBuf = (char *)malloc(size); else @@ -145,20 +148,20 @@ char *game_loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) { dataPtr = dataBuf; while (size > 32000) { // BUG: huge->far conversion. Need normalization? - data_readData(handle, (char *)dataPtr, 32000); + _vm->_dataio->readData(handle, (char *)dataPtr, 32000); size -= 32000; dataPtr += 32000; } - data_readData(handle, (char *)dataPtr, size); + _vm->_dataio->readData(handle, (char *)dataPtr, size); if (commonHandle != -1) { - data_closeData(commonHandle); - game_extHandle = data_openData(game_curExtFile); + _vm->_dataio->closeData(commonHandle); + extHandle = _vm->_dataio->openData(curExtFile); } if (isPacked != 0) { packedBuf = dataBuf; dataBuf = (char *)malloc(READ_LE_UINT32(packedBuf)); - unpackData(packedBuf, dataBuf); + _vm->_pack->unpackData(packedBuf, dataBuf); free(packedBuf); } @@ -166,30 +169,30 @@ char *game_loadExtData(int16 itemId, int16 *pResWidth, int16 *pResHeight) { } -void game_clearCollisions() { +void Game::clearCollisions() { int16 i; for (i = 0; i < 250; i++) { - game_collisionAreas[i].id = 0; - game_collisionAreas[i].left = -1; + collisionAreas[i].id = 0; + collisionAreas[i].left = -1; } } -void game_addNewCollision(int16 id, int16 left, int16 top, int16 right, int16 bottom, +void Game::addNewCollision(int16 id, int16 left, int16 top, int16 right, int16 bottom, int16 flags, int16 key, int16 funcEnter, int16 funcLeave) { int16 i; - Game_Collision *ptr; + Collision *ptr; - debug(5, "game_addNewCollision"); + debug(5, "addNewCollision"); debug(5, "id = %x", id); debug(5, "left = %d, top = %d, right = %d, bottom = %d", left, top, right, bottom); debug(5, "flags = %x, key = %x", flags, key); debug(5, "funcEnter = %d, funcLeave = %d", funcEnter, funcLeave); for (i = 0; i < 250; i++) { - if (game_collisionAreas[i].left != -1) + if (collisionAreas[i].left != -1) continue; - ptr = &game_collisionAreas[i]; + ptr = &collisionAreas[i]; ptr->id = id; ptr->left = left; ptr->top = top; @@ -201,63 +204,63 @@ void game_addNewCollision(int16 id, int16 left, int16 top, int16 right, int16 bo ptr->funcLeave = funcLeave; return; } - error("game_addNewCollision: Collision array full!\n"); + error("addNewCollision: Collision array full!\n"); } -void game_freeCollision(int16 id) { +void Game::freeCollision(int16 id) { int16 i; for (i = 0; i < 250; i++) { - if (game_collisionAreas[i].id == id) - game_collisionAreas[i].left = -1; + if (collisionAreas[i].id == id) + collisionAreas[i].left = -1; } } -void game_pushCollisions(char all) { - Game_Collision *srcPtr; - Game_Collision *destPtr; +void Game::pushCollisions(char all) { + Collision *srcPtr; + Collision *destPtr; int16 size; - debug(4, "game_pushCollisions"); - for (size = 0, srcPtr = game_collisionAreas; srcPtr->left != -1; + debug(4, "pushCollisions"); + for (size = 0, srcPtr = collisionAreas; srcPtr->left != -1; srcPtr++) { if (all || (srcPtr->id & 0x8000)) size++; } - destPtr = (Game_Collision *)malloc(size * sizeof(Game_Collision)); - game_collStack[game_collStackSize] = destPtr; - game_collStackElemSizes[game_collStackSize] = size; - game_collStackSize++; + destPtr = (Collision *)malloc(size * sizeof(Collision)); + collStack[collStackSize] = destPtr; + collStackElemSizes[collStackSize] = size; + collStackSize++; - for (srcPtr = game_collisionAreas; srcPtr->left != -1; srcPtr++) { + for (srcPtr = collisionAreas; srcPtr->left != -1; srcPtr++) { if (all || (srcPtr->id & 0x8000)) { - memcpy(destPtr, srcPtr, sizeof(Game_Collision)); + memcpy(destPtr, srcPtr, sizeof(Collision)); srcPtr->left = -1; destPtr++; } } } -void game_popCollisions(void) { - Game_Collision *destPtr; - Game_Collision *srcPtr; +void Game::popCollisions(void) { + Collision *destPtr; + Collision *srcPtr; - debug(4, "game_popCollision"); + debug(4, "popCollision"); - game_collStackSize--; - for (destPtr = game_collisionAreas; destPtr->left != -1; destPtr++); + collStackSize--; + for (destPtr = collisionAreas; destPtr->left != -1; destPtr++); - srcPtr = game_collStack[game_collStackSize]; + srcPtr = collStack[collStackSize]; memcpy(destPtr, srcPtr, - game_collStackElemSizes[game_collStackSize] * - sizeof(Game_Collision)); + collStackElemSizes[collStackSize] * + sizeof(Collision)); - free(game_collStack[game_collStackSize]); + free(collStack[collStackSize]); } -int16 game_checkMousePoint(int16 all, int16 *resId, int16 *resIndex) { - Game_Collision *ptr; +int16 Game::checkMousePoint(int16 all, int16 *resId, int16 *resIndex) { + Collision *ptr; int16 i; if (resId != 0) @@ -265,7 +268,7 @@ int16 game_checkMousePoint(int16 all, int16 *resId, int16 *resIndex) { *resIndex = 0; - ptr = game_collisionAreas; + ptr = collisionAreas; for (i = 0; ptr->left != -1; ptr++, i++) { if (all) { if ((ptr->flags & 0xf) > 1) @@ -274,10 +277,10 @@ int16 game_checkMousePoint(int16 all, int16 *resId, int16 *resIndex) { if ((ptr->flags & 0xff00) != 0) continue; - if (inter_mouseX < ptr->left - || inter_mouseX > ptr->right - || inter_mouseY < ptr->top - || inter_mouseY > ptr->bottom) + if (_vm->_global->inter_mouseX < ptr->left + || _vm->_global->inter_mouseX > ptr->right + || _vm->_global->inter_mouseY < ptr->top + || _vm->_global->inter_mouseY > ptr->bottom) continue; if (resId != 0) @@ -292,14 +295,14 @@ int16 game_checkMousePoint(int16 all, int16 *resId, int16 *resIndex) { if ((ptr->flags & 0xf) != 1 && (ptr->flags & 0xf) != 2) continue; - if ((ptr->flags & 0xf0) >> 4 != game_mouseButtons - 1 + if ((ptr->flags & 0xf0) >> 4 != mouseButtons - 1 && (ptr->flags & 0xf0) >> 4 != 2) continue; - if (inter_mouseX < ptr->left - || inter_mouseX > ptr->right - || inter_mouseY < ptr->top - || inter_mouseY > ptr->bottom) + if (_vm->_global->inter_mouseX < ptr->left + || _vm->_global->inter_mouseX > ptr->right + || _vm->_global->inter_mouseY < ptr->top + || _vm->_global->inter_mouseY > ptr->bottom) continue; if (resId != 0) @@ -309,88 +312,88 @@ int16 game_checkMousePoint(int16 all, int16 *resId, int16 *resIndex) { } } - if (game_mouseButtons != 1 && all == 0) + if (mouseButtons != 1 && all == 0) return 0x11b; return 0; } -void game_capturePush(int16 left, int16 top, int16 width, int16 height) { +void Game::capturePush(int16 left, int16 top, int16 width, int16 height) { int16 right; - if (game_captureCount == 20) - error("game_capturePush: Capture stack overflow!"); + if (captureCount == 20) + error("capturePush: Capture stack overflow!"); - game_captureStack[game_captureCount].left = left; - game_captureStack[game_captureCount].top = top; - game_captureStack[game_captureCount].right = left + width; - game_captureStack[game_captureCount].bottom = top + height; + captureStack[captureCount].left = left; + captureStack[captureCount].top = top; + captureStack[captureCount].right = left + width; + captureStack[captureCount].bottom = top + height; - draw_spriteTop = top; - draw_spriteBottom = height; + _vm->_draw->spriteTop = top; + _vm->_draw->spriteBottom = height; right = left + width - 1; left &= 0xfff0; right |= 0xf; - draw_spritesArray[30 + game_captureCount] = - vid_initSurfDesc(videoMode, right - left + 1, height, 0); + _vm->_draw->spritesArray[30 + captureCount] = + _vm->_video->initSurfDesc(_vm->_global->videoMode, right - left + 1, height, 0); - draw_sourceSurface = 21; - draw_destSurface = 30 + game_captureCount; + _vm->_draw->sourceSurface = 21; + _vm->_draw->destSurface = 30 + captureCount; - draw_spriteLeft = left; - draw_spriteRight = right - left + 1; - draw_destSpriteX = 0; - draw_destSpriteY = 0; - draw_transparency = 0; - draw_spriteOperation(0); - game_captureCount++; + _vm->_draw->spriteLeft = left; + _vm->_draw->spriteRight = right - left + 1; + _vm->_draw->destSpriteX = 0; + _vm->_draw->destSpriteY = 0; + _vm->_draw->transparency = 0; + _vm->_draw->spriteOperation(0); + captureCount++; } -void game_capturePop(char doDraw) { - if (game_captureCount <= 0) +void Game::capturePop(char doDraw) { + if (captureCount <= 0) return; - game_captureCount--; + captureCount--; if (doDraw) { - draw_destSpriteX = game_captureStack[game_captureCount].left; - draw_destSpriteY = game_captureStack[game_captureCount].top; - draw_spriteRight = - game_captureStack[game_captureCount].width(); - draw_spriteBottom = - game_captureStack[game_captureCount].height(); - - draw_transparency = 0; - draw_sourceSurface = 30 + game_captureCount; - draw_destSurface = 21; - draw_spriteLeft = draw_destSpriteX & 0xf; - draw_spriteTop = 0; - draw_spriteOperation(0); + _vm->_draw->destSpriteX = captureStack[captureCount].left; + _vm->_draw->destSpriteY = captureStack[captureCount].top; + _vm->_draw->spriteRight = + captureStack[captureCount].width(); + _vm->_draw->spriteBottom = + captureStack[captureCount].height(); + + _vm->_draw->transparency = 0; + _vm->_draw->sourceSurface = 30 + captureCount; + _vm->_draw->destSurface = 21; + _vm->_draw->spriteLeft = _vm->_draw->destSpriteX & 0xf; + _vm->_draw->spriteTop = 0; + _vm->_draw->spriteOperation(0); } - vid_freeSurfDesc(draw_spritesArray[30 + game_captureCount]); + _vm->_video->freeSurfDesc(_vm->_draw->spritesArray[30 + captureCount]); } -char *game_loadTotResource(int16 id) { - Game_TotResItem *itemPtr; +char *Game::loadTotResource(int16 id) { + TotResItem *itemPtr; int32 offset; - itemPtr = &game_totResourceTable->items[id]; + itemPtr = &totResourceTable->items[id]; offset = itemPtr->offset; if (offset >= 0) { - return ((char *)game_totResourceTable) + szGame_TotResTable + - szGame_TotResItem * game_totResourceTable->itemsCount + offset; + return ((char *)totResourceTable) + szGame_TotResTable + + szGame_TotResItem * totResourceTable->itemsCount + offset; } else { - return (char *)(game_imFileData + (int32)READ_LE_UINT32(&((int32 *)game_imFileData)[-offset - 1])); + return (char *)(imFileData + (int32)READ_LE_UINT32(&((int32 *)imFileData)[-offset - 1])); } } -void game_loadSound(int16 slot, char *dataPtr) { - Snd_SoundDesc *soundDesc; +void Game::loadSound(int16 slot, char *dataPtr) { + Snd::SoundDesc *soundDesc; - soundDesc = (Snd_SoundDesc *)malloc(sizeof(Snd_SoundDesc)); + soundDesc = (Snd::SoundDesc *)malloc(sizeof(Snd::SoundDesc)); - game_soundSamples[slot] = soundDesc; + soundSamples[slot] = soundDesc; soundDesc->frequency = (dataPtr[4] << 8) + dataPtr[5]; soundDesc->size = (dataPtr[1] << 16) + (dataPtr[2] << 8) + dataPtr[3]; @@ -401,77 +404,77 @@ void game_loadSound(int16 slot, char *dataPtr) { soundDesc->flag = 0; } -void game_interLoadSound(int16 slot) { +void Game::interLoadSound(int16 slot) { char *dataPtr; int16 id; if (slot == -1) - slot = parse_parseValExpr(); + slot = _vm->_parse->parseValExpr(); - id = inter_load16(); + id = _vm->_inter->load16(); if (id == -1) { - inter_execPtr += 9; + _vm->_global->inter_execPtr += 9; return; } if (id >= 30000) { - dataPtr = game_loadExtData(id, 0, 0); - game_soundFromExt[slot] = 1; + dataPtr = loadExtData(id, 0, 0); + soundFromExt[slot] = 1; } else { - dataPtr = game_loadTotResource(id); - game_soundFromExt[slot] = 0; + dataPtr = loadTotResource(id); + soundFromExt[slot] = 0; } - game_loadSound(slot, dataPtr); + loadSound(slot, dataPtr); } -void game_freeSoundSlot(int16 slot) { +void Game::freeSoundSlot(int16 slot) { if (slot == -1) - slot = parse_parseValExpr(); + slot = _vm->_parse->parseValExpr(); - if (game_soundSamples[slot] == 0) + if (soundSamples[slot] == 0) return; - if (game_soundFromExt[slot] == 1) { - free(game_soundSamples[slot]->data - 6); - game_soundFromExt[slot] = 0; + if (soundFromExt[slot] == 1) { + free(soundSamples[slot]->data - 6); + soundFromExt[slot] = 0; } - free(game_soundSamples[slot]); - game_soundSamples[slot] = 0; + free(soundSamples[slot]); + soundSamples[slot] = 0; } -int16 game_checkKeys(int16 *pMouseX, int16 *pMouseY, int16 *pButtons, char handleMouse) { - util_processInput(); +int16 Game::checkKeys(int16 *pMouseX, int16 *pMouseY, int16 *pButtons, char handleMouse) { + _vm->_util->processInput(); if (VAR(58) != 0) { - if (mult_frameStart != (int)VAR(58) - 1) - mult_frameStart++; + if (_vm->_mult->frameStart != (int)VAR(58) - 1) + _vm->_mult->frameStart++; else - mult_frameStart = 0; + _vm->_mult->frameStart = 0; - mult_playMult(mult_frameStart + VAR(57), mult_frameStart + VAR(57), 1, + _vm->_mult->playMult(_vm->_mult->frameStart + VAR(57), _vm->_mult->frameStart + VAR(57), 1, handleMouse); } - if (inter_soundEndTimeKey != 0 - && util_getTimeKey() >= inter_soundEndTimeKey) { - snd_stopSound(inter_soundStopVal); - inter_soundEndTimeKey = 0; + if (_vm->_inter->soundEndTimeKey != 0 + && _vm->_util->getTimeKey() >= _vm->_inter->soundEndTimeKey) { + _vm->_snd->stopSound(_vm->_inter->soundStopVal); + _vm->_inter->soundEndTimeKey = 0; } - if (useMouse == 0) - error("game_checkKeys: Can't work without mouse!"); + if (_vm->_global->useMouse == 0) + error("checkKeys: Can't work without mouse!"); - util_getMouseState(pMouseX, pMouseY, pButtons); + _vm->_util->getMouseState(pMouseX, pMouseY, pButtons); if (*pButtons == 3) *pButtons = 0; - return util_checkKey(); + return _vm->_util->checkKey(); } -int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId, +int16 Game::checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId, int16 *pResIndex) { char *savedIP; int16 resIndex; @@ -481,9 +484,9 @@ int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId, uint32 timeKey; if (deltaTime >= -1) { - game_lastCollKey = 0; - game_lastCollAreaIndex = 0; - game_lastCollId = 0; + lastCollKey = 0; + lastCollAreaIndex = 0; + lastCollId = 0; } if (pResId != 0) @@ -491,48 +494,48 @@ int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId, resIndex = 0; - if (draw_cursorIndex == -1 && handleMouse != 0 - && game_lastCollKey == 0) { - game_lastCollKey = - game_checkMousePoint(1, &game_lastCollId, - &game_lastCollAreaIndex); + if (_vm->_draw->gcursorIndex == -1 && handleMouse != 0 + && lastCollKey == 0) { + lastCollKey = + checkMousePoint(1, &lastCollId, + &lastCollAreaIndex); - if (game_lastCollKey != 0 && (game_lastCollId & 0x8000) != 0) { - savedIP = inter_execPtr; - inter_execPtr = (char *)game_totFileData + - game_collisionAreas[game_lastCollAreaIndex].funcEnter; + if (lastCollKey != 0 && (lastCollId & 0x8000) != 0) { + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = (char *)totFileData + + collisionAreas[lastCollAreaIndex].funcEnter; - inter_funcBlock(0); - inter_execPtr = savedIP; + _vm->_inter->funcBlock(0); + _vm->_global->inter_execPtr = savedIP; } } if (handleMouse != 0) - draw_animateCursor(-1); + _vm->_draw->animateCursor(-1); - timeKey = util_getTimeKey(); + timeKey = _vm->_util->getTimeKey(); while (1) { - if (inter_terminate != 0) { + if (_vm->_inter->terminate != 0) { if (handleMouse) - draw_blitCursor(); + _vm->_draw->blitCursor(); return 0; } - if (draw_noInvalidated == 0) { + if (_vm->_draw->noInvalidated == 0) { if (handleMouse) - draw_animateCursor(-1); + _vm->_draw->animateCursor(-1); else - draw_blitInvalidated(); + _vm->_draw->blitInvalidated(); } - // NOTE: the original asm does the below game_checkKeys call + // NOTE: the original asm does the below checkKeys call // _before_ this check. However, that can cause keypresses to get lost // since there's a return statement in this check. // Additionally, I added a 'deltaTime == -1' check there, since - // when this function is called with deltaTime == -1 in game_inputArea, + // when this function is called with deltaTime == -1 in inputArea, // and the return value is then discarded. if (deltaTime < 0) { - uint32 curtime = util_getTimeKey(); + uint32 curtime = _vm->_util->getTimeKey(); if (deltaTime == -1 || curtime + deltaTime > timeKey) { if (pResId != 0) *pResId = 0; @@ -544,18 +547,18 @@ int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId, } } - key = game_checkKeys(&inter_mouseX, &inter_mouseY, - &game_mouseButtons, handleMouse); + key = checkKeys(&_vm->_global->inter_mouseX, &_vm->_global->inter_mouseY, + &mouseButtons, handleMouse); - if (handleMouse == 0 && game_mouseButtons != 0) { - util_waitMouseRelease(0); + if (handleMouse == 0 && mouseButtons != 0) { + _vm->_util->waitMouseRelease(0); key = 3; } if (key != 0) { if (handleMouse == 1) - draw_blitCursor(); + _vm->_draw->blitCursor(); if (pResId != 0) *pResId = 0; @@ -563,118 +566,118 @@ int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId, if (pResIndex != 0) *pResIndex = 0; - if (game_lastCollKey != 0 && - game_collisionAreas[game_lastCollAreaIndex].funcLeave != 0) { - savedIP = inter_execPtr; - inter_execPtr = (char *)game_totFileData + - game_collisionAreas[game_lastCollAreaIndex].funcLeave; + if (lastCollKey != 0 && + collisionAreas[lastCollAreaIndex].funcLeave != 0) { + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = (char *)totFileData + + collisionAreas[lastCollAreaIndex].funcLeave; - inter_funcBlock(0); - inter_execPtr = savedIP; + _vm->_inter->funcBlock(0); + _vm->_global->inter_execPtr = savedIP; } - game_lastCollKey = 0; + lastCollKey = 0; if (key != 0) return key; } if (handleMouse != 0) { - if (game_mouseButtons != 0) { + if (mouseButtons != 0) { oldIndex = 0; - draw_animateCursor(2); + _vm->_draw->animateCursor(2); if (deltaTime <= 0) { if (handleMouse == 1) - util_waitMouseRelease(1); + _vm->_util->waitMouseRelease(1); } else if (deltaTime > 0) { - util_delay(deltaTime); + _vm->_util->delay(deltaTime); } - draw_animateCursor(-1); + _vm->_draw->animateCursor(-1); if (pResId != 0) *pResId = 0; - key = game_checkMousePoint(0, pResId, &resIndex); + key = checkMousePoint(0, pResId, &resIndex); if (pResIndex != 0) *pResIndex = resIndex; if (key != 0 || (pResId != 0 && *pResId != 0)) { if (handleMouse == 1 && (deltaTime <= 0 - || game_mouseButtons == 0)) - draw_blitCursor(); - - if (game_lastCollKey != 0 && - game_collisionAreas[game_lastCollAreaIndex].funcLeave != 0) { - savedIP = inter_execPtr; - inter_execPtr = - (char *)game_totFileData + - game_collisionAreas[game_lastCollAreaIndex].funcLeave; - - inter_funcBlock(0); - inter_execPtr = savedIP; + || mouseButtons == 0)) + _vm->_draw->blitCursor(); + + if (lastCollKey != 0 && + collisionAreas[lastCollAreaIndex].funcLeave != 0) { + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = + (char *)totFileData + + collisionAreas[lastCollAreaIndex].funcLeave; + + _vm->_inter->funcBlock(0); + _vm->_global->inter_execPtr = savedIP; } - game_lastCollKey = 0; + lastCollKey = 0; return key; } - if (game_lastCollKey != 0 && - game_collisionAreas[game_lastCollAreaIndex].funcLeave != 0) { - savedIP = inter_execPtr; - inter_execPtr = - (char *)game_totFileData + - game_collisionAreas[game_lastCollAreaIndex].funcLeave; + if (lastCollKey != 0 && + collisionAreas[lastCollAreaIndex].funcLeave != 0) { + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = + (char *)totFileData + + collisionAreas[lastCollAreaIndex].funcLeave; - inter_funcBlock(0); - inter_execPtr = savedIP; + _vm->_inter->funcBlock(0); + _vm->_global->inter_execPtr = savedIP; } - game_lastCollKey = - game_checkMousePoint(1, &game_lastCollId, - &game_lastCollAreaIndex); + lastCollKey = + checkMousePoint(1, &lastCollId, + &lastCollAreaIndex); - if (game_lastCollKey != 0 - && (game_lastCollId & 0x8000) != 0) { - savedIP = inter_execPtr; - inter_execPtr = - (char *)game_totFileData + - game_collisionAreas[game_lastCollAreaIndex].funcEnter; + if (lastCollKey != 0 + && (lastCollId & 0x8000) != 0) { + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = + (char *)totFileData + + collisionAreas[lastCollAreaIndex].funcEnter; - inter_funcBlock(0); - inter_execPtr = savedIP; + _vm->_inter->funcBlock(0); + _vm->_global->inter_execPtr = savedIP; } } else { if (handleMouse != 0 && - (inter_mouseX != draw_cursorX - || inter_mouseY != draw_cursorY)) { - oldIndex = game_lastCollAreaIndex; - oldId = game_lastCollId; + (_vm->_global->inter_mouseX != _vm->_draw->cursorX + || _vm->_global->inter_mouseY != _vm->_draw->cursorY)) { + oldIndex = lastCollAreaIndex; + oldId = lastCollId; key = - game_checkMousePoint(1, - &game_lastCollId, - &game_lastCollAreaIndex); + checkMousePoint(1, + &lastCollId, + &lastCollAreaIndex); - if (key != game_lastCollKey) { - if (game_lastCollKey != 0 + if (key != lastCollKey) { + if (lastCollKey != 0 && (oldId & 0x8000) != 0) { - savedIP = inter_execPtr; - inter_execPtr = (char *)game_totFileData + - game_collisionAreas[oldIndex].funcLeave; + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = (char *)totFileData + + collisionAreas[oldIndex].funcLeave; - inter_funcBlock(0); - inter_execPtr = savedIP; + _vm->_inter->funcBlock(0); + _vm->_global->inter_execPtr = savedIP; } - game_lastCollKey = key; - if (game_lastCollKey != 0 && (game_lastCollId & 0x8000) != 0) { - savedIP = inter_execPtr; - inter_execPtr = (char *)game_totFileData + - game_collisionAreas[game_lastCollAreaIndex].funcEnter; + lastCollKey = key; + if (lastCollKey != 0 && (lastCollId & 0x8000) != 0) { + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = (char *)totFileData + + collisionAreas[lastCollAreaIndex].funcEnter; - inter_funcBlock(0); - inter_execPtr = savedIP; + _vm->_inter->funcBlock(0); + _vm->_global->inter_execPtr = savedIP; } } } @@ -682,19 +685,19 @@ int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId, } if (handleMouse != 0) - draw_animateCursor(-1); + _vm->_draw->animateCursor(-1); - util_delay(10); + _vm->_util->delay(10); - snd_loopSounds(); + _vm->_snd->loopSounds(); } } -int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 backColor, +int16 Game::inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 backColor, int16 frontColor, char *str, int16 fontIndex, char inpType, int16 *pTotTime) { int16 handleMouse; uint32 editSize; - FontDesc *pFont; + Video::FontDesc *pFont; char curSym; int16 key; const char *str1; @@ -704,116 +707,116 @@ int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 ba int16 flag; int16 savedKey; - if (game_handleMouse != 0 && - (useMouse != 0 || game_forceHandleMouse != 0)) + if (ghandleMouse != 0 && + (_vm->_global->useMouse != 0 || forceHandleMouse != 0)) handleMouse = 1; else handleMouse = 0; pos = strlen(str); - pFont = draw_fonts[fontIndex]; + pFont = _vm->_draw->fonts[fontIndex]; editSize = width / pFont->itemWidth; while (1) { - strcpy(game_tempStr, str); - strcat(game_tempStr, " "); - if (strlen(game_tempStr) > editSize) - strcpy(game_tempStr, str); - - draw_destSpriteX = xPos; - draw_destSpriteY = yPos; - draw_spriteRight = editSize * pFont->itemWidth; - draw_spriteBottom = height; - - draw_destSurface = 21; - draw_backColor = backColor; - draw_frontColor = frontColor; - draw_textToPrint = game_tempStr; - draw_transparency = 1; - draw_fontIndex = fontIndex; - draw_spriteOperation(DRAW_FILLRECT); - - draw_destSpriteY = yPos + (height - 8) / 2; - - draw_spriteOperation(DRAW_PRINTTEXT); + strcpy(tempStr, str); + strcat(tempStr, " "); + if (strlen(tempStr) > editSize) + strcpy(tempStr, str); + + _vm->_draw->destSpriteX = xPos; + _vm->_draw->destSpriteY = yPos; + _vm->_draw->spriteRight = editSize * pFont->itemWidth; + _vm->_draw->spriteBottom = height; + + _vm->_draw->destSurface = 21; + _vm->_draw->backColor = backColor; + _vm->_draw->frontColor = frontColor; + _vm->_draw->textToPrint = tempStr; + _vm->_draw->transparency = 1; + _vm->_draw->fontIndex = fontIndex; + _vm->_draw->spriteOperation(DRAW_FILLRECT); + + _vm->_draw->destSpriteY = yPos + (height - 8) / 2; + + _vm->_draw->spriteOperation(DRAW_PRINTTEXT); if (pos == editSize) pos--; - curSym = game_tempStr[pos]; + curSym = tempStr[pos]; flag = 1; while (1) { - game_tempStr[0] = curSym; - game_tempStr[1] = 0; + tempStr[0] = curSym; + tempStr[1] = 0; - draw_destSpriteX = xPos + pFont->itemWidth * pos; - draw_destSpriteY = yPos + height - 1; - draw_spriteRight = pFont->itemWidth; - draw_spriteBottom = 1; - draw_destSurface = 21; - draw_backColor = frontColor; - draw_spriteOperation(DRAW_FILLRECT); + _vm->_draw->destSpriteX = xPos + pFont->itemWidth * pos; + _vm->_draw->destSpriteY = yPos + height - 1; + _vm->_draw->spriteRight = pFont->itemWidth; + _vm->_draw->spriteBottom = 1; + _vm->_draw->destSurface = 21; + _vm->_draw->backColor = frontColor; + _vm->_draw->spriteOperation(DRAW_FILLRECT); if (flag != 0) { - key = game_checkCollisions(handleMouse, -1, - &game_activeCollResId, - &game_activeCollIndex); + key = checkCollisions(handleMouse, -1, + &activeCollResId, + &activeCollIndex); } flag = 0; - key = game_checkCollisions(handleMouse, -300, - &game_activeCollResId, &game_activeCollIndex); + key = checkCollisions(handleMouse, -300, + &activeCollResId, &activeCollIndex); if (*pTotTime > 0) { *pTotTime -= 300; if (*pTotTime <= 1) { key = 0; - game_activeCollResId = 0; + activeCollResId = 0; break; } } - game_tempStr[0] = curSym; - game_tempStr[1] = 0; - draw_destSpriteX = xPos + pFont->itemWidth * pos; - draw_destSpriteY = yPos + height - 1; - draw_spriteRight = pFont->itemWidth; - draw_spriteBottom = 1; - draw_destSurface = 21; - draw_backColor = backColor; - draw_frontColor = frontColor; - draw_textToPrint = game_tempStr; - draw_transparency = 1; - draw_spriteOperation(DRAW_FILLRECT); - - draw_destSpriteY = yPos + (height - 8) / 2; - draw_spriteOperation(DRAW_PRINTTEXT); - - if (key != 0 || game_activeCollResId != 0) + tempStr[0] = curSym; + tempStr[1] = 0; + _vm->_draw->destSpriteX = xPos + pFont->itemWidth * pos; + _vm->_draw->destSpriteY = yPos + height - 1; + _vm->_draw->spriteRight = pFont->itemWidth; + _vm->_draw->spriteBottom = 1; + _vm->_draw->destSurface = 21; + _vm->_draw->backColor = backColor; + _vm->_draw->frontColor = frontColor; + _vm->_draw->textToPrint = tempStr; + _vm->_draw->transparency = 1; + _vm->_draw->spriteOperation(DRAW_FILLRECT); + + _vm->_draw->destSpriteY = yPos + (height - 8) / 2; + _vm->_draw->spriteOperation(DRAW_PRINTTEXT); + + if (key != 0 || activeCollResId != 0) break; - key = game_checkCollisions(handleMouse, -300, - &game_activeCollResId, &game_activeCollIndex); + key = checkCollisions(handleMouse, -300, + &activeCollResId, &activeCollIndex); if (*pTotTime > 0) { *pTotTime -= 300; if (*pTotTime <= 1) { key = 0; - game_activeCollResId = 0; + activeCollResId = 0; break; } } - if (key != 0 || game_activeCollResId != 0) + if (key != 0 || activeCollResId != 0) break; - if (inter_terminate != 0) + if (_vm->_inter->terminate != 0) return 0; } - if (key == 0 || game_activeCollResId != 0 - || inter_terminate != 0) + if (key == 0 || activeCollResId != 0 + || _vm->_inter->terminate != 0) return 0; switch (key) { @@ -833,7 +836,7 @@ int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 ba case 0xe08: // Backspace if (pos > 0) { - util_cutFromStr(str, pos - 1, 1); + _vm->_util->cutFromStr(str, pos - 1, 1); pos--; continue; } @@ -843,7 +846,7 @@ int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 ba if (pos >= strlen(str)) continue; - util_cutFromStr(str, pos, 1); + _vm->_util->cutFromStr(str, pos, 1); continue; case 0x1c0d: // Enter @@ -862,21 +865,21 @@ int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 ba return key; case 0x11b: // Escape - if (useMouse != 0) + if (_vm->_global->useMouse != 0) continue; - game_forceHandleMouse = !game_forceHandleMouse; + forceHandleMouse = !forceHandleMouse; - if (game_handleMouse != 0 && - (useMouse != 0 || game_forceHandleMouse != 0)) + if (ghandleMouse != 0 && + (_vm->_global->useMouse != 0 || forceHandleMouse != 0)) handleMouse = 1; else handleMouse = 0; - if (pressedKeys[1] == 0) + if (_vm->_global->pressedKeys[1] == 0) continue; - while (pressedKeys[1] != 0); + while (_vm->_global->pressedKeys[1] != 0); continue; default: @@ -906,17 +909,17 @@ int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 ba if (key >= ' ' && key <= 0xff) { if (editSize == strlen(str)) - util_cutFromStr(str, strlen(str) - 1, + _vm->_util->cutFromStr(str, strlen(str) - 1, 1); if (key >= 'a' && key <= 'z') key += ('A' - 'a'); pos++; - game_tempStr[0] = key; - game_tempStr[1] = 0; + tempStr[0] = key; + tempStr[1] = 0; - util_insertStr(game_tempStr, str, pos - 1); + _vm->_util->insertStr(tempStr, str, pos - 1); //strupr(str); } @@ -924,8 +927,8 @@ int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 ba } } -int16 game_multiEdit(int16 time, int16 index, int16 *pCurPos, Game_InputDesc * inpDesc) { - Game_Collision *collArea; +int16 Game::multiEdit(int16 time, int16 index, int16 *pCurPos, InputDesc * inpDesc) { + Collision *collArea; int16 descInd; int16 key; int16 found = -1; @@ -933,7 +936,7 @@ int16 game_multiEdit(int16 time, int16 index, int16 *pCurPos, Game_InputDesc * i descInd = 0; for (i = 0; i < 250; i++) { - collArea = &game_collisionAreas[i]; + collArea = &collisionAreas[i]; if (collArea->left == -1) continue; @@ -947,25 +950,25 @@ int16 game_multiEdit(int16 time, int16 index, int16 *pCurPos, Game_InputDesc * i if ((collArea->flags & 0x0f) > 10) continue; - strcpy(game_tempStr, inter_variables + collArea->key); + strcpy(tempStr, _vm->_global->inter_variables + collArea->key); - draw_destSpriteX = collArea->left; - draw_destSpriteY = collArea->top; - draw_spriteRight = collArea->right - collArea->left + 1; - draw_spriteBottom = collArea->bottom - collArea->top + 1; + _vm->_draw->destSpriteX = collArea->left; + _vm->_draw->destSpriteY = collArea->top; + _vm->_draw->spriteRight = collArea->right - collArea->left + 1; + _vm->_draw->spriteBottom = collArea->bottom - collArea->top + 1; - draw_destSurface = 21; + _vm->_draw->destSurface = 21; - draw_backColor = inpDesc[descInd].backColor; - draw_frontColor = inpDesc[descInd].frontColor; - draw_textToPrint = game_tempStr; - draw_transparency = 1; - draw_fontIndex = inpDesc[descInd].fontIndex; - draw_spriteOperation(DRAW_FILLRECT); - draw_destSpriteY += + _vm->_draw->backColor = inpDesc[descInd].backColor; + _vm->_draw->frontColor = inpDesc[descInd].frontColor; + _vm->_draw->textToPrint = tempStr; + _vm->_draw->transparency = 1; + _vm->_draw->fontIndex = inpDesc[descInd].fontIndex; + _vm->_draw->spriteOperation(DRAW_FILLRECT); + _vm->_draw->destSpriteY += ((collArea->bottom - collArea->top + 1) - 8) / 2; - draw_spriteOperation(DRAW_PRINTTEXT); + _vm->_draw->spriteOperation(DRAW_PRINTTEXT); descInd++; } @@ -977,7 +980,7 @@ int16 game_multiEdit(int16 time, int16 index, int16 *pCurPos, Game_InputDesc * i descInd = 0; for (i = 0; i < 250; i++) { - collArea = &game_collisionAreas[i]; + collArea = &collisionAreas[i]; if (collArea->left == -1) continue; @@ -1001,34 +1004,34 @@ int16 game_multiEdit(int16 time, int16 index, int16 *pCurPos, Game_InputDesc * i assert(found != -1); - collArea = &game_collisionAreas[found]; + collArea = &collisionAreas[found]; - key = game_inputArea(collArea->left, collArea->top, + key = inputArea(collArea->left, collArea->top, collArea->right - collArea->left + 1, collArea->bottom - collArea->top + 1, inpDesc[*pCurPos].backColor, inpDesc[*pCurPos].frontColor, - inter_variables + collArea->key, + _vm->_global->inter_variables + collArea->key, inpDesc[*pCurPos].fontIndex, collArea->flags, &time); - if (inter_terminate != 0) + if (_vm->_inter->terminate != 0) return 0; switch (key) { case 0: - if (game_activeCollResId == 0) + if (activeCollResId == 0) return 0; - if ((game_collisionAreas[game_activeCollIndex]. + if ((collisionAreas[activeCollIndex]. flags & 0x0f) < 3) return 0; - if ((game_collisionAreas[game_activeCollIndex]. + if ((collisionAreas[activeCollIndex]. flags & 0x0f) > 10) return 0; *pCurPos = 0; for (i = 0; i < 250; i++) { - collArea = &game_collisionAreas[i]; + collArea = &collisionAreas[i]; if (collArea->left == -1) continue; @@ -1042,7 +1045,7 @@ int16 game_multiEdit(int16 time, int16 index, int16 *pCurPos, Game_InputDesc * i if ((collArea->flags & 0x0f) > 10) continue; - if (i == game_activeCollIndex) + if (i == activeCollIndex) break; pCurPos[0]++; @@ -1087,15 +1090,15 @@ int16 game_multiEdit(int16 time, int16 index, int16 *pCurPos, Game_InputDesc * i } } -int16 game_adjustKey(int16 key) { +int16 Game::adjustKey(int16 key) { if (key <= 0x60 || key >= 0x7b) return key; return key - 0x20; } -void game_collisionsBlock(void) { - Game_InputDesc descArray[20]; +void Game::collisionsBlock(void) { + InputDesc descArray[20]; int16 array[250]; char count; int16 collResId; @@ -1125,29 +1128,29 @@ void game_collisionsBlock(void) { int16 var_24; int16 var_26; int16 collStackPos; - Game_Collision *collPtr; + Collision *collPtr; int16 timeKey; char *savedIP; - if (game_shouldPushColls) - game_pushCollisions(1); + if (shouldPushColls) + pushCollisions(1); collResId = -1; - inter_execPtr++; - count = *inter_execPtr++; - game_handleMouse = inter_execPtr[0]; - deltaTime = 1000 * (byte)inter_execPtr[1]; - descIndex2 = (byte)inter_execPtr[2]; - stackPos2 = (byte)inter_execPtr[3]; - descIndex = (byte)inter_execPtr[4]; + _vm->_global->inter_execPtr++; + count = *_vm->_global->inter_execPtr++; + ghandleMouse = _vm->_global->inter_execPtr[0]; + deltaTime = 1000 * (byte)_vm->_global->inter_execPtr[1]; + descIndex2 = (byte)_vm->_global->inter_execPtr[2]; + stackPos2 = (byte)_vm->_global->inter_execPtr[3]; + descIndex = (byte)_vm->_global->inter_execPtr[4]; if (stackPos2 != 0 || descIndex != 0) deltaTime /= 100; timeVal = deltaTime; - inter_execPtr += 6; + _vm->_global->inter_execPtr += 6; - startIP = inter_execPtr; + startIP = _vm->_global->inter_execPtr; WRITE_VAR(16, 0); var_22 = 0; index = 0; @@ -1155,31 +1158,31 @@ void game_collisionsBlock(void) { for (curCmd = 0; curCmd < count; curCmd++) { array[curCmd] = 0; - cmd = *inter_execPtr++; + cmd = *_vm->_global->inter_execPtr++; if ((cmd & 0x40) != 0) { cmd -= 0x40; - cmdHigh = (byte)*inter_execPtr; - inter_execPtr++; + cmdHigh = (byte)*_vm->_global->inter_execPtr; + _vm->_global->inter_execPtr++; cmdHigh <<= 8; } else { cmdHigh = 0; } if ((cmd & 0x80) != 0) { - left = parse_parseValExpr(); - top = parse_parseValExpr(); - width = parse_parseValExpr(); - height = parse_parseValExpr(); + left = _vm->_parse->parseValExpr(); + top = _vm->_parse->parseValExpr(); + width = _vm->_parse->parseValExpr(); + height = _vm->_parse->parseValExpr(); } else { - left = inter_load16(); - top = inter_load16(); - width = inter_load16(); - height = inter_load16(); + left = _vm->_inter->load16(); + top = _vm->_inter->load16(); + width = _vm->_inter->load16(); + height = _vm->_inter->load16(); } cmd &= 0x7f; - debug(4, "game_collisionsBlock(%d)", cmd); + debug(4, "collisionsBlock(%d)", cmd); switch (cmd) { case 3: @@ -1191,41 +1194,41 @@ void game_collisionsBlock(void) { case 9: case 10: - util_waitKey(); + _vm->_util->waitKey(); var_22 = 1; - key = parse_parseVarIndex(); - descArray[index].fontIndex = inter_load16(); - descArray[index].backColor = *inter_execPtr++; - descArray[index].frontColor = *inter_execPtr++; + key = _vm->_parse->parseVarIndex(); + descArray[index].fontIndex = _vm->_inter->load16(); + descArray[index].backColor = *_vm->_global->inter_execPtr++; + descArray[index].frontColor = *_vm->_global->inter_execPtr++; if (cmd < 5 || cmd > 8) { descArray[index].ptr = 0; } else { - descArray[index].ptr = inter_execPtr + 2; - inter_execPtr += inter_load16(); + descArray[index].ptr = _vm->_global->inter_execPtr + 2; + _vm->_global->inter_execPtr += _vm->_inter->load16(); } if (left == -1) break; if ((cmd & 1) == 0) { - game_addNewCollision(curCmd + 0x8000, left, + addNewCollision(curCmd + 0x8000, left, top, left + width * - draw_fonts[descArray[index].fontIndex]-> + _vm->_draw->fonts[descArray[index].fontIndex]-> itemWidth - 1, top + height - 1, cmd, key, 0, - inter_execPtr - (char *)game_totFileData); + _vm->_global->inter_execPtr - (char *)totFileData); - inter_execPtr += 2; - inter_execPtr += READ_LE_UINT16(inter_execPtr); + _vm->_global->inter_execPtr += 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr); } else { - game_addNewCollision(curCmd + 0x8000, left, + addNewCollision(curCmd + 0x8000, left, top, left + width * - draw_fonts[descArray[index].fontIndex]-> + _vm->_draw->fonts[descArray[index].fontIndex]-> itemWidth - 1, top + height - 1, cmd, key, 0, 0); } @@ -1233,18 +1236,18 @@ void game_collisionsBlock(void) { break; case 21: - key = inter_load16(); - array[curCmd] = inter_load16(); - flags = inter_load16() & 3; + key = _vm->_inter->load16(); + array[curCmd] = _vm->_inter->load16(); + flags = _vm->_inter->load16() & 3; - game_addNewCollision(curCmd + 0x8000, left, top, + addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1, (flags << 4) + cmdHigh + 2, key, - inter_execPtr - (char *)game_totFileData, 0); + _vm->_global->inter_execPtr - (char *)totFileData, 0); - inter_execPtr += 2; - inter_execPtr += READ_LE_UINT16(inter_execPtr); + _vm->_global->inter_execPtr += 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr); break; case 20: @@ -1252,97 +1255,97 @@ void game_collisionsBlock(void) { // Fall through to case 2 case 2: - key = inter_load16(); - array[curCmd] = inter_load16(); - flags = inter_load16() & 3; + key = _vm->_inter->load16(); + array[curCmd] = _vm->_inter->load16(); + flags = _vm->_inter->load16() & 3; - game_addNewCollision(curCmd + 0x8000, left, top, + addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1, (flags << 4) + cmdHigh + 2, key, 0, - inter_execPtr - (char *)game_totFileData); + _vm->_global->inter_execPtr - (char *)totFileData); - inter_execPtr += 2; - inter_execPtr += READ_LE_UINT16(inter_execPtr); + _vm->_global->inter_execPtr += 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr); break; case 0: - inter_execPtr += 6; - startIP = inter_execPtr; - inter_execPtr += 2; - inter_execPtr += READ_LE_UINT16(inter_execPtr); + _vm->_global->inter_execPtr += 6; + startIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr += 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr); key = curCmd + 0xA000; - game_addNewCollision(curCmd + 0x8000, left, top, + addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1, cmd + cmdHigh, key, - startIP - (char *)game_totFileData, - inter_execPtr - (char *)game_totFileData); + startIP - (char *)totFileData, + _vm->_global->inter_execPtr - (char *)totFileData); - inter_execPtr += 2; - inter_execPtr += READ_LE_UINT16(inter_execPtr); + _vm->_global->inter_execPtr += 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr); break; case 1: - key = inter_load16(); - array[curCmd] = inter_load16(); - flags = inter_load16() & 3; + key = _vm->_inter->load16(); + array[curCmd] = _vm->_inter->load16(); + flags = _vm->_inter->load16() & 3; - startIP = inter_execPtr; - inter_execPtr += 2; - inter_execPtr += READ_LE_UINT16(inter_execPtr); + startIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr += 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr); if (key == 0) key = curCmd + 0xa000; - game_addNewCollision(curCmd + 0x8000, left, top, + addNewCollision(curCmd + 0x8000, left, top, left + width - 1, top + height - 1, (flags << 4) + cmd + cmdHigh, key, - startIP - (char *)game_totFileData, - inter_execPtr - (char *)game_totFileData); + startIP - (char *)totFileData, + _vm->_global->inter_execPtr - (char *)totFileData); - inter_execPtr += 2; - inter_execPtr += READ_LE_UINT16(inter_execPtr); + _vm->_global->inter_execPtr += 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr); break; } } - game_forceHandleMouse = 0; - util_waitKey(); + forceHandleMouse = 0; + _vm->_util->waitKey(); do { if (var_22 != 0) { key = - game_multiEdit(deltaTime, index, &curEditIndex, + multiEdit(deltaTime, index, &curEditIndex, descArray); if (key == 0x1c0d) { for (i = 0; i < 250; i++) { - if (game_collisionAreas[i].left == -1) + if (collisionAreas[i].left == -1) continue; - if ((game_collisionAreas[i].id & 0x8000) == 0) + if ((collisionAreas[i].id & 0x8000) == 0) continue; - if ((game_collisionAreas[i].flags & 1) != 0) + if ((collisionAreas[i].flags & 1) != 0) continue; - if ((game_collisionAreas[i].flags & 0x0f) <= 2) + if ((collisionAreas[i].flags & 0x0f) <= 2) continue; - collResId = game_collisionAreas[i].id; - game_activeCollResId = collResId; + collResId = collisionAreas[i].id; + activeCollResId = collResId; collResId &= 0x7fff; - game_activeCollIndex = i; + activeCollIndex = i; break; } break; } } else { key = - game_checkCollisions(game_handleMouse, -deltaTime, - &game_activeCollResId, &game_activeCollIndex); + checkCollisions(ghandleMouse, -deltaTime, + &activeCollResId, &activeCollIndex); } if ((key & 0xff) >= ' ' && (key & 0xff) <= 0xff && @@ -1350,44 +1353,44 @@ void game_collisionsBlock(void) { key = '0' + (((key >> 8) - 1) % 10) + (key & 0xff00); } - if (game_activeCollResId == 0) { + if (activeCollResId == 0) { if (key != 0) { for (i = 0; i < 250; i++) { - if (game_collisionAreas[i].left == -1) + if (collisionAreas[i].left == -1) continue; - if ((game_collisionAreas[i]. + if ((collisionAreas[i]. id & 0x8000) == 0) continue; - if (game_collisionAreas[i].key == key - || game_collisionAreas[i].key == + if (collisionAreas[i].key == key + || collisionAreas[i].key == 0x7fff) { - game_activeCollResId = - game_collisionAreas[i].id; - game_activeCollIndex = i; + activeCollResId = + collisionAreas[i].id; + activeCollIndex = i; break; } } - if (game_activeCollResId == 0) { + if (activeCollResId == 0) { for (i = 0; i < 250; i++) { - if (game_collisionAreas[i].left == -1) + if (collisionAreas[i].left == -1) continue; - if ((game_collisionAreas[i].id & 0x8000) == 0) + if ((collisionAreas[i].id & 0x8000) == 0) continue; - if ((game_collisionAreas[i].key & 0xff00) != 0) + if ((collisionAreas[i].key & 0xff00) != 0) continue; - if (game_collisionAreas[i].key == 0) + if (collisionAreas[i].key == 0) continue; - if (game_adjustKey(key & 0xff) == game_adjustKey(game_collisionAreas[i].key) || game_collisionAreas[i].key == 0x7fff) { - game_activeCollResId = game_collisionAreas[i].id; - game_activeCollIndex = i; + if (adjustKey(key & 0xff) == adjustKey(collisionAreas[i].key) || collisionAreas[i].key == 0x7fff) { + activeCollResId = collisionAreas[i].id; + activeCollIndex = i; break; } } @@ -1397,9 +1400,9 @@ void game_collisionsBlock(void) { if (deltaTime != 0 && VAR(16) == 0) { if (stackPos2 != 0) { collStackPos = 0; - collPtr = game_collisionAreas; + collPtr = collisionAreas; - for (i = 0, collPtr = game_collisionAreas; collPtr->left != -1; i++, collPtr++) { + for (i = 0, collPtr = collisionAreas; collPtr->left != -1; i++, collPtr++) { if ((collPtr->id & 0x8000) == 0) continue; @@ -1407,64 +1410,64 @@ void game_collisionsBlock(void) { if (collStackPos != stackPos2) continue; - game_activeCollResId = collPtr->id; - game_activeCollIndex = i; - WRITE_VAR(2, inter_mouseX); - WRITE_VAR(3, inter_mouseY); - WRITE_VAR(4, game_mouseButtons); - WRITE_VAR(16, array[(uint16)game_activeCollResId & ~0x8000]); + activeCollResId = collPtr->id; + activeCollIndex = i; + WRITE_VAR(2, _vm->_global->inter_mouseX); + WRITE_VAR(3, _vm->_global->inter_mouseY); + WRITE_VAR(4, mouseButtons); + WRITE_VAR(16, array[(uint16)activeCollResId & ~0x8000]); if (collPtr->funcLeave != 0) { - timeKey = util_getTimeKey(); - savedIP = inter_execPtr; - inter_execPtr = (char *)game_totFileData + collPtr->funcLeave; - game_shouldPushColls = 1; - savedCollStackSize = game_collStackSize; - inter_funcBlock(0); + timeKey = _vm->_util->getTimeKey(); + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = (char *)totFileData + collPtr->funcLeave; + shouldPushColls = 1; + savedCollStackSize = collStackSize; + _vm->_inter->funcBlock(0); - if (savedCollStackSize != game_collStackSize) - game_popCollisions(); + if (savedCollStackSize != collStackSize) + popCollisions(); - game_shouldPushColls = 0; - inter_execPtr = savedIP; - deltaTime = timeVal - (util_getTimeKey() - timeKey); + shouldPushColls = 0; + _vm->_global->inter_execPtr = savedIP; + deltaTime = timeVal - (_vm->_util->getTimeKey() - timeKey); if (deltaTime < 2) deltaTime = 2; } if (VAR(16) == 0) - game_activeCollResId = 0; + activeCollResId = 0; break; } } else { if (descIndex != 0) { counter = 0; for (i = 0; i < 250; i++) { - if (game_collisionAreas[i].left == -1) + if (collisionAreas[i].left == -1) continue; - if ((game_collisionAreas[i].id & 0x8000) == 0) + if ((collisionAreas[i].id & 0x8000) == 0) continue; counter++; if (counter != descIndex) continue; - game_activeCollResId = game_collisionAreas[i].id; - game_activeCollIndex = i; + activeCollResId = collisionAreas[i].id; + activeCollIndex = i; break; } } else { for (i = 0; i < 250; i++) { - if (game_collisionAreas[i].left == -1) + if (collisionAreas[i].left == -1) continue; - if ((game_collisionAreas[i].id & 0x8000) == 0) + if ((collisionAreas[i].id & 0x8000) == 0) continue; - game_activeCollResId = game_collisionAreas[i].id; - game_activeCollIndex = i; + activeCollResId = collisionAreas[i].id; + activeCollIndex = i; break; } } @@ -1473,18 +1476,18 @@ void game_collisionsBlock(void) { if (descIndex2 != 0) { counter = 0; for (i = 0; i < 250; i++) { - if (game_collisionAreas[i].left == -1) + if (collisionAreas[i].left == -1) continue; - if ((game_collisionAreas[i].id & 0x8000) == 0) + if ((collisionAreas[i].id & 0x8000) == 0) continue; counter++; if (counter != descIndex2) continue; - game_activeCollResId = game_collisionAreas[i].id; - game_activeCollIndex = i; + activeCollResId = collisionAreas[i].id; + activeCollIndex = i; break; } } @@ -1492,86 +1495,86 @@ void game_collisionsBlock(void) { } } - if (game_activeCollResId == 0) + if (activeCollResId == 0) continue; - if (game_collisionAreas[game_activeCollIndex].funcLeave != 0) + if (collisionAreas[activeCollIndex].funcLeave != 0) continue; - WRITE_VAR(2, inter_mouseX); - WRITE_VAR(3, inter_mouseY); - WRITE_VAR(4, game_mouseButtons); - WRITE_VAR(16, array[(uint16)game_activeCollResId & ~0x8000]); + WRITE_VAR(2, _vm->_global->inter_mouseX); + WRITE_VAR(3, _vm->_global->inter_mouseY); + WRITE_VAR(4, mouseButtons); + WRITE_VAR(16, array[(uint16)activeCollResId & ~0x8000]); - if (game_collisionAreas[game_activeCollIndex].funcEnter != 0) { - savedIP = inter_execPtr; - inter_execPtr = (char *)game_totFileData + - game_collisionAreas[game_activeCollIndex]. + if (collisionAreas[activeCollIndex].funcEnter != 0) { + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = (char *)totFileData + + collisionAreas[activeCollIndex]. funcEnter; - game_shouldPushColls = 1; + shouldPushColls = 1; - collStackPos = game_collStackSize; - inter_funcBlock(0); - if (collStackPos != game_collStackSize) - game_popCollisions(); - game_shouldPushColls = 0; - inter_execPtr = savedIP; + collStackPos = collStackSize; + _vm->_inter->funcBlock(0); + if (collStackPos != collStackSize) + popCollisions(); + shouldPushColls = 0; + _vm->_global->inter_execPtr = savedIP; } WRITE_VAR(16, 0); - game_activeCollResId = 0; + activeCollResId = 0; } - while (game_activeCollResId == 0 && inter_terminate == 0); + while (activeCollResId == 0 && _vm->_inter->terminate == 0); - if (((uint16)game_activeCollResId & ~0x8000) == collResId) { + if (((uint16)activeCollResId & ~0x8000) == collResId) { collStackPos = 0; var_24 = 0; var_26 = 1; for (i = 0; i < 250; i++) { - if (game_collisionAreas[i].left == -1) + if (collisionAreas[i].left == -1) continue; - if ((game_collisionAreas[i].id & 0x8000) == 0) + if ((collisionAreas[i].id & 0x8000) == 0) continue; - if ((game_collisionAreas[i].flags & 0x0f) < 3) + if ((collisionAreas[i].flags & 0x0f) < 3) continue; - if ((game_collisionAreas[i].flags & 0x0f) > 10) + if ((collisionAreas[i].flags & 0x0f) > 10) continue; - if ((game_collisionAreas[i].flags & 0x0f) > 8) { - strcpy(game_tempStr, - inter_variables + game_collisionAreas[i].key); + if ((collisionAreas[i].flags & 0x0f) > 8) { + strcpy(tempStr, + _vm->_global->inter_variables + collisionAreas[i].key); while ((pos = - util_strstr(" ", game_tempStr)) != 0) { - util_cutFromStr(game_tempStr, pos - 1, 1); - pos = util_strstr(" ", game_tempStr); + _vm->_util->strstr(" ", tempStr)) != 0) { + _vm->_util->cutFromStr(tempStr, pos - 1, 1); + pos = _vm->_util->strstr(" ", tempStr); } - strcpy(inter_variables + game_collisionAreas[i].key, game_tempStr); + strcpy(_vm->_global->inter_variables + collisionAreas[i].key, tempStr); } - if ((game_collisionAreas[i].flags & 0x0f) >= 5 && - (game_collisionAreas[i].flags & 0x0f) <= 8) { + if ((collisionAreas[i].flags & 0x0f) >= 5 && + (collisionAreas[i].flags & 0x0f) <= 8) { str = descArray[var_24].ptr; - strcpy(game_tempStr, inter_variables + game_collisionAreas[i].key); + strcpy(tempStr, _vm->_global->inter_variables + collisionAreas[i].key); - if ((game_collisionAreas[i].flags & 0x0f) < 7) - util_prepareStr(game_tempStr); + if ((collisionAreas[i].flags & 0x0f) < 7) + _vm->_util->prepareStr(tempStr); pos = 0; do { - strcpy(game_collStr, str); + strcpy(collStr, str); pos += strlen(str) + 1; str += strlen(str) + 1; - if ((game_collisionAreas[i].flags & 0x0f) < 7) - util_prepareStr(game_collStr); + if ((collisionAreas[i].flags & 0x0f) < 7) + _vm->_util->prepareStr(collStr); - if (strcmp(game_tempStr, game_collStr) == 0) { + if (strcmp(tempStr, collStr) == 0) { VAR(17)++; WRITE_VAR(17 + var_26, 1); break; @@ -1592,137 +1595,137 @@ void game_collisionsBlock(void) { } savedIP = 0; - if (inter_terminate == 0) { - savedIP = (char *)game_totFileData + - game_collisionAreas[game_activeCollIndex].funcLeave; + if (_vm->_inter->terminate == 0) { + savedIP = (char *)totFileData + + collisionAreas[activeCollIndex].funcLeave; - WRITE_VAR(2, inter_mouseX); - WRITE_VAR(3, inter_mouseY); - WRITE_VAR(4, game_mouseButtons); + WRITE_VAR(2, _vm->_global->inter_mouseX); + WRITE_VAR(3, _vm->_global->inter_mouseY); + WRITE_VAR(4, mouseButtons); if (VAR(16) == 0) { - WRITE_VAR(16, array[(uint16)game_activeCollResId & ~0x8000]); + WRITE_VAR(16, array[(uint16)activeCollResId & ~0x8000]); } } for (curCmd = 0; curCmd < count; curCmd++) { - game_freeCollision(curCmd + 0x8000); + freeCollision(curCmd + 0x8000); } - inter_execPtr = savedIP; + _vm->_global->inter_execPtr = savedIP; } -void game_prepareStart(void) { +void Game::prepareStart(void) { int16 i; - game_clearCollisions(); + clearCollisions(); - pPaletteDesc->unused2 = draw_unusedPalette2; - pPaletteDesc->unused1 = draw_unusedPalette1; - pPaletteDesc->vgaPal = draw_vgaPalette; + _vm->_global->pPaletteDesc->unused2 = _vm->_draw->unusedPalette2; + _vm->_global->pPaletteDesc->unused1 = _vm->_draw->unusedPalette1; + _vm->_global->pPaletteDesc->vgaPal = _vm->_draw->vgaPalette; - vid_setFullPalette(pPaletteDesc); + _vm->_video->setFullPalette(_vm->_global->pPaletteDesc); - draw_backSurface = vid_initSurfDesc(videoMode, 320, 200, 0); + _vm->_draw->backSurface = _vm->_video->initSurfDesc(_vm->_global->videoMode, 320, 200, 0); - vid_fillRect(draw_backSurface, 0, 0, 319, 199, 1); - draw_frontSurface = pPrimarySurfDesc; - vid_fillRect(draw_frontSurface, 0, 0, 319, 199, 1); + _vm->_video->fillRect(_vm->_draw->backSurface, 0, 0, 319, 199, 1); + _vm->_draw->frontSurface = _vm->_global->pPrimarySurfDesc; + _vm->_video->fillRect(_vm->_draw->frontSurface, 0, 0, 319, 199, 1); - util_setMousePos(152, 92); + _vm->_util->setMousePos(152, 92); - draw_cursorX = 152; - inter_mouseX = 152; + _vm->_draw->cursorX = 152; + _vm->_global->inter_mouseX = 152; - draw_cursorY = 92; - inter_mouseY = 92; - draw_invalidatedCount = 0; - draw_noInvalidated = 1; - draw_applyPal = 0; - draw_paletteCleared = 0; - draw_cursorWidth = 16; - draw_cursorHeight = 16; - draw_transparentCursor = 1; + _vm->_draw->cursorY = 92; + _vm->_global->inter_mouseY = 92; + _vm->_draw->invalidatedCount = 0; + _vm->_draw->noInvalidated = 1; + _vm->_draw->applyPal = 0; + _vm->_draw->paletteCleared = 0; + _vm->_draw->cursorWidth = 16; + _vm->_draw->cursorHeight = 16; + _vm->_draw->transparentCursor = 1; for (i = 0; i < 40; i++) { - draw_cursorAnimLow[i] = -1; - draw_cursorAnimDelays[i] = 0; - draw_cursorAnimHigh[i] = 0; + _vm->_draw->cursorAnimLow[i] = -1; + _vm->_draw->cursorAnimDelays[i] = 0; + _vm->_draw->cursorAnimHigh[i] = 0; } - draw_cursorAnimLow[1] = 0; - draw_cursorSprites = vid_initSurfDesc(videoMode, 32, 16, 2); - draw_cursorBack = vid_initSurfDesc(videoMode, 16, 16, 0); - draw_renderFlags = 0; - draw_backDeltaX = 0; - draw_backDeltaY = 0; + _vm->_draw->cursorAnimLow[1] = 0; + _vm->_draw->cursorSprites = _vm->_video->initSurfDesc(_vm->_global->videoMode, 32, 16, 2); + _vm->_draw->cursorBack = _vm->_video->initSurfDesc(_vm->_global->videoMode, 16, 16, 0); + _vm->_draw->renderFlags = 0; + _vm->_draw->backDeltaX = 0; + _vm->_draw->backDeltaY = 0; - game_startTimeKey = util_getTimeKey(); + startTimeKey = _vm->_util->getTimeKey(); } -void game_loadTotFile(char *path) { +void Game::loadTotFile(char *path) { int16 handle; - handle = data_openData(path); + handle = _vm->_dataio->openData(path); if (handle >= 0) { - data_closeData(handle); - game_totFileData = data_getData(path); + _vm->_dataio->closeData(handle); + totFileData = _vm->_dataio->getData(path); } else { - game_totFileData = 0; + totFileData = 0; } } -void game_loadExtTable(void) { +void Game::loadExtTable(void) { int16 count, i; // Function is correct. [sev] - game_extHandle = data_openData(game_curExtFile); - if (game_extHandle < 0) + extHandle = _vm->_dataio->openData(curExtFile); + if (extHandle < 0) return; - data_readData(game_extHandle, (char *)&count, 2); + _vm->_dataio->readData(extHandle, (char *)&count, 2); count = FROM_LE_16(count); - data_seekData(game_extHandle, 0, 0); - game_extTable = (Game_ExtTable *)malloc(sizeof(Game_ExtTable) - + sizeof(Game_ExtItem) * count); + _vm->_dataio->seekData(extHandle, 0, 0); + extTable = (ExtTable *)malloc(sizeof(ExtTable) + + sizeof(ExtItem) * count); - data_readData(game_extHandle, (char *)&game_extTable->itemsCount, 2); - game_extTable->itemsCount = FROM_LE_16(game_extTable->itemsCount); - data_readData(game_extHandle, (char *)&game_extTable->unknown, 1); + _vm->_dataio->readData(extHandle, (char *)&extTable->itemsCount, 2); + extTable->itemsCount = FROM_LE_16(extTable->itemsCount); + _vm->_dataio->readData(extHandle, (char *)&extTable->unknown, 1); for (i = 0; i < count; i++) { - data_readData(game_extHandle, (char *)&game_extTable->items[i].offset, 4); - game_extTable->items[i].offset = FROM_LE_32(game_extTable->items[i].offset); - data_readData(game_extHandle, (char *)&game_extTable->items[i].size, 2); - game_extTable->items[i].size = FROM_LE_16(game_extTable->items[i].size); - data_readData(game_extHandle, (char *)&game_extTable->items[i].width, 2); - game_extTable->items[i].width = FROM_LE_16(game_extTable->items[i].width); - data_readData(game_extHandle, (char *)&game_extTable->items[i].height, 2); - game_extTable->items[i].height = FROM_LE_16(game_extTable->items[i].height); + _vm->_dataio->readData(extHandle, (char *)&extTable->items[i].offset, 4); + extTable->items[i].offset = FROM_LE_32(extTable->items[i].offset); + _vm->_dataio->readData(extHandle, (char *)&extTable->items[i].size, 2); + extTable->items[i].size = FROM_LE_16(extTable->items[i].size); + _vm->_dataio->readData(extHandle, (char *)&extTable->items[i].width, 2); + extTable->items[i].width = FROM_LE_16(extTable->items[i].width); + _vm->_dataio->readData(extHandle, (char *)&extTable->items[i].height, 2); + extTable->items[i].height = FROM_LE_16(extTable->items[i].height); } } -void game_loadImFile(void) { +void Game::loadImFile(void) { char path[20]; int16 handle; - if (game_totFileData[0x3d] != 0 && game_totFileData[0x3b] == 0) + if (totFileData[0x3d] != 0 && totFileData[0x3b] == 0) return; strcpy(path, "commun.im1"); - if (game_totFileData[0x3b] != 0) - path[strlen(path) - 1] = '0' + game_totFileData[0x3b]; + if (totFileData[0x3b] != 0) + path[strlen(path) - 1] = '0' + totFileData[0x3b]; - handle = data_openData(path); + handle = _vm->_dataio->openData(path); if (handle < 0) return; - data_closeData(handle); - game_imFileData = data_getData(path); + _vm->_dataio->closeData(handle); + imFileData = _vm->_dataio->getData(path); } -void game_playTot(int16 skipPlay) { +void Game::playTot(int16 skipPlay) { char savedTotName[20]; int16 *oldCaptureCounter; int16 *oldBreakFrom; @@ -1738,202 +1741,202 @@ void game_playTot(int16 skipPlay) { char *savedIP; int16 i; - oldNestLevel = inter_nestLevel; - oldBreakFrom = inter_breakFromLevel; - oldCaptureCounter = scen_pCaptureCounter; - savedIP = inter_execPtr; + oldNestLevel = _vm->_inter->nestLevel; + oldBreakFrom = _vm->_inter->breakFromLevel; + oldCaptureCounter = _vm->_scenery->pCaptureCounter; + savedIP = _vm->_global->inter_execPtr; - inter_nestLevel = &nestLevel; - inter_breakFromLevel = &breakFrom; - scen_pCaptureCounter = &captureCounter; - strcpy(savedTotName, game_curTotFile); + _vm->_inter->nestLevel = &nestLevel; + _vm->_inter->breakFromLevel = &breakFrom; + _vm->_scenery->pCaptureCounter = &captureCounter; + strcpy(savedTotName, curTotFile); if (skipPlay == 0) { while (1) { for (i = 0; i < 4; i++) { - draw_fontToSprite[i].sprite = -1; - draw_fontToSprite[i].base = -1; - draw_fontToSprite[i].width = -1; - draw_fontToSprite[i].height = -1; + _vm->_draw->fontToSprite[i].sprite = -1; + _vm->_draw->fontToSprite[i].base = -1; + _vm->_draw->fontToSprite[i].width = -1; + _vm->_draw->fontToSprite[i].height = -1; } - cd_stopPlaying(); - draw_animateCursor(4); - inter_initControlVars(); - mult_initAll(); - mult_zeroMultData(); + _vm->_cdrom->stopPlaying(); + _vm->_draw->animateCursor(4); + _vm->_inter->initControlVars(); + _vm->_mult->initAll(); + _vm->_mult->zeroMultData(); for (i = 0; i < 20; i++) - draw_spritesArray[i] = 0; + _vm->_draw->spritesArray[i] = 0; - draw_spritesArray[20] = draw_frontSurface; - draw_spritesArray[21] = draw_backSurface; - draw_spritesArray[23] = draw_cursorSprites; + _vm->_draw->spritesArray[20] = _vm->_draw->frontSurface; + _vm->_draw->spritesArray[21] = _vm->_draw->backSurface; + _vm->_draw->spritesArray[23] = _vm->_draw->cursorSprites; for (i = 0; i < 20; i++) - game_soundSamples[i] = 0; + soundSamples[i] = 0; - game_totTextData = 0; - game_totResourceTable = 0; - game_imFileData = 0; - game_extTable = 0; - game_extHandle = -1; + totTextData = 0; + totResourceTable = 0; + imFileData = 0; + extTable = 0; + extHandle = -1; needFreeResTable = 1; needTextFree = 1; - game_totToLoad[0] = 0; + totToLoad[0] = 0; - if (game_curTotFile[0] == 0 && game_totFileData == 0) + if (curTotFile[0] == 0 && totFileData == 0) break; - game_loadTotFile(game_curTotFile); - if (game_totFileData == 0) { - draw_blitCursor(); + loadTotFile(curTotFile); + if (totFileData == 0) { + _vm->_draw->blitCursor(); break; } - strcpy(game_curImaFile, game_curTotFile); - strcpy(game_curExtFile, game_curTotFile); + strcpy(curImaFile, curTotFile); + strcpy(curExtFile, curTotFile); - game_curImaFile[strlen(game_curImaFile) - 4] = 0; - strcat(game_curImaFile, ".ima"); + curImaFile[strlen(curImaFile) - 4] = 0; + strcat(curImaFile, ".ima"); - game_curExtFile[strlen(game_curExtFile) - 4] = 0; - strcat(game_curExtFile, ".ext"); + curExtFile[strlen(curExtFile) - 4] = 0; + strcat(curExtFile, ".ext"); - debug(4, "IMA: %s", game_curImaFile); - debug(4, "EXT: %s", game_curExtFile); + debug(4, "IMA: %s", curImaFile); + debug(4, "EXT: %s", curExtFile); - filePtr = (char *)game_totFileData + 0x30; + filePtr = (char *)totFileData + 0x30; if (READ_LE_UINT32(filePtr) != (uint32)-1) { - curPtr = game_totFileData; - game_totTextData = - (Game_TotTextTable *) (curPtr + - READ_LE_UINT32((char *)game_totFileData + 0x30)); + curPtr = totFileData; + totTextData = + (TotTextTable *) (curPtr + + READ_LE_UINT32((char *)totFileData + 0x30)); - game_totTextData->itemsCount = (int16)READ_LE_UINT16(&game_totTextData->itemsCount); + totTextData->itemsCount = (int16)READ_LE_UINT16(&totTextData->itemsCount); - for (i = 0; i < game_totTextData->itemsCount; ++i) { - game_totTextData->items[i].offset = (int16)READ_LE_UINT16(&game_totTextData->items[i].offset); - game_totTextData->items[i].size = (int16)READ_LE_UINT16(&game_totTextData->items[i].size); + for (i = 0; i < totTextData->itemsCount; ++i) { + totTextData->items[i].offset = (int16)READ_LE_UINT16(&totTextData->items[i].offset); + totTextData->items[i].size = (int16)READ_LE_UINT16(&totTextData->items[i].size); } needTextFree = 0; } - filePtr = (char *)game_totFileData + 0x34; + filePtr = (char *)totFileData + 0x34; if (READ_LE_UINT32(filePtr) != (uint32)-1) { - curPtr = game_totFileData; + curPtr = totFileData; - game_totResourceTable = - (Game_TotResTable *)(curPtr + - READ_LE_UINT32((char *)game_totFileData + 0x34)); + totResourceTable = + (TotResTable *)(curPtr + + READ_LE_UINT32((char *)totFileData + 0x34)); - game_totResourceTable->itemsCount = (int16)READ_LE_UINT16(&game_totResourceTable->itemsCount); + totResourceTable->itemsCount = (int16)READ_LE_UINT16(&totResourceTable->itemsCount); - for (i = 0; i < game_totResourceTable->itemsCount; ++i) { - game_totResourceTable->items[i].offset = (int32)READ_LE_UINT32(&game_totResourceTable->items[i].offset); - game_totResourceTable->items[i].size = (int16)READ_LE_UINT16(&game_totResourceTable->items[i].size); - game_totResourceTable->items[i].width = (int16)READ_LE_UINT16(&game_totResourceTable->items[i].width); - game_totResourceTable->items[i].height = (int16)READ_LE_UINT16(&game_totResourceTable->items[i].height); + for (i = 0; i < totResourceTable->itemsCount; ++i) { + totResourceTable->items[i].offset = (int32)READ_LE_UINT32(&totResourceTable->items[i].offset); + totResourceTable->items[i].size = (int16)READ_LE_UINT16(&totResourceTable->items[i].size); + totResourceTable->items[i].width = (int16)READ_LE_UINT16(&totResourceTable->items[i].width); + totResourceTable->items[i].height = (int16)READ_LE_UINT16(&totResourceTable->items[i].height); } needFreeResTable = 0; } - game_loadImFile(); - game_loadExtTable(); + loadImFile(); + loadExtTable(); - inter_animDataSize = READ_LE_UINT16((char *)game_totFileData + 0x38); - if (inter_variables == 0) { - variablesCount = READ_LE_UINT32((char *)game_totFileData + 0x2c); - inter_variables = (char *)malloc(variablesCount * 4); + _vm->_global->inter_animDataSize = READ_LE_UINT16((char *)totFileData + 0x38); + if (_vm->_global->inter_variables == 0) { + variablesCount = READ_LE_UINT32((char *)totFileData + 0x2c); + _vm->_global->inter_variables = (char *)malloc(variablesCount * 4); for (i = 0; i < variablesCount; i++) WRITE_VAR(i, 0); } - inter_execPtr = (char *)game_totFileData; - inter_execPtr += READ_LE_UINT32((char *)game_totFileData + 0x64); + _vm->_global->inter_execPtr = (char *)totFileData; + _vm->_global->inter_execPtr += READ_LE_UINT32((char *)totFileData + 0x64); - inter_renewTimeInVars(); + _vm->_inter->renewTimeInVars(); - WRITE_VAR(13, useMouse); - WRITE_VAR(14, soundFlags); - WRITE_VAR(15, videoMode); - WRITE_VAR(16, language); + WRITE_VAR(13, _vm->_global->useMouse); + WRITE_VAR(14, _vm->_global->soundFlags); + WRITE_VAR(15, _vm->_global->videoMode); + WRITE_VAR(16, _vm->_global->language); - inter_callSub(2); + _vm->_inter->callSub(2); - if (game_totToLoad[0] != 0) - inter_terminate = 0; + if (totToLoad[0] != 0) + _vm->_inter->terminate = 0; - variablesCount = READ_LE_UINT32((char *)game_totFileData + 0x2c); - draw_blitInvalidated(); - free(game_totFileData); - game_totFileData = 0; + variablesCount = READ_LE_UINT32((char *)totFileData + 0x2c); + _vm->_draw->blitInvalidated(); + free(totFileData); + totFileData = 0; if (needTextFree) - free(game_totTextData); - game_totTextData = 0; + free(totTextData); + totTextData = 0; if (needFreeResTable) - free(game_totResourceTable); - game_totResourceTable = 0; + free(totResourceTable); + totResourceTable = 0; - free(game_imFileData); - game_imFileData = 0; + free(imFileData); + imFileData = 0; - free(game_extTable); - game_extTable = 0; + free(extTable); + extTable = 0; - if (game_extHandle >= 0) - data_closeData(game_extHandle); + if (extHandle >= 0) + _vm->_dataio->closeData(extHandle); - game_extHandle = -1; + extHandle = -1; - for (i = 0; i < *scen_pCaptureCounter; i++) - game_capturePop(0); + for (i = 0; i < *_vm->_scenery->pCaptureCounter; i++) + capturePop(0); - mult_checkFreeMult(); - mult_freeAll(); + _vm->_mult->checkFreeMult(); + _vm->_mult->freeAll(); for (i = 0; i < 20; i++) { - if (draw_spritesArray[i] != 0) - vid_freeSurfDesc(draw_spritesArray[i]); - draw_spritesArray[i] = 0; + if (_vm->_draw->spritesArray[i] != 0) + _vm->_video->freeSurfDesc(_vm->_draw->spritesArray[i]); + _vm->_draw->spritesArray[i] = 0; } - snd_stopSound(0); + _vm->_snd->stopSound(0); for (i = 0; i < 20; i++) - game_freeSoundSlot(i); + freeSoundSlot(i); - if (game_totToLoad[0] == 0) + if (totToLoad[0] == 0) break; - strcpy(game_curTotFile, game_totToLoad); + strcpy(curTotFile, totToLoad); } } - strcpy(game_curTotFile, savedTotName); + strcpy(curTotFile, savedTotName); - inter_nestLevel = oldNestLevel; - inter_breakFromLevel = oldBreakFrom; - scen_pCaptureCounter = oldCaptureCounter; - inter_execPtr = savedIP; + _vm->_inter->nestLevel = oldNestLevel; + _vm->_inter->breakFromLevel = oldBreakFrom; + _vm->_scenery->pCaptureCounter = oldCaptureCounter; + _vm->_global->inter_execPtr = savedIP; } -void game_start(void) { - game_collisionAreas = (Game_Collision *)malloc(250 * sizeof(Game_Collision)); - game_prepareStart(); - game_playTot(0); +void Game::start(void) { + collisionAreas = (Collision *)malloc(250 * sizeof(Collision)); + prepareStart(); + playTot(0); - free(game_collisionAreas); + free(collisionAreas); - vid_freeSurfDesc(draw_cursorSprites); - vid_freeSurfDesc(draw_cursorBack); - vid_freeSurfDesc(draw_backSurface); + _vm->_video->freeSurfDesc(_vm->_draw->cursorSprites); + _vm->_video->freeSurfDesc(_vm->_draw->cursorBack); + _vm->_video->freeSurfDesc(_vm->_draw->backSurface); } } // End of namespace Gob diff --git a/gob/game.h b/gob/game.h index 6f98b23da6..bc126463a1 100644 --- a/gob/game.h +++ b/gob/game.h @@ -26,139 +26,162 @@ namespace Gob { -#pragma START_PACK_STRUCTS -#define szGame_ExtItem (4 + 2 + 2 + 2) -typedef struct Game_ExtItem { - int32 offset; // offset from the table end - uint16 size; - int16 width; // width&0x7fff - width, width&0x8000 - pack flag - int16 height; // not zero -} GCC_PACK Game_ExtItem; - -#define szGame_ExtTable (2 + 1) -typedef struct Game_ExtTable { - int16 itemsCount; - byte unknown; - Game_ExtItem items[1]; -} GCC_PACK Game_ExtTable; +class Game { +public: +#pragma START_PACK_STRUCTS #define szGame_TotResItem (4 + 2 + 2 + 2) -typedef struct Game_TotResItem { - int32 offset; // if > 0, then offset from end of resource table. - // If < 0, then -offset-1 is index in .IM file table - int16 size; - int16 width; - int16 height; -} GCC_PACK Game_TotResItem; + typedef struct Collision { + int16 id; + int16 left; + int16 top; + int16 right; + int16 bottom; + int16 flags; + int16 key; + int16 funcEnter; + int16 funcLeave; + } GCC_PACK Collision; + + typedef struct TotResItem { + int32 offset; // if > 0, then offset from end of resource table. + // If < 0, then -offset-1 is index in .IM file table + int16 size; + int16 width; + int16 height; + } GCC_PACK TotResItem; #define szGame_TotResTable (2 + 1) -typedef struct Game_TotResTable { - int16 itemsCount; - byte unknown; - Game_TotResItem items[1]; -} GCC_PACK Game_TotResTable; + typedef struct TotResTable { + int16 itemsCount; + byte unknown; + TotResItem items[1]; + } GCC_PACK TotResTable; + +#define szGame_ExtItem (4 + 2 + 2 + 2) + typedef struct ExtItem { + int32 offset; // offset from the table end + uint16 size; + int16 width; // width&0x7fff - width, width&0x8000 - pack flag + int16 height; // not zero + } GCC_PACK ExtItem; + +#define szGame_ExtTable (2 + 1) + typedef struct ExtTable { + int16 itemsCount; + byte unknown; + ExtItem items[1]; + } GCC_PACK ExtTable; #define szGame_TotTextItem (2 + 2) -typedef struct Game_TotTextItem { - int16 offset; - int16 size; -} GCC_PACK Game_TotTextItem; + typedef struct TotTextItem { + int16 offset; + int16 size; + } GCC_PACK TotTextItem; #define szGame_TotTextTable (2) -typedef struct Game_TotTextTable { - int16 itemsCount; - Game_TotTextItem items[1]; -} GCC_PACK Game_TotTextTable; - -typedef struct Game_Collision { - int16 id; - int16 left; - int16 top; - int16 right; - int16 bottom; - int16 flags; - int16 key; - int16 funcEnter; - int16 funcLeave; -} GCC_PACK Game_Collision; - -typedef struct Game_InputDesc { - int16 fontIndex; - int16 backColor; - int16 frontColor; - char *ptr; -} GCC_PACK Game_InputDesc; + typedef struct TotTextTable { + int16 itemsCount; + TotTextItem items[1]; + } GCC_PACK TotTextTable; + + typedef struct InputDesc { + int16 fontIndex; + int16 backColor; + int16 frontColor; + char *ptr; + } GCC_PACK InputDesc; #pragma END_PACK_STRUCTS -extern Game_Collision *game_collisionAreas; - -extern int16 game_lastCollKey; -extern int16 game_lastCollAreaIndex; -extern int16 game_lastCollId; - -extern int16 game_activeCollResId; -extern int16 game_activeCollIndex; -extern char game_handleMouse; -extern char game_forceHandleMouse; - -extern char game_tempStr[256]; - -extern Game_ExtTable *game_extTable; -extern char *game_totFileData; -extern Game_TotTextTable *game_totTextData; -extern Game_TotResTable *game_totResourceTable; -extern char *game_imFileData; -extern int16 game_extHandle; -extern char game_curExtFile[14]; -extern char game_curTotFile[14]; -extern char game_curImaFile[18]; - -extern int16 game_collStackSize; -extern Game_Collision *game_collStack[3]; -extern int16 game_collStackElemSizes[3]; - -extern int16 game_mouseButtons; - -extern Snd_SoundDesc *game_soundSamples[20]; - -extern char game_soundFromExt[20]; -extern char game_totToLoad[20]; - -extern int32 game_startTimeKey; -extern char game_shouldPushColls; - -// Functions - -char *game_loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight); -void game_clearCollisions(void); -void game_addNewCollision(int16 val_0, int16 left, int16 top, int16 right, int16 bottom, - int16 flags, int16 key, int16 val_E, int16 val_10); -void game_freeCollision(int16 id); -char *game_loadTotResource(int16 id); -void game_capturePush(int16 left, int16 top, int16 width, int16 height); - -void game_capturePush(int16 left, int16 top, int16 width, int16 height); -void game_capturePop(char doDraw); - -void game_loadSound(int16 slot, char *dataPtr); -void game_interLoadSound(int16 slot); -void game_freeSoundSlot(int16 slot); -int16 game_checkKeys(int16 *pMousex, int16 *pMouseY, int16 *pButtons, - char handleMouse); -int16 game_checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId, - int16 *pResIndex); -int16 game_inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 backColor, - int16 frontColor, char *str, int16 fontIndex, char inpType, int16 *pTotTime); -int16 game_multiEdit(int16 time, int16 index, int16 *pCurPos, - Game_InputDesc * inpDesc); -int16 game_adjustKey(int16 key); -void game_collisionsBlock(void); -void game_prepareStart(void); -void game_loadTotFile(char *path); -void game_loadExtTable(void); -void game_loadImFile(void); -void game_playTot(int16 skipPlay); -void game_start(void); + TotResTable *totResourceTable; + Collision *collisionAreas; + Collision *collStack[3]; + + TotTextTable *totTextData; + + char curTotFile[14]; + char curExtFile[14]; + + char *imFileData; + char *totFileData; + + int16 extHandle; + + Snd::SoundDesc *soundSamples[20]; + + char totToLoad[20]; + + int32 startTimeKey; + int16 mouseButtons; + + Game(GobEngine *vm); + + char *loadExtData(int16 dataId, int16 *pResWidth, int16 *pResHeight); + char *loadTotResource(int16 id); + + void capturePush(int16 left, int16 top, int16 width, int16 height); + + void capturePop(char doDraw); + void interLoadSound(int16 slot); + void freeSoundSlot(int16 slot); + int16 checkKeys(int16 *pMousex, int16 *pMouseY, int16 *pButtons, + char handleMouse); + int16 checkCollisions(char handleMouse, int16 deltaTime, int16 *pResId, + int16 *pResIndex); + void clearCollisions(void); + void addNewCollision(int16 val_0, int16 left, int16 top, int16 right, int16 bottom, + int16 flags, int16 key, int16 val_E, int16 val_10); + void freeCollision(int16 id); + + void loadSound(int16 slot, char *dataPtr); + int16 inputArea(int16 xPos, int16 yPos, int16 width, int16 height, int16 backColor, + int16 frontColor, char *str, int16 fontIndex, char inpType, int16 *pTotTime); + int16 multiEdit(int16 time, int16 index, int16 *pCurPos, + InputDesc * inpDesc); + int16 adjustKey(int16 key); + void collisionsBlock(void); + void prepareStart(void); + void loadTotFile(char *path); + void loadExtTable(void); + void loadImFile(void); + void playTot(int16 skipPlay); + void start(void); + +protected: + + int16 lastCollKey; + int16 lastCollAreaIndex; + int16 lastCollId; + + int16 activeCollResId; + int16 activeCollIndex; + char ghandleMouse; + char forceHandleMouse; + + char tempStr[256]; + + ExtTable *extTable; + char curImaFile[18]; + + int16 collStackSize; + int16 collStackElemSizes[3]; + + char soundFromExt[20]; + + char shouldPushColls; + + // Capture + static Common::Rect captureStack[20]; + static int16 captureCount; + + char collStr[256]; + + GobEngine *_vm; + + void pushCollisions(char all); + void popCollisions(void); + int16 checkMousePoint(int16 all, int16 *resId, int16 *resIndex); +}; } // End of namespace Gob diff --git a/gob/global.cpp b/gob/global.cpp index aab918e17a..13bfa2fe92 100644 --- a/gob/global.cpp +++ b/gob/global.cpp @@ -24,135 +24,130 @@ namespace Gob { -char pressedKeys[128]; - -char useMouse = UNDEF; -int16 mousePresent = UNDEF; - -int16 presentCGA = UNDEF; -int16 presentEGA = UNDEF; -int16 presentVGA = UNDEF; -int16 presentHER = UNDEF; - -int16 videoMode = 0; - -int16 disableVideoCfg; - -/* Sound */ -uint16 presentSound = 0x8000; /* undefined values */ -uint16 soundFlags = 0x8000; -int16 blasterPort = 0; -int16 disableSoundCfg = 0; - -//char playingSound = 0; - -/* Mouse */ -int16 disableMouseCfg = 0; - -int16 mouseXShift = 3; -int16 mouseYShift = 3; - -int16 mouseMaxCol = 320; -int16 mouseMaxRow = 200; - -/* Language */ -uint16 disableLangCfg = 0x8000; -uint16 language = 0x8000; - -/* Timer variables */ -int32 startTime = 0; -int16 timer_delta = 1000; - -int16 frameWaitTime = 0; -int32 startFrameTime = 0; - -/* Timer and delays */ -int16 delayTime = 0; - -/* Joystick */ -char useJoystick = 1; - -/* Files */ -Common::File filesHandles[MAX_FILES]; - -/* Data files */ -struct ChunkDesc *dataFiles[MAX_DATA_FILES]; -int16 numDataChunks[MAX_DATA_FILES]; -int16 dataFileHandles[MAX_DATA_FILES]; -int32 chunkPos[MAX_SLOT_COUNT * MAX_DATA_FILES]; -int32 chunkOffset[MAX_SLOT_COUNT * MAX_DATA_FILES]; -int32 chunkSize[MAX_SLOT_COUNT * MAX_DATA_FILES]; -char isCurrentSlot[MAX_SLOT_COUNT * MAX_DATA_FILES]; -int32 packedSize = 0; - -int16 sprAllocated = 0; - -SurfaceDesc primarySurfDesc; -SurfaceDesc *pPrimarySurfDesc; - -int16 primaryWidth; -int16 primaryHeight; - -int16 doRangeClamp = 0; - -char redPalette[256]; -char greenPalette[256]; -char bluePalette[256]; - -int16 setAllPalette = 0; - -int16 oldMode = 3; -char dontSetPalette = 0; -SurfaceDesc *curPrimaryDesc = 0; -SurfaceDesc *allocatedPrimary = 0; - -PalDesc *pPaletteDesc = 0; - -int16 unusedPalette1[18] = { - 0, 0x0b, 0, (int16)0x5555, (int16)0xAAAA, (int16)0xFFFF, 0, (int16)0x5555, - (int16)0xAAAA, (int16)0xFFFF, 0, (int16)0x5555, - (int16)0xAAAA, (int16)0xFFFF, 0, (int16)0x5555, (int16)0xAAAA, (int16)0xFFFF -}; - -int16 unusedPalette2[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 -}; - -Color vgaPalette[16] = { - {0x00, 0x00, 0x00}, - {0x00, 0x00, 0x2a}, - {0x00, 0x2a, 0x00}, - {0x00, 0x2a, 0x2a}, - {0x2a, 0x00, 0x00}, - {0x2a, 0x00, 0x2a}, - {0x2a, 0x15, 0x00}, - {0x2a, 0x2a, 0x2a}, - {0x15, 0x15, 0x15}, - {0x15, 0x15, 0x3f}, - {0x15, 0x3f, 0x15}, - {0x15, 0x3f, 0x3f}, - {0x3f, 0x15, 0x15}, - {0x3f, 0x15, 0x3f}, - {0x3f, 0x3f, 0x15}, - {0x3f, 0x3f, 0x3f} -}; - -PalDesc paletteStruct; - -int16 debugFlag = 0; -int16 inVM = 0; -int16 colorCount = 16; - -char inter_resStr[200]; -int32 inter_resVal = 0; - -char *inter_variables = 0; -char *inter_execPtr = 0; -int16 inter_animDataSize = 10; - -int16 inter_mouseX = 0; -int16 inter_mouseY = 0; - -char *tmpPalBuffer = 0; +Global::Global(GobEngine *vm) : _vm(vm) { + useMouse = UNDEF; + mousePresent = UNDEF; + + presentCGA = UNDEF; + presentEGA = UNDEF; + presentVGA = UNDEF; + presentHER = UNDEF; + + videoMode = 0; + + /* Sound */ + presentSound = 0x8000; /* undefined values */ + soundFlags = 0x8000; + blasterPort = 0; + disableSoundCfg = 0; + + //char playingSound = 0; + + /* Mouse */ + disableMouseCfg = 0; + + mouseXShift = 3; + mouseYShift = 3; + + mouseMaxCol = 320; + mouseMaxRow = 200; + + /* Language */ + disableLangCfg = 0x8000; + language = 0x8000; + + /* Timer variables */ + startTime = 0; + timer_delta = 1000; + + frameWaitTime = 0; + startFrameTime = 0; + + /* Timer and delays */ + delayTime = 0; + + /* Joystick */ + useJoystick = 1; + + /* Data files */ + packedSize = 0; + for (int i = 0; i < MAX_DATA_FILES; i++) { + dataFiles[i] = 0; + numDataChunks[i] = 0; + dataFileHandles[i] = -1; + } + + primaryWidth = 0; + primaryHeight = 0; + + sprAllocated = 0; + + doRangeClamp = 0; + + setAllPalette = 0; + + oldMode = 3; + dontSetPalette = 0; + curPrimaryDesc = 0; + allocatedPrimary = 0; + pPrimarySurfDesc = 0; + + pPaletteDesc = 0; + + unusedPalette1[0] = (int16)0; + unusedPalette1[1] = (int16)0x0b; + unusedPalette1[2] = (int16)0; + unusedPalette1[3] = (int16)0x5555; + unusedPalette1[4] = (int16)0xAAAA; + unusedPalette1[5] = (int16)0xFFFF; + unusedPalette1[6] = (int16)0; + unusedPalette1[7] = (int16)0x5555; + unusedPalette1[8] = (int16)0xAAAA; + unusedPalette1[9] = (int16)0xFFFF; + unusedPalette1[10] = (int16)0; + unusedPalette1[11] = (int16)0x5555; + unusedPalette1[12] = (int16)0xAAAA; + unusedPalette1[13] = (int16)0xFFFF; + unusedPalette1[14] = (int16)0; + unusedPalette1[15] = (int16)0x5555; + unusedPalette1[16] = (int16)0xAAAA; + unusedPalette1[17] = (int16)0xFFFF; + + for (int i = 0; i < 16 ;i++) + unusedPalette2[i] = i; + + vgaPalette[0].red = 0x00; vgaPalette[0].green = 0x00; vgaPalette[0].blue = 0x00; + vgaPalette[1].red = 0x00; vgaPalette[1].green = 0x00; vgaPalette[1].blue = 0x2a; + vgaPalette[2].red = 0x00; vgaPalette[2].green = 0x2a; vgaPalette[2].blue = 0x00; + vgaPalette[3].red = 0x00; vgaPalette[3].green = 0x2a; vgaPalette[3].blue = 0x2a; + vgaPalette[4].red = 0x2a; vgaPalette[4].green = 0x00; vgaPalette[4].blue = 0x00; + vgaPalette[5].red = 0x2a; vgaPalette[5].green = 0x00; vgaPalette[5].blue = 0x2a; + vgaPalette[6].red = 0x2a; vgaPalette[6].green = 0x15; vgaPalette[6].blue = 0x00; + vgaPalette[7].red = 0x2a; vgaPalette[7].green = 0x2a; vgaPalette[7].blue = 0x2a; + vgaPalette[8].red = 0x15; vgaPalette[8].green = 0x15; vgaPalette[8].blue = 0x15; + vgaPalette[9].red = 0x15; vgaPalette[9].green = 0x15; vgaPalette[9].blue = 0x3f; + vgaPalette[10].red = 0x15; vgaPalette[10].green = 0x3f; vgaPalette[10].blue = 0x15; + vgaPalette[11].red = 0x15; vgaPalette[11].green = 0x3f; vgaPalette[11].blue = 0x3f; + vgaPalette[12].red = 0x3f; vgaPalette[12].green = 0x15; vgaPalette[12].blue = 0x15; + vgaPalette[13].red = 0x3f; vgaPalette[13].green = 0x15; vgaPalette[13].blue = 0x3f; + vgaPalette[14].red = 0x3f; vgaPalette[14].green = 0x3f; vgaPalette[14].blue = 0x15; + vgaPalette[15].red = 0x3f; vgaPalette[15].green = 0x3f; vgaPalette[15].blue = 0x3f; + + debugFlag = 0; + inVM = 0; + colorCount = 16; + + inter_resStr[0] = 0; + inter_resVal = 0; + + inter_variables = 0; + inter_execPtr = 0; + inter_animDataSize = 10; + + inter_mouseX = 0; + inter_mouseY = 0; + + tmpPalBuffer = 0; +} } // End of namespace Gob diff --git a/gob/global.h b/gob/global.h index a8a3d45fb8..d6b9fd8d4c 100644 --- a/gob/global.h +++ b/gob/global.h @@ -29,29 +29,11 @@ namespace Gob { -extern char pressedKeys[128]; - -extern char useMouse; -extern int16 mousePresent; - -extern int16 presentCGA; -extern int16 presentEGA; -extern int16 presentVGA; -extern int16 presentHER; - -extern int16 videoMode; - -extern int16 disableVideoCfg; - #define VIDMODE_CGA 0x05 #define VIDMODE_EGA 0x0d #define VIDMODE_VGA 0x13 #define VIDMODE_HER 7 -extern uint16 presentSound; -extern uint16 soundFlags; -extern int16 disableSoundCfg; - #define PROAUDIO_FLAG 0x10 #define ADLIB_FLAG 0x08 #define BLASTER_FLAG 0x04 @@ -59,9 +41,6 @@ extern int16 disableSoundCfg; #define SPEAKER_FLAG 0x01 #define MIDI_FLAG 0x4000 -extern uint16 disableLangCfg; -extern uint16 language; - #define NO 0 #define YES 1 #define UNDEF 2 @@ -75,92 +54,122 @@ extern uint16 language; #define ESCAPE 0x001b #define ENTER 0x000d -/* Timer variables */ -extern int32 startTime; -extern int16 timer_delta; +#define MAX_FILES 30 -extern int16 frameWaitTime; -extern int32 startFrameTime; +/* Video drivers */ +#define UNK_DRIVER 0 +#define VGA_DRIVER 1 +#define EGA_DRIVER 2 +#define CGA_DRIVER 3 +#define HER_DRIVER 4 -/* Mouse */ -extern int16 disableMouseCfg; +class Global { +public: + char pressedKeys[128]; -extern int16 mouseXShift; -extern int16 mouseYShift; -extern int16 mouseMaxCol; -extern int16 mouseMaxRow; + char useMouse; + int16 mousePresent; -/* Timer and delays */ -extern int16 delayTime; + int16 presentCGA; + int16 presentEGA; + int16 presentVGA; + int16 presentHER; -/* Joystick */ -extern char useJoystick; + int16 videoMode; -/* Files */ -#define MAX_FILES 30 + int16 disableVideoCfg; -extern Common::File filesHandles[MAX_FILES]; + uint16 presentSound; + uint16 soundFlags; + int16 disableSoundCfg; + int16 blasterPort; -/* Data files */ -extern struct ChunkDesc *dataFiles[MAX_DATA_FILES]; -extern int16 numDataChunks[MAX_DATA_FILES]; -extern int16 dataFileHandles[MAX_DATA_FILES]; -extern int32 chunkPos[MAX_SLOT_COUNT * MAX_DATA_FILES]; -extern int32 chunkOffset[MAX_SLOT_COUNT * MAX_DATA_FILES]; -extern int32 chunkSize[MAX_SLOT_COUNT * MAX_DATA_FILES]; -extern char isCurrentSlot[MAX_SLOT_COUNT * MAX_DATA_FILES]; -extern int32 packedSize; + uint16 disableLangCfg; + uint16 language; -/* Video drivers */ -#define UNK_DRIVER 0 -#define VGA_DRIVER 1 -#define EGA_DRIVER 2 -#define CGA_DRIVER 3 -#define HER_DRIVER 4 + // Timer variables + int32 startTime; + int16 timer_delta; + + int16 frameWaitTime; + int32 startFrameTime; + + // Mouse + int16 disableMouseCfg; + + int16 mouseXShift; + int16 mouseYShift; + int16 mouseMaxCol; + int16 mouseMaxRow; + + // Timer and delays + int16 delayTime; + + // Joystick + char useJoystick; + + // Files + Common::File filesHandles[MAX_FILES]; + + // Data files + struct DataIO::ChunkDesc *dataFiles[MAX_DATA_FILES]; + int16 numDataChunks[MAX_DATA_FILES]; + int16 dataFileHandles[MAX_DATA_FILES]; + int32 chunkPos[MAX_SLOT_COUNT * MAX_DATA_FILES]; + int32 chunkOffset[MAX_SLOT_COUNT * MAX_DATA_FILES]; + int32 chunkSize[MAX_SLOT_COUNT * MAX_DATA_FILES]; + char isCurrentSlot[MAX_SLOT_COUNT * MAX_DATA_FILES]; + int32 packedSize; + + int16 sprAllocated; + + int16 primaryWidth; + int16 primaryHeight; -extern SurfaceDesc primarySurfDesc; -extern SurfaceDesc *pPrimarySurfDesc; -extern int16 sprAllocated; + int16 doRangeClamp; -extern int16 primaryWidth; -extern int16 primaryHeight; + char redPalette[256]; + char greenPalette[256]; + char bluePalette[256]; -extern int16 doRangeClamp; + int16 setAllPalette; -extern char redPalette[256]; -extern char greenPalette[256]; -extern char bluePalette[256]; + Video::SurfaceDesc *curPrimaryDesc; + Video::SurfaceDesc *allocatedPrimary; + Video::SurfaceDesc_t primarySurfDesc; + Video::SurfaceDesc *pPrimarySurfDesc; -extern int16 setAllPalette; + int16 oldMode; + char dontSetPalette; -extern SurfaceDesc *curPrimaryDesc; -extern SurfaceDesc *allocatedPrimary; + Video::PalDesc *pPaletteDesc; -extern int16 oldMode; -extern char dontSetPalette; + int16 unusedPalette1[18]; + int16 unusedPalette2[16]; + Video::Color vgaPalette[16]; + Video::PalDesc paletteStruct; -extern PalDesc *pPaletteDesc; + int16 debugFlag; + int16 inVM; + int16 colorCount; -extern int16 unusedPalette1[18]; -extern int16 unusedPalette2[16]; -extern Color vgaPalette[16]; -extern PalDesc paletteStruct; + char inter_resStr[200]; + int32 inter_resVal; -extern int16 debugFlag; -extern int16 inVM; -extern int16 colorCount; + char *inter_variables; + char *inter_execPtr; + int16 inter_animDataSize; -extern char inter_resStr[200]; -extern int32 inter_resVal; + int16 inter_mouseX; + int16 inter_mouseY; -extern char *inter_variables; -extern char *inter_execPtr; -extern int16 inter_animDataSize; + char *tmpPalBuffer; -extern int16 inter_mouseX; -extern int16 inter_mouseY; + Global(GobEngine *vm); -extern char *tmpPalBuffer; +protected: + GobEngine *_vm; +}; } // End of namespace Gob diff --git a/gob/gob.cpp b/gob/gob.cpp index e304563c3d..a4815eda27 100644 --- a/gob/gob.cpp +++ b/gob/gob.cpp @@ -31,6 +31,19 @@ #include "gob/game.h" #include "gob/sound.h" #include "gob/init.h" +#include "gob/inter.h" +#include "gob/draw.h" +#include "gob/anim.h" +#include "gob/cdrom.h" +#include "gob/goblin.h" +#include "gob/map.h" +#include "gob/mult.h" +#include "gob/pack.h" +#include "gob/palanim.h" +#include "gob/parse.h" +#include "gob/scenery.h" +#include "gob/timer.h" +#include "gob/util.h" enum { // We only compute MD5 of the first megabyte of our data files. @@ -50,53 +63,53 @@ struct GobGameSettings { static const GobGameSettings gob_games[] = { // Supplied by Florian Zeitz on scummvm-devel - {"gob1", "Gobliiins (DOS EGA)", GF_GOB1, "82aea70ef26f41fa963dfae270993e49"}, - {"gob1", "Gobliiins (DOS EGA)", GF_GOB1, "1f499458837008058b8ba6ae07057214"}, - {"gob1", "Gobliiins (Windows)", GF_GOB1, "8a5e850c49d7cacdba5f5eb1fcc77b89"}, + {"gob1", "Gobliiins (DOS EGA)", Gob::GF_GOB1, "82aea70ef26f41fa963dfae270993e49"}, + {"gob1", "Gobliiins (DOS EGA)", Gob::GF_GOB1, "1f499458837008058b8ba6ae07057214"}, + {"gob1", "Gobliiins (Windows)", Gob::GF_GOB1, "8a5e850c49d7cacdba5f5eb1fcc77b89"}, // Supplied by Theruler76 in bug report #1201233 - {"gob1", "Gobliiins (DOS VGA)", GF_GOB1, "a5e232fcd02733c7dffff107d22d36eb"}, + {"gob1", "Gobliiins (DOS VGA)", Gob::GF_GOB1, "a5e232fcd02733c7dffff107d22d36eb"}, // CD 1.000 version. Multilingual - {"gob1", "Gobliiins (CD)", GF_GOB1 | GF_CD, "037db48ebce94bdfe42e2c9510da9211"}, + {"gob1", "Gobliiins (CD)", Gob::GF_GOB1 | Gob::GF_CD, "037db48ebce94bdfe42e2c9510da9211"}, // CD 1.02 version. Multilingual - {"gob1", "Gobliiins (CD)", GF_GOB1 | GF_CD, "45f9c1162dd7040fd05fd013ccc176e2"}, + {"gob1", "Gobliiins (CD)", Gob::GF_GOB1 | Gob::GF_CD, "45f9c1162dd7040fd05fd013ccc176e2"}, - {"gob1", "Gobliiins (Amiga)", GF_GOB1, "d9f8736b7dc0ea891cd06592a72e8a72"}, - {"gob1", "Gobliiins (Amiga)", GF_GOB1, "69f9ae85252271e7dfa62883e581e5e9"}, - {"gob1", "Gobliiins (Amiga)", GF_GOB1, "26de406cb09228d902274446a6a2eceb"}, - {"gob1", "Gobliiins (Amiga)", GF_GOB1, "baf88a95928edb3f51067983f2dffa93"}, + {"gob1", "Gobliiins (Amiga)", Gob::GF_GOB1, "d9f8736b7dc0ea891cd06592a72e8a72"}, + {"gob1", "Gobliiins (Amiga)", Gob::GF_GOB1, "69f9ae85252271e7dfa62883e581e5e9"}, + {"gob1", "Gobliiins (Amiga)", Gob::GF_GOB1, "26de406cb09228d902274446a6a2eceb"}, + {"gob1", "Gobliiins (Amiga)", Gob::GF_GOB1, "baf88a95928edb3f51067983f2dffa93"}, - {"gob1", "Gobliiins (Interactive Demo)", GF_GOB1, "4f5bf4b9e4c39ebb93579747fc678e97"}, + {"gob1", "Gobliiins (Interactive Demo)", Gob::GF_GOB1, "4f5bf4b9e4c39ebb93579747fc678e97"}, #if 0 - {"gob2", "Gobliins 2 (DOS)", GF_GOB2, "abb5f762f9979d4253002de20f6e7b56"}, - {"gob2", "Gobliins 2 (DOS)", GF_GOB2, "9b6de65d811c08eebf50391b84fcba92"}, - {"gob2", "Gobliins 2 (DOS)", GF_GOB2, "54d59c200e3823ad0af11a605a6fd06a"}, - {"gob2", "Gobliins 2 (DOS Ru)", GF_GOB2, "b6d47494bf88398ae59c1b5656cafce4"}, + {"gob2", "Gobliins 2 (DOS)", Gob::GF_GOB2, "abb5f762f9979d4253002de20f6e7b56"}, + {"gob2", "Gobliins 2 (DOS)", Gob::GF_GOB2, "9b6de65d811c08eebf50391b84fcba92"}, + {"gob2", "Gobliins 2 (DOS)", Gob::GF_GOB2, "54d59c200e3823ad0af11a605a6fd06a"}, + {"gob2", "Gobliins 2 (DOS Ru)", Gob::GF_GOB2, "b6d47494bf88398ae59c1b5656cafce4"}, // CD 1.000. - {"gob2", "Gobliins 2 (CD)", GF_GOB2, "02bf538fd8003b8da23a3546299c3df4"}, + {"gob2", "Gobliins 2 (CD)", Gob::GF_GOB2, "02bf538fd8003b8da23a3546299c3df4"}, // CD 1.01 - {"gob2", "Gobliins 2 (CD)", GF_GOB2, "410e632682ab11969bc3b3b588066d95"}, - {"gob2", "Gobliins 2 (Demo)", GF_GOB2, "be8b111191f965ac9b28fe530580d14e"}, + {"gob2", "Gobliins 2 (CD)", Gob::GF_GOB2, "410e632682ab11969bc3b3b588066d95"}, + {"gob2", "Gobliins 2 (Demo)", Gob::GF_GOB2, "be8b111191f965ac9b28fe530580d14e"}, - {"gob3", "Goblins Quest 3", GF_GOB3, "36d9b4032b39a794c8640e500e98893a"}, - {"gob3", "Goblins Quest 3", GF_GOB3, "d129f639f6ca8d6b5f0f4e15edb91058"}, - {"gob3", "Goblins Quest 3", GF_GOB3, "8d17b0abc514b1512fdedc6072acd48b"}, + {"gob3", "Goblins Quest 3", Gob::GF_GOB3, "36d9b4032b39a794c8640e500e98893a"}, + {"gob3", "Goblins Quest 3", Gob::GF_GOB3, "d129f639f6ca8d6b5f0f4e15edb91058"}, + {"gob3", "Goblins Quest 3", Gob::GF_GOB3, "8d17b0abc514b1512fdedc6072acd48b"}, // CD 1.000 - {"gob3", "Goblins Quest 3 (CD)", GF_GOB3, "8d17b0abc514b1512fdedc6072acd48b"}, + {"gob3", "Goblins Quest 3 (CD)", Gob::GF_GOB3, "8d17b0abc514b1512fdedc6072acd48b"}, // CD 1.02. Spanish "Computer Gaming World"* distribution in Spain - {"gob3", "Goblins Quest 3 (CD)", GF_GOB3, "7d7ab9a987be7208b9b685846fbd3e82"}, + {"gob3", "Goblins Quest 3 (CD)", Gob::GF_GOB3, "7d7ab9a987be7208b9b685846fbd3e82"}, - {"gob3", "Goblins Quest 3 (Interactive Demo)", GF_GOB3, "4986b44cec309589508d7904f924c217"}, - {"gob3", "Goblins Quest 3 (Demo)", GF_GOB3, "5024e7de8d6377fbbeabbaa92e0452bc"}, - {"gob3", "Goblins Quest 3 (Interactive Demo)", GF_GOB3, "59ab69dab5fddbbf698c77a84297a5a2"}, + {"gob3", "Goblins Quest 3 (Interactive Demo)", Gob::GF_GOB3, "4986b44cec309589508d7904f924c217"}, + {"gob3", "Goblins Quest 3 (Demo)", Gob::GF_GOB3, "5024e7de8d6377fbbeabbaa92e0452bc"}, + {"gob3", "Goblins Quest 3 (Interactive Demo)", Gob::GF_GOB3, "59ab69dab5fddbbf698c77a84297a5a2"}, // CD 1.0 - {"woodruff", "The Bizarre Adventures of Woodruff and the Schnibble", GF_WOODRUFF, "c27402cee260d2ff1c4cecb2006a630a"}, + {"woodruff", "The Bizarre Adventures of Woodruff and the Schnibble", Gob::GF_WOODRUFF, "c27402cee260d2ff1c4cecb2006a630a"}, // CD 1.00, German release (INTRO.STRK seems to be multilingual, though?) - {"woodruff", "The Bizarre Adventures of Woodruff and the Schnibble", GF_WOODRUFF, "751ba028d215e0db1e0254853de6a7e4"}, + {"woodruff", "The Bizarre Adventures of Woodruff and the Schnibble", Gob::GF_WOODRUFF, "751ba028d215e0db1e0254853de6a7e4"}, #endif {0, 0, 0, 0} }; @@ -111,8 +124,8 @@ static const struct GobGameList { return dummy; } } gob_list[] = { - {"gob1", "Gobliiins", GF_GOB1}, - {"gob2", "Gobliins 2", GF_GOB2}, + {"gob1", "Gobliiins", Gob::GF_GOB1}, + {"gob2", "Gobliins 2", Gob::GF_GOB2}, {0, 0, 0} }; @@ -183,7 +196,6 @@ namespace Gob { GobEngine *_vm = NULL; GobEngine::GobEngine(GameDetector *detector, OSystem * syst) : Engine(syst) { - // Setup mixer if (!_mixer->isReady()) { warning("Sound initialization failed."); @@ -232,6 +244,25 @@ GobEngine::GobEngine(GameDetector *detector, OSystem * syst) : Engine(syst) { } GobEngine::~GobEngine() { + delete _game; + delete _snd; + delete _video; + delete _global; + delete _draw; + delete _anim; + delete _cdrom; + delete _dataio; + delete _goblin; + delete _init; + delete _inter; + delete _map; + delete _mult; + delete _pack; + delete _palanim; + delete _parse; + delete _scenery; + delete _gtimer; + delete _util; } void GobEngine::errorString(const char *buf1, char *buf2) { @@ -239,6 +270,26 @@ void GobEngine::errorString(const char *buf1, char *buf2) { } int GobEngine::init(GameDetector &detector) { + _game = new Game(this); + _snd = new Snd(this); + _video = new Video(this); + _global = new Global(this); + _draw = new Draw(this); + _anim = new Anim(); + _cdrom = new CDROM(this); + _dataio = new DataIO(this); + _goblin = new Goblin(this); + _init = new Init(this); + _inter = new Inter(this); + _map = new Map(this); + _mult = new Mult(this); + _pack = new Pack(); + _palanim = new PalAnim(this); + _parse = new Parse(this); + _scenery = new Scenery(this); + _gtimer = new GTimer(); + _util = new Util(this); + _system->beginGFXTransaction(); initCommonGFX(detector); _system->initSize(320, 200); @@ -252,30 +303,30 @@ int GobEngine::init(GameDetector &detector) { if (cd_num >= 0) _system->openCD(cd_num); - debugFlag = 1; - doRangeClamp = 1; + _global->debugFlag = 1; + _global->doRangeClamp = 1; - videoMode = 0x13; - snd_soundPort = 1; - useMouse = 1; - soundFlags = 0; + _global->videoMode = 0x13; + _snd->soundPort = 1; + _global->useMouse = 1; + _global->soundFlags = 0; switch (Common::parseLanguage(ConfMan.get("language"))) { case Common::FR_FRA: - language = 0; + _global->language = 0; break; case Common::DE_DEU: - language = 1; + _global->language = 1; break; case Common::ES_ESP: - language = 3; + _global->language = 3; break; case Common::IT_ITA: - language = 4; + _global->language = 4; break; default: // Default to English - language = 2; + _global->language = 2; break; } @@ -289,7 +340,7 @@ int GobEngine::init(GameDetector &detector) { } int GobEngine::go() { - init_initGame(0); + _init->initGame(0); return 0; } @@ -29,15 +29,39 @@ #include "base/engine.h" -#define VAR_OFFSET(offs) (*(uint32 *)(inter_variables + (offs))) +#include "gob/dataio.h" +#include "gob/video.h" +#include "common/file.h" + +namespace Gob { + +class Game; +class Snd; +class Video; +class Global; +class Draw; +class Anim; +class CDROM; +class DataIO; +class Goblin; +class Init; +class Inter; +class Map; +class Mult; +class Pack; +class PalAnim; +class Parse; +class Scenery; +class GTimer; +class Util; + +#define VAR_OFFSET(offs) (*(uint32 *)(_vm->_global->inter_variables + (offs))) #define VAR(var) VAR_OFFSET((var) << 2) #define VAR_ADDRESS(var) (&VAR(var)) #define WRITE_VAR_OFFSET(offs, val) (VAR_OFFSET(offs) = (val)) #define WRITE_VAR(var, val) WRITE_VAR_OFFSET((var) << 2, (val)) -// TODO: Should be in the Gob namespace, I guess - enum { GF_GOB1 = 1 << 0, GF_GOB2 = 1 << 1, @@ -46,8 +70,6 @@ enum { GF_CD = 1 << 4 }; -namespace Gob { - class GobEngine : public Engine { void errorString(const char *buf_input, char *buf_output); @@ -64,6 +86,25 @@ public: Common::RandomSource _rnd; int32 _features; + Game *_game; + Snd *_snd; + Video *_video; + Global *_global; + Draw *_draw; + Anim *_anim; + CDROM *_cdrom; + DataIO *_dataio; + Goblin *_goblin; + Init *_init; + Inter *_inter; + Map *_map; + Mult *_mult; + Pack *_pack; + PalAnim *_palanim; + Parse *_parse; + Scenery *_scenery; + GTimer *_gtimer; + Util *_util; }; extern GobEngine *_vm; diff --git a/gob/goblin.cpp b/gob/goblin.cpp index f88514ab83..3da9c50764 100644 --- a/gob/goblin.cpp +++ b/gob/goblin.cpp @@ -35,125 +35,137 @@ namespace Gob { -Util_List *gob_objList; -Gob_Object *gob_goblins[4]; -int16 gob_currentGoblin; -Snd_SoundDesc *gob_soundData[16]; -int16 gob_gobStateLayer; -char gob_goesAtTarget = 0; -char gob_readyToAct = 0; -int16 gob_gobAction = 0; -Gob_Pos gob_gobPositions[3]; -int16 gob_gobDestX; -int16 gob_gobDestY; -int16 gob_pressedMapX; -int16 gob_pressedMapY; -char gob_pathExistence; - -int16 gob_itemIndInPocket = 5; -int16 gob_itemIdInPocket = 2; -char gob_itemByteFlag = 0; -int16 gob_destItemId = -1; -int16 gob_destActionItem = 0; -Gob_Object *gob_actDestItemDesc = 0; -int16 gob_forceNextState[10] = { - -1, -1, -1, -1, -1, -1, -1, 0, 0, 0 -}; - -char gob_rotStates[4][4] = { - {0, 22, 23, 24}, - {13, 2, 12, 14}, - {16, 15, 4, 17}, - {27, 25, 26, 6} -}; - -int16 gob_destItemType; -int16 gob_destItemState; -// Pointers to interpreter variables -int32 *gob_some0ValPtr; - -int32 *gob_gobRetVarPtr; -int32 *gob_curGobVarPtr; -int32 *gob_curGobXPosVarPtr; -int32 *gob_curGobYPosVarPtr; -int32 *gob_itemInPocketVarPtr; -int32 *gob_curGobStateVarPtr; -int32 *gob_curGobFrameVarPtr; -int32 *gob_curGobMultStateVarPtr; -int32 *gob_curGobNextStateVarPtr; -int32 *gob_curGobScrXVarPtr; -int32 *gob_curGobScrYVarPtr; -int32 *gob_curGobLeftVarPtr; -int32 *gob_curGobTopVarPtr; -int32 *gob_curGobRightVarPtr; -int32 *gob_curGobBottomVarPtr; -int32 *gob_curGobDoAnimVarPtr; -int32 *gob_curGobOrderVarPtr; -int32 *gob_curGobNoTickVarPtr; -int32 *gob_curGobTypeVarPtr; -int32 *gob_curGobMaxTickVarPtr; -int32 *gob_curGobTickVarPtr; -int32 *gob_curGobActStartStateVarPtr; -int32 *gob_curGobLookDirVarPtr; -int32 *gob_curGobPickableVarPtr; -int32 *gob_curGobRelaxVarPtr; -int32 *gob_curGobMaxFrameVarPtr; - -int32 *gob_destItemStateVarPtr; -int32 *gob_destItemFrameVarPtr; -int32 *gob_destItemMultStateVarPtr; -int32 *gob_destItemNextStateVarPtr; -int32 *gob_destItemScrXVarPtr; -int32 *gob_destItemScrYVarPtr; -int32 *gob_destItemLeftVarPtr; -int32 *gob_destItemTopVarPtr; -int32 *gob_destItemRightVarPtr; -int32 *gob_destItemBottomVarPtr; -int32 *gob_destItemDoAnimVarPtr; -int32 *gob_destItemOrderVarPtr; -int32 *gob_destItemNoTickVarPtr; -int32 *gob_destItemTypeVarPtr; -int32 *gob_destItemMaxTickVarPtr; -int32 *gob_destItemTickVarPtr; -int32 *gob_destItemActStartStVarPtr; -int32 *gob_destItemLookDirVarPtr; -int32 *gob_destItemPickableVarPtr; -int32 *gob_destItemRelaxVarPtr; -int32 *gob_destItemMaxFrameVarPtr; - -// -int16 gob_itemToObject[20]; -Gob_Object *gob_objects[20]; -int16 gob_objCount; -int16 gob_gobsCount; -char gob_boreCounter = 0; -int16 gob_positionedGob = 5; - -char gob_noPick = 0; - -char gob_rotateState(int16 from, int16 to) { - return gob_rotStates[from / 2][to / 2]; +Goblin::Goblin(GobEngine *vm) : _vm(vm) { + goesAtTarget = 0; + readyToAct = 0; + gobAction = 0; + itemIndInPocket = 5; + itemIdInPocket = 2; + itemByteFlag = 0; + destItemId = -1; + destActionItem = 0; + actDestItemDesc = 0; + forceNextState[0] = -1; + forceNextState[1] = -1; + forceNextState[2] = -1; + forceNextState[3] = -1; + forceNextState[4] = -1; + forceNextState[5] = -1; + forceNextState[6] = -1; + forceNextState[7] = 0; + forceNextState[8] = 0; + forceNextState[9] = 0; + + rotStates[0][0] = 0; rotStates[0][1] = 22; rotStates[0][2] = 23; rotStates[0][3] = 24; + rotStates[1][0] = 13; rotStates[1][1] = 2; rotStates[1][2] = 12; rotStates[1][3] = 14; + rotStates[2][0] = 16; rotStates[2][1] = 15; rotStates[2][2] = 4; rotStates[2][3] = 17; + rotStates[3][0] = 27; rotStates[3][1] = 25; rotStates[3][2] = 26; rotStates[3][3] = 6; + + boreCounter = 0; + positionedGob = 5; + + noPick = 0; + objList = 0; + for (int i = 0; i < 4; i++) + goblins[i] = 0; + currentGoblin = 0; + for (int i = 0; i < 16; i++) + soundData[i] = 0; + for (int i = 0; i < 3; i++) { + gobPositions[i].x = 0; + gobPositions[i].y = 0; + } + gobDestX = 0; + gobDestY = 0; + pressedMapX = 0; + pressedMapY = 0; + pathExistence = 0; + + some0ValPtr = 0; + + gobRetVarPtr = 0; + curGobVarPtr = 0; + curGobXPosVarPtr = 0; + curGobYPosVarPtr = 0; + itemInPocketVarPtr = 0; + + curGobStateVarPtr = 0; + curGobFrameVarPtr = 0; + curGobMultStateVarPtr = 0; + curGobNextStateVarPtr = 0; + curGobScrXVarPtr = 0; + curGobScrYVarPtr = 0; + curGobLeftVarPtr = 0; + curGobTopVarPtr = 0; + curGobRightVarPtr = 0; + curGobBottomVarPtr = 0; + curGobDoAnimVarPtr = 0; + curGobOrderVarPtr = 0; + curGobNoTickVarPtr = 0; + curGobTypeVarPtr = 0; + curGobMaxTickVarPtr = 0; + curGobTickVarPtr = 0; + curGobActStartStateVarPtr = 0; + curGobLookDirVarPtr = 0; + curGobPickableVarPtr = 0; + curGobRelaxVarPtr = 0; + curGobMaxFrameVarPtr = 0; + + destItemStateVarPtr = 0; + destItemFrameVarPtr = 0; + destItemMultStateVarPtr = 0; + destItemNextStateVarPtr = 0; + destItemScrXVarPtr = 0; + destItemScrYVarPtr = 0; + destItemLeftVarPtr = 0; + destItemTopVarPtr = 0; + destItemRightVarPtr = 0; + destItemBottomVarPtr = 0; + destItemDoAnimVarPtr = 0; + destItemOrderVarPtr = 0; + destItemNoTickVarPtr = 0; + destItemTypeVarPtr = 0; + destItemMaxTickVarPtr = 0; + destItemTickVarPtr = 0; + destItemActStartStVarPtr = 0; + destItemLookDirVarPtr = 0; + destItemPickableVarPtr = 0; + destItemRelaxVarPtr = 0; + destItemMaxFrameVarPtr = 0; + + destItemType = 0; + destItemState = 0; + for (int i = 0; i < 20; i++) { + itemToObject[i] = 0; + objects[i] = 0; + } + objCount = 0; + gobsCount = 0; +} + +char Goblin::rotateState(int16 from, int16 to) { + return rotStates[from / 2][to / 2]; } -int16 gob_peekGoblin(Gob_Object *curGob) { - Util_ListNode *ptr; +int16 Goblin::peekGoblin(Gob_Object *curGob) { + Util::ListNode *ptr; Gob_Object *desc; int16 index; int16 i; - ptr = gob_objList->pHead; + ptr = objList->pHead; index = 0; while (ptr != 0) { desc = (Gob_Object *) ptr->pData; if (desc != curGob) { for (i = 0; i < 3; i++) { - if (desc != gob_goblins[i]) + if (desc != goblins[i]) continue; - if (inter_mouseX < desc->right && - inter_mouseX > desc->left && - inter_mouseY < desc->bottom && - inter_mouseY > desc->top) { + if (_vm->_global->inter_mouseX < desc->right && + _vm->_global->inter_mouseX > desc->left && + _vm->_global->inter_mouseY < desc->bottom && + _vm->_global->inter_mouseY > desc->top) { index = i + 1; } } @@ -163,15 +175,15 @@ int16 gob_peekGoblin(Gob_Object *curGob) { return index; } -void gob_initList(void) { - gob_objList = (Util_List *) malloc(sizeof(Util_List)); - gob_objList->pHead = 0; - gob_objList->pTail = 0; +void Goblin::initList(void) { + objList = (Util::List *) malloc(sizeof(Util::List)); + objList->pHead = 0; + objList->pTail = 0; } -void gob_sortByOrder(Util_List *list) { - Util_ListNode *ptr; - Util_ListNode *ptr2; +void Goblin::sortByOrder(Util::List *list) { + Util::ListNode *ptr; + Util::ListNode *ptr2; ptr = list->pHead; while (ptr->pNext != 0) { @@ -187,7 +199,7 @@ void gob_sortByOrder(Util_List *list) { if (objDesc->bottom != objDesc2->bottom) continue; - if (objDesc != gob_goblins[gob_currentGoblin]) + if (objDesc != goblins[currentGoblin]) continue; } } @@ -198,23 +210,23 @@ void gob_sortByOrder(Util_List *list) { } } -void gob_playSound(Snd_SoundDesc *snd, int16 repCount, int16 freq) { +void Goblin::playSound(Snd::SoundDesc *snd, int16 repCount, int16 freq) { if (snd != 0) { - snd_stopSound(0); - snd_playSample(snd, repCount, freq); + _vm->_snd->stopSound(0); + _vm->_snd->playSample(snd, repCount, freq); } } -void gob_drawObjects(void) { - Util_ListNode *ptr; - Util_ListNode *ptr2; +void Goblin::drawObjects(void) { + Util::ListNode *ptr; + Util::ListNode *ptr2; Gob_Object *objDesc; Gob_Object *gobDesc2; int16 layer; - ptr = gob_objList->pHead; - for (ptr = gob_objList->pHead; ptr != 0; ptr = ptr->pNext) { + ptr = objList->pHead; + for (ptr = objList->pHead; ptr != 0; ptr = ptr->pNext) { objDesc = (Gob_Object *) ptr->pData; if (objDesc->type == 3) @@ -223,16 +235,16 @@ void gob_drawObjects(void) { objDesc->toRedraw = 0; } - for (ptr = gob_objList->pHead; ptr != 0; ptr = ptr->pNext) { + for (ptr = objList->pHead; ptr != 0; ptr = ptr->pNext) { objDesc = (Gob_Object *) ptr->pData; if (objDesc->toRedraw == 0) continue; - vid_drawSprite(anim_underAnimSurf, draw_backSurface, + _vm->_video->drawSprite(_vm->_anim->_animSurf, _vm->_draw->backSurface, objDesc->left, objDesc->top, objDesc->right, objDesc->bottom, objDesc->left, objDesc->top, 0); - draw_invalidateRect(objDesc->left, objDesc->top, + _vm->_draw->invalidateRect(objDesc->left, objDesc->top, objDesc->right, objDesc->bottom); if (objDesc->type != 0) @@ -241,23 +253,23 @@ void gob_drawObjects(void) { layer = objDesc->stateMach[objDesc->state][objDesc->stateColumn]-> layer; - scen_updateAnim(layer, objDesc->curFrame, objDesc->animation, + _vm->_scenery->updateAnim(layer, objDesc->curFrame, objDesc->animation, 0, objDesc->xPos, objDesc->yPos, 0); - if (scen_toRedrawLeft == -12345) { + if (_vm->_scenery->toRedrawLeft == -12345) { objDesc->dirtyLeft = objDesc->left; objDesc->dirtyRight = objDesc->right; objDesc->dirtyTop = objDesc->top; objDesc->dirtyBottom = objDesc->bottom; } else { objDesc->dirtyLeft = - MIN(objDesc->left, scen_toRedrawLeft); + MIN(objDesc->left, _vm->_scenery->toRedrawLeft); objDesc->dirtyRight = - MAX(objDesc->right, scen_toRedrawRight); + MAX(objDesc->right, _vm->_scenery->toRedrawRight); objDesc->dirtyTop = - MIN(objDesc->top, scen_toRedrawTop); + MIN(objDesc->top, _vm->_scenery->toRedrawTop); objDesc->dirtyBottom = - MAX(objDesc->bottom, scen_toRedrawBottom); + MAX(objDesc->bottom, _vm->_scenery->toRedrawBottom); } objDesc->dirtyLeft = 0; @@ -266,8 +278,8 @@ void gob_drawObjects(void) { objDesc->dirtyBottom = 199; } - gob_sortByOrder(gob_objList); - for (ptr = gob_objList->pHead; ptr != 0; ptr = ptr->pNext) { + sortByOrder(objList); + for (ptr = objList->pHead; ptr != 0; ptr = ptr->pNext) { objDesc = (Gob_Object *) ptr->pData; if (objDesc->toRedraw) { layer = @@ -276,33 +288,33 @@ void gob_drawObjects(void) { if (objDesc->type == 0) { if (objDesc->visible == 0) { - scen_updateAnim(layer, + _vm->_scenery->updateAnim(layer, objDesc->curFrame, objDesc->animation, 0, objDesc->xPos, objDesc->yPos, 0); } else { - scen_updateAnim(layer, + _vm->_scenery->updateAnim(layer, objDesc->curFrame, objDesc->animation, 2, objDesc->xPos, objDesc->yPos, 1); } - if (scen_toRedrawLeft == -12345) { + if (_vm->_scenery->toRedrawLeft == -12345) { objDesc->left = 0; objDesc->top = 0; objDesc->right = 0; objDesc->bottom = 0; } else { - draw_invalidateRect(scen_toRedrawLeft, - scen_toRedrawTop, - scen_toRedrawRight, - scen_toRedrawBottom); - - objDesc->left = scen_toRedrawLeft; - objDesc->top = scen_toRedrawTop; - objDesc->right = scen_toRedrawRight; - objDesc->bottom = scen_toRedrawBottom; - scen_updateStatic(objDesc->order); + _vm->_draw->invalidateRect(_vm->_scenery->toRedrawLeft, + _vm->_scenery->toRedrawTop, + _vm->_scenery->toRedrawRight, + _vm->_scenery->toRedrawBottom); + + objDesc->left = _vm->_scenery->toRedrawLeft; + objDesc->top = _vm->_scenery->toRedrawTop; + objDesc->right = _vm->_scenery->toRedrawRight; + objDesc->bottom = _vm->_scenery->toRedrawBottom; + _vm->_scenery->updateStatic(objDesc->order); } } else { objDesc->left = 0; @@ -315,7 +327,7 @@ void gob_drawObjects(void) { } if (objDesc->type == 0 && objDesc->visible != 0) { - for (ptr2 = gob_objList->pHead; ptr2 != 0; + for (ptr2 = objList->pHead; ptr2 != 0; ptr2 = ptr2->pNext) { gobDesc2 = (Gob_Object *) ptr2->pData; @@ -334,25 +346,25 @@ void gob_drawObjects(void) { if (gobDesc2->dirtyBottom < objDesc->top) continue; - scen_toRedrawLeft = gobDesc2->dirtyLeft; - scen_toRedrawRight = gobDesc2->dirtyRight; - scen_toRedrawTop = gobDesc2->dirtyTop; - scen_toRedrawBottom = gobDesc2->dirtyBottom; + _vm->_scenery->toRedrawLeft = gobDesc2->dirtyLeft; + _vm->_scenery->toRedrawRight = gobDesc2->dirtyRight; + _vm->_scenery->toRedrawTop = gobDesc2->dirtyTop; + _vm->_scenery->toRedrawBottom = gobDesc2->dirtyBottom; layer = objDesc->stateMach[objDesc-> state][objDesc->stateColumn]->layer; - scen_updateAnim(layer, objDesc->curFrame, + _vm->_scenery->updateAnim(layer, objDesc->curFrame, objDesc->animation, 4, objDesc->xPos, objDesc->yPos, 1); - scen_updateStatic(objDesc->order); + _vm->_scenery->updateStatic(objDesc->order); } } } - for (ptr = gob_objList->pHead; ptr != 0; ptr = ptr->pNext) { + for (ptr = objList->pHead; ptr != 0; ptr = ptr->pNext) { objDesc = (Gob_Object *) ptr->pData; if (objDesc->toRedraw == 0 || objDesc->type == 1) continue; @@ -376,7 +388,7 @@ void gob_drawObjects(void) { if (objDesc->curFrame == sndFrame) { if (sndItem != 0xff) { - gob_playSound(gob_soundData[sndItem], + playSound(soundData[sndItem], repCount, freq); } } @@ -388,7 +400,7 @@ void gob_drawObjects(void) { if (objDesc->curFrame == sndFrame) { if (sndItem != 0xff) { - gob_playSound(gob_soundData[sndItem], + playSound(soundData[sndItem], repCount, freq); } } @@ -401,23 +413,23 @@ void gob_drawObjects(void) { if (objDesc->curFrame == sndFrame) { if (sndItem != -1) { - gob_playSound(gob_soundData[sndItem], + playSound(soundData[sndItem], repCount, freq); } } } } -// scen_updateAnim(27, 0, 9, 2, 10, 10, 1); +// _vm->_scenery->updateAnim(27, 0, 9, 2, 10, 10, 1); } -void gob_animateObjects(void) { - Util_ListNode *node; +void Goblin::animateObjects(void) { + Util::ListNode *node; Gob_Object *objDesc; - Scen_AnimLayer *pLayer; + Scenery::AnimLayer *pLayer; int16 layer; - for (node = gob_objList->pHead; node != 0; node = node->pNext) { + for (node = objList->pHead; node != 0; node = node->pNext) { objDesc = (Gob_Object *) node->pData; if (objDesc->doAnim != 1 || objDesc->type != 0) continue; @@ -434,7 +446,7 @@ void gob_animateObjects(void) { layer = objDesc->stateMach[objDesc->state][0]->layer; pLayer = - scen_animations[objDesc->animation].layers[layer]; + _vm->_scenery->animations[objDesc->animation].layers[layer]; if (objDesc->curFrame < pLayer->framesCount) continue; @@ -453,7 +465,7 @@ void gob_animateObjects(void) { if (objDesc->multState != -1) { if (objDesc->multState > 39) { - objDesc->stateMach = gob_goblins[(int)(objDesc->multObjIndex)]->stateMach; + objDesc->stateMach = goblins[(int)(objDesc->multObjIndex)]->stateMach; objDesc->state = objDesc->multState - 40; } else { objDesc->stateMach = objDesc->realStateMach; @@ -479,7 +491,7 @@ void gob_animateObjects(void) { } } -void gob_placeObject(Gob_Object *objDesc, char animated) { +void Goblin::placeObject(Gob_Object *objDesc, char animated) { int16 layer; if (objDesc->stateMach[objDesc->state][0] != 0) { @@ -503,13 +515,13 @@ void gob_placeObject(Gob_Object *objDesc, char animated) { objDesc->pickable = 0; objDesc->unk14 = 0; - objDesc->relaxTime = util_getRandom(30); + objDesc->relaxTime = _vm->_util->getRandom(30); layer = objDesc->stateMach[objDesc->state][0]->layer; - scen_updateAnim(layer, 0, objDesc->animation, 0, + _vm->_scenery->updateAnim(layer, 0, objDesc->animation, 0, objDesc->xPos, objDesc->yPos, 0); - objDesc->order = scen_toRedrawBottom / 24 + 3; + objDesc->order = _vm->_scenery->toRedrawBottom / 24 + 3; objDesc->left = objDesc->xPos; objDesc->right = objDesc->xPos; @@ -521,19 +533,19 @@ void gob_placeObject(Gob_Object *objDesc, char animated) { objDesc->dirtyTop = objDesc->yPos; objDesc->dirtyBottom = objDesc->yPos; - util_listInsertBack(gob_objList, objDesc); + _vm->_util->listInsertBack(objList, objDesc); } } -int16 gob_getObjMaxFrame(Gob_Object * objDesc) { +int16 Goblin::getObjMaxFrame(Gob_Object * objDesc) { int16 layer; layer = objDesc->stateMach[objDesc->state][0]->layer; - return scen_animations[objDesc->animation].layers[layer]->framesCount - + return _vm->_scenery->animations[objDesc->animation].layers[layer]->framesCount - 1; } -int16 gob_objIntersected(Gob_Object *obj1, Gob_Object *obj2) { +int16 Goblin::objIntersected(Gob_Object *obj1, Gob_Object *obj2) { if (obj1->type == 1 || obj2->type == 1) return 0; @@ -552,11 +564,11 @@ int16 gob_objIntersected(Gob_Object *obj1, Gob_Object *obj2) { return 1; } -void gob_setMultStates(Gob_Object * gobDesc) { - gobDesc->stateMach = gob_goblins[(int)gobDesc->multObjIndex]->stateMach; +void Goblin::setMultStates(Gob_Object * gobDesc) { + gobDesc->stateMach = goblins[(int)gobDesc->multObjIndex]->stateMach; } -int16 gob_nextLayer(Gob_Object *gobDesc) { +int16 Goblin::nextLayer(Gob_Object *gobDesc) { if (gobDesc->nextState == 10) gobDesc->curLookDir = 0; @@ -564,7 +576,7 @@ int16 gob_nextLayer(Gob_Object *gobDesc) { gobDesc->curLookDir = 4; if (gobDesc->nextState > 39) { - gob_setMultStates(gobDesc); + setMultStates(gobDesc); } else { gobDesc->stateMach = gobDesc->realStateMach; } @@ -579,7 +591,7 @@ int16 gob_nextLayer(Gob_Object *gobDesc) { return gobDesc->stateMach[gobDesc->state][0]->layer; } -void gob_showBoredom(int16 gobIndex) { +void Goblin::showBoredom(int16 gobIndex) { Gob_Object *gobDesc; int16 frame; int16 frameCount; @@ -587,20 +599,20 @@ void gob_showBoredom(int16 gobIndex) { int16 state; int16 boreFlag; - gobDesc = gob_goblins[gobIndex]; + gobDesc = goblins[gobIndex]; layer = gobDesc->stateMach[gobDesc->state][0]->layer; frameCount = - scen_animations[gobDesc->animation].layers[layer]->framesCount; + _vm->_scenery->animations[gobDesc->animation].layers[layer]->framesCount; state = gobDesc->state; frame = gobDesc->curFrame; gobDesc->noTick = 0; gobDesc->toRedraw = 1; - boreFlag = 1 << util_getRandom(7); + boreFlag = 1 << _vm->_util->getRandom(7); - if (gobIndex != gob_currentGoblin && util_getRandom(3) != 0) { + if (gobIndex != currentGoblin && _vm->_util->getRandom(3) != 0) { if (state == 21) { if ((boreFlag & 16) || (boreFlag & 32)) { gobDesc->multState = 92 + gobIndex; @@ -628,103 +640,103 @@ void gob_showBoredom(int16 gobIndex) { // index - goblin to select+1 // index==0 - switch to next -void gob_switchGoblin(int16 index) { +void Goblin::switchGoblin(int16 index) { int16 next; int16 tmp; - debug(4, "gob_switchGoblin"); + debug(4, "switchGoblin"); if (VAR(59) != 0) return; - if (gob_goblins[gob_currentGoblin]->state <= 39 && - gob_goblins[gob_currentGoblin]->curFrame != 0) + if (goblins[currentGoblin]->state <= 39 && + goblins[currentGoblin]->curFrame != 0) return; - if (index != 0 && gob_goblins[index - 1]->type != 0) + if (index != 0 && goblins[index - 1]->type != 0) return; if (index == 0) - next = (gob_currentGoblin + 1) % 3; + next = (currentGoblin + 1) % 3; else next = index - 1; - if (map_passMap[map_curGoblinY][map_curGoblinX] == 3 || - map_passMap[map_curGoblinY][map_curGoblinX] == 6) + if (_vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 3 || + _vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 6) return; - if (gob_goblins[(gob_currentGoblin + 1) % 3]->type != 0 && - gob_goblins[(gob_currentGoblin + 2) % 3]->type != 0) + if (goblins[(currentGoblin + 1) % 3]->type != 0 && + goblins[(currentGoblin + 2) % 3]->type != 0) return; - gob_gobPositions[gob_currentGoblin].x = map_curGoblinX; - gob_gobPositions[gob_currentGoblin].y = map_curGoblinY; + gobPositions[currentGoblin].x = _vm->_map->curGoblinX; + gobPositions[currentGoblin].y = _vm->_map->curGoblinY; - gob_goblins[gob_currentGoblin]->doAnim = 1; - gob_goblins[gob_currentGoblin]->nextState = 21; + goblins[currentGoblin]->doAnim = 1; + goblins[currentGoblin]->nextState = 21; - gob_nextLayer(gob_goblins[gob_currentGoblin]); + nextLayer(goblins[currentGoblin]); - gob_currentGoblin = next; - if (gob_goblins[gob_currentGoblin]->type != 0) - gob_currentGoblin = (gob_currentGoblin + 1) % 3; + currentGoblin = next; + if (goblins[currentGoblin]->type != 0) + currentGoblin = (currentGoblin + 1) % 3; - gob_goblins[gob_currentGoblin]->doAnim = 0; - if (gob_goblins[gob_currentGoblin]->curLookDir == 4) - gob_goblins[gob_currentGoblin]->nextState = 18; + goblins[currentGoblin]->doAnim = 0; + if (goblins[currentGoblin]->curLookDir == 4) + goblins[currentGoblin]->nextState = 18; else - gob_goblins[gob_currentGoblin]->nextState = 19; - - gob_goblins[gob_currentGoblin]->toRedraw = 1; - gob_nextLayer(gob_goblins[gob_currentGoblin]); - - tmp = gob_gobPositions[gob_currentGoblin].x; - gob_pressedMapX = tmp; - map_destX = tmp; - gob_gobDestX = tmp; - map_curGoblinX = tmp; - - tmp = gob_gobPositions[gob_currentGoblin].y; - gob_pressedMapY = tmp; - map_destY = tmp; - gob_gobDestY = tmp; - map_curGoblinY = tmp; - - *gob_curGobVarPtr = gob_currentGoblin; - gob_pathExistence = 0; - gob_readyToAct = 0; + goblins[currentGoblin]->nextState = 19; + + goblins[currentGoblin]->toRedraw = 1; + nextLayer(goblins[currentGoblin]); + + tmp = gobPositions[currentGoblin].x; + pressedMapX = tmp; + _vm->_map->destX = tmp; + gobDestX = tmp; + _vm->_map->curGoblinX = tmp; + + tmp = gobPositions[currentGoblin].y; + pressedMapY = tmp; + _vm->_map->destY = tmp; + gobDestY = tmp; + _vm->_map->curGoblinY = tmp; + + *curGobVarPtr = currentGoblin; + pathExistence = 0; + readyToAct = 0; } -void gob_adjustDest(int16 posX, int16 posY) { +void Goblin::adjustDest(int16 posX, int16 posY) { int16 resDelta; int16 resDeltaDir; int16 resDeltaPix; int16 deltaPix; int16 i; - if (map_passMap[gob_pressedMapY][gob_pressedMapX] == 0 && - (gob_gobAction == 0 - || map_itemsMap[gob_pressedMapY][gob_pressedMapX] == 0)) { + if (_vm->_map->passMap[pressedMapY][pressedMapX] == 0 && + (gobAction == 0 + || _vm->_map->itemsMap[pressedMapY][pressedMapX] == 0)) { resDelta = -1; resDeltaDir = 0; resDeltaPix = 0; for (i = 1; - i <= gob_pressedMapX - && map_passMap[gob_pressedMapY][gob_pressedMapX - i] == 0; + i <= pressedMapX + && _vm->_map->passMap[pressedMapY][pressedMapX - i] == 0; i++); - if (i <= gob_pressedMapX) { + if (i <= pressedMapX) { resDeltaPix = (i - 1) * 12 + (posX % 12) + 1; resDelta = i; } for (i = 1; - (i + gob_pressedMapX) < kMapWidth - && map_passMap[gob_pressedMapY][gob_pressedMapX + i] == 0; + (i + pressedMapX) < Map::kMapWidth + && _vm->_map->passMap[pressedMapY][pressedMapX + i] == 0; i++); - if (gob_pressedMapX + i < kMapWidth) { + if (pressedMapX + i < Map::kMapWidth) { deltaPix = (i * 12) - (posX % 12); if (resDelta == -1 || deltaPix < resDeltaPix) { resDeltaPix = deltaPix; @@ -734,11 +746,11 @@ void gob_adjustDest(int16 posX, int16 posY) { } for (i = 1; - (i + gob_pressedMapY) < kMapHeight - && map_passMap[gob_pressedMapY + i][gob_pressedMapX] == 0; + (i + pressedMapY) < Map::kMapHeight + && _vm->_map->passMap[pressedMapY + i][pressedMapX] == 0; i++); - if (gob_pressedMapY + i < kMapHeight) { + if (pressedMapY + i < Map::kMapHeight) { deltaPix = (i * 6) - (posY % 6); if (resDelta == -1 || deltaPix < resDeltaPix) { resDeltaPix = deltaPix; @@ -748,11 +760,11 @@ void gob_adjustDest(int16 posX, int16 posY) { } for (i = 1; - i <= gob_pressedMapY - && map_passMap[gob_pressedMapY - i][gob_pressedMapX] == 0; + i <= pressedMapY + && _vm->_map->passMap[pressedMapY - i][pressedMapX] == 0; i++); - if (i <= gob_pressedMapY) { + if (i <= pressedMapY) { deltaPix = (i * 6) + (posY % 6); if (resDelta == -1 || deltaPix < resDeltaPix) { resDeltaPix = deltaPix; @@ -763,62 +775,62 @@ void gob_adjustDest(int16 posX, int16 posY) { switch (resDeltaDir) { case 0: - gob_pressedMapX -= resDelta; + pressedMapX -= resDelta; break; case 1: - gob_pressedMapX += resDelta; + pressedMapX += resDelta; break; case 2: - gob_pressedMapY += resDelta; + pressedMapY += resDelta; break; case 3: - gob_pressedMapY -= resDelta; + pressedMapY -= resDelta; break; } } } -void gob_adjustTarget(void) { - if (gob_gobAction == 4 - && map_itemsMap[gob_pressedMapY][gob_pressedMapX] == 0) { +void Goblin::adjustTarget(void) { + if (gobAction == 4 + && _vm->_map->itemsMap[pressedMapY][pressedMapX] == 0) { - if (gob_pressedMapY > 0 - && map_itemsMap[gob_pressedMapY - 1][gob_pressedMapX] != + if (pressedMapY > 0 + && _vm->_map->itemsMap[pressedMapY - 1][pressedMapX] != 0) { - gob_pressedMapY--; - } else if (gob_pressedMapX < kMapWidth - 1 - && map_itemsMap[gob_pressedMapY][gob_pressedMapX + 1] != + pressedMapY--; + } else if (pressedMapX < Map::kMapWidth - 1 + && _vm->_map->itemsMap[pressedMapY][pressedMapX + 1] != 0) { - gob_pressedMapX++; - } else if (gob_pressedMapX < kMapWidth - 1 && gob_pressedMapY > 0 - && map_itemsMap[gob_pressedMapY - 1][gob_pressedMapX + + pressedMapX++; + } else if (pressedMapX < Map::kMapWidth - 1 && pressedMapY > 0 + && _vm->_map->itemsMap[pressedMapY - 1][pressedMapX + 1] != 0) { - gob_pressedMapY--; - gob_pressedMapX++; + pressedMapY--; + pressedMapX++; } } } -void gob_targetDummyItem(Gob_Object *gobDesc) { - if (map_itemsMap[gob_pressedMapY][gob_pressedMapX] == 0 && - map_passMap[gob_pressedMapY][gob_pressedMapX] == 1) { +void Goblin::targetDummyItem(Gob_Object *gobDesc) { + if (_vm->_map->itemsMap[pressedMapY][pressedMapX] == 0 && + _vm->_map->passMap[pressedMapY][pressedMapX] == 1) { if (gobDesc->curLookDir == 0) { - map_itemPoses[0].x = gob_pressedMapX; - map_itemPoses[0].y = gob_pressedMapY; - map_itemPoses[0].orient = -4; + _vm->_map->itemPoses[0].x = pressedMapX; + _vm->_map->itemPoses[0].y = pressedMapY; + _vm->_map->itemPoses[0].orient = -4; } else { - map_itemPoses[0].x = gob_pressedMapX; - map_itemPoses[0].y = gob_pressedMapY; - map_itemPoses[0].orient = -1; + _vm->_map->itemPoses[0].x = pressedMapX; + _vm->_map->itemPoses[0].y = pressedMapY; + _vm->_map->itemPoses[0].orient = -1; } } } -void gob_targetItem(void) { +void Goblin::targetItem(void) { int16 tmpX; int16 tmpY; int16 items; @@ -827,106 +839,106 @@ void gob_targetItem(void) { int16 tmpPosY; Gob_Object *itemDesc; - if (gob_gobAction == 3 || gob_gobAction == 4) { - items = map_itemsMap[gob_pressedMapY][gob_pressedMapX]; - if (gob_gobAction == 4 && (items & 0xff00) != 0 && - gob_objects[gob_itemToObject[(items & 0xff00) >> 8]]-> + if (gobAction == 3 || gobAction == 4) { + items = _vm->_map->itemsMap[pressedMapY][pressedMapX]; + if (gobAction == 4 && (items & 0xff00) != 0 && + objects[itemToObject[(items & 0xff00) >> 8]]-> pickable == 1) { - gob_destItemId = (items & 0xff00) >> 8; - gob_destActionItem = (items & 0xff00) >> 8; - gob_itemByteFlag = 1; + destItemId = (items & 0xff00) >> 8; + destActionItem = (items & 0xff00) >> 8; + itemByteFlag = 1; } else if ((items & 0xff) == 0) { - gob_destItemId = (items & 0xff00) >> 8; - gob_destActionItem = (items & 0xff00) >> 8; - gob_itemByteFlag = 1; - } else if (gob_gobAction == 3 && gob_currentGoblin == 2 && + destItemId = (items & 0xff00) >> 8; + destActionItem = (items & 0xff00) >> 8; + itemByteFlag = 1; + } else if (gobAction == 3 && currentGoblin == 2 && (items & 0xff00) != 0) { - gob_destItemId = (items & 0xff00) >> 8; - gob_destActionItem = (items & 0xff00) >> 8; - gob_itemByteFlag = 1; + destItemId = (items & 0xff00) >> 8; + destActionItem = (items & 0xff00) >> 8; + itemByteFlag = 1; } else { - gob_destItemId = items & 0xff; - gob_destActionItem = items & 0xff; - gob_itemByteFlag = 0; + destItemId = items & 0xff; + destActionItem = items & 0xff; + itemByteFlag = 0; } - gob_pressedMapY = map_itemPoses[gob_destItemId].y; - map_destY = map_itemPoses[gob_destItemId].y; - gob_gobDestY = map_itemPoses[gob_destItemId].y; + pressedMapY = _vm->_map->itemPoses[destItemId].y; + _vm->_map->destY = _vm->_map->itemPoses[destItemId].y; + gobDestY = _vm->_map->itemPoses[destItemId].y; - if (gob_gobAction == 3 || gob_destActionItem == 0) { - gob_pressedMapX = map_itemPoses[gob_destItemId].x; - map_destX = map_itemPoses[gob_destItemId].x; - gob_gobDestX = map_itemPoses[gob_destItemId].x; + if (gobAction == 3 || destActionItem == 0) { + pressedMapX = _vm->_map->itemPoses[destItemId].x; + _vm->_map->destX = _vm->_map->itemPoses[destItemId].x; + gobDestX = _vm->_map->itemPoses[destItemId].x; } else if ((items & 0xff00) != 0) { - if (map_itemPoses[gob_destItemId].orient == 4) { - if ((map_itemsMap[gob_pressedMapY] - [gob_pressedMapX - 1] & 0xff00) == - (map_itemsMap[gob_pressedMapY] - [gob_pressedMapX] & 0xff00)) { - gob_pressedMapX--; - map_destX = gob_pressedMapX; - gob_gobDestX = gob_pressedMapX; + if (_vm->_map->itemPoses[destItemId].orient == 4) { + if ((_vm->_map->itemsMap[pressedMapY] + [pressedMapX - 1] & 0xff00) == + (_vm->_map->itemsMap[pressedMapY] + [pressedMapX] & 0xff00)) { + pressedMapX--; + _vm->_map->destX = pressedMapX; + gobDestX = pressedMapX; } - } else if (map_itemPoses[gob_destItemId].orient == 0) { - - if ((map_itemsMap[gob_pressedMapY] - [gob_pressedMapX + 1] & 0xff00) == - (map_itemsMap[gob_pressedMapY] - [gob_pressedMapX] & 0xff00)) { - gob_pressedMapX++; - map_destX = gob_pressedMapX; - gob_gobDestX = gob_pressedMapX; + } else if (_vm->_map->itemPoses[destItemId].orient == 0) { + + if ((_vm->_map->itemsMap[pressedMapY] + [pressedMapX + 1] & 0xff00) == + (_vm->_map->itemsMap[pressedMapY] + [pressedMapX] & 0xff00)) { + pressedMapX++; + _vm->_map->destX = pressedMapX; + gobDestX = pressedMapX; } } - if ((map_itemsMap[gob_pressedMapY + - 1][gob_pressedMapX] & 0xff00) == - (map_itemsMap[gob_pressedMapY][gob_pressedMapX] & + if ((_vm->_map->itemsMap[pressedMapY + + 1][pressedMapX] & 0xff00) == + (_vm->_map->itemsMap[pressedMapY][pressedMapX] & 0xff00)) { - gob_pressedMapY++; - map_destY = gob_pressedMapY; - gob_gobDestY = gob_pressedMapY; + pressedMapY++; + _vm->_map->destY = pressedMapY; + gobDestY = pressedMapY; } } else { - if (map_itemPoses[gob_destItemId].orient == 4) { - if ((map_itemsMap[gob_pressedMapY] - [gob_pressedMapX - 1]) == - (map_itemsMap[gob_pressedMapY] - [gob_pressedMapX])) { - gob_pressedMapX--; - map_destX = gob_pressedMapX; - gob_gobDestX = gob_pressedMapX; + if (_vm->_map->itemPoses[destItemId].orient == 4) { + if ((_vm->_map->itemsMap[pressedMapY] + [pressedMapX - 1]) == + (_vm->_map->itemsMap[pressedMapY] + [pressedMapX])) { + pressedMapX--; + _vm->_map->destX = pressedMapX; + gobDestX = pressedMapX; } - } else if (map_itemPoses[gob_destItemId].orient == 0) { - - if ((map_itemsMap[gob_pressedMapY] - [gob_pressedMapX + 1]) == - (map_itemsMap[gob_pressedMapY] - [gob_pressedMapX])) { - gob_pressedMapX++; - map_destX = gob_pressedMapX; - gob_gobDestX = gob_pressedMapX; + } else if (_vm->_map->itemPoses[destItemId].orient == 0) { + + if ((_vm->_map->itemsMap[pressedMapY] + [pressedMapX + 1]) == + (_vm->_map->itemsMap[pressedMapY] + [pressedMapX])) { + pressedMapX++; + _vm->_map->destX = pressedMapX; + gobDestX = pressedMapX; } } - if ((map_itemsMap[gob_pressedMapY + - 1][gob_pressedMapX]) == - (map_itemsMap[gob_pressedMapY][gob_pressedMapX])) { - gob_pressedMapY++; - map_destY = gob_pressedMapY; - gob_gobDestY = gob_pressedMapY; + if ((_vm->_map->itemsMap[pressedMapY + + 1][pressedMapX]) == + (_vm->_map->itemsMap[pressedMapY][pressedMapX])) { + pressedMapY++; + _vm->_map->destY = pressedMapY; + gobDestY = pressedMapY; } } - if (gob_gobAction == 4 && gob_destActionItem != 0 && - gob_itemToObject[gob_destActionItem] != -1 && - gob_objects[gob_itemToObject[gob_destActionItem]]-> + if (gobAction == 4 && destActionItem != 0 && + itemToObject[destActionItem] != -1 && + objects[itemToObject[destActionItem]]-> pickable == 1) { itemDesc = - gob_objects[gob_itemToObject[gob_destActionItem]]; + objects[itemToObject[destActionItem]]; itemDesc->animation = itemDesc->stateMach[itemDesc->state][0]->animation; @@ -934,11 +946,11 @@ void gob_targetItem(void) { itemDesc->stateMach[itemDesc->state][itemDesc-> stateColumn]->layer; - scen_updateAnim(layer, 0, itemDesc->animation, 0, + _vm->_scenery->updateAnim(layer, 0, itemDesc->animation, 0, itemDesc->xPos, itemDesc->yPos, 0); - tmpX = (scen_toRedrawRight + scen_toRedrawLeft) / 2; - tmpY = scen_toRedrawBottom; + tmpX = (_vm->_scenery->toRedrawRight + _vm->_scenery->toRedrawLeft) / 2; + tmpY = _vm->_scenery->toRedrawBottom; tmpPosY = tmpY / 6; if ((tmpY % 3) < 3 && tmpPosY > 0) @@ -948,358 +960,358 @@ void gob_targetItem(void) { if ((tmpX % 12) < 6 && tmpPosX > 0) tmpPosX--; - if (map_itemPoses[gob_destActionItem].orient == 0 || - map_itemPoses[gob_destActionItem].orient == -1) { + if (_vm->_map->itemPoses[destActionItem].orient == 0 || + _vm->_map->itemPoses[destActionItem].orient == -1) { tmpPosX++; } - if (map_passMap[tmpPosY][tmpPosX] == 1) { - gob_pressedMapX = tmpPosX; - map_destX = tmpPosX; - gob_gobDestX = tmpPosX; + if (_vm->_map->passMap[tmpPosY][tmpPosX] == 1) { + pressedMapX = tmpPosX; + _vm->_map->destX = tmpPosX; + gobDestX = tmpPosX; - gob_pressedMapY = tmpPosY; - map_destY = tmpPosY; - gob_gobDestY = tmpPosY; + pressedMapY = tmpPosY; + _vm->_map->destY = tmpPosY; + gobDestY = tmpPosY; } } } } -void gob_initiateMove(void) { - map_findNearestToDest(); - map_findNearestToGob(); - map_optimizePoints(); +void Goblin::initiateMove(void) { + _vm->_map->findNearestToDest(); + _vm->_map->findNearestToGob(); + _vm->_map->optimizePoints(); - gob_pathExistence = map_checkDirectPath(map_curGoblinX, map_curGoblinY, - gob_pressedMapX, gob_pressedMapY); + pathExistence = _vm->_map->checkDirectPath(_vm->_map->curGoblinX, _vm->_map->curGoblinY, + pressedMapX, pressedMapY); - if (gob_pathExistence == 3) { - if (map_checkLongPath(map_curGoblinX, map_curGoblinY, - gob_pressedMapX, gob_pressedMapY, - map_nearestWayPoint, map_nearestDest) == 0) { - gob_pathExistence = 0; + if (pathExistence == 3) { + if (_vm->_map->checkLongPath(_vm->_map->curGoblinX, _vm->_map->curGoblinY, + pressedMapX, pressedMapY, + _vm->_map->nearestWayPoint, _vm->_map->nearestDest) == 0) { + pathExistence = 0; } else { - map_destX = map_wayPoints[map_nearestWayPoint].x; - map_destY = map_wayPoints[map_nearestWayPoint].y; + _vm->_map->destX = _vm->_map->wayPoints[_vm->_map->nearestWayPoint].x; + _vm->_map->destY = _vm->_map->wayPoints[_vm->_map->nearestWayPoint].y; } } } -void gob_moveFindItem(int16 posX, int16 posY) { +void Goblin::moveFindItem(int16 posX, int16 posY) { int16 i; - if (gob_gobAction == 3 || gob_gobAction == 4) { + if (gobAction == 3 || gobAction == 4) { for (i = 0; i < 20; i++) { - if (gob_objects[i] == 0) + if (objects[i] == 0) continue; - if (gob_objects[i]->type != 0) + if (objects[i]->type != 0) continue; - if (gob_objects[i]->left > posX) + if (objects[i]->left > posX) continue; - if (gob_objects[i]->right < posX) + if (objects[i]->right < posX) continue; - if (gob_objects[i]->top > posY) + if (objects[i]->top > posY) continue; - if (gob_objects[i]->bottom < posY) + if (objects[i]->bottom < posY) continue; - if (gob_objects[i]->right - gob_objects[i]->left < 40) + if (objects[i]->right - objects[i]->left < 40) posX = - (gob_objects[i]->left + - gob_objects[i]->right) / 2; + (objects[i]->left + + objects[i]->right) / 2; - if (gob_objects[i]->bottom - gob_objects[i]->top < 40) + if (objects[i]->bottom - objects[i]->top < 40) posY = - (gob_objects[i]->top + - gob_objects[i]->bottom) / 2; + (objects[i]->top + + objects[i]->bottom) / 2; break; } - gob_pressedMapX = posX / 12; - gob_pressedMapY = posY / 6; + pressedMapX = posX / 12; + pressedMapY = posY / 6; - if (map_itemsMap[gob_pressedMapY][gob_pressedMapX] == 0 + if (_vm->_map->itemsMap[pressedMapY][pressedMapX] == 0 && i < 20) { - if (map_itemsMap[gob_pressedMapY + - 1][gob_pressedMapX] != 0) { - gob_pressedMapY++; - } else if (map_itemsMap[gob_pressedMapY + - 1][gob_pressedMapX + 1] != 0) { - gob_pressedMapX++; - gob_pressedMapY++; + if (_vm->_map->itemsMap[pressedMapY + + 1][pressedMapX] != 0) { + pressedMapY++; + } else if (_vm->_map->itemsMap[pressedMapY + + 1][pressedMapX + 1] != 0) { + pressedMapX++; + pressedMapY++; } else - if (map_itemsMap[gob_pressedMapY][gob_pressedMapX + + if (_vm->_map->itemsMap[pressedMapY][pressedMapX + 1] != 0) { - gob_pressedMapX++; - } else if (map_itemsMap[gob_pressedMapY - - 1][gob_pressedMapX + 1] != 0) { - gob_pressedMapX++; - gob_pressedMapY--; - } else if (map_itemsMap[gob_pressedMapY - - 1][gob_pressedMapX] != 0) { - gob_pressedMapY--; - } else if (map_itemsMap[gob_pressedMapY - - 1][gob_pressedMapX - 1] != 0) { - gob_pressedMapY--; - gob_pressedMapX--; + pressedMapX++; + } else if (_vm->_map->itemsMap[pressedMapY - + 1][pressedMapX + 1] != 0) { + pressedMapX++; + pressedMapY--; + } else if (_vm->_map->itemsMap[pressedMapY - + 1][pressedMapX] != 0) { + pressedMapY--; + } else if (_vm->_map->itemsMap[pressedMapY - + 1][pressedMapX - 1] != 0) { + pressedMapY--; + pressedMapX--; } else - if (map_itemsMap[gob_pressedMapY][gob_pressedMapX - + if (_vm->_map->itemsMap[pressedMapY][pressedMapX - 1] != 0) { - gob_pressedMapX--; - } else if (map_itemsMap[gob_pressedMapY + - 1][gob_pressedMapX - 1] != 0) { - gob_pressedMapX--; - gob_pressedMapY++; + pressedMapX--; + } else if (_vm->_map->itemsMap[pressedMapY + + 1][pressedMapX - 1] != 0) { + pressedMapX--; + pressedMapY++; } } } else { - gob_pressedMapX = posX / 12; - gob_pressedMapY = posY / 6; + pressedMapX = posX / 12; + pressedMapY = posY / 6; } } -void gob_moveCheckSelect(int16 framesCount, Gob_Object * gobDesc, int16 *pGobIndex, +void Goblin::moveCheckSelect(int16 framesCount, Gob_Object * gobDesc, int16 *pGobIndex, int16 *nextAct) { - if (gobDesc->right > inter_mouseX && - gobDesc->left < inter_mouseX && - gobDesc->bottom > inter_mouseY && - gobDesc->bottom - 10 < inter_mouseY && gob_gobAction == 0) { + if (gobDesc->right > _vm->_global->inter_mouseX && + gobDesc->left < _vm->_global->inter_mouseX && + gobDesc->bottom > _vm->_global->inter_mouseY && + gobDesc->bottom - 10 < _vm->_global->inter_mouseY && gobAction == 0) { if (gobDesc->curLookDir & 4) *nextAct = 16; else *nextAct = 23; gobDesc->curFrame = framesCount - 1; - gob_pathExistence = 0; + pathExistence = 0; } else { - *pGobIndex = gob_peekGoblin(gobDesc); + *pGobIndex = peekGoblin(gobDesc); if (*pGobIndex != 0) { - gob_pathExistence = 0; - } else if (map_curGoblinX == gob_pressedMapX && - map_curGoblinY == gob_pressedMapY) { + pathExistence = 0; + } else if (_vm->_map->curGoblinX == pressedMapX && + _vm->_map->curGoblinY == pressedMapY) { - if (gob_gobAction != 0) - gob_readyToAct = 1; + if (gobAction != 0) + readyToAct = 1; - gob_pathExistence = 0; + pathExistence = 0; } } } -void gob_moveInitStep(int16 framesCount, int16 action, int16 cont, +void Goblin::moveInitStep(int16 framesCount, int16 action, int16 cont, Gob_Object *gobDesc, int16 *pGobIndex, int16 *pNextAct) { int16 posX; int16 posY; - if (cont != 0 && gob_goesAtTarget == 0 && - gob_readyToAct == 0 && VAR(59) == 0 && + if (cont != 0 && goesAtTarget == 0 && + readyToAct == 0 && VAR(59) == 0 && gobDesc->type != 1 && gobDesc->state != 10 && gobDesc->state != 11) { if (gobDesc->state >= 40) { gobDesc->curFrame = framesCount - 1; } - gob_gobAction = action; - gob_forceNextState[0] = -1; - gob_forceNextState[1] = -1; - gob_forceNextState[2] = -1; + gobAction = action; + forceNextState[0] = -1; + forceNextState[1] = -1; + forceNextState[2] = -1; if (action == 3) { - posX = inter_mouseX + 6; - posY = inter_mouseY + 7; + posX = _vm->_global->inter_mouseX + 6; + posY = _vm->_global->inter_mouseY + 7; } else if (action == 4) { - posX = inter_mouseX + 7; - posY = inter_mouseY + 12; + posX = _vm->_global->inter_mouseX + 7; + posY = _vm->_global->inter_mouseY + 12; } else { - posX = inter_mouseX; - posY = inter_mouseY; + posX = _vm->_global->inter_mouseX; + posY = _vm->_global->inter_mouseY; } - gob_moveFindItem(posX, posY); - gob_adjustDest(posX, posY); - gob_adjustTarget(); + moveFindItem(posX, posY); + adjustDest(posX, posY); + adjustTarget(); - map_destX = gob_pressedMapX; - gob_gobDestX = gob_pressedMapX; + _vm->_map->destX = pressedMapX; + gobDestX = pressedMapX; - map_destY = gob_pressedMapY; - gob_gobDestY = gob_pressedMapY; + _vm->_map->destY = pressedMapY; + gobDestY = pressedMapY; - gob_targetDummyItem(gobDesc); + targetDummyItem(gobDesc); - gob_targetItem(); - gob_initiateMove(); + targetItem(); + initiateMove(); - gob_moveCheckSelect(framesCount, gobDesc, pGobIndex, pNextAct); + moveCheckSelect(framesCount, gobDesc, pGobIndex, pNextAct); } else { - if (gob_readyToAct != 0 && - (map_curGoblinX != gob_pressedMapX || - map_curGoblinY != gob_pressedMapY)) - gob_readyToAct = 0; + if (readyToAct != 0 && + (_vm->_map->curGoblinX != pressedMapX || + _vm->_map->curGoblinY != pressedMapY)) + readyToAct = 0; if (gobDesc->type == 1) { - *pGobIndex = gob_peekGoblin(gobDesc); + *pGobIndex = peekGoblin(gobDesc); } } } -void gob_moveTreatRopeStairs(Gob_Object *gobDesc) { - if (gob_currentGoblin != 1) +void Goblin::moveTreatRopeStairs(Gob_Object *gobDesc) { + if (currentGoblin != 1) return; if (gobDesc->nextState == 28 - && map_passMap[map_curGoblinY - 1][map_curGoblinX] == 6) { - gob_forceNextState[0] = 28; - gob_forceNextState[1] = -1; + && _vm->_map->passMap[_vm->_map->curGoblinY - 1][_vm->_map->curGoblinX] == 6) { + forceNextState[0] = 28; + forceNextState[1] = -1; } if (gobDesc->nextState == 29 - && map_passMap[map_curGoblinY + 1][map_curGoblinX] == 6) { - gob_forceNextState[0] = 29; - gob_forceNextState[1] = -1; + && _vm->_map->passMap[_vm->_map->curGoblinY + 1][_vm->_map->curGoblinX] == 6) { + forceNextState[0] = 29; + forceNextState[1] = -1; } if ((gobDesc->nextState == 28 || gobDesc->nextState == 29 || gobDesc->nextState == 20) - && map_passMap[map_curGoblinY][map_curGoblinX] == 6) { + && _vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 6) { if ((gobDesc->curLookDir == 0 || gobDesc->curLookDir == 4 || gobDesc->curLookDir == 2) - && map_passMap[map_curGoblinY - 1][map_curGoblinX] == 6) { - gob_forceNextState[0] = 28; - gob_forceNextState[1] = -1; + && _vm->_map->passMap[_vm->_map->curGoblinY - 1][_vm->_map->curGoblinX] == 6) { + forceNextState[0] = 28; + forceNextState[1] = -1; } else if ((gobDesc->curLookDir == 0 || gobDesc->curLookDir == 4 || gobDesc->curLookDir == 6) - && map_passMap[map_curGoblinY + 1][map_curGoblinX] == 6) { - gob_forceNextState[0] = 29; - gob_forceNextState[1] = -1; + && _vm->_map->passMap[_vm->_map->curGoblinY + 1][_vm->_map->curGoblinX] == 6) { + forceNextState[0] = 29; + forceNextState[1] = -1; } } if (gobDesc->nextState == 8 - && map_passMap[map_curGoblinY - 1][map_curGoblinX] == 3) { - gob_forceNextState[0] = 8; - gob_forceNextState[1] = -1; + && _vm->_map->passMap[_vm->_map->curGoblinY - 1][_vm->_map->curGoblinX] == 3) { + forceNextState[0] = 8; + forceNextState[1] = -1; } if (gobDesc->nextState == 9 - && map_passMap[map_curGoblinY + 1][map_curGoblinX] == 3) { - gob_forceNextState[0] = 9; - gob_forceNextState[1] = -1; + && _vm->_map->passMap[_vm->_map->curGoblinY + 1][_vm->_map->curGoblinX] == 3) { + forceNextState[0] = 9; + forceNextState[1] = -1; } if (gobDesc->nextState == 20 - && map_passMap[map_curGoblinY][map_curGoblinX] == 3) { + && _vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 3) { if ((gobDesc->curLookDir == 0 || gobDesc->curLookDir == 4 || gobDesc->curLookDir == 2) - && map_passMap[map_curGoblinY - 1][map_curGoblinX] == 3) { - gob_forceNextState[0] = 8; - gob_forceNextState[1] = -1; + && _vm->_map->passMap[_vm->_map->curGoblinY - 1][_vm->_map->curGoblinX] == 3) { + forceNextState[0] = 8; + forceNextState[1] = -1; } else if ((gobDesc->curLookDir == 0 || gobDesc->curLookDir == 4 || gobDesc->curLookDir == 6) - && map_passMap[map_curGoblinY + 1][map_curGoblinX] == 3) { - gob_forceNextState[0] = 9; - gob_forceNextState[1] = -1; + && _vm->_map->passMap[_vm->_map->curGoblinY + 1][_vm->_map->curGoblinX] == 3) { + forceNextState[0] = 9; + forceNextState[1] = -1; } } } -void gob_movePathFind(Gob_Object *gobDesc, int16 nextAct) { - if (gob_pathExistence == 1) { - map_curGoblinX = gob_gobPositions[gob_currentGoblin].x; - map_curGoblinY = gob_gobPositions[gob_currentGoblin].y; +void Goblin::movePathFind(Gob_Object *gobDesc, int16 nextAct) { + if (pathExistence == 1) { + _vm->_map->curGoblinX = gobPositions[currentGoblin].x; + _vm->_map->curGoblinY = gobPositions[currentGoblin].y; - if (map_curGoblinX == gob_pressedMapX && - map_curGoblinY == gob_pressedMapY && gob_gobAction != 0) { - gob_readyToAct = 1; - gob_pathExistence = 0; + if (_vm->_map->curGoblinX == pressedMapX && + _vm->_map->curGoblinY == pressedMapY && gobAction != 0) { + readyToAct = 1; + pathExistence = 0; } - nextAct = map_getDirection(map_curGoblinX, map_curGoblinY, - map_destX, map_destY); + nextAct = _vm->_map->getDirection(_vm->_map->curGoblinX, _vm->_map->curGoblinY, + _vm->_map->destX, _vm->_map->destY); if (nextAct == 0) - gob_pathExistence = 0; - } else if (gob_pathExistence == 3) { - map_curGoblinX = gob_gobPositions[gob_currentGoblin].x; - map_curGoblinY = gob_gobPositions[gob_currentGoblin].y; - - if (map_curGoblinX == gob_gobDestX && map_curGoblinY == gob_gobDestY) { - gob_pathExistence = 1; - map_destX = gob_pressedMapX; - map_destY = gob_pressedMapY; + pathExistence = 0; + } else if (pathExistence == 3) { + _vm->_map->curGoblinX = gobPositions[currentGoblin].x; + _vm->_map->curGoblinY = gobPositions[currentGoblin].y; + + if (_vm->_map->curGoblinX == gobDestX && _vm->_map->curGoblinY == gobDestY) { + pathExistence = 1; + _vm->_map->destX = pressedMapX; + _vm->_map->destY = pressedMapY; } else { - if (map_checkDirectPath(map_curGoblinX, map_curGoblinY, - gob_gobDestX, gob_gobDestY) == 1) { - map_destX = gob_gobDestX; - map_destY = gob_gobDestY; - } else if (map_curGoblinX == map_destX && map_curGoblinY == map_destY) { + if (_vm->_map->checkDirectPath(_vm->_map->curGoblinX, _vm->_map->curGoblinY, + gobDestX, gobDestY) == 1) { + _vm->_map->destX = gobDestX; + _vm->_map->destY = gobDestY; + } else if (_vm->_map->curGoblinX == _vm->_map->destX && _vm->_map->curGoblinY == _vm->_map->destY) { - if (map_nearestWayPoint > map_nearestDest) { - map_optimizePoints(); + if (_vm->_map->nearestWayPoint > _vm->_map->nearestDest) { + _vm->_map->optimizePoints(); - map_destX = - map_wayPoints[map_nearestWayPoint]. + _vm->_map->destX = + _vm->_map->wayPoints[_vm->_map->nearestWayPoint]. x; - map_destY = - map_wayPoints[map_nearestWayPoint]. + _vm->_map->destY = + _vm->_map->wayPoints[_vm->_map->nearestWayPoint]. y; - if (map_nearestWayPoint > map_nearestDest) - map_nearestWayPoint--; - } else if (map_nearestWayPoint < map_nearestDest) { - map_optimizePoints(); + if (_vm->_map->nearestWayPoint > _vm->_map->nearestDest) + _vm->_map->nearestWayPoint--; + } else if (_vm->_map->nearestWayPoint < _vm->_map->nearestDest) { + _vm->_map->optimizePoints(); - map_destX = - map_wayPoints[map_nearestWayPoint]. + _vm->_map->destX = + _vm->_map->wayPoints[_vm->_map->nearestWayPoint]. x; - map_destY = - map_wayPoints[map_nearestWayPoint]. + _vm->_map->destY = + _vm->_map->wayPoints[_vm->_map->nearestWayPoint]. y; - if (map_nearestWayPoint < map_nearestDest) - map_nearestWayPoint++; + if (_vm->_map->nearestWayPoint < _vm->_map->nearestDest) + _vm->_map->nearestWayPoint++; } else { - if (map_checkDirectPath(map_curGoblinX, - map_curGoblinY, gob_gobDestX, - gob_gobDestY) == 3 && map_passMap[gob_pressedMapY][gob_pressedMapX] != 0) { - map_destX = map_wayPoints[map_nearestWayPoint].x; - map_destY = map_wayPoints[map_nearestWayPoint].y; + if (_vm->_map->checkDirectPath(_vm->_map->curGoblinX, + _vm->_map->curGoblinY, gobDestX, + gobDestY) == 3 && _vm->_map->passMap[pressedMapY][pressedMapX] != 0) { + _vm->_map->destX = _vm->_map->wayPoints[_vm->_map->nearestWayPoint].x; + _vm->_map->destY = _vm->_map->wayPoints[_vm->_map->nearestWayPoint].y; } else { - gob_pathExistence = 1; - map_destX = gob_pressedMapX; - map_destY = gob_pressedMapY; + pathExistence = 1; + _vm->_map->destX = pressedMapX; + _vm->_map->destY = pressedMapY; } } } nextAct = - map_getDirection(map_curGoblinX, map_curGoblinY, - map_destX, map_destY); + _vm->_map->getDirection(_vm->_map->curGoblinX, _vm->_map->curGoblinY, + _vm->_map->destX, _vm->_map->destY); } } - if (gob_readyToAct != 0 && (gob_gobAction == 3 || gob_gobAction == 4)) + if (readyToAct != 0 && (gobAction == 3 || gobAction == 4)) nextAct = 0x4dc8; switch (nextAct) { - case kDirW: - gobDesc->nextState = gob_rotateState(gobDesc->curLookDir, 0); + case Map::kDirW: + gobDesc->nextState = rotateState(gobDesc->curLookDir, 0); break; - case kDirE: - gobDesc->nextState = gob_rotateState(gobDesc->curLookDir, 4); + case Map::kDirE: + gobDesc->nextState = rotateState(gobDesc->curLookDir, 4); break; case 16: @@ -1310,52 +1322,52 @@ void gob_movePathFind(Gob_Object *gobDesc, int16 nextAct) { gobDesc->nextState = 23; break; - case kDirN: - if (map_passMap[map_curGoblinY - 1][map_curGoblinX] == 6 && - gob_currentGoblin != 1) { - gob_pathExistence = 0; + case Map::kDirN: + if (_vm->_map->passMap[_vm->_map->curGoblinY - 1][_vm->_map->curGoblinX] == 6 && + currentGoblin != 1) { + pathExistence = 0; break; } - if (map_passMap[map_curGoblinY][map_curGoblinX] == 3) { + if (_vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 3) { gobDesc->nextState = 8; break; } - if (map_passMap[map_curGoblinY][map_curGoblinX] == 6 && - gob_currentGoblin == 1) { + if (_vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 6 && + currentGoblin == 1) { gobDesc->nextState = 28; break; } - gobDesc->nextState = gob_rotateState(gobDesc->curLookDir, 2); + gobDesc->nextState = rotateState(gobDesc->curLookDir, 2); break; - case kDirS: - if (map_passMap[map_curGoblinY + 1][map_curGoblinX] == 6 && - gob_currentGoblin != 1) { - gob_pathExistence = 0; + case Map::kDirS: + if (_vm->_map->passMap[_vm->_map->curGoblinY + 1][_vm->_map->curGoblinX] == 6 && + currentGoblin != 1) { + pathExistence = 0; break; } - if (map_passMap[map_curGoblinY][map_curGoblinX] == 3) { + if (_vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 3) { gobDesc->nextState = 9; break; } - if (map_passMap[map_curGoblinY][map_curGoblinX] == 6 && - gob_currentGoblin == 1) { + if (_vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 6 && + currentGoblin == 1) { gobDesc->nextState = 29; break; } - gobDesc->nextState = gob_rotateState(gobDesc->curLookDir, 6); + gobDesc->nextState = rotateState(gobDesc->curLookDir, 6); break; - case kDirSE: - if (map_passMap[map_curGoblinY + 1][map_curGoblinX + 1] == 6 && - gob_currentGoblin != 1) { - gob_pathExistence = 0; + case Map::kDirSE: + if (_vm->_map->passMap[_vm->_map->curGoblinY + 1][_vm->_map->curGoblinX + 1] == 6 && + currentGoblin != 1) { + pathExistence = 0; break; } @@ -1363,13 +1375,13 @@ void gob_movePathFind(Gob_Object *gobDesc, int16 nextAct) { if (gobDesc->curLookDir == 4) break; - gobDesc->nextState = gob_rotateState(gobDesc->curLookDir, 4); + gobDesc->nextState = rotateState(gobDesc->curLookDir, 4); break; - case kDirSW: - if (map_passMap[map_curGoblinY + 1][map_curGoblinX - 1] == 6 && - gob_currentGoblin != 1) { - gob_pathExistence = 0; + case Map::kDirSW: + if (_vm->_map->passMap[_vm->_map->curGoblinY + 1][_vm->_map->curGoblinX - 1] == 6 && + currentGoblin != 1) { + pathExistence = 0; break; } @@ -1377,13 +1389,13 @@ void gob_movePathFind(Gob_Object *gobDesc, int16 nextAct) { if (gobDesc->curLookDir == 0) break; - gobDesc->nextState = gob_rotateState(gobDesc->curLookDir, 0); + gobDesc->nextState = rotateState(gobDesc->curLookDir, 0); break; - case kDirNW: - if (map_passMap[map_curGoblinY - 1][map_curGoblinX - 1] == 6 && - gob_currentGoblin != 1) { - gob_pathExistence = 0; + case Map::kDirNW: + if (_vm->_map->passMap[_vm->_map->curGoblinY - 1][_vm->_map->curGoblinX - 1] == 6 && + currentGoblin != 1) { + pathExistence = 0; break; } @@ -1391,13 +1403,13 @@ void gob_movePathFind(Gob_Object *gobDesc, int16 nextAct) { if (gobDesc->curLookDir == 0) break; - gobDesc->nextState = gob_rotateState(gobDesc->curLookDir, 0); + gobDesc->nextState = rotateState(gobDesc->curLookDir, 0); break; - case kDirNE: - if (map_passMap[map_curGoblinY - 1][map_curGoblinX + 1] == 6 && - gob_currentGoblin != 1) { - gob_pathExistence = 0; + case Map::kDirNE: + if (_vm->_map->passMap[_vm->_map->curGoblinY - 1][_vm->_map->curGoblinX + 1] == 6 && + currentGoblin != 1) { + pathExistence = 0; break; } @@ -1405,58 +1417,58 @@ void gob_movePathFind(Gob_Object *gobDesc, int16 nextAct) { if (gobDesc->curLookDir == 4) break; - gobDesc->nextState = gob_rotateState(gobDesc->curLookDir, 4); + gobDesc->nextState = rotateState(gobDesc->curLookDir, 4); break; case 0x4dc8: - if (gob_currentGoblin == 0 && gob_gobAction == 3 - && gob_itemIndInPocket == -1) { - gob_destItemId = -1; - gob_readyToAct = 0; + if (currentGoblin == 0 && gobAction == 3 + && itemIndInPocket == -1) { + destItemId = -1; + readyToAct = 0; break; } - if (gob_currentGoblin == 0 && gob_gobAction == 4 && - gob_itemIndInPocket == -1 && gob_destActionItem == 0) { + if (currentGoblin == 0 && gobAction == 4 && + itemIndInPocket == -1 && destActionItem == 0) { gobDesc->multState = 104; - gob_destItemId = -1; - gob_readyToAct = 0; + destItemId = -1; + readyToAct = 0; break; } - if (gob_currentGoblin == 0 && gob_gobAction == 4 && - gob_itemIndInPocket == -1 && gob_destActionItem != 0 && - gob_itemToObject[gob_destActionItem] != -1 && - gob_objects[gob_itemToObject[gob_destActionItem]]-> + if (currentGoblin == 0 && gobAction == 4 && + itemIndInPocket == -1 && destActionItem != 0 && + itemToObject[destActionItem] != -1 && + objects[itemToObject[destActionItem]]-> pickable == 0) { gobDesc->multState = 104; - gob_destItemId = -1; - gob_readyToAct = 0; + destItemId = -1; + readyToAct = 0; break; } - switch (map_itemPoses[gob_destActionItem].orient) { + switch (_vm->_map->itemPoses[destActionItem].orient) { case 0: case -4: gobDesc->nextState = 10; gobDesc->curLookDir = 0; - gob_destItemId = -1; + destItemId = -1; break; case -1: case 4: gobDesc->nextState = 11; gobDesc->curLookDir = 4; - gob_destItemId = -1; + destItemId = -1; break; } break; default: - if (map_passMap[map_curGoblinY][map_curGoblinX] == 3 || - (map_passMap[map_curGoblinY][map_curGoblinX] == 6 - && gob_currentGoblin == 1)) { + if (_vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 3 || + (_vm->_map->passMap[_vm->_map->curGoblinY][_vm->_map->curGoblinX] == 6 + && currentGoblin == 1)) { gobDesc->nextState = 20; break; } @@ -1477,19 +1489,19 @@ void gob_movePathFind(Gob_Object *gobDesc, int16 nextAct) { return; } -void gob_moveAdvance(Gob_Object *gobDesc, int16 nextAct, int16 framesCount) { +void Goblin::moveAdvance(Gob_Object *gobDesc, int16 nextAct, int16 framesCount) { int16 i; int16 newX; int16 newY; int16 flag; - gob_movePathFind(gobDesc, nextAct); + movePathFind(gobDesc, nextAct); gobDesc->curFrame++; if (gobDesc->curFrame == 1) gobDesc->actionStartState = gobDesc->state; - if (gob_goesAtTarget == 0 + if (goesAtTarget == 0 && gobDesc->stateMach == gobDesc->realStateMach) { switch (gobDesc->state) { case 0: @@ -1511,7 +1523,7 @@ void gob_moveAdvance(Gob_Object *gobDesc, int16 nextAct, int16 framesCount) { break; case 28: - if (gob_currentGoblin != 1) + if (currentGoblin != 1) break; gobDesc->curLookDir = 2; break; @@ -1525,7 +1537,7 @@ void gob_moveAdvance(Gob_Object *gobDesc, int16 nextAct, int16 framesCount) { break; case 29: - if (gob_currentGoblin != 1) + if (currentGoblin != 1) break; gobDesc->curLookDir = 6; @@ -1544,27 +1556,27 @@ void gob_moveAdvance(Gob_Object *gobDesc, int16 nextAct, int16 framesCount) { if (gobDesc->state >= 0 && gobDesc->state < 10 && gobDesc->stateMach == gobDesc->realStateMach && (gobDesc->curFrame == 3 || gobDesc->curFrame == 6)) { - snd_speakerOn(10 * util_getRandom(3) + 50, 5); + _vm->_snd->speakerOn(10 * _vm->_util->getRandom(3) + 50, 5); } - if (gob_currentGoblin == 0 + if (currentGoblin == 0 && gobDesc->stateMach == gobDesc->realStateMach && (gobDesc->state == 10 || gobDesc->state == 11) && gobDesc->curFrame == 9) { - snd_stopSound(0); - if (gob_itemIndInPocket != -1) { - snd_playSample(gob_soundData[14], 1, 9000); + _vm->_snd->stopSound(0); + if (itemIndInPocket != -1) { + _vm->_snd->playSample(soundData[14], 1, 9000); } - if (gob_itemIndInPocket == -1) { - snd_playSample(gob_soundData[14], 1, 5000); + if (itemIndInPocket == -1) { + _vm->_snd->playSample(soundData[14], 1, 5000); } } - if (gob_boreCounter++ == 120) { - gob_boreCounter = 0; + if (boreCounter++ == 120) { + boreCounter = 0; for (i = 0; i < 3; i++) - gob_showBoredom(i); + showBoredom(i); } if (gobDesc->multState != -1 && gobDesc->curFrame == framesCount && @@ -1573,14 +1585,14 @@ void gob_moveAdvance(Gob_Object *gobDesc, int16 nextAct, int16 framesCount) { gobDesc->multState = -1; newX = - scen_animations[gobDesc->animation]. - layers[gob_gobStateLayer]->animDeltaX + gobDesc->xPos; + _vm->_scenery->animations[gobDesc->animation]. + layers[gobStateLayer]->animDeltaX + gobDesc->xPos; newY = - scen_animations[gobDesc->animation]. - layers[gob_gobStateLayer]->animDeltaY + gobDesc->yPos; + _vm->_scenery->animations[gobDesc->animation]. + layers[gobStateLayer]->animDeltaY + gobDesc->yPos; - gob_gobStateLayer = gob_nextLayer(gobDesc); + gobStateLayer = nextLayer(gobDesc); gobDesc->xPos = newX; gobDesc->yPos = newY; @@ -1588,180 +1600,180 @@ void gob_moveAdvance(Gob_Object *gobDesc, int16 nextAct, int16 framesCount) { if (gobDesc->curFrame == 3 && gobDesc->stateMach == gobDesc->realStateMach && (gobDesc->state < 10 || - (gob_currentGoblin == 1 && (gobDesc->state == 28 + (currentGoblin == 1 && (gobDesc->state == 28 || gobDesc->state == 29)) )) { flag = 0; - if (gob_forceNextState[0] != -1) { - gobDesc->nextState = gob_forceNextState[0]; + if (forceNextState[0] != -1) { + gobDesc->nextState = forceNextState[0]; for (i = 0; i < 9; i++) - gob_forceNextState[i] = - gob_forceNextState[i + 1]; + forceNextState[i] = + forceNextState[i + 1]; } - map_curGoblinX = gob_gobPositions[gob_currentGoblin].x; - map_curGoblinY = gob_gobPositions[gob_currentGoblin].y; + _vm->_map->curGoblinX = gobPositions[currentGoblin].x; + _vm->_map->curGoblinY = gobPositions[currentGoblin].y; if (gobDesc->nextState != gobDesc->state) { - gob_gobStateLayer = gob_nextLayer(gobDesc); + gobStateLayer = nextLayer(gobDesc); flag = 1; } switch (gobDesc->state) { case 0: - gob_gobPositions[gob_currentGoblin].x--; + gobPositions[currentGoblin].x--; break; case 2: case 8: - gob_gobPositions[gob_currentGoblin].y--; + gobPositions[currentGoblin].y--; break; case 4: - gob_gobPositions[gob_currentGoblin].x++; + gobPositions[currentGoblin].x++; break; case 6: case 9: - gob_gobPositions[gob_currentGoblin].y++; + gobPositions[currentGoblin].y++; break; case 1: - gob_gobPositions[gob_currentGoblin].x--; - gob_gobPositions[gob_currentGoblin].y--; + gobPositions[currentGoblin].x--; + gobPositions[currentGoblin].y--; break; case 3: - gob_gobPositions[gob_currentGoblin].x++; - gob_gobPositions[gob_currentGoblin].y--; + gobPositions[currentGoblin].x++; + gobPositions[currentGoblin].y--; break; case 5: - gob_gobPositions[gob_currentGoblin].x++; - gob_gobPositions[gob_currentGoblin].y++; + gobPositions[currentGoblin].x++; + gobPositions[currentGoblin].y++; break; case 7: - gob_gobPositions[gob_currentGoblin].x--; - gob_gobPositions[gob_currentGoblin].y++; + gobPositions[currentGoblin].x--; + gobPositions[currentGoblin].y++; break; case 38: - gob_gobPositions[gob_currentGoblin].y++; + gobPositions[currentGoblin].y++; break; } - if (gob_currentGoblin == 1) { + if (currentGoblin == 1) { if (gobDesc->state == 28) - gob_gobPositions[1].y--; + gobPositions[1].y--; if (gobDesc->state == 29) - gob_gobPositions[1].y++; + gobPositions[1].y++; } if (flag != 0) { - scen_updateAnim(gob_gobStateLayer, 0, + _vm->_scenery->updateAnim(gobStateLayer, 0, gobDesc->animation, 0, gobDesc->xPos, gobDesc->yPos, 0); gobDesc->yPos = - (map_curGoblinY + 1) * 6 - - (scen_toRedrawBottom - scen_animTop); + (_vm->_map->curGoblinY + 1) * 6 - + (_vm->_scenery->toRedrawBottom - _vm->_scenery->animTop); gobDesc->xPos = - map_curGoblinX * 12 - (scen_toRedrawLeft - - scen_animLeft); + _vm->_map->curGoblinX * 12 - (_vm->_scenery->toRedrawLeft - + _vm->_scenery->animLeft); } if ((gobDesc->state == 10 || gobDesc->state == 11) - && gob_currentGoblin != 0) - gob_goesAtTarget = 1; + && currentGoblin != 0) + goesAtTarget = 1; } if (gobDesc->curFrame != framesCount) return; - if (gob_forceNextState[0] != -1) { - gobDesc->nextState = gob_forceNextState[0]; + if (forceNextState[0] != -1) { + gobDesc->nextState = forceNextState[0]; for (i = 0; i < 10; i++) - gob_forceNextState[i] = - gob_forceNextState[i + 1]; + forceNextState[i] = + forceNextState[i + 1]; } - map_curGoblinX = gob_gobPositions[gob_currentGoblin].x; - map_curGoblinY = gob_gobPositions[gob_currentGoblin].y; + _vm->_map->curGoblinX = gobPositions[currentGoblin].x; + _vm->_map->curGoblinY = gobPositions[currentGoblin].y; - gob_gobStateLayer = gob_nextLayer(gobDesc); + gobStateLayer = nextLayer(gobDesc); if (gobDesc->stateMach == gobDesc->realStateMach) { switch (gobDesc->nextState) { case 0: - gob_gobPositions[gob_currentGoblin].x--; + gobPositions[currentGoblin].x--; break; case 2: case 8: - gob_gobPositions[gob_currentGoblin].y--; + gobPositions[currentGoblin].y--; break; case 4: - gob_gobPositions[gob_currentGoblin].x++; + gobPositions[currentGoblin].x++; break; case 6: case 9: - gob_gobPositions[gob_currentGoblin].y++; + gobPositions[currentGoblin].y++; break; case 1: - gob_gobPositions[gob_currentGoblin].x--; - gob_gobPositions[gob_currentGoblin].y--; + gobPositions[currentGoblin].x--; + gobPositions[currentGoblin].y--; break; case 3: - gob_gobPositions[gob_currentGoblin].x++; - gob_gobPositions[gob_currentGoblin].y--; + gobPositions[currentGoblin].x++; + gobPositions[currentGoblin].y--; break; case 5: - gob_gobPositions[gob_currentGoblin].x++; - gob_gobPositions[gob_currentGoblin].y++; + gobPositions[currentGoblin].x++; + gobPositions[currentGoblin].y++; break; case 7: - gob_gobPositions[gob_currentGoblin].x--; - gob_gobPositions[gob_currentGoblin].y++; + gobPositions[currentGoblin].x--; + gobPositions[currentGoblin].y++; break; case 38: - gob_gobPositions[gob_currentGoblin].y++; + gobPositions[currentGoblin].y++; break; } - if (gob_currentGoblin == 1) { + if (currentGoblin == 1) { if (gobDesc->nextState == 28) - gob_gobPositions[1].y--; + gobPositions[1].y--; if (gobDesc->nextState == 29) - gob_gobPositions[1].y++; + gobPositions[1].y++; } } - scen_updateAnim(gob_gobStateLayer, 0, gobDesc->animation, 0, + _vm->_scenery->updateAnim(gobStateLayer, 0, gobDesc->animation, 0, gobDesc->xPos, gobDesc->yPos, 0); gobDesc->yPos = - (map_curGoblinY + 1) * 6 - (scen_toRedrawBottom - - scen_animTop); + (_vm->_map->curGoblinY + 1) * 6 - (_vm->_scenery->toRedrawBottom - + _vm->_scenery->animTop); gobDesc->xPos = - map_curGoblinX * 12 - (scen_toRedrawLeft - scen_animLeft); + _vm->_map->curGoblinX * 12 - (_vm->_scenery->toRedrawLeft - _vm->_scenery->animLeft); if ((gobDesc->state == 10 || gobDesc->state == 11) - && gob_currentGoblin != 0) - gob_goesAtTarget = 1; + && currentGoblin != 0) + goesAtTarget = 1; } return; } -int16 gob_doMove(Gob_Object *gobDesc, int16 cont, int16 action) { +int16 Goblin::doMove(Gob_Object *gobDesc, int16 cont, int16 action) { int16 framesCount; int16 nextAct; int16 gobIndex; @@ -1772,423 +1784,423 @@ int16 gob_doMove(Gob_Object *gobDesc, int16 cont, int16 action) { layer = gobDesc->stateMach[gobDesc->state][0]->layer; framesCount = - scen_animations[gobDesc->animation].layers[layer]->framesCount; + _vm->_scenery->animations[gobDesc->animation].layers[layer]->framesCount; if (VAR(59) == 0 && gobDesc->state != 30 && gobDesc->state != 31) { gobDesc->order = (gobDesc->bottom) / 24 + 3; } - if (gob_positionedGob != gob_currentGoblin) { - map_curGoblinX = gob_gobPositions[gob_currentGoblin].x; - map_curGoblinY = gob_gobPositions[gob_currentGoblin].y; + if (positionedGob != currentGoblin) { + _vm->_map->curGoblinX = gobPositions[currentGoblin].x; + _vm->_map->curGoblinY = gobPositions[currentGoblin].y; } - gob_positionedGob = gob_currentGoblin; + positionedGob = currentGoblin; gobDesc->animation = gobDesc->stateMach[gobDesc->state][gobDesc->stateColumn]-> animation; - gob_gobStateLayer = + gobStateLayer = gobDesc->stateMach[gobDesc->state][gobDesc->stateColumn]->layer; - gob_moveInitStep(framesCount, action, cont, gobDesc, &gobIndex, + moveInitStep(framesCount, action, cont, gobDesc, &gobIndex, &nextAct); - gob_moveTreatRopeStairs(gobDesc); - gob_moveAdvance(gobDesc, nextAct, framesCount); + moveTreatRopeStairs(gobDesc); + moveAdvance(gobDesc, nextAct, framesCount); return gobIndex; } -void gob_freeObjects(void) { +void Goblin::freeObjects(void) { int16 i; int16 state; int16 col; for (i = 0; i < 16; i++) { - if (gob_soundData[i] == 0) + if (soundData[i] == 0) continue; - snd_freeSoundData(gob_soundData[i]); - gob_soundData[i] = 0; + _vm->_snd->freeSoundData(soundData[i]); + soundData[i] = 0; } for (i = 0; i < 4; i++) { - if (gob_goblins[i] == 0) + if (goblins[i] == 0) continue; - gob_goblins[i]->stateMach = gob_goblins[i]->realStateMach; + goblins[i]->stateMach = goblins[i]->realStateMach; for (state = 0; state < 40; state++) { for (col = 0; col < 6; col++) { - free(gob_goblins[i]->stateMach[state][col]); - gob_goblins[i]->stateMach[state][col] = 0; + free(goblins[i]->stateMach[state][col]); + goblins[i]->stateMach[state][col] = 0; } } if (i == 3) { for (state = 40; state < 70; state++) { - free(gob_goblins[3]->stateMach[state][0]); - gob_goblins[3]->stateMach[state][0] = 0; + free(goblins[3]->stateMach[state][0]); + goblins[3]->stateMach[state][0] = 0; } } - free(gob_goblins[i]->stateMach); - free(gob_goblins[i]); - gob_goblins[i] = 0; + free(goblins[i]->stateMach); + free(goblins[i]); + goblins[i] = 0; } for (i = 0; i < 20; i++) { - if (gob_objects[i] == 0) + if (objects[i] == 0) continue; - gob_objects[i]->stateMach = gob_objects[i]->realStateMach; + objects[i]->stateMach = objects[i]->realStateMach; for (state = 0; state < 40; state++) { for (col = 0; col < 6; col++) { - free(gob_objects[i]->stateMach[state][col]); - gob_objects[i]->stateMach[state][col] = 0; + free(objects[i]->stateMach[state][col]); + objects[i]->stateMach[state][col] = 0; } } - free(gob_objects[i]->stateMach); - free(gob_objects[i]); - gob_objects[i] = 0; + free(objects[i]->stateMach); + free(objects[i]); + objects[i] = 0; } } -void gob_zeroObjects(void) { +void Goblin::zeroObjects(void) { int16 i; for (i = 0; i < 4; i++) - gob_goblins[i] = 0; + goblins[i] = 0; for (i = 0; i < 20; i++) - gob_objects[i] = 0; + objects[i] = 0; for (i = 0; i < 16; i++) - gob_soundData[i] = 0; + soundData[i] = 0; } -void gob_freeAllObjects(void) { - util_deleteList(gob_objList); - gob_freeObjects(); +void Goblin::freeAllObjects(void) { + _vm->_util->deleteList(objList); + freeObjects(); } -void gob_loadObjects(char *source) { +void Goblin::loadObjects(char *source) { int16 i; - gob_zeroObjects(); + zeroObjects(); for (i = 0; i < 20; i++) - gob_itemToObject[i] = 100; + itemToObject[i] = 100; - gob_freeObjects(); - gob_initList(); - strcpy(map_sourceFile, source); + freeObjects(); + initList(); + strcpy(_vm->_map->sourceFile, source); - map_sourceFile[strlen(map_sourceFile) - 4] = 0; - map_loadMapObjects(source); + _vm->_map->sourceFile[strlen(_vm->_map->sourceFile) - 4] = 0; + _vm->_map->loadMapObjects(source); - for (i = 0; i < gob_gobsCount; i++) - gob_placeObject(gob_goblins[i], 0); + for (i = 0; i < gobsCount; i++) + placeObject(goblins[i], 0); - for (i = 0; i < gob_objCount; i++) { - gob_placeObject(gob_objects[i], 1); + for (i = 0; i < objCount; i++) { + placeObject(objects[i], 1); } - gob_initVarPointers(); - gob_actDestItemDesc = 0; + initVarPointers(); + actDestItemDesc = 0; } -void gob_saveGobDataToVars(int16 xPos, int16 yPos, int16 someVal) { +void Goblin::saveGobDataToVars(int16 xPos, int16 yPos, int16 someVal) { Gob_Object *obj; - *gob_some0ValPtr = someVal; - *gob_curGobXPosVarPtr = xPos; - *gob_curGobYPosVarPtr = yPos; - *gob_itemInPocketVarPtr = gob_itemIndInPocket; - - obj = gob_goblins[gob_currentGoblin]; - - *gob_curGobStateVarPtr = obj->state; - *gob_curGobFrameVarPtr = obj->curFrame; - *gob_curGobMultStateVarPtr = obj->multState; - *gob_curGobNextStateVarPtr = obj->nextState; - *gob_curGobScrXVarPtr = obj->xPos; - *gob_curGobScrYVarPtr = obj->yPos; - *gob_curGobLeftVarPtr = obj->left; - *gob_curGobTopVarPtr = obj->top; - *gob_curGobRightVarPtr = obj->right; - *gob_curGobBottomVarPtr = obj->bottom; - *gob_curGobDoAnimVarPtr = obj->doAnim; - *gob_curGobOrderVarPtr = obj->order; - *gob_curGobNoTickVarPtr = obj->noTick; - *gob_curGobTypeVarPtr = obj->type; - *gob_curGobMaxTickVarPtr = obj->maxTick; - *gob_curGobTickVarPtr = obj->tick; - *gob_curGobActStartStateVarPtr = obj->actionStartState; - *gob_curGobLookDirVarPtr = obj->curLookDir; - *gob_curGobPickableVarPtr = obj->pickable; - *gob_curGobRelaxVarPtr = obj->relaxTime; - *gob_curGobMaxFrameVarPtr = gob_getObjMaxFrame(obj); - - if (gob_actDestItemDesc == 0) + *some0ValPtr = someVal; + *curGobXPosVarPtr = xPos; + *curGobYPosVarPtr = yPos; + *itemInPocketVarPtr = itemIndInPocket; + + obj = goblins[currentGoblin]; + + *curGobStateVarPtr = obj->state; + *curGobFrameVarPtr = obj->curFrame; + *curGobMultStateVarPtr = obj->multState; + *curGobNextStateVarPtr = obj->nextState; + *curGobScrXVarPtr = obj->xPos; + *curGobScrYVarPtr = obj->yPos; + *curGobLeftVarPtr = obj->left; + *curGobTopVarPtr = obj->top; + *curGobRightVarPtr = obj->right; + *curGobBottomVarPtr = obj->bottom; + *curGobDoAnimVarPtr = obj->doAnim; + *curGobOrderVarPtr = obj->order; + *curGobNoTickVarPtr = obj->noTick; + *curGobTypeVarPtr = obj->type; + *curGobMaxTickVarPtr = obj->maxTick; + *curGobTickVarPtr = obj->tick; + *curGobActStartStateVarPtr = obj->actionStartState; + *curGobLookDirVarPtr = obj->curLookDir; + *curGobPickableVarPtr = obj->pickable; + *curGobRelaxVarPtr = obj->relaxTime; + *curGobMaxFrameVarPtr = getObjMaxFrame(obj); + + if (actDestItemDesc == 0) return; - obj = gob_actDestItemDesc; - *gob_destItemStateVarPtr = obj->state; - *gob_destItemFrameVarPtr = obj->curFrame; - *gob_destItemMultStateVarPtr = obj->multState; - *gob_destItemNextStateVarPtr = obj->nextState; - *gob_destItemScrXVarPtr = obj->xPos; - *gob_destItemScrYVarPtr = obj->yPos; - *gob_destItemLeftVarPtr = obj->left; - *gob_destItemTopVarPtr = obj->top; - *gob_destItemRightVarPtr = obj->right; - *gob_destItemBottomVarPtr = obj->bottom; - *gob_destItemDoAnimVarPtr = obj->doAnim; - *gob_destItemOrderVarPtr = obj->order; - *gob_destItemNoTickVarPtr = obj->noTick; - *gob_destItemTypeVarPtr = obj->type; - *gob_destItemMaxTickVarPtr = obj->maxTick; - *gob_destItemTickVarPtr = obj->tick; - *gob_destItemActStartStVarPtr = obj->actionStartState; - *gob_destItemLookDirVarPtr = obj->curLookDir; - *gob_destItemPickableVarPtr = obj->pickable; - *gob_destItemRelaxVarPtr = obj->relaxTime; - *gob_destItemMaxFrameVarPtr = gob_getObjMaxFrame(obj); - - gob_destItemState = obj->state; - gob_destItemType = obj->type; + obj = actDestItemDesc; + *destItemStateVarPtr = obj->state; + *destItemFrameVarPtr = obj->curFrame; + *destItemMultStateVarPtr = obj->multState; + *destItemNextStateVarPtr = obj->nextState; + *destItemScrXVarPtr = obj->xPos; + *destItemScrYVarPtr = obj->yPos; + *destItemLeftVarPtr = obj->left; + *destItemTopVarPtr = obj->top; + *destItemRightVarPtr = obj->right; + *destItemBottomVarPtr = obj->bottom; + *destItemDoAnimVarPtr = obj->doAnim; + *destItemOrderVarPtr = obj->order; + *destItemNoTickVarPtr = obj->noTick; + *destItemTypeVarPtr = obj->type; + *destItemMaxTickVarPtr = obj->maxTick; + *destItemTickVarPtr = obj->tick; + *destItemActStartStVarPtr = obj->actionStartState; + *destItemLookDirVarPtr = obj->curLookDir; + *destItemPickableVarPtr = obj->pickable; + *destItemRelaxVarPtr = obj->relaxTime; + *destItemMaxFrameVarPtr = getObjMaxFrame(obj); + + destItemState = obj->state; + destItemType = obj->type; } -void gob_initVarPointers(void) { - gob_gobRetVarPtr = (int32 *)VAR_ADDRESS(59); - gob_curGobStateVarPtr = (int32 *)VAR_ADDRESS(60); - gob_curGobFrameVarPtr = (int32 *)VAR_ADDRESS(61); - gob_curGobMultStateVarPtr = (int32 *)VAR_ADDRESS(62); - gob_curGobNextStateVarPtr = (int32 *)VAR_ADDRESS(63); - gob_curGobScrXVarPtr = (int32 *)VAR_ADDRESS(64); - gob_curGobScrYVarPtr = (int32 *)VAR_ADDRESS(65); - gob_curGobLeftVarPtr = (int32 *)VAR_ADDRESS(66); - gob_curGobTopVarPtr = (int32 *)VAR_ADDRESS(67); - gob_curGobRightVarPtr = (int32 *)VAR_ADDRESS(68); - gob_curGobBottomVarPtr = (int32 *)VAR_ADDRESS(69); - gob_curGobDoAnimVarPtr = (int32 *)VAR_ADDRESS(70); - gob_curGobOrderVarPtr = (int32 *)VAR_ADDRESS(71); - gob_curGobNoTickVarPtr = (int32 *)VAR_ADDRESS(72); - gob_curGobTypeVarPtr = (int32 *)VAR_ADDRESS(73); - gob_curGobMaxTickVarPtr = (int32 *)VAR_ADDRESS(74); - gob_curGobTickVarPtr = (int32 *)VAR_ADDRESS(75); - gob_curGobActStartStateVarPtr = (int32 *)VAR_ADDRESS(76); - gob_curGobLookDirVarPtr = (int32 *)VAR_ADDRESS(77); - gob_curGobPickableVarPtr = (int32 *)VAR_ADDRESS(80); - gob_curGobRelaxVarPtr = (int32 *)VAR_ADDRESS(81); - gob_destItemStateVarPtr = (int32 *)VAR_ADDRESS(82); - gob_destItemFrameVarPtr = (int32 *)VAR_ADDRESS(83); - gob_destItemMultStateVarPtr = (int32 *)VAR_ADDRESS(84); - gob_destItemNextStateVarPtr = (int32 *)VAR_ADDRESS(85); - gob_destItemScrXVarPtr = (int32 *)VAR_ADDRESS(86); - gob_destItemScrYVarPtr = (int32 *)VAR_ADDRESS(87); - gob_destItemLeftVarPtr = (int32 *)VAR_ADDRESS(88); - gob_destItemTopVarPtr = (int32 *)VAR_ADDRESS(89); - gob_destItemRightVarPtr = (int32 *)VAR_ADDRESS(90); - gob_destItemBottomVarPtr = (int32 *)VAR_ADDRESS(91); - gob_destItemDoAnimVarPtr = (int32 *)VAR_ADDRESS(92); - gob_destItemOrderVarPtr = (int32 *)VAR_ADDRESS(93); - gob_destItemNoTickVarPtr = (int32 *)VAR_ADDRESS(94); - gob_destItemTypeVarPtr = (int32 *)VAR_ADDRESS(95); - gob_destItemMaxTickVarPtr = (int32 *)VAR_ADDRESS(96); - gob_destItemTickVarPtr = (int32 *)VAR_ADDRESS(97); - gob_destItemActStartStVarPtr = (int32 *)VAR_ADDRESS(98); - gob_destItemLookDirVarPtr = (int32 *)VAR_ADDRESS(99); - gob_destItemPickableVarPtr = (int32 *)VAR_ADDRESS(102); - gob_destItemRelaxVarPtr = (int32 *)VAR_ADDRESS(103); - gob_destItemMaxFrameVarPtr = (int32 *)VAR_ADDRESS(105); - gob_curGobVarPtr = (int32 *)VAR_ADDRESS(106); - gob_some0ValPtr = (int32 *)VAR_ADDRESS(107); - gob_curGobXPosVarPtr = (int32 *)VAR_ADDRESS(108); - gob_curGobYPosVarPtr = (int32 *)VAR_ADDRESS(109); - gob_curGobMaxFrameVarPtr = (int32 *)VAR_ADDRESS(110); - - gob_itemInPocketVarPtr = (int32 *)VAR_ADDRESS(114); - - *gob_itemInPocketVarPtr = -2; +void Goblin::initVarPointers(void) { + gobRetVarPtr = (int32 *)VAR_ADDRESS(59); + curGobStateVarPtr = (int32 *)VAR_ADDRESS(60); + curGobFrameVarPtr = (int32 *)VAR_ADDRESS(61); + curGobMultStateVarPtr = (int32 *)VAR_ADDRESS(62); + curGobNextStateVarPtr = (int32 *)VAR_ADDRESS(63); + curGobScrXVarPtr = (int32 *)VAR_ADDRESS(64); + curGobScrYVarPtr = (int32 *)VAR_ADDRESS(65); + curGobLeftVarPtr = (int32 *)VAR_ADDRESS(66); + curGobTopVarPtr = (int32 *)VAR_ADDRESS(67); + curGobRightVarPtr = (int32 *)VAR_ADDRESS(68); + curGobBottomVarPtr = (int32 *)VAR_ADDRESS(69); + curGobDoAnimVarPtr = (int32 *)VAR_ADDRESS(70); + curGobOrderVarPtr = (int32 *)VAR_ADDRESS(71); + curGobNoTickVarPtr = (int32 *)VAR_ADDRESS(72); + curGobTypeVarPtr = (int32 *)VAR_ADDRESS(73); + curGobMaxTickVarPtr = (int32 *)VAR_ADDRESS(74); + curGobTickVarPtr = (int32 *)VAR_ADDRESS(75); + curGobActStartStateVarPtr = (int32 *)VAR_ADDRESS(76); + curGobLookDirVarPtr = (int32 *)VAR_ADDRESS(77); + curGobPickableVarPtr = (int32 *)VAR_ADDRESS(80); + curGobRelaxVarPtr = (int32 *)VAR_ADDRESS(81); + destItemStateVarPtr = (int32 *)VAR_ADDRESS(82); + destItemFrameVarPtr = (int32 *)VAR_ADDRESS(83); + destItemMultStateVarPtr = (int32 *)VAR_ADDRESS(84); + destItemNextStateVarPtr = (int32 *)VAR_ADDRESS(85); + destItemScrXVarPtr = (int32 *)VAR_ADDRESS(86); + destItemScrYVarPtr = (int32 *)VAR_ADDRESS(87); + destItemLeftVarPtr = (int32 *)VAR_ADDRESS(88); + destItemTopVarPtr = (int32 *)VAR_ADDRESS(89); + destItemRightVarPtr = (int32 *)VAR_ADDRESS(90); + destItemBottomVarPtr = (int32 *)VAR_ADDRESS(91); + destItemDoAnimVarPtr = (int32 *)VAR_ADDRESS(92); + destItemOrderVarPtr = (int32 *)VAR_ADDRESS(93); + destItemNoTickVarPtr = (int32 *)VAR_ADDRESS(94); + destItemTypeVarPtr = (int32 *)VAR_ADDRESS(95); + destItemMaxTickVarPtr = (int32 *)VAR_ADDRESS(96); + destItemTickVarPtr = (int32 *)VAR_ADDRESS(97); + destItemActStartStVarPtr = (int32 *)VAR_ADDRESS(98); + destItemLookDirVarPtr = (int32 *)VAR_ADDRESS(99); + destItemPickableVarPtr = (int32 *)VAR_ADDRESS(102); + destItemRelaxVarPtr = (int32 *)VAR_ADDRESS(103); + destItemMaxFrameVarPtr = (int32 *)VAR_ADDRESS(105); + curGobVarPtr = (int32 *)VAR_ADDRESS(106); + some0ValPtr = (int32 *)VAR_ADDRESS(107); + curGobXPosVarPtr = (int32 *)VAR_ADDRESS(108); + curGobYPosVarPtr = (int32 *)VAR_ADDRESS(109); + curGobMaxFrameVarPtr = (int32 *)VAR_ADDRESS(110); + + itemInPocketVarPtr = (int32 *)VAR_ADDRESS(114); + + *itemInPocketVarPtr = -2; } -void gob_loadGobDataFromVars(void) { +void Goblin::loadGobDataFromVars(void) { Gob_Object *obj; - gob_itemIndInPocket = *gob_itemInPocketVarPtr; - - obj = gob_goblins[gob_currentGoblin]; - - obj->state = *gob_curGobStateVarPtr; - obj->curFrame = *gob_curGobFrameVarPtr; - obj->multState = *gob_curGobMultStateVarPtr; - obj->nextState = *gob_curGobNextStateVarPtr; - obj->xPos = *gob_curGobScrXVarPtr; - obj->yPos = *gob_curGobScrYVarPtr; - obj->left = *gob_curGobLeftVarPtr; - obj->top = *gob_curGobTopVarPtr; - obj->right = *gob_curGobRightVarPtr; - obj->bottom = *gob_curGobBottomVarPtr; - obj->doAnim = *gob_curGobDoAnimVarPtr; - obj->order = *gob_curGobOrderVarPtr; - obj->noTick = *gob_curGobNoTickVarPtr; - obj->type = *gob_curGobTypeVarPtr; - obj->maxTick = *gob_curGobMaxTickVarPtr; - obj->tick = *gob_curGobTickVarPtr; - obj->actionStartState = *gob_curGobActStartStateVarPtr; - obj->curLookDir = *gob_curGobLookDirVarPtr; - obj->pickable = *gob_curGobPickableVarPtr; - obj->relaxTime = *gob_curGobRelaxVarPtr; - - if (gob_actDestItemDesc == 0) + itemIndInPocket = *itemInPocketVarPtr; + + obj = goblins[currentGoblin]; + + obj->state = *curGobStateVarPtr; + obj->curFrame = *curGobFrameVarPtr; + obj->multState = *curGobMultStateVarPtr; + obj->nextState = *curGobNextStateVarPtr; + obj->xPos = *curGobScrXVarPtr; + obj->yPos = *curGobScrYVarPtr; + obj->left = *curGobLeftVarPtr; + obj->top = *curGobTopVarPtr; + obj->right = *curGobRightVarPtr; + obj->bottom = *curGobBottomVarPtr; + obj->doAnim = *curGobDoAnimVarPtr; + obj->order = *curGobOrderVarPtr; + obj->noTick = *curGobNoTickVarPtr; + obj->type = *curGobTypeVarPtr; + obj->maxTick = *curGobMaxTickVarPtr; + obj->tick = *curGobTickVarPtr; + obj->actionStartState = *curGobActStartStateVarPtr; + obj->curLookDir = *curGobLookDirVarPtr; + obj->pickable = *curGobPickableVarPtr; + obj->relaxTime = *curGobRelaxVarPtr; + + if (actDestItemDesc == 0) return; - obj = gob_actDestItemDesc; - - obj->state = *gob_destItemStateVarPtr; - obj->curFrame = *gob_destItemFrameVarPtr; - obj->multState = *gob_destItemMultStateVarPtr; - obj->nextState = *gob_destItemNextStateVarPtr; - obj->xPos = *gob_destItemScrXVarPtr; - obj->yPos = *gob_destItemScrYVarPtr; - obj->left = *gob_destItemLeftVarPtr; - obj->top = *gob_destItemTopVarPtr; - obj->right = *gob_destItemRightVarPtr; - obj->bottom = *gob_destItemBottomVarPtr; - obj->doAnim = *gob_destItemDoAnimVarPtr; - obj->order = *gob_destItemOrderVarPtr; - obj->noTick = *gob_destItemNoTickVarPtr; - obj->type = *gob_destItemTypeVarPtr; - obj->maxTick = *gob_destItemMaxTickVarPtr; - obj->tick = *gob_destItemTickVarPtr; - obj->actionStartState = *gob_destItemActStartStVarPtr; - obj->curLookDir = *gob_destItemLookDirVarPtr; - obj->pickable = *gob_destItemPickableVarPtr; - obj->relaxTime = *gob_destItemRelaxVarPtr; - - if (obj->type != gob_destItemType) + obj = actDestItemDesc; + + obj->state = *destItemStateVarPtr; + obj->curFrame = *destItemFrameVarPtr; + obj->multState = *destItemMultStateVarPtr; + obj->nextState = *destItemNextStateVarPtr; + obj->xPos = *destItemScrXVarPtr; + obj->yPos = *destItemScrYVarPtr; + obj->left = *destItemLeftVarPtr; + obj->top = *destItemTopVarPtr; + obj->right = *destItemRightVarPtr; + obj->bottom = *destItemBottomVarPtr; + obj->doAnim = *destItemDoAnimVarPtr; + obj->order = *destItemOrderVarPtr; + obj->noTick = *destItemNoTickVarPtr; + obj->type = *destItemTypeVarPtr; + obj->maxTick = *destItemMaxTickVarPtr; + obj->tick = *destItemTickVarPtr; + obj->actionStartState = *destItemActStartStVarPtr; + obj->curLookDir = *destItemLookDirVarPtr; + obj->pickable = *destItemPickableVarPtr; + obj->relaxTime = *destItemRelaxVarPtr; + + if (obj->type != destItemType) obj->toRedraw = 1; - if (obj->state != gob_destItemState && obj->type == 0) + if (obj->state != destItemState && obj->type == 0) obj->toRedraw = 1; } -void gob_pickItem(int16 indexToPocket, int16 idToPocket) { +void Goblin::pickItem(int16 indexToPocket, int16 idToPocket) { int16 x; int16 y; - if (gob_objects[indexToPocket]->pickable != 1) + if (objects[indexToPocket]->pickable != 1) return; - gob_objects[indexToPocket]->type = 3; + objects[indexToPocket]->type = 3; - gob_itemIndInPocket = indexToPocket; - gob_itemIdInPocket = idToPocket; + itemIndInPocket = indexToPocket; + itemIdInPocket = idToPocket; - for (y = 0; y < kMapHeight; y++) { - for (x = 0; x < kMapWidth; x++) { - if (gob_itemByteFlag == 1) { - if (((map_itemsMap[y][x] & 0xff00) >> 8) == + for (y = 0; y < Map::kMapHeight; y++) { + for (x = 0; x < Map::kMapWidth; x++) { + if (itemByteFlag == 1) { + if (((_vm->_map->itemsMap[y][x] & 0xff00) >> 8) == idToPocket) - map_itemsMap[y][x] &= 0xff; + _vm->_map->itemsMap[y][x] &= 0xff; } else { - if ((map_itemsMap[y][x] & 0xff) == idToPocket) - map_itemsMap[y][x] &= 0xff00; + if ((_vm->_map->itemsMap[y][x] & 0xff) == idToPocket) + _vm->_map->itemsMap[y][x] &= 0xff00; } } } if (idToPocket >= 0 && idToPocket < 20) { - map_itemPoses[gob_itemIdInPocket].x = 0; - map_itemPoses[gob_itemIdInPocket].y = 0; - map_itemPoses[gob_itemIdInPocket].orient = 0; + _vm->_map->itemPoses[itemIdInPocket].x = 0; + _vm->_map->itemPoses[itemIdInPocket].y = 0; + _vm->_map->itemPoses[itemIdInPocket].orient = 0; } } -void gob_placeItem(int16 indexInPocket, int16 idInPocket) { +void Goblin::placeItem(int16 indexInPocket, int16 idInPocket) { Gob_Object *itemDesc; int16 lookDir; int16 xPos; int16 yPos; int16 layer; - itemDesc = gob_objects[indexInPocket]; - lookDir = gob_goblins[0]->curLookDir & 4; + itemDesc = objects[indexInPocket]; + lookDir = goblins[0]->curLookDir & 4; - xPos = gob_gobPositions[0].x; - yPos = gob_gobPositions[0].y; + xPos = gobPositions[0].x; + yPos = gobPositions[0].y; - gob_itemIndInPocket = -1; - gob_itemIdInPocket = 0; + itemIndInPocket = -1; + itemIdInPocket = 0; itemDesc->pickable = 1; itemDesc->type = 0; itemDesc->toRedraw = 1; itemDesc->curFrame = 0; - itemDesc->order = gob_goblins[0]->order; + itemDesc->order = goblins[0]->order; itemDesc->animation = itemDesc->stateMach[itemDesc->state][0]->animation; layer = itemDesc->stateMach[itemDesc->state][itemDesc->stateColumn]->layer; - scen_updateAnim(layer, 0, itemDesc->animation, 0, + _vm->_scenery->updateAnim(layer, 0, itemDesc->animation, 0, itemDesc->xPos, itemDesc->yPos, 0); itemDesc->yPos += - (gob_gobPositions[0].y * 6) + 5 - scen_toRedrawBottom; + (gobPositions[0].y * 6) + 5 - _vm->_scenery->toRedrawBottom; if (lookDir == 4) { - itemDesc->xPos += (gob_gobPositions[0].x * 12 + 14) - - (scen_toRedrawLeft + scen_toRedrawRight) / 2; + itemDesc->xPos += (gobPositions[0].x * 12 + 14) + - (_vm->_scenery->toRedrawLeft + _vm->_scenery->toRedrawRight) / 2; } else { - itemDesc->xPos += (gob_gobPositions[0].x * 12) - - (scen_toRedrawLeft + scen_toRedrawRight) / 2; + itemDesc->xPos += (gobPositions[0].x * 12) + - (_vm->_scenery->toRedrawLeft + _vm->_scenery->toRedrawRight) / 2; } - map_placeItem(xPos, yPos, idInPocket); + _vm->_map->placeItem(xPos, yPos, idInPocket); if (yPos > 0) { - map_placeItem(xPos, yPos - 1, idInPocket); + _vm->_map->placeItem(xPos, yPos - 1, idInPocket); } if (lookDir == 4) { - if (xPos < kMapWidth - 1) { - map_placeItem(xPos + 1, yPos, idInPocket); + if (xPos < Map::kMapWidth - 1) { + _vm->_map->placeItem(xPos + 1, yPos, idInPocket); if (yPos > 0) { - map_placeItem(xPos + 1, yPos - 1, idInPocket); + _vm->_map->placeItem(xPos + 1, yPos - 1, idInPocket); } } } else { if (xPos > 0) { - map_placeItem(xPos - 1, yPos, idInPocket); + _vm->_map->placeItem(xPos - 1, yPos, idInPocket); if (yPos > 0) { - map_placeItem(xPos - 1, yPos - 1, idInPocket); + _vm->_map->placeItem(xPos - 1, yPos - 1, idInPocket); } } } if (idInPocket >= 0 && idInPocket < 20) { - map_itemPoses[idInPocket].x = gob_gobPositions[0].x; - map_itemPoses[idInPocket].y = gob_gobPositions[0].y; - map_itemPoses[idInPocket].orient = lookDir; - if (map_itemPoses[idInPocket].orient == 0) { -// map_itemPoses[idInPocket].x++; - if (map_passMap[(int)map_itemPoses[idInPocket].y][map_itemPoses[idInPocket].x + 1] == 1) - map_itemPoses[idInPocket].x++; + _vm->_map->itemPoses[idInPocket].x = gobPositions[0].x; + _vm->_map->itemPoses[idInPocket].y = gobPositions[0].y; + _vm->_map->itemPoses[idInPocket].orient = lookDir; + if (_vm->_map->itemPoses[idInPocket].orient == 0) { +// _vm->_map->itemPoses[idInPocket].x++; + if (_vm->_map->passMap[(int)_vm->_map->itemPoses[idInPocket].y][_vm->_map->itemPoses[idInPocket].x + 1] == 1) + _vm->_map->itemPoses[idInPocket].x++; } else { - if (map_passMap[(int)map_itemPoses[idInPocket].y][map_itemPoses[idInPocket].x - 1] == 1) - map_itemPoses[idInPocket].x--; + if (_vm->_map->passMap[(int)_vm->_map->itemPoses[idInPocket].y][_vm->_map->itemPoses[idInPocket].x - 1] == 1) + _vm->_map->itemPoses[idInPocket].x--; } } } -void gob_swapItems(int16 indexToPick, int16 idToPick) { +void Goblin::swapItems(int16 indexToPick, int16 idToPick) { int16 layer; Gob_Object *pickObj; Gob_Object *placeObj; @@ -2196,51 +2208,51 @@ void gob_swapItems(int16 indexToPick, int16 idToPick) { int16 x; int16 y; - pickObj = gob_objects[indexToPick]; - placeObj = gob_objects[gob_itemIndInPocket]; + pickObj = objects[indexToPick]; + placeObj = objects[itemIndInPocket]; - idToPlace = gob_itemIdInPocket; + idToPlace = itemIdInPocket; pickObj->type = 3; - gob_itemIndInPocket = indexToPick; - gob_itemIdInPocket = idToPick; - - if (gob_itemByteFlag == 0) { - for (y = 0; y < kMapHeight; y++) { - for (x = 0; x < kMapWidth; x++) { - if ((map_itemsMap[y][x] & 0xff) == idToPick) - map_itemsMap[y][x] = - (map_itemsMap[y][x] & 0xff00) + + itemIndInPocket = indexToPick; + itemIdInPocket = idToPick; + + if (itemByteFlag == 0) { + for (y = 0; y < Map::kMapHeight; y++) { + for (x = 0; x < Map::kMapWidth; x++) { + if ((_vm->_map->itemsMap[y][x] & 0xff) == idToPick) + _vm->_map->itemsMap[y][x] = + (_vm->_map->itemsMap[y][x] & 0xff00) + idToPlace; } } } else { - for (y = 0; y < kMapHeight; y++) { - for (x = 0; x < kMapWidth; x++) { - if (((map_itemsMap[y][x] & 0xff00) >> 8) == + for (y = 0; y < Map::kMapHeight; y++) { + for (x = 0; x < Map::kMapWidth; x++) { + if (((_vm->_map->itemsMap[y][x] & 0xff00) >> 8) == idToPick) - map_itemsMap[y][x] = - (map_itemsMap[y][x] & 0xff) + + _vm->_map->itemsMap[y][x] = + (_vm->_map->itemsMap[y][x] & 0xff) + (idToPlace << 8); } } } if (idToPick >= 0 && idToPick < 20) { - map_itemPoses[idToPlace].x = - map_itemPoses[gob_itemIdInPocket].x; - map_itemPoses[idToPlace].y = - map_itemPoses[gob_itemIdInPocket].y; - map_itemPoses[idToPlace].orient = - map_itemPoses[gob_itemIdInPocket].orient; - - map_itemPoses[gob_itemIdInPocket].x = 0; - map_itemPoses[gob_itemIdInPocket].y = 0; - map_itemPoses[gob_itemIdInPocket].orient = 0; + _vm->_map->itemPoses[idToPlace].x = + _vm->_map->itemPoses[itemIdInPocket].x; + _vm->_map->itemPoses[idToPlace].y = + _vm->_map->itemPoses[itemIdInPocket].y; + _vm->_map->itemPoses[idToPlace].orient = + _vm->_map->itemPoses[itemIdInPocket].orient; + + _vm->_map->itemPoses[itemIdInPocket].x = 0; + _vm->_map->itemPoses[itemIdInPocket].y = 0; + _vm->_map->itemPoses[itemIdInPocket].orient = 0; } - gob_itemIndInPocket = -1; - gob_itemIdInPocket = 0; + itemIndInPocket = -1; + itemIdInPocket = 0; placeObj->type = 0; placeObj->nextState = -1; @@ -2248,33 +2260,33 @@ void gob_swapItems(int16 indexToPick, int16 idToPick) { placeObj->unk14 = 0; placeObj->toRedraw = 1; placeObj->curFrame = 0; - placeObj->order = gob_goblins[0]->order; + placeObj->order = goblins[0]->order; placeObj->animation = placeObj->stateMach[placeObj->state][0]->animation; layer = placeObj->stateMach[placeObj->state][placeObj->stateColumn]->layer; - scen_updateAnim(layer, 0, placeObj->animation, 0, placeObj->xPos, + _vm->_scenery->updateAnim(layer, 0, placeObj->animation, 0, placeObj->xPos, placeObj->yPos, 0); placeObj->yPos += - (gob_gobPositions[0].y * 6) + 5 - scen_toRedrawBottom; + (gobPositions[0].y * 6) + 5 - _vm->_scenery->toRedrawBottom; - if (map_itemPoses[idToPlace].orient == 4) { - placeObj->xPos += (gob_gobPositions[0].x * 12 + 14) - - (scen_toRedrawLeft + scen_toRedrawRight) / 2; + if (_vm->_map->itemPoses[idToPlace].orient == 4) { + placeObj->xPos += (gobPositions[0].x * 12 + 14) + - (_vm->_scenery->toRedrawLeft + _vm->_scenery->toRedrawRight) / 2; } else { - placeObj->xPos += (gob_gobPositions[0].x * 12) - - (scen_toRedrawLeft + scen_toRedrawRight) / 2; + placeObj->xPos += (gobPositions[0].x * 12) + - (_vm->_scenery->toRedrawLeft + _vm->_scenery->toRedrawRight) / 2; } } -void gob_treatItemPick(int16 itemId) { +void Goblin::treatItemPick(int16 itemId) { int16 itemIndex; Gob_Object *gobDesc; - gobDesc = gob_goblins[gob_currentGoblin]; + gobDesc = goblins[currentGoblin]; if (gobDesc->curFrame != 9) return; @@ -2282,88 +2294,88 @@ void gob_treatItemPick(int16 itemId) { if (gobDesc->stateMach != gobDesc->realStateMach) return; - gob_readyToAct = 0; - gob_goesAtTarget = 0; + readyToAct = 0; + goesAtTarget = 0; - itemIndex = gob_itemToObject[itemId]; + itemIndex = itemToObject[itemId]; if (itemId != 0 && itemIndex != -1 - && gob_objects[itemIndex]->pickable != 1) + && objects[itemIndex]->pickable != 1) itemIndex = -1; - if (gob_itemIndInPocket != -1 && gob_itemIndInPocket == itemIndex) + if (itemIndInPocket != -1 && itemIndInPocket == itemIndex) itemIndex = -1; - if (gob_itemIndInPocket != -1 && itemIndex != -1 - && gob_objects[itemIndex]->pickable == 1) { - gob_swapItems(itemIndex, itemId); - gob_itemIndInPocket = itemIndex; - gob_itemIdInPocket = itemId; + if (itemIndInPocket != -1 && itemIndex != -1 + && objects[itemIndex]->pickable == 1) { + swapItems(itemIndex, itemId); + itemIndInPocket = itemIndex; + itemIdInPocket = itemId; return; } - if (gob_itemIndInPocket != -1 && itemIndex == -1) { - gob_placeItem(gob_itemIndInPocket, gob_itemIdInPocket); + if (itemIndInPocket != -1 && itemIndex == -1) { + placeItem(itemIndInPocket, itemIdInPocket); return; } - if (gob_itemIndInPocket == -1 && itemIndex != -1) { - gob_pickItem(itemIndex, itemId); + if (itemIndInPocket == -1 && itemIndex != -1) { + pickItem(itemIndex, itemId); return; } } -int16 gob_treatItem(int16 action) { +int16 Goblin::treatItem(int16 action) { int16 state; - state = gob_goblins[gob_currentGoblin]->state; + state = goblins[currentGoblin]->state; if ((state == 10 || state == 11) && - gob_goblins[gob_currentGoblin]->curFrame == 0) { - gob_readyToAct = 0; + goblins[currentGoblin]->curFrame == 0) { + readyToAct = 0; } - if (action == 3 && gob_currentGoblin == 0 && - (state == 10 || state == 11) && gob_goblins[0]->curFrame == 0) { - gob_saveGobDataToVars(gob_gobPositions[gob_currentGoblin].x, - gob_gobPositions[gob_currentGoblin].y, 0); - gob_goesAtTarget = 1; + if (action == 3 && currentGoblin == 0 && + (state == 10 || state == 11) && goblins[0]->curFrame == 0) { + saveGobDataToVars(gobPositions[currentGoblin].x, + gobPositions[currentGoblin].y, 0); + goesAtTarget = 1; return -1; } - if (gob_noPick == 0 && gob_currentGoblin == 0 && + if (noPick == 0 && currentGoblin == 0 && (state == 10 || state == 11)) { - gob_treatItemPick(gob_destActionItem); + treatItemPick(destActionItem); - gob_saveGobDataToVars(gob_gobPositions[gob_currentGoblin].x, - gob_gobPositions[gob_currentGoblin].y, 0); + saveGobDataToVars(gobPositions[currentGoblin].x, + gobPositions[currentGoblin].y, 0); return 0; } - if (gob_goesAtTarget == 0) { - gob_saveGobDataToVars(gob_gobPositions[gob_currentGoblin].x, - gob_gobPositions[gob_currentGoblin].y, 0); + if (goesAtTarget == 0) { + saveGobDataToVars(gobPositions[currentGoblin].x, + gobPositions[currentGoblin].y, 0); return 0; } else { - if (gob_itemToObject[gob_destActionItem] != 100 && - gob_destActionItem != 0) { + if (itemToObject[destActionItem] != 100 && + destActionItem != 0) { - if (gob_itemToObject[gob_destActionItem] == -1) { - gob_actDestItemDesc = 0; + if (itemToObject[destActionItem] == -1) { + actDestItemDesc = 0; } else { - gob_actDestItemDesc = - gob_objects[gob_itemToObject - [gob_destActionItem]]; + actDestItemDesc = + objects[itemToObject + [destActionItem]]; } } - gob_goesAtTarget = 0; - gob_saveGobDataToVars(gob_gobPositions[gob_currentGoblin].x, - gob_gobPositions[gob_currentGoblin].y, 0); - return gob_destActionItem; + goesAtTarget = 0; + saveGobDataToVars(gobPositions[currentGoblin].x, + gobPositions[currentGoblin].y, 0); + return destActionItem; } } -void gob_interFunc(void) { +void Goblin::interFunc(void) { int16 cmd; int16 extraData = 0; Gob_Object *objDesc = NULL; @@ -2381,31 +2393,31 @@ void gob_interFunc(void) { retVarPtr = (int32 *)VAR_ADDRESS(59); - cmd = inter_load16(); - inter_execPtr += 2; + cmd = _vm->_inter->load16(); + _vm->_global->inter_execPtr += 2; if (cmd > 0 && cmd < 17) { - extraData = inter_load16(); - objDesc = gob_objects[extraData]; + extraData = _vm->_inter->load16(); + objDesc = objects[extraData]; objDescSet = true; - extraData = inter_load16(); + extraData = _vm->_inter->load16(); } if (cmd > 90 && cmd < 107) { - extraData = inter_load16(); - objDesc = gob_goblins[extraData]; + extraData = _vm->_inter->load16(); + objDesc = goblins[extraData]; objDescSet = true; - extraData = inter_load16(); + extraData = _vm->_inter->load16(); cmd -= 90; } if (cmd > 110 && cmd < 128) { - extraData = inter_load16(); - objDesc = gob_goblins[extraData]; + extraData = _vm->_inter->load16(); + objDesc = goblins[extraData]; objDescSet = true; cmd -= 90; } else if (cmd > 20 && cmd < 38) { - extraData = inter_load16(); - objDesc = gob_objects[extraData]; + extraData = _vm->_inter->load16(); + objDesc = objects[extraData]; objDescSet = true; } @@ -2414,7 +2426,7 @@ void gob_interFunc(void) { variable, so we manually check if objDesc is properly set before checking if it is zero. If it was not set, we do not return. This fixes a crash in the EGA version if the life bar is depleted, because - gob_interFunc is called multiple times with cmd == 39. + interFunc is called multiple times with cmd == 39. Bug #1324814 */ @@ -2427,50 +2439,50 @@ void gob_interFunc(void) { case 1: objDesc->state = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemStateVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemStateVarPtr = extraData; break; case 2: objDesc->curFrame = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemFrameVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemFrameVarPtr = extraData; break; case 3: objDesc->nextState = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemNextStateVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemNextStateVarPtr = extraData; break; case 4: objDesc->multState = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemMultStateVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemMultStateVarPtr = extraData; break; case 5: objDesc->order = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemOrderVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemOrderVarPtr = extraData; break; case 6: objDesc->actionStartState = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemActStartStVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemActStartStVarPtr = extraData; break; case 7: objDesc->curLookDir = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemLookDirVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemLookDirVarPtr = extraData; break; case 8: objDesc->type = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemTypeVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemTypeVarPtr = extraData; if (extraData == 0) objDesc->toRedraw = 1; @@ -2478,44 +2490,44 @@ void gob_interFunc(void) { case 9: objDesc->noTick = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemNoTickVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemNoTickVarPtr = extraData; break; case 10: objDesc->pickable = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemPickableVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemPickableVarPtr = extraData; break; case 12: objDesc->xPos = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemScrXVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemScrXVarPtr = extraData; break; case 13: objDesc->yPos = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemScrYVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemScrYVarPtr = extraData; break; case 14: objDesc->doAnim = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemDoAnimVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemDoAnimVarPtr = extraData; break; case 15: objDesc->relaxTime = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemRelaxVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemRelaxVarPtr = extraData; break; case 16: objDesc->maxTick = extraData; - if (objDesc == gob_actDestItemDesc) - *gob_destItemMaxTickVarPtr = extraData; + if (objDesc == actDestItemDesc) + *destItemMaxTickVarPtr = extraData; break; case 21: @@ -2559,7 +2571,7 @@ void gob_interFunc(void) { break; case 32: - *retVarPtr = gob_getObjMaxFrame(objDesc); + *retVarPtr = getObjMaxFrame(objDesc); break; case 33: @@ -2584,9 +2596,9 @@ void gob_interFunc(void) { case 40: case 42: - xPos = inter_load16(); - yPos = inter_load16(); - item = inter_load16(); + xPos = _vm->_inter->load16(); + yPos = _vm->_inter->load16(); + item = _vm->_inter->load16(); if (cmd == 42) { xPos = VAR(xPos); @@ -2594,109 +2606,109 @@ void gob_interFunc(void) { item = VAR(item); } - for (y = 0; y < kMapHeight; y++) { - for (x = 0; x < kMapWidth; x++) { - if ((map_itemsMap[y][x] & 0xff) == item) { - map_itemsMap[y][x] &= 0xff00; - } else if (((map_itemsMap[y][x] & 0xff00) >> 8) + for (y = 0; y < Map::kMapHeight; y++) { + for (x = 0; x < Map::kMapWidth; x++) { + if ((_vm->_map->itemsMap[y][x] & 0xff) == item) { + _vm->_map->itemsMap[y][x] &= 0xff00; + } else if (((_vm->_map->itemsMap[y][x] & 0xff00) >> 8) == item) { - map_itemsMap[y][x] &= 0xff; + _vm->_map->itemsMap[y][x] &= 0xff; } } } - if (xPos < kMapWidth - 1) { + if (xPos < Map::kMapWidth - 1) { if (yPos > 0) { - if ((map_itemsMap[yPos][xPos] & 0xff00) != 0 || - (map_itemsMap[yPos - 1][xPos] & 0xff00) != + if ((_vm->_map->itemsMap[yPos][xPos] & 0xff00) != 0 || + (_vm->_map->itemsMap[yPos - 1][xPos] & 0xff00) != 0 - || (map_itemsMap[yPos][xPos + + || (_vm->_map->itemsMap[yPos][xPos + 1] & 0xff00) != 0 - || (map_itemsMap[yPos - 1][xPos + + || (_vm->_map->itemsMap[yPos - 1][xPos + 1] & 0xff00) != 0) { - map_itemsMap[yPos][xPos] = - (map_itemsMap[yPos][xPos] & 0xff00) + _vm->_map->itemsMap[yPos][xPos] = + (_vm->_map->itemsMap[yPos][xPos] & 0xff00) + item; - map_itemsMap[yPos - 1][xPos] = - (map_itemsMap[yPos - + _vm->_map->itemsMap[yPos - 1][xPos] = + (_vm->_map->itemsMap[yPos - 1][xPos] & 0xff00) + item; - map_itemsMap[yPos][xPos + 1] = - (map_itemsMap[yPos][xPos + + _vm->_map->itemsMap[yPos][xPos + 1] = + (_vm->_map->itemsMap[yPos][xPos + 1] & 0xff00) + item; - map_itemsMap[yPos - 1][xPos + 1] = - (map_itemsMap[yPos - 1][xPos + + _vm->_map->itemsMap[yPos - 1][xPos + 1] = + (_vm->_map->itemsMap[yPos - 1][xPos + 1] & 0xff00) + item; } else { - map_itemsMap[yPos][xPos] = - (map_itemsMap[yPos][xPos] & 0xff) + + _vm->_map->itemsMap[yPos][xPos] = + (_vm->_map->itemsMap[yPos][xPos] & 0xff) + (item << 8); - map_itemsMap[yPos - 1][xPos] = - (map_itemsMap[yPos - + _vm->_map->itemsMap[yPos - 1][xPos] = + (_vm->_map->itemsMap[yPos - 1][xPos] & 0xff) + (item << 8); - map_itemsMap[yPos][xPos + 1] = - (map_itemsMap[yPos][xPos + + _vm->_map->itemsMap[yPos][xPos + 1] = + (_vm->_map->itemsMap[yPos][xPos + 1] & 0xff) + (item << 8); - map_itemsMap[yPos - 1][xPos + 1] = - (map_itemsMap[yPos - 1][xPos + + _vm->_map->itemsMap[yPos - 1][xPos + 1] = + (_vm->_map->itemsMap[yPos - 1][xPos + 1] & 0xff) + (item << 8); } } else { - if ((map_itemsMap[yPos][xPos] & 0xff00) != 0 || - (map_itemsMap[yPos][xPos + 1] & 0xff00) != + if ((_vm->_map->itemsMap[yPos][xPos] & 0xff00) != 0 || + (_vm->_map->itemsMap[yPos][xPos + 1] & 0xff00) != 0) { - map_itemsMap[yPos][xPos] = - (map_itemsMap[yPos][xPos] & 0xff00) + _vm->_map->itemsMap[yPos][xPos] = + (_vm->_map->itemsMap[yPos][xPos] & 0xff00) + item; - map_itemsMap[yPos][xPos + 1] = - (map_itemsMap[yPos][xPos + + _vm->_map->itemsMap[yPos][xPos + 1] = + (_vm->_map->itemsMap[yPos][xPos + 1] & 0xff00) + item; } else { - map_itemsMap[yPos][xPos] = - (map_itemsMap[yPos][xPos] & 0xff) + + _vm->_map->itemsMap[yPos][xPos] = + (_vm->_map->itemsMap[yPos][xPos] & 0xff) + (item << 8); - map_itemsMap[yPos][xPos + 1] = - (map_itemsMap[yPos][xPos + + _vm->_map->itemsMap[yPos][xPos + 1] = + (_vm->_map->itemsMap[yPos][xPos + 1] & 0xff) + (item << 8); } } } else { if (yPos > 0) { - if ((map_itemsMap[yPos][xPos] & 0xff00) != 0 || - (map_itemsMap[yPos - 1][xPos] & 0xff00) != + if ((_vm->_map->itemsMap[yPos][xPos] & 0xff00) != 0 || + (_vm->_map->itemsMap[yPos - 1][xPos] & 0xff00) != 0) { - map_itemsMap[yPos][xPos] = - (map_itemsMap[yPos][xPos] & 0xff00) + _vm->_map->itemsMap[yPos][xPos] = + (_vm->_map->itemsMap[yPos][xPos] & 0xff00) + item; - map_itemsMap[yPos - 1][xPos] = - (map_itemsMap[yPos - + _vm->_map->itemsMap[yPos - 1][xPos] = + (_vm->_map->itemsMap[yPos - 1][xPos] & 0xff00) + item; } else { - map_itemsMap[yPos][xPos] = - (map_itemsMap[yPos][xPos] & 0xff) + + _vm->_map->itemsMap[yPos][xPos] = + (_vm->_map->itemsMap[yPos][xPos] & 0xff) + (item << 8); - map_itemsMap[yPos - 1][xPos] = - (map_itemsMap[yPos - + _vm->_map->itemsMap[yPos - 1][xPos] = + (_vm->_map->itemsMap[yPos - 1][xPos] & 0xff) + (item << 8); } } else { - if ((map_itemsMap[yPos][xPos] & 0xff00) != 0) { - map_itemsMap[yPos][xPos] = - (map_itemsMap[yPos][xPos] & 0xff00) + if ((_vm->_map->itemsMap[yPos][xPos] & 0xff00) != 0) { + _vm->_map->itemsMap[yPos][xPos] = + (_vm->_map->itemsMap[yPos][xPos] & 0xff00) + item; } else { - map_itemsMap[yPos][xPos] = - (map_itemsMap[yPos][xPos] & 0xff) + + _vm->_map->itemsMap[yPos][xPos] = + (_vm->_map->itemsMap[yPos][xPos] & 0xff) + (item << 8); } } @@ -2705,505 +2717,505 @@ void gob_interFunc(void) { if (item < 0 || item >= 20) break; - if (xPos > 1 && map_passMap[yPos][xPos - 2] == 1) { - map_itemPoses[item].x = xPos - 2; - map_itemPoses[item].y = yPos; - map_itemPoses[item].orient = 4; + if (xPos > 1 && _vm->_map->passMap[yPos][xPos - 2] == 1) { + _vm->_map->itemPoses[item].x = xPos - 2; + _vm->_map->itemPoses[item].y = yPos; + _vm->_map->itemPoses[item].orient = 4; break; } - if (xPos < kMapWidth - 2 && map_passMap[yPos][xPos + 2] == 1) { - map_itemPoses[item].x = xPos + 2; - map_itemPoses[item].y = yPos; - map_itemPoses[item].orient = 0; + if (xPos < Map::kMapWidth - 2 && _vm->_map->passMap[yPos][xPos + 2] == 1) { + _vm->_map->itemPoses[item].x = xPos + 2; + _vm->_map->itemPoses[item].y = yPos; + _vm->_map->itemPoses[item].orient = 0; break; } - if (xPos < kMapWidth - 1 && map_passMap[yPos][xPos + 1] == 1) { - map_itemPoses[item].x = xPos + 1; - map_itemPoses[item].y = yPos; - map_itemPoses[item].orient = 0; + if (xPos < Map::kMapWidth - 1 && _vm->_map->passMap[yPos][xPos + 1] == 1) { + _vm->_map->itemPoses[item].x = xPos + 1; + _vm->_map->itemPoses[item].y = yPos; + _vm->_map->itemPoses[item].orient = 0; break; } - if (xPos > 0 && map_passMap[yPos][xPos - 1] == 1) { - map_itemPoses[item].x = xPos - 1; - map_itemPoses[item].y = yPos; - map_itemPoses[item].orient = 4; + if (xPos > 0 && _vm->_map->passMap[yPos][xPos - 1] == 1) { + _vm->_map->itemPoses[item].x = xPos - 1; + _vm->_map->itemPoses[item].y = yPos; + _vm->_map->itemPoses[item].orient = 4; break; } break; case 41: case 43: - xPos = inter_load16(); - yPos = inter_load16(); + xPos = _vm->_inter->load16(); + yPos = _vm->_inter->load16(); if (cmd == 43) { xPos = VAR(xPos); yPos = VAR(yPos); } - if ((map_itemsMap[yPos][xPos] & 0xff00) != 0) { - *retVarPtr = (map_itemsMap[yPos][xPos] & 0xff00) >> 8; + if ((_vm->_map->itemsMap[yPos][xPos] & 0xff00) != 0) { + *retVarPtr = (_vm->_map->itemsMap[yPos][xPos] & 0xff00) >> 8; } else { - *retVarPtr = map_itemsMap[yPos][xPos]; + *retVarPtr = _vm->_map->itemsMap[yPos][xPos]; } break; case 44: - xPos = inter_load16(); - yPos = inter_load16(); - val = inter_load16(); - map_passMap[yPos][xPos] = val; + xPos = _vm->_inter->load16(); + yPos = _vm->_inter->load16(); + val = _vm->_inter->load16(); + _vm->_map->passMap[yPos][xPos] = val; break; case 50: - item = inter_load16(); - xPos = inter_load16(); - yPos = inter_load16(); + item = _vm->_inter->load16(); + xPos = _vm->_inter->load16(); + yPos = _vm->_inter->load16(); - gob_gobPositions[item].x = xPos * 2; - gob_gobPositions[item].y = yPos * 2; + gobPositions[item].x = xPos * 2; + gobPositions[item].y = yPos * 2; - objDesc = gob_goblins[item]; + objDesc = goblins[item]; objDesc->nextState = 21; - gob_nextLayer(objDesc); + nextLayer(objDesc); layer = objDesc->stateMach[objDesc->state][0]->layer; - scen_updateAnim(layer, 0, objDesc->animation, 0, + _vm->_scenery->updateAnim(layer, 0, objDesc->animation, 0, objDesc->xPos, objDesc->yPos, 0); objDesc->yPos = - (gob_gobPositions[item].y * 6 + 6) - (scen_toRedrawBottom - - scen_animTop); + (gobPositions[item].y * 6 + 6) - (_vm->_scenery->toRedrawBottom - + _vm->_scenery->animTop); objDesc->xPos = - gob_gobPositions[item].x * 12 - (scen_toRedrawLeft - - scen_animLeft); + gobPositions[item].x * 12 - (_vm->_scenery->toRedrawLeft - + _vm->_scenery->animLeft); objDesc->curFrame = 0; objDesc->state = 21; - if (gob_currentGoblin == item) { - *gob_curGobScrXVarPtr = objDesc->xPos; - *gob_curGobScrYVarPtr = objDesc->yPos; + if (currentGoblin == item) { + *curGobScrXVarPtr = objDesc->xPos; + *curGobScrYVarPtr = objDesc->yPos; - *gob_curGobFrameVarPtr = 0; - *gob_curGobStateVarPtr = 18; - gob_pressedMapX = gob_gobPositions[item].x; - gob_pressedMapY = gob_gobPositions[item].y; + *curGobFrameVarPtr = 0; + *curGobStateVarPtr = 18; + pressedMapX = gobPositions[item].x; + pressedMapY = gobPositions[item].y; } break; case 52: - item = inter_load16(); - *retVarPtr = gob_gobPositions[item].x >> 1; + item = _vm->_inter->load16(); + *retVarPtr = gobPositions[item].x >> 1; break; case 53: - item = inter_load16(); - *retVarPtr = gob_gobPositions[item].y >> 1; + item = _vm->_inter->load16(); + *retVarPtr = gobPositions[item].y >> 1; break; case 150: - item = inter_load16(); - xPos = inter_load16(); - yPos = inter_load16(); + item = _vm->_inter->load16(); + xPos = _vm->_inter->load16(); + yPos = _vm->_inter->load16(); - objDesc = gob_goblins[item]; + objDesc = goblins[item]; if (yPos == 0) { objDesc->multState = xPos; objDesc->nextState = xPos; - gob_nextLayer(objDesc); + nextLayer(objDesc); layer = objDesc->stateMach[objDesc->state][0]->layer; objDesc->xPos = - scen_animations[objDesc->animation].layers[layer]-> + _vm->_scenery->animations[objDesc->animation].layers[layer]-> posX; objDesc->yPos = - scen_animations[objDesc->animation].layers[layer]-> + _vm->_scenery->animations[objDesc->animation].layers[layer]-> posY; - *gob_curGobScrXVarPtr = objDesc->xPos; - *gob_curGobScrYVarPtr = objDesc->yPos; - *gob_curGobFrameVarPtr = 0; - *gob_curGobStateVarPtr = objDesc->state; - *gob_curGobNextStateVarPtr = objDesc->nextState; - *gob_curGobMultStateVarPtr = objDesc->multState; - *gob_curGobMaxFrameVarPtr = - gob_getObjMaxFrame(objDesc); - gob_noPick = 1; + *curGobScrXVarPtr = objDesc->xPos; + *curGobScrYVarPtr = objDesc->yPos; + *curGobFrameVarPtr = 0; + *curGobStateVarPtr = objDesc->state; + *curGobNextStateVarPtr = objDesc->nextState; + *curGobMultStateVarPtr = objDesc->multState; + *curGobMaxFrameVarPtr = + getObjMaxFrame(objDesc); + noPick = 1; break; } objDesc->multState = 21; objDesc->nextState = 21; objDesc->state = 21; - gob_nextLayer(objDesc); + nextLayer(objDesc); layer = objDesc->stateMach[objDesc->state][0]->layer; - scen_updateAnim(layer, 0, objDesc->animation, 0, + _vm->_scenery->updateAnim(layer, 0, objDesc->animation, 0, objDesc->xPos, objDesc->yPos, 0); objDesc->yPos = - (yPos * 6 + 6) - (scen_toRedrawBottom - scen_animTop); + (yPos * 6 + 6) - (_vm->_scenery->toRedrawBottom - _vm->_scenery->animTop); objDesc->xPos = - xPos * 12 - (scen_toRedrawLeft - scen_animLeft); + xPos * 12 - (_vm->_scenery->toRedrawLeft - _vm->_scenery->animLeft); - gob_gobPositions[item].x = xPos; - gob_pressedMapX = xPos; - map_curGoblinX = xPos; + gobPositions[item].x = xPos; + pressedMapX = xPos; + _vm->_map->curGoblinX = xPos; - gob_gobPositions[item].y = yPos; - gob_pressedMapY = yPos; - map_curGoblinY = yPos; + gobPositions[item].y = yPos; + pressedMapY = yPos; + _vm->_map->curGoblinY = yPos; - *gob_curGobScrXVarPtr = objDesc->xPos; - *gob_curGobScrYVarPtr = objDesc->yPos; - *gob_curGobFrameVarPtr = 0; - *gob_curGobStateVarPtr = 21; - *gob_curGobNextStateVarPtr = 21; - *gob_curGobMultStateVarPtr = -1; - gob_noPick = 0; + *curGobScrXVarPtr = objDesc->xPos; + *curGobScrYVarPtr = objDesc->yPos; + *curGobFrameVarPtr = 0; + *curGobStateVarPtr = 21; + *curGobNextStateVarPtr = 21; + *curGobMultStateVarPtr = -1; + noPick = 0; break; case 250: - item = inter_load16(); - xPos = inter_load16(); - yPos = inter_load16(); + item = _vm->_inter->load16(); + xPos = _vm->_inter->load16(); + yPos = _vm->_inter->load16(); - gob_gobPositions[item].x = xPos; - gob_gobPositions[item].y = yPos; + gobPositions[item].x = xPos; + gobPositions[item].y = yPos; - objDesc = gob_goblins[item]; + objDesc = goblins[item]; objDesc->nextState = 21; - gob_nextLayer(objDesc); + nextLayer(objDesc); layer = objDesc->stateMach[objDesc->state][0]->layer; - scen_updateAnim(layer, 0, objDesc->animation, 0, + _vm->_scenery->updateAnim(layer, 0, objDesc->animation, 0, objDesc->xPos, objDesc->yPos, 0); objDesc->yPos = - (yPos * 6 + 6) - (scen_toRedrawBottom - scen_animTop); + (yPos * 6 + 6) - (_vm->_scenery->toRedrawBottom - _vm->_scenery->animTop); objDesc->xPos = - xPos * 12 - (scen_toRedrawLeft - scen_animLeft); + xPos * 12 - (_vm->_scenery->toRedrawLeft - _vm->_scenery->animLeft); objDesc->curFrame = 0; objDesc->state = 21; - if (gob_currentGoblin == item) { - *gob_curGobScrXVarPtr = objDesc->xPos; - *gob_curGobScrYVarPtr = objDesc->yPos; - *gob_curGobFrameVarPtr = 0; - *gob_curGobStateVarPtr = 18; + if (currentGoblin == item) { + *curGobScrXVarPtr = objDesc->xPos; + *curGobScrYVarPtr = objDesc->yPos; + *curGobFrameVarPtr = 0; + *curGobStateVarPtr = 18; - gob_pressedMapX = gob_gobPositions[item].x; - gob_pressedMapY = gob_gobPositions[item].y; + pressedMapX = gobPositions[item].x; + pressedMapY = gobPositions[item].y; } break; case 251: - item = inter_load16(); - state = inter_load16(); + item = _vm->_inter->load16(); + state = _vm->_inter->load16(); - objDesc = gob_goblins[item]; + objDesc = goblins[item]; objDesc->nextState = state; - gob_nextLayer(objDesc); + nextLayer(objDesc); layer = objDesc->stateMach[objDesc->state][0]->layer; objDesc->xPos = - scen_animations[objDesc->animation].layers[layer]->posX; + _vm->_scenery->animations[objDesc->animation].layers[layer]->posX; objDesc->yPos = - scen_animations[objDesc->animation].layers[layer]->posY; + _vm->_scenery->animations[objDesc->animation].layers[layer]->posY; - if (item == gob_currentGoblin) { - *gob_curGobScrXVarPtr = objDesc->xPos; - *gob_curGobScrYVarPtr = objDesc->yPos; - *gob_curGobFrameVarPtr = 0; - *gob_curGobStateVarPtr = objDesc->state; - *gob_curGobMultStateVarPtr = objDesc->multState; + if (item == currentGoblin) { + *curGobScrXVarPtr = objDesc->xPos; + *curGobScrYVarPtr = objDesc->yPos; + *curGobFrameVarPtr = 0; + *curGobStateVarPtr = objDesc->state; + *curGobMultStateVarPtr = objDesc->multState; } break; case 252: - item = inter_load16(); - state = inter_load16(); - objDesc = gob_objects[item]; + item = _vm->_inter->load16(); + state = _vm->_inter->load16(); + objDesc = objects[item]; objDesc->nextState = state; - gob_nextLayer(objDesc); + nextLayer(objDesc); layer = objDesc->stateMach[objDesc->state][0]->layer; objDesc->xPos = - scen_animations[objDesc->animation].layers[layer]->posX; + _vm->_scenery->animations[objDesc->animation].layers[layer]->posX; objDesc->yPos = - scen_animations[objDesc->animation].layers[layer]->posY; + _vm->_scenery->animations[objDesc->animation].layers[layer]->posY; objDesc->toRedraw = 1; objDesc->type = 0; - if (objDesc == gob_actDestItemDesc) { - *gob_destItemScrXVarPtr = objDesc->xPos; - *gob_destItemScrYVarPtr = objDesc->yPos; + if (objDesc == actDestItemDesc) { + *destItemScrXVarPtr = objDesc->xPos; + *destItemScrYVarPtr = objDesc->yPos; - *gob_destItemStateVarPtr = objDesc->state; - *gob_destItemNextStateVarPtr = -1; - *gob_destItemMultStateVarPtr = -1; - *gob_destItemFrameVarPtr = 0; + *destItemStateVarPtr = objDesc->state; + *destItemNextStateVarPtr = -1; + *destItemMultStateVarPtr = -1; + *destItemFrameVarPtr = 0; } break; case 152: - item = inter_load16(); - val = inter_load16(); - objDesc = gob_objects[item]; + item = _vm->_inter->load16(); + val = _vm->_inter->load16(); + objDesc = objects[item]; objDesc->unk14 = val; break; case 200: - gob_itemIdInPocket = inter_load16(); + itemIdInPocket = _vm->_inter->load16(); break; case 201: - gob_itemIndInPocket = inter_load16(); + itemIndInPocket = _vm->_inter->load16(); break; case 202: - *retVarPtr = gob_itemIdInPocket; + *retVarPtr = itemIdInPocket; break; case 203: - *retVarPtr = gob_itemIndInPocket; + *retVarPtr = itemIndInPocket; break; case 204: - item = inter_load16(); - xPos = inter_load16(); - yPos = inter_load16(); - val = inter_load16(); + item = _vm->_inter->load16(); + xPos = _vm->_inter->load16(); + yPos = _vm->_inter->load16(); + val = _vm->_inter->load16(); - map_itemPoses[item].x = xPos; - map_itemPoses[item].y = yPos; - map_itemPoses[item].orient = val; + _vm->_map->itemPoses[item].x = xPos; + _vm->_map->itemPoses[item].y = yPos; + _vm->_map->itemPoses[item].orient = val; break; case 500: - extraData = inter_load16(); - objDesc = gob_objects[extraData]; + extraData = _vm->_inter->load16(); + objDesc = objects[extraData]; objDesc->relaxTime--; if (objDesc->relaxTime < 0 && - gob_getObjMaxFrame(objDesc) == objDesc->curFrame) { - objDesc->relaxTime = util_getRandom(100) + 50; + getObjMaxFrame(objDesc) == objDesc->curFrame) { + objDesc->relaxTime = _vm->_util->getRandom(100) + 50; objDesc->curFrame = 0; objDesc->toRedraw = 1; } break; case 502: - item = inter_load16(); - *retVarPtr = gob_gobPositions[item].x; + item = _vm->_inter->load16(); + *retVarPtr = gobPositions[item].x; break; case 503: - item = inter_load16(); - *retVarPtr = gob_gobPositions[item].y; + item = _vm->_inter->load16(); + *retVarPtr = gobPositions[item].y; break; case 600: - gob_pathExistence = 0; + pathExistence = 0; break; case 601: - extraData = inter_load16(); - gob_goblins[extraData]->visible = 1; + extraData = _vm->_inter->load16(); + goblins[extraData]->visible = 1; break; case 602: - extraData = inter_load16(); - gob_goblins[extraData]->visible = 0; + extraData = _vm->_inter->load16(); + goblins[extraData]->visible = 0; break; case 603: - extraData = inter_load16(); - item = inter_load16(); + extraData = _vm->_inter->load16(); + item = _vm->_inter->load16(); - objDesc = gob_objects[extraData]; - if (gob_objIntersected(objDesc, gob_goblins[item]) != 0) + objDesc = objects[extraData]; + if (objIntersected(objDesc, goblins[item]) != 0) *retVarPtr = 1; else *retVarPtr = 0; break; case 604: - extraData = inter_load16(); - item = inter_load16(); + extraData = _vm->_inter->load16(); + item = _vm->_inter->load16(); - objDesc = gob_goblins[extraData]; - if (gob_objIntersected(objDesc, gob_goblins[item]) != 0) + objDesc = goblins[extraData]; + if (objIntersected(objDesc, goblins[item]) != 0) *retVarPtr = 1; else *retVarPtr = 0; break; case 605: - item = inter_load16(); - xPos = inter_load16(); - yPos = inter_load16(); - val = inter_load16(); + item = _vm->_inter->load16(); + xPos = _vm->_inter->load16(); + yPos = _vm->_inter->load16(); + val = _vm->_inter->load16(); - map_itemPoses[item].x = xPos; - map_itemPoses[item].y = yPos; - map_itemPoses[item].orient = val; + _vm->_map->itemPoses[item].x = xPos; + _vm->_map->itemPoses[item].y = yPos; + _vm->_map->itemPoses[item].orient = val; break; case 1000: - extraData = inter_load16(); - if (game_extHandle >= 0) - data_closeData(game_extHandle); + extraData = _vm->_inter->load16(); + if (_vm->_game->extHandle >= 0) + _vm->_dataio->closeData(_vm->_game->extHandle); - gob_loadObjects((char *)VAR_ADDRESS(extraData)); - game_extHandle = data_openData(game_curExtFile); + loadObjects((char *)VAR_ADDRESS(extraData)); + _vm->_game->extHandle = _vm->_dataio->openData(_vm->_game->curExtFile); break; case 1001: - gob_freeAllObjects(); + freeAllObjects(); break; case 1002: - gob_animateObjects(); + animateObjects(); break; case 1003: - gob_drawObjects(); + drawObjects(); - if (cd_getTrackPos() == -1) - cd_playBgMusic(); + if (_vm->_cdrom->getTrackPos() == -1) + _vm->_cdrom->playBgMusic(); break; case 1004: - map_loadMapsInitGobs(); + _vm->_map->loadMapsInitGobs(); break; case 1005: - extraData = inter_load16(); - xPos = inter_load16(); + extraData = _vm->_inter->load16(); + xPos = _vm->_inter->load16(); if ((uint16)VAR(xPos) == 0) { item = - gob_doMove(gob_goblins[gob_currentGoblin], 1, + doMove(goblins[currentGoblin], 1, (uint16)VAR(extraData)); } else { item = - gob_doMove(gob_goblins[gob_currentGoblin], 1, 3); + doMove(goblins[currentGoblin], 1, 3); } if (item != 0) - gob_switchGoblin(item); + switchGoblin(item); break; case 1006: - gob_switchGoblin(0); + switchGoblin(0); break; case 1008: - gob_loadGobDataFromVars(); + loadGobDataFromVars(); break; case 1009: - extraData = inter_load16(); - cmd = inter_load16(); - xPos = inter_load16(); + extraData = _vm->_inter->load16(); + cmd = _vm->_inter->load16(); + xPos = _vm->_inter->load16(); if ((uint16)VAR(xPos) == 0) { - WRITE_VAR(cmd, gob_treatItem((uint16)VAR(extraData))); + WRITE_VAR(cmd, treatItem((uint16)VAR(extraData))); break; } - WRITE_VAR(cmd, gob_treatItem(3)); + WRITE_VAR(cmd, treatItem(3)); break; case 1010: - gob_doMove(gob_goblins[gob_currentGoblin], 0, 0); + doMove(goblins[currentGoblin], 0, 0); break; case 1011: - extraData = inter_load16(); + extraData = _vm->_inter->load16(); if (VAR(extraData) != 0) - gob_goesAtTarget = 1; + goesAtTarget = 1; else - gob_goesAtTarget = 0; + goesAtTarget = 0; break; case 1015: - extraData = inter_load16(); + extraData = _vm->_inter->load16(); extraData = VAR(extraData); - gob_objects[10]->xPos = extraData; + objects[10]->xPos = extraData; - extraData = inter_load16(); + extraData = _vm->_inter->load16(); extraData = VAR(extraData); - gob_objects[10]->yPos = extraData; + objects[10]->yPos = extraData; break; case 2005: - gobDesc = gob_goblins[0]; - if (gob_currentGoblin != 0) { - gob_goblins[gob_currentGoblin]->doAnim = 1; - gob_goblins[gob_currentGoblin]->nextState = 21; + gobDesc = goblins[0]; + if (currentGoblin != 0) { + goblins[currentGoblin]->doAnim = 1; + goblins[currentGoblin]->nextState = 21; - gob_nextLayer(gob_goblins[gob_currentGoblin]); - gob_currentGoblin = 0; + nextLayer(goblins[currentGoblin]); + currentGoblin = 0; gobDesc->doAnim = 0; gobDesc->type = 0; gobDesc->toRedraw = 1; - gob_pressedMapX = gob_gobPositions[0].x; - map_destX = gob_gobPositions[0].x; - gob_gobDestX = gob_gobPositions[0].x; + pressedMapX = gobPositions[0].x; + _vm->_map->destX = gobPositions[0].x; + gobDestX = gobPositions[0].x; - gob_pressedMapY = gob_gobPositions[0].y; - map_destY = gob_gobPositions[0].y; - gob_gobDestY = gob_gobPositions[0].y; + pressedMapY = gobPositions[0].y; + _vm->_map->destY = gobPositions[0].y; + gobDestY = gobPositions[0].y; - *gob_curGobVarPtr = 0; - gob_pathExistence = 0; - gob_readyToAct = 0; + *curGobVarPtr = 0; + pathExistence = 0; + readyToAct = 0; } - if (gobDesc->state != 10 && gob_itemIndInPocket != -1 && - gob_getObjMaxFrame(gobDesc) == gobDesc->curFrame) { + if (gobDesc->state != 10 && itemIndInPocket != -1 && + getObjMaxFrame(gobDesc) == gobDesc->curFrame) { gobDesc->stateMach = gobDesc->realStateMach; - xPos = gob_gobPositions[0].x; - yPos = gob_gobPositions[0].y; + xPos = gobPositions[0].x; + yPos = gobPositions[0].y; gobDesc->nextState = 10; - layer = gob_nextLayer(gobDesc); + layer = nextLayer(gobDesc); - scen_updateAnim(layer, 0, gobDesc->animation, 0, + _vm->_scenery->updateAnim(layer, 0, gobDesc->animation, 0, gobDesc->xPos, gobDesc->yPos, 0); gobDesc->yPos = - (yPos * 6 + 6) - (scen_toRedrawBottom - - scen_animTop); + (yPos * 6 + 6) - (_vm->_scenery->toRedrawBottom - + _vm->_scenery->animTop); gobDesc->xPos = - xPos * 12 - (scen_toRedrawLeft - scen_animLeft); + xPos * 12 - (_vm->_scenery->toRedrawLeft - _vm->_scenery->animLeft); } if (gobDesc->state != 10) break; - if (gob_itemIndInPocket == -1) + if (itemIndInPocket == -1) break; if (gobDesc->curFrame != 10) break; - objDesc = gob_objects[gob_itemIndInPocket]; + objDesc = objects[itemIndInPocket]; objDesc->type = 0; objDesc->toRedraw = 1; objDesc->curFrame = 0; @@ -3214,30 +3226,30 @@ void gob_interFunc(void) { layer = objDesc->stateMach[objDesc->state][0]->layer; - scen_updateAnim(layer, 0, objDesc->animation, 0, + _vm->_scenery->updateAnim(layer, 0, objDesc->animation, 0, objDesc->xPos, objDesc->yPos, 0); objDesc->yPos += - (gob_gobPositions[0].y * 6 + 5) - scen_toRedrawBottom; + (gobPositions[0].y * 6 + 5) - _vm->_scenery->toRedrawBottom; if (gobDesc->curLookDir == 4) { - objDesc->xPos += gob_gobPositions[0].x * 12 + 14 - - (scen_toRedrawLeft + scen_toRedrawRight) / 2; + objDesc->xPos += gobPositions[0].x * 12 + 14 + - (_vm->_scenery->toRedrawLeft + _vm->_scenery->toRedrawRight) / 2; } else { - objDesc->xPos += gob_gobPositions[0].x * 12 - - (scen_toRedrawLeft + scen_toRedrawRight) / 2; + objDesc->xPos += gobPositions[0].x * 12 + - (_vm->_scenery->toRedrawLeft + _vm->_scenery->toRedrawRight) / 2; } - gob_itemIndInPocket = -1; - gob_itemIdInPocket = -1; - util_beep(50); + itemIndInPocket = -1; + itemIdInPocket = -1; + _vm->_util->beep(50); break; default: - warning("gob_interFunc: Unknown command %d!", cmd); - inter_execPtr -= 2; - cmd = inter_load16(); - inter_execPtr += cmd * 2; + warning("interFunc: Unknown command %d!", cmd); + _vm->_global->inter_execPtr -= 2; + cmd = _vm->_inter->load16(); + _vm->_global->inter_execPtr += cmd * 2; break; } return; diff --git a/gob/goblin.h b/gob/goblin.h index 2903b00f0b..36c76b14f0 100644 --- a/gob/goblin.h +++ b/gob/goblin.h @@ -31,175 +31,201 @@ namespace Gob { #define TYPE_AMORPHOUS 1 #define TYPE_MOBILE 3 +class Goblin { +public: #pragma START_PACK_STRUCTS -typedef struct Gob_State { - int16 animation;// +0h - int16 layer; // +2h - int16 unk0; // +4h - int16 unk1; // +6h - int16 sndItem; // +8h, high/low byte - sound sample index - int16 freq; // +Ah, high/low byte * 100 - frequency - int16 repCount; // +Ch high/low byte - repeat count - int16 sndFrame; // +Eh -} GCC_PACK Gob_State; - -typedef struct Gob_State *Gob_PState; + typedef struct Gob_State { + int16 animation;// +0h + int16 layer; // +2h + int16 unk0; // +4h + int16 unk1; // +6h + int16 sndItem; // +8h, high/low byte - sound sample index + int16 freq; // +Ah, high/low byte * 100 - frequency + int16 repCount; // +Ch high/low byte - repeat count + int16 sndFrame; // +Eh + } GCC_PACK Gob_State; + + typedef Gob_State *Gob_PState; #define szGob_StateLine 24 -typedef Gob_PState Gob_StateLine[6]; - -typedef struct Gob_Object { - int16 animation; // +0h - int16 state; // +2h - int16 stateColumn; // +4h - int16 curFrame; // +6h - int16 xPos; // +8h - int16 yPos; // +Ah - int16 dirtyLeft; // +Ch - int16 dirtyTop; // +Eh - int16 dirtyRight; // +10h - int16 dirtyBottom; // +12h - int16 left; // +14h - int16 top; // +16h - int16 right; // +18h - int16 bottom; // +1ah - int16 nextState; // +1ch - int16 multState; // +1eh - int16 actionStartState; // +20h - int16 curLookDir; // +22h - int16 pickable; // +24h - int16 relaxTime; // +26h - Gob_StateLine *stateMach; // +28h - Gob_StateLine *realStateMach; // +2ch - char doAnim; // +30h - char order; // +31h - char noTick; // +32h - char toRedraw; // +33h - char type; // +34h - char maxTick; // +35h - char tick; // +36h - char multObjIndex; // +37h, from which play mult animations - char unk14; // +38h - char visible; // +39h -} GCC_PACK Gob_Object; - -typedef struct Gob_Pos { - char x; - char y; -} GCC_PACK Gob_Pos; + typedef Gob_PState Gob_StateLine[6]; + + typedef struct Gob_Object { + int16 animation; // +0h + int16 state; // +2h + int16 stateColumn; // +4h + int16 curFrame; // +6h + int16 xPos; // +8h + int16 yPos; // +Ah + int16 dirtyLeft; // +Ch + int16 dirtyTop; // +Eh + int16 dirtyRight; // +10h + int16 dirtyBottom; // +12h + int16 left; // +14h + int16 top; // +16h + int16 right; // +18h + int16 bottom; // +1ah + int16 nextState; // +1ch + int16 multState; // +1eh + int16 actionStartState; // +20h + int16 curLookDir; // +22h + int16 pickable; // +24h + int16 relaxTime; // +26h + Gob_StateLine *stateMach; // +28h + Gob_StateLine *realStateMach; // +2ch + char doAnim; // +30h + char order; // +31h + char noTick; // +32h + char toRedraw; // +33h + char type; // +34h + char maxTick; // +35h + char tick; // +36h + char multObjIndex; // +37h, from which play mult animations + char unk14; // +38h + char visible; // +39h + } GCC_PACK Gob_Object; + + typedef struct Gob_Pos { + char x; + char y; + } GCC_PACK Gob_Pos; #pragma END_PACK_STRUCTS -extern Util_List *gob_objList; -extern Gob_Object *gob_goblins[4]; -extern int16 gob_currentGoblin; -extern Snd_SoundDesc *gob_soundData[16]; -extern int16 gob_gobStateLayer; -extern char gob_goesAtTarget; -extern char gob_readyToAct; -extern int16 gob_gobAction; // 0 - move, 3 - do action, 4 - pick - // goblins 0 - picker, 1 - fighter, 2 - mage -extern Gob_Pos gob_gobPositions[3]; -extern int16 gob_gobDestX; -extern int16 gob_gobDestY; -extern int16 gob_pressedMapX; -extern int16 gob_pressedMapY; -extern char gob_pathExistence; - -// Pointers to interpreter variables -extern int32 *gob_some0ValPtr; - -extern int32 *gob_gobRetVarPtr; -extern int32 *gob_curGobVarPtr; -extern int32 *gob_curGobXPosVarPtr; -extern int32 *gob_curGobYPosVarPtr; -extern int32 *gob_itemInPocketVarPtr; - -extern int32 *gob_curGobStateVarPtr; -extern int32 *gob_curGobFrameVarPtr; -extern int32 *gob_curGobMultStateVarPtr; -extern int32 *gob_curGobNextStateVarPtr; -extern int32 *gob_curGobScrXVarPtr; -extern int32 *gob_curGobScrYVarPtr; -extern int32 *gob_curGobLeftVarPtr; -extern int32 *gob_curGobTopVarPtr; -extern int32 *gob_curGobRightVarPtr; -extern int32 *gob_curGobBottomVarPtr; -extern int32 *gob_curGobDoAnimVarPtr; -extern int32 *gob_curGobOrderVarPtr; -extern int32 *gob_curGobNoTickVarPtr; -extern int32 *gob_curGobTypeVarPtr; -extern int32 *gob_curGobMaxTickVarPtr; -extern int32 *gob_curGobTickVarPtr; -extern int32 *gob_curGobActStartStateVarPtr; -extern int32 *gob_curGobLookDirVarPtr; -extern int32 *gob_curGobPickableVarPtr; -extern int32 *gob_curGobRelaxVarPtr; -extern int32 *gob_curGobMaxFrameVarPtr; - -extern int32 *gob_destItemStateVarPtr; -extern int32 *gob_destItemFrameVarPtr; -extern int32 *gob_destItemMultStateVarPtr; -extern int32 *gob_destItemNextStateVarPtr; -extern int32 *gob_destItemScrXVarPtr; -extern int32 *gob_destItemScrYVarPtr; -extern int32 *gob_destItemLeftVarPtr; -extern int32 *gob_destItemTopVarPtr; -extern int32 *gob_destItemRightVarPtr; -extern int32 *gob_destItemBottomVarPtr; -extern int32 *gob_destItemDoAnimVarPtr; -extern int32 *gob_destItemOrderVarPtr; -extern int32 *gob_destItemNoTickVarPtr; -extern int32 *gob_destItemTypeVarPtr; -extern int32 *gob_destItemMaxTickVarPtr; -extern int32 *gob_destItemTickVarPtr; -extern int32 *gob_destItemActStartStVarPtr; -extern int32 *gob_destItemLookDirVarPtr; -extern int32 *gob_destItemPickableVarPtr; -extern int32 *gob_destItemRelaxVarPtr; -extern int32 *gob_destItemMaxFrameVarPtr; - -extern int16 gob_destItemType; -extern int16 gob_destItemState; -extern int16 gob_itemToObject[20]; -extern Gob_Object *gob_objects[20]; -extern int16 gob_objCount; -extern int16 gob_gobsCount; -extern int16 gob_itemIndInPocket; -extern int16 gob_itemIdInPocket; -extern char gob_itemByteFlag; -extern int16 gob_destItemId; -extern int16 gob_destActionItem; -extern Gob_Object *gob_actDestItemDesc; -extern int16 gob_forceNextState[10]; -extern char gob_boreCounter; -extern int16 gob_positionedGob; -extern char gob_noPick; - -// Functions -char gob_rotateState(int16 from, int16 to); -void gob_playSound(Snd_SoundDesc * snd, int16 repCount, int16 freq); -void gob_drawObjects(void); -void gob_animateObjects(void); -void gob_placeObject(Gob_Object * objDesc, char animated); -int16 gob_getObjMaxFrame(Gob_Object * obj); -int16 gob_objIntersected(Gob_Object * obj1, Gob_Object * obj2); -void gob_setMultStates(Gob_Object * gobDesc); -int16 gob_nextLayer(Gob_Object * gobDesc); -void gob_showBoredom(int16 gobIndex); -void gob_switchGoblin(int16 index); -void gob_freeObjects(void); -void gob_zeroObjects(void); -void gob_freeAllObjects(void); -void gob_loadObjects(char *source); -void gob_initVarPointers(void); -void gob_saveGobDataToVars(int16 xPos, int16 yPos, int16 someVal); -void gob_loadGobDataFromVars(void); -void gob_pickItem(int16 indexToPocket, int16 idToPocket); -void gob_placeItem(int16 indexInPocket, int16 idInPocket); -void gob_swapItems(int16 indexToPick, int16 idToPick); -void gob_treatItemPick(int16 itemId); -int16 gob_treatItem(int16 action); -void gob_interFunc(void); + Util::List *objList; + Gob_Object *goblins[4]; + int16 currentGoblin; + Snd::SoundDesc *soundData[16]; + int16 gobStateLayer; + char goesAtTarget; + char readyToAct; + int16 gobAction; // 0 - move, 3 - do action, 4 - pick + // goblins 0 - picker, 1 - fighter, 2 - mage + Gob_Pos gobPositions[3]; + int16 gobDestX; + int16 gobDestY; + int16 pressedMapX; + int16 pressedMapY; + char pathExistence; + + // Pointers to interpreter variables + int32 *some0ValPtr; + + int32 *gobRetVarPtr; + int32 *curGobVarPtr; + int32 *curGobXPosVarPtr; + int32 *curGobYPosVarPtr; + int32 *itemInPocketVarPtr; + + int32 *curGobStateVarPtr; + int32 *curGobFrameVarPtr; + int32 *curGobMultStateVarPtr; + int32 *curGobNextStateVarPtr; + int32 *curGobScrXVarPtr; + int32 *curGobScrYVarPtr; + int32 *curGobLeftVarPtr; + int32 *curGobTopVarPtr; + int32 *curGobRightVarPtr; + int32 *curGobBottomVarPtr; + int32 *curGobDoAnimVarPtr; + int32 *curGobOrderVarPtr; + int32 *curGobNoTickVarPtr; + int32 *curGobTypeVarPtr; + int32 *curGobMaxTickVarPtr; + int32 *curGobTickVarPtr; + int32 *curGobActStartStateVarPtr; + int32 *curGobLookDirVarPtr; + int32 *curGobPickableVarPtr; + int32 *curGobRelaxVarPtr; + int32 *curGobMaxFrameVarPtr; + + int32 *destItemStateVarPtr; + int32 *destItemFrameVarPtr; + int32 *destItemMultStateVarPtr; + int32 *destItemNextStateVarPtr; + int32 *destItemScrXVarPtr; + int32 *destItemScrYVarPtr; + int32 *destItemLeftVarPtr; + int32 *destItemTopVarPtr; + int32 *destItemRightVarPtr; + int32 *destItemBottomVarPtr; + int32 *destItemDoAnimVarPtr; + int32 *destItemOrderVarPtr; + int32 *destItemNoTickVarPtr; + int32 *destItemTypeVarPtr; + int32 *destItemMaxTickVarPtr; + int32 *destItemTickVarPtr; + int32 *destItemActStartStVarPtr; + int32 *destItemLookDirVarPtr; + int32 *destItemPickableVarPtr; + int32 *destItemRelaxVarPtr; + int32 *destItemMaxFrameVarPtr; + + int16 destItemType; + int16 destItemState; + int16 itemToObject[20]; + Gob_Object *objects[20]; + int16 objCount; + int16 gobsCount; + int16 itemIndInPocket; + int16 itemIdInPocket; + char itemByteFlag; + int16 destItemId; + int16 destActionItem; + Gob_Object *actDestItemDesc; + int16 forceNextState[10]; + char boreCounter; + int16 positionedGob; + char noPick; + + // Functions + char rotateState(int16 from, int16 to); + void playSound(Snd::SoundDesc * snd, int16 repCount, int16 freq); + void drawObjects(void); + void animateObjects(void); + void placeObject(Gob_Object * objDesc, char animated); + int16 getObjMaxFrame(Gob_Object * obj); + int16 objIntersected(Gob_Object * obj1, Gob_Object * obj2); + void setMultStates(Gob_Object * gobDesc); + int16 nextLayer(Gob_Object * gobDesc); + void showBoredom(int16 gobIndex); + void switchGoblin(int16 index); + void freeObjects(void); + void zeroObjects(void); + void freeAllObjects(void); + void loadObjects(char *source); + void initVarPointers(void); + void saveGobDataToVars(int16 xPos, int16 yPos, int16 someVal); + void loadGobDataFromVars(void); + void pickItem(int16 indexToPocket, int16 idToPocket); + void placeItem(int16 indexInPocket, int16 idInPocket); + void swapItems(int16 indexToPick, int16 idToPick); + void treatItemPick(int16 itemId); + int16 treatItem(int16 action); + void interFunc(void); + + Goblin(GobEngine *vm); + +protected: + int16 rotStates[4][4]; + GobEngine *_vm; + + int16 peekGoblin(Gob_Object *curGob); + void initList(void); + void sortByOrder(Util::List *list); + void adjustDest(int16 posX, int16 posY); + void adjustTarget(void); + void targetDummyItem(Gob_Object *gobDesc); + void targetItem(void); + void initiateMove(void); + void moveFindItem(int16 posX, int16 posY); + void moveCheckSelect(int16 framesCount, Gob_Object * gobDesc, int16 *pGobIndex, int16 *nextAct); + void moveInitStep(int16 framesCount, int16 action, int16 cont, + Gob_Object *gobDesc, int16 *pGobIndex, int16 *pNextAct); + void moveTreatRopeStairs(Gob_Object *gobDesc); + void movePathFind(Gob_Object *gobDesc, int16 nextAct); + void moveAdvance(Gob_Object *gobDesc, int16 nextAct, int16 framesCount); + int16 doMove(Gob_Object *gobDesc, int16 cont, int16 action); +}; } // End of namespace Gob diff --git a/gob/init.cpp b/gob/init.cpp index 4e3367c393..f038b7ca51 100644 --- a/gob/init.cpp +++ b/gob/init.cpp @@ -36,102 +36,99 @@ namespace Gob { void game_start(void); -extern int16 debugFlag; -extern int16 inVM; -extern int16 colorCount; - -PalDesc *init_palDesc; - -static const char *init_fontNames[] = - { "jeulet1.let", "jeulet2.let", "jeucar1.let", "jeumath.let" }; - -void init_findBestCfg(void) { - videoMode = VIDMODE_VGA; - useMouse = mousePresent; - if (presentSound & BLASTER_FLAG) - soundFlags = BLASTER_FLAG | SPEAKER_FLAG | MIDI_FLAG; - else if (presentSound & PROAUDIO_FLAG) - soundFlags = PROAUDIO_FLAG | SPEAKER_FLAG | MIDI_FLAG; - else if (presentSound & ADLIB_FLAG) - soundFlags = ADLIB_FLAG | SPEAKER_FLAG | MIDI_FLAG; - else if (presentSound & INTERSOUND_FLAG) - soundFlags = INTERSOUND_FLAG | SPEAKER_FLAG; - else if (presentSound & SPEAKER_FLAG) - soundFlags = SPEAKER_FLAG; +const char *Init::fontNames[] = { "jeulet1.let", "jeulet2.let", "jeucar1.let", "jeumath.let" }; + +Init::Init(GobEngine *vm) : _vm(vm) { + palDesc = 0; +} + +void Init::findBestCfg(void) { + _vm->_global->videoMode = VIDMODE_VGA; + _vm->_global->useMouse = _vm->_global->mousePresent; + if (_vm->_global->presentSound & BLASTER_FLAG) + _vm->_global->soundFlags = BLASTER_FLAG | SPEAKER_FLAG | MIDI_FLAG; + else if (_vm->_global->presentSound & PROAUDIO_FLAG) + _vm->_global->soundFlags = PROAUDIO_FLAG | SPEAKER_FLAG | MIDI_FLAG; + else if (_vm->_global->presentSound & ADLIB_FLAG) + _vm->_global->soundFlags = ADLIB_FLAG | SPEAKER_FLAG | MIDI_FLAG; + else if (_vm->_global->presentSound & INTERSOUND_FLAG) + _vm->_global->soundFlags = INTERSOUND_FLAG | SPEAKER_FLAG; + else if (_vm->_global->presentSound & SPEAKER_FLAG) + _vm->_global->soundFlags = SPEAKER_FLAG; else - soundFlags = 0; + _vm->_global->soundFlags = 0; } -void init_soundVideo(int32 smallHeap, int16 flag) { - if (videoMode != 0x13 && videoMode != 0) - error("init_soundVideo: Video mode 0x%x is not supported!", - videoMode); +void Init::soundVideo(int32 smallHeap, int16 flag) { + if (_vm->_global->videoMode != 0x13 && _vm->_global->videoMode != 0) + error("soundVideo: Video mode 0x%x is not supported!", + _vm->_global->videoMode); //if ((flag & 4) == 0) - // vid_findVideo(); + // _vm->_video->findVideo(); - mousePresent = 1; + _vm->_global->mousePresent = 1; - inVM = 0; + _vm->_global->inVM = 0; - presentSound = 0; // FIXME: sound is not supported yet + _vm->_global->presentSound = 0; // FIXME: sound is not supported yet - sprAllocated = 0; - timer_enableTimer(); + _vm->_global->sprAllocated = 0; + _vm->_gtimer->enableTimer(); - // snd_setResetTimerFlag(debugFlag); // TODO + // _vm->_snd->setResetTimerFlag(debugFlag); // TODO - if (videoMode == 0x13) - colorCount = 256; + if (_vm->_global->videoMode == 0x13) + _vm->_global->colorCount = 256; - pPaletteDesc = &paletteStruct; - pPaletteDesc->vgaPal = vgaPalette; - pPaletteDesc->unused1 = unusedPalette1; - pPaletteDesc->unused2 = unusedPalette2; - pPrimarySurfDesc = &primarySurfDesc; + _vm->_global->pPaletteDesc = &_vm->_global->paletteStruct; + _vm->_global->pPaletteDesc->vgaPal = _vm->_global->vgaPalette; + _vm->_global->pPaletteDesc->unused1 = _vm->_global->unusedPalette1; + _vm->_global->pPaletteDesc->unused2 = _vm->_global->unusedPalette2; + _vm->_global->pPrimarySurfDesc = &_vm->_global->primarySurfDesc; - if (videoMode != 0) - vid_initSurfDesc(videoMode, 320, 200, PRIMARY_SURFACE); + if (_vm->_global->videoMode != 0) + _vm->_video->initSurfDesc(_vm->_global->videoMode, 320, 200, PRIMARY_SURFACE); - if (soundFlags & MIDI_FLAG) { - soundFlags &= presentSound; - if (presentSound & ADLIB_FLAG) - soundFlags |= MIDI_FLAG; + if (_vm->_global->soundFlags & MIDI_FLAG) { + _vm->_global->soundFlags &= _vm->_global->presentSound; + if (_vm->_global->presentSound & ADLIB_FLAG) + _vm->_global->soundFlags |= MIDI_FLAG; } else { - soundFlags &= presentSound; + _vm->_global->soundFlags &= _vm->_global->presentSound; } } -void init_cleanup(void) { - if (debugFlag == 0) - timer_disableTimer(); +void Init::cleanup(void) { + if (_vm->_global->debugFlag == 0) + _vm->_gtimer->disableTimer(); - vid_freeDriver(); - if (curPrimaryDesc != 0) { - vid_freeSurfDesc(curPrimaryDesc); - vid_freeSurfDesc(allocatedPrimary); - allocatedPrimary = 0; - curPrimaryDesc = 0; + _vm->_video->freeDriver(); + if (_vm->_global->curPrimaryDesc != 0) { + _vm->_video->freeSurfDesc(_vm->_global->curPrimaryDesc); + _vm->_video->freeSurfDesc(_vm->_global->allocatedPrimary); + _vm->_global->allocatedPrimary = 0; + _vm->_global->curPrimaryDesc = 0; } - pPrimarySurfDesc = 0; - if (snd_cleanupFunc != 0 && snd_playingSound != 0) { - (*snd_cleanupFunc) (0); - snd_cleanupFunc = 0; + _vm->_global->pPrimarySurfDesc = 0; + if (_vm->_snd->cleanupFunc != 0 && _vm->_snd->playingSound != 0) { + (*_vm->_snd->cleanupFunc) (0); + _vm->_snd->cleanupFunc = 0; } - snd_speakerOff(); + _vm->_snd->speakerOff(); - data_closeDataFile(); + _vm->_dataio->closeDataFile(); - if (sprAllocated != 0) - error("init_cleanup: Error! Allocated sprites left: %d", - sprAllocated); + if (_vm->_global->sprAllocated != 0) + error("cleanup: Error! Allocated sprites left: %d", + _vm->_global->sprAllocated); - snd_stopSound(0); - keyboard_release(); + _vm->_snd->stopSound(0); + _vm->_util->keyboard_release(); g_system->quit(); } -void init_initGame(char *totName) { +void Init::initGame(char *totName) { int16 handle2; int16 i; int16 handle; @@ -154,58 +151,58 @@ numFromTot = word ptr -0Ah memAvail = dword ptr -6 memBlocks = word ptr -2*/ - disableVideoCfg = 0x11; - disableMouseCfg = 0x15; - init_soundVideo(1000, 1); + _vm->_global->disableVideoCfg = 0x11; + _vm->_global->disableMouseCfg = 0x15; + soundVideo(1000, 1); - handle2 = data_openData("intro.stk"); + handle2 = _vm->_dataio->openData("intro.stk"); if (handle2 >= 0) { - data_closeData(handle2); - data_openDataFile("intro.stk"); + _vm->_dataio->closeData(handle2); + _vm->_dataio->openDataFile("intro.stk"); } - util_initInput(); + _vm->_util->initInput(); - vid_setHandlers(); - vid_initPrimary(videoMode); - mouseXShift = 1; - mouseYShift = 1; + _vm->_video->setHandlers(); + _vm->_video->initPrimary(_vm->_global->videoMode); + _vm->_global->mouseXShift = 1; + _vm->_global->mouseYShift = 1; - game_totTextData = 0; - game_totFileData = 0; - game_totResourceTable = 0; - inter_variables = 0; - init_palDesc = (PalDesc *)malloc(12); + _vm->_game->totTextData = 0; + _vm->_game->totFileData = 0; + _vm->_game->totResourceTable = 0; + _vm->_global->inter_variables = 0; + palDesc = (Video::PalDesc *)malloc(12); - if (videoMode != 0x13) - error("init_initGame: Only 0x13 video mode is supported!"); + if (_vm->_global->videoMode != 0x13) + error("initGame: Only 0x13 video mode is supported!"); - init_palDesc->vgaPal = draw_vgaPalette; - init_palDesc->unused1 = draw_unusedPalette1; - init_palDesc->unused2 = draw_unusedPalette2; - vid_setFullPalette(init_palDesc); + palDesc->vgaPal = _vm->_draw->vgaPalette; + palDesc->unused1 = _vm->_draw->unusedPalette1; + palDesc->unused2 = _vm->_draw->unusedPalette2; + _vm->_video->setFullPalette(palDesc); for (i = 0; i < 4; i++) - draw_fonts[i] = 0; + _vm->_draw->fonts[i] = 0; - handle = data_openData("intro.inf"); + handle = _vm->_dataio->openData("intro.inf"); if (handle < 0) { for (i = 0; i < 4; i++) { - handle2 = data_openData(init_fontNames[i]); + handle2 = _vm->_dataio->openData(fontNames[i]); if (handle2 >= 0) { - data_closeData(handle2); - draw_fonts[i] = - util_loadFont(init_fontNames[i]); + _vm->_dataio->closeData(handle2); + _vm->_draw->fonts[i] = + _vm->_util->loadFont(fontNames[i]); } } } else { - data_closeData(handle); + _vm->_dataio->closeData(handle); - infPtr = data_getData("intro.inf"); + infPtr = _vm->_dataio->getData("intro.inf"); infBuf = infPtr; - infEnd = infBuf + data_getDataSize("intro.inf"); + infEnd = infBuf + _vm->_dataio->getDataSize("intro.inf"); for (i = 0; i < 4; i++, infPtr++) { for (j = 0; *infPtr >= ' ' && infPtr != infEnd; @@ -214,10 +211,10 @@ memBlocks = word ptr -2*/ buffer[j] = 0; strcat(buffer, ".let"); - handle2 = data_openData(buffer); + handle2 = _vm->_dataio->openData(buffer); if (handle2 >= 0) { - data_closeData(handle2); - draw_fonts[i] = util_loadFont(buffer); + _vm->_dataio->closeData(handle2); + _vm->_draw->fonts[i] = _vm->_util->loadFont(buffer); } if (infPtr == infEnd) @@ -238,42 +235,42 @@ memBlocks = word ptr -2*/ strcpy(buffer, "intro.tot"); } - handle = data_openData(buffer); + handle = _vm->_dataio->openData(buffer); if (handle >= 0) { // Get variables count - data_seekData(handle, 0x2c, SEEK_SET); - data_readData(handle, (char *)&varsCount, 4); + _vm->_dataio->seekData(handle, 0x2c, SEEK_SET); + _vm->_dataio->readData(handle, (char *)&varsCount, 4); varsCount = FROM_LE_32(varsCount); - data_closeData(handle); + _vm->_dataio->closeData(handle); - inter_variables = (char *)malloc(varsCount * 4); - memset(inter_variables, 0, varsCount * 4); + _vm->_global->inter_variables = (char *)malloc(varsCount * 4); + memset(_vm->_global->inter_variables, 0, varsCount * 4); - strcpy(game_curTotFile, buffer); + strcpy(_vm->_game->curTotFile, buffer); - cd_testCD(1, "GOB"); - cd_readLIC("gob.lic"); - game_start(); + _vm->_cdrom->testCD(1, "GOB"); + _vm->_cdrom->readLIC("gob.lic"); + _vm->_game->start(); - cd_stopPlaying(); - cd_freeLICbuffer(); + _vm->_cdrom->stopPlaying(); + _vm->_cdrom->freeLICbuffer(); - free(inter_variables); - free(game_totFileData); - free(game_totTextData); - free(game_totResourceTable); + free(_vm->_global->inter_variables); + free(_vm->_game->totFileData); + free(_vm->_game->totTextData); + free(_vm->_game->totResourceTable); } for (i = 0; i < 4; i++) { - if (draw_fonts[i] != 0) - util_freeFont(draw_fonts[i]); + if (_vm->_draw->fonts[i] != 0) + _vm->_util->freeFont(_vm->_draw->fonts[i]); } - free(init_palDesc); - data_closeDataFile(); - vid_initPrimary(-1); - init_cleanup(); + free(palDesc); + _vm->_dataio->closeDataFile(); + _vm->_video->initPrimary(-1); + cleanup(); } } // End of namespace Gob diff --git a/gob/init.h b/gob/init.h index a54c5d064f..964ea0f582 100644 --- a/gob/init.h +++ b/gob/init.h @@ -24,10 +24,22 @@ namespace Gob { -void init_findBestCfg(void); -void init_soundVideo(int32 smallHeapSize, int16 flag); +class Init { +public: + void findBestCfg(void); + void soundVideo(int32 smallHeapSize, int16 flag); -void init_initGame(char *totFile); + void initGame(char *totFile); + + Init(GobEngine *vm); + +protected: + Video::PalDesc *palDesc; + static const char *fontNames[4]; + GobEngine *_vm; + + void cleanup(void); +}; } // End of namespace Gob diff --git a/gob/inter.cpp b/gob/inter.cpp index d4022542bb..50c063cff2 100644 --- a/gob/inter.cpp +++ b/gob/inter.cpp @@ -33,42 +33,44 @@ namespace Gob { -int16 inter_animPalLowIndex; -int16 inter_animPalHighIndex; -int16 inter_animPalDir; -uint32 inter_soundEndTimeKey; -int16 inter_soundStopVal; -char inter_terminate = 0; -char inter_breakFlag = 0; -int16 *inter_breakFromLevel; -int16 *inter_nestLevel; - -int16 inter_load16(void) { - int16 tmp = (int16)READ_LE_UINT16(inter_execPtr); - inter_execPtr += 2; +Inter::Inter(GobEngine *vm) : _vm(vm) { + terminate = 0; + breakFlag = 0; + animPalLowIndex = 0; + animPalHighIndex = 0; + animPalDir = 0; + soundEndTimeKey = 0; + soundStopVal = 0; + breakFromLevel = 0; + nestLevel = 0; +} + +int16 Inter::load16(void) { + int16 tmp = (int16)READ_LE_UINT16(_vm->_global->inter_execPtr); + _vm->_global->inter_execPtr += 2; return tmp; } -void inter_setMousePos(void) { - inter_mouseX = parse_parseValExpr(); - inter_mouseY = parse_parseValExpr(); - if (useMouse != 0) - util_setMousePos(inter_mouseX, inter_mouseY); +void Inter::setMousePos(void) { + _vm->_global->inter_mouseX = _vm->_parse->parseValExpr(); + _vm->_global->inter_mouseY = _vm->_parse->parseValExpr(); + if (_vm->_global->useMouse != 0) + _vm->_util->setMousePos(_vm->_global->inter_mouseX, _vm->_global->inter_mouseY); } -char inter_evalExpr(int16 *pRes) { +char Inter::evalExpr(int16 *pRes) { byte token; // - parse_printExpr(99); + _vm->_parse->printExpr(99); - parse_parseExpr(99, &token); + _vm->_parse->parseExpr(99, &token); if (pRes == 0) return token; switch (token) { case 20: - *pRes = inter_resVal; + *pRes = _vm->_global->inter_resVal; break; case 22: @@ -83,291 +85,291 @@ char inter_evalExpr(int16 *pRes) { return token; } -char inter_evalBoolResult() { +char Inter::evalBoolResult() { byte token; - parse_printExpr(99); + _vm->_parse->printExpr(99); - parse_parseExpr(99, &token); - if (token == 24 || (token == 20 && inter_resVal != 0)) + _vm->_parse->parseExpr(99, &token); + if (token == 24 || (token == 20 && _vm->_global->inter_resVal != 0)) return 1; else return 0; } -void inter_evaluateStore(void) { +void Inter::evaluateStore(void) { char *savedPos; int16 token; int16 result; int16 varOff; - savedPos = inter_execPtr; - varOff = parse_parseVarIndex(); - token = inter_evalExpr(&result); + savedPos = _vm->_global->inter_execPtr; + varOff = _vm->_parse->parseVarIndex(); + token = evalExpr(&result); switch (savedPos[0]) { case 23: case 26: - WRITE_VAR_OFFSET(varOff, inter_resVal); + WRITE_VAR_OFFSET(varOff, _vm->_global->inter_resVal); break; case 25: case 28: if (token == 20) - *(inter_variables + varOff) = result; + *(_vm->_global->inter_variables + varOff) = result; else - strcpy(inter_variables + varOff, inter_resStr); + strcpy(_vm->_global->inter_variables + varOff, _vm->_global->inter_resStr); break; } return; } -void inter_capturePush(void) { +void Inter::capturePush(void) { int16 left; int16 top; int16 width; int16 height; - left = parse_parseValExpr(); - top = parse_parseValExpr(); - width = parse_parseValExpr(); - height = parse_parseValExpr(); - game_capturePush(left, top, width, height); - (*scen_pCaptureCounter)++; + left = _vm->_parse->parseValExpr(); + top = _vm->_parse->parseValExpr(); + width = _vm->_parse->parseValExpr(); + height = _vm->_parse->parseValExpr(); + _vm->_game->capturePush(left, top, width, height); + (*_vm->_scenery->pCaptureCounter)++; } -void inter_capturePop(void) { - if (*scen_pCaptureCounter != 0) { - (*scen_pCaptureCounter)--; - game_capturePop(1); +void Inter::capturePop(void) { + if (*_vm->_scenery->pCaptureCounter != 0) { + (*_vm->_scenery->pCaptureCounter)--; + _vm->_game->capturePop(1); } } -void inter_printText(void) { +void Inter::printText(void) { char buf[60]; int16 i; - debug(3, "inter_printText"); - draw_destSpriteX = parse_parseValExpr(); - draw_destSpriteY = parse_parseValExpr(); + debug(3, "printText"); + _vm->_draw->destSpriteX = _vm->_parse->parseValExpr(); + _vm->_draw->destSpriteY = _vm->_parse->parseValExpr(); - draw_backColor = parse_parseValExpr(); - draw_frontColor = parse_parseValExpr(); - draw_fontIndex = parse_parseValExpr(); - draw_destSurface = 21; - draw_textToPrint = buf; - draw_transparency = 0; + _vm->_draw->backColor = _vm->_parse->parseValExpr(); + _vm->_draw->frontColor = _vm->_parse->parseValExpr(); + _vm->_draw->fontIndex = _vm->_parse->parseValExpr(); + _vm->_draw->destSurface = 21; + _vm->_draw->textToPrint = buf; + _vm->_draw->transparency = 0; - if (draw_backColor >= 16) { - draw_backColor = 0; - draw_transparency = 1; + if (_vm->_draw->backColor >= 16) { + _vm->_draw->backColor = 0; + _vm->_draw->transparency = 1; } do { - for (i = 0; *inter_execPtr != '.' && (byte)*inter_execPtr != 200; - i++, inter_execPtr++) { - buf[i] = *inter_execPtr; + for (i = 0; *_vm->_global->inter_execPtr != '.' && (byte)*_vm->_global->inter_execPtr != 200; + i++, _vm->_global->inter_execPtr++) { + buf[i] = *_vm->_global->inter_execPtr; } - if ((byte)*inter_execPtr != 200) { - inter_execPtr++; - switch (*inter_execPtr) { + if ((byte)*_vm->_global->inter_execPtr != 200) { + _vm->_global->inter_execPtr++; + switch (*_vm->_global->inter_execPtr) { case 23: case 26: - sprintf(buf + i, "%d", VAR_OFFSET(parse_parseVarIndex())); + sprintf(buf + i, "%d", VAR_OFFSET(_vm->_parse->parseVarIndex())); break; case 25: case 28: - sprintf(buf + i, "%s", inter_variables + parse_parseVarIndex()); + sprintf(buf + i, "%s", _vm->_global->inter_variables + _vm->_parse->parseVarIndex()); break; } - inter_execPtr++; + _vm->_global->inter_execPtr++; } else { buf[i] = 0; } - draw_spriteOperation(DRAW_PRINTTEXT); - } while ((byte)*inter_execPtr != 200); - inter_execPtr++; + _vm->_draw->spriteOperation(DRAW_PRINTTEXT); + } while ((byte)*_vm->_global->inter_execPtr != 200); + _vm->_global->inter_execPtr++; } -void inter_animPalette(void) { +void Inter::animPalette(void) { int16 i; - Color col; + Video::Color col; - if (inter_animPalDir == 0) + if (animPalDir == 0) return; - vid_waitRetrace(videoMode); + _vm->_video->waitRetrace(_vm->_global->videoMode); - if (inter_animPalDir == -1) { - col = draw_vgaSmallPalette[inter_animPalLowIndex]; + if (animPalDir == -1) { + col = _vm->_draw->vgaSmallPalette[animPalLowIndex]; - for (i = inter_animPalLowIndex; i < inter_animPalHighIndex; i++) - draw_vgaSmallPalette[i] = draw_vgaSmallPalette[i + 1]; + for (i = animPalLowIndex; i < animPalHighIndex; i++) + _vm->_draw->vgaSmallPalette[i] = _vm->_draw->vgaSmallPalette[i + 1]; - draw_vgaSmallPalette[inter_animPalHighIndex] = col; + _vm->_draw->vgaSmallPalette[animPalHighIndex] = col; } else { - col = draw_vgaSmallPalette[inter_animPalHighIndex]; - for (i = inter_animPalHighIndex; i > inter_animPalLowIndex; i--) - draw_vgaSmallPalette[i] = draw_vgaSmallPalette[i - 1]; + col = _vm->_draw->vgaSmallPalette[animPalHighIndex]; + for (i = animPalHighIndex; i > animPalLowIndex; i--) + _vm->_draw->vgaSmallPalette[i] = _vm->_draw->vgaSmallPalette[i - 1]; - draw_vgaSmallPalette[inter_animPalLowIndex] = col; + _vm->_draw->vgaSmallPalette[animPalLowIndex] = col; } - pPaletteDesc->vgaPal = draw_vgaSmallPalette; - vid_setFullPalette(pPaletteDesc); + _vm->_global->pPaletteDesc->vgaPal = _vm->_draw->vgaSmallPalette; + _vm->_video->setFullPalette(_vm->_global->pPaletteDesc); } -void inter_animPalInit(void) { - inter_animPalDir = inter_load16(); - inter_animPalLowIndex = parse_parseValExpr(); - inter_animPalHighIndex = parse_parseValExpr(); +void Inter::animPalInit(void) { + animPalDir = load16(); + animPalLowIndex = _vm->_parse->parseValExpr(); + animPalHighIndex = _vm->_parse->parseValExpr(); } -void inter_loadMult(void) { +void Inter::loadMult(void) { int16 resId; - resId = inter_load16(); - mult_loadMult(resId); + resId = load16(); + _vm->_mult->loadMult(resId); } -void inter_playMult(void) { +void Inter::playMult(void) { int16 checkEscape; - checkEscape = inter_load16(); - mult_playMult(VAR(57), -1, checkEscape, 0); + checkEscape = load16(); + _vm->_mult->playMult(VAR(57), -1, checkEscape, 0); } -void inter_freeMult(void) { - inter_load16(); // unused - mult_freeMultKeys(); +void Inter::freeMult(void) { + load16(); // unused + _vm->_mult->freeMultKeys(); } -void inter_initCursor(void) { +void Inter::initCursor(void) { int16 width; int16 height; int16 count; int16 i; - draw_cursorXDeltaVar = parse_parseVarIndex(); - draw_cursorYDeltaVar = parse_parseVarIndex(); + _vm->_draw->cursorXDeltaVar = _vm->_parse->parseVarIndex(); + _vm->_draw->cursorYDeltaVar = _vm->_parse->parseVarIndex(); - width = inter_load16(); + width = load16(); if (width < 16) width = 16; - height = inter_load16(); + height = load16(); if (height < 16) height = 16; - count = inter_load16(); + count = load16(); if (count < 2) count = 2; - if (width != draw_cursorWidth || height != draw_cursorHeight || - draw_cursorSprites->width != width * count) { + if (width != _vm->_draw->cursorWidth || height != _vm->_draw->cursorHeight || + _vm->_draw->cursorSprites->width != width * count) { - vid_freeSurfDesc(draw_cursorSprites); - vid_freeSurfDesc(draw_cursorBack); + _vm->_video->freeSurfDesc(_vm->_draw->cursorSprites); + _vm->_video->freeSurfDesc(_vm->_draw->cursorBack); - draw_cursorWidth = width; - draw_cursorHeight = height; + _vm->_draw->cursorWidth = width; + _vm->_draw->cursorHeight = height; if (count < 0x80) - draw_transparentCursor = 1; + _vm->_draw->transparentCursor = 1; else - draw_transparentCursor = 0; + _vm->_draw->transparentCursor = 0; if (count > 0x80) count -= 0x80; - draw_cursorSprites = - vid_initSurfDesc(videoMode, draw_cursorWidth * count, - draw_cursorHeight, 2); - draw_spritesArray[23] = draw_cursorSprites; + _vm->_draw->cursorSprites = + _vm->_video->initSurfDesc(_vm->_global->videoMode, _vm->_draw->cursorWidth * count, + _vm->_draw->cursorHeight, 2); + _vm->_draw->spritesArray[23] = _vm->_draw->cursorSprites; - draw_cursorBack = - vid_initSurfDesc(videoMode, draw_cursorWidth, - draw_cursorHeight, 0); + _vm->_draw->cursorBack = + _vm->_video->initSurfDesc(_vm->_global->videoMode, _vm->_draw->cursorWidth, + _vm->_draw->cursorHeight, 0); for (i = 0; i < 40; i++) { - draw_cursorAnimLow[i] = -1; - draw_cursorAnimDelays[i] = 0; - draw_cursorAnimHigh[i] = 0; + _vm->_draw->cursorAnimLow[i] = -1; + _vm->_draw->cursorAnimDelays[i] = 0; + _vm->_draw->cursorAnimHigh[i] = 0; } - draw_cursorAnimLow[1] = 0; + _vm->_draw->cursorAnimLow[1] = 0; } } -void inter_initCursorAnim(void) { +void Inter::initCursorAnim(void) { int16 ind; - ind = parse_parseValExpr(); - draw_cursorAnimLow[ind] = inter_load16(); - draw_cursorAnimHigh[ind] = inter_load16(); - draw_cursorAnimDelays[ind] = inter_load16(); + ind = _vm->_parse->parseValExpr(); + _vm->_draw->cursorAnimLow[ind] = load16(); + _vm->_draw->cursorAnimHigh[ind] = load16(); + _vm->_draw->cursorAnimDelays[ind] = load16(); } -void inter_clearCursorAnim(void) { +void Inter::clearCursorAnim(void) { int16 ind; - ind = parse_parseValExpr(); - draw_cursorAnimLow[ind] = -1; - draw_cursorAnimHigh[ind] = 0; - draw_cursorAnimDelays[ind] = 0; + ind = _vm->_parse->parseValExpr(); + _vm->_draw->cursorAnimLow[ind] = -1; + _vm->_draw->cursorAnimHigh[ind] = 0; + _vm->_draw->cursorAnimDelays[ind] = 0; } -void inter_drawOperations(void) { +void Inter::drawOperations(void) { byte cmd; int16 i; - cmd = *inter_execPtr++; + cmd = *_vm->_global->inter_execPtr++; - debug(4, "inter_drawOperations(%d)", cmd); + debug(4, "drawOperations(%d)", cmd); switch (cmd) { case 0: - inter_loadMult(); + loadMult(); break; case 1: - inter_playMult(); + playMult(); break; case 2: - inter_freeMult(); + freeMult(); break; case 7: - inter_initCursor(); + initCursor(); break; case 8: - inter_initCursorAnim(); + initCursorAnim(); break; case 9: - inter_clearCursorAnim(); + clearCursorAnim(); break; case 10: - draw_renderFlags = parse_parseValExpr(); + _vm->_draw->renderFlags = _vm->_parse->parseValExpr(); break; case 11: - //word_23EC_DE = parse_parseValExpr(); + //word_23EC_DE = _vm->_parse->parseValExpr(); break; case 16: - scen_loadAnim(0); + _vm->_scenery->loadAnim(0); break; case 17: - scen_freeAnim(-1); + _vm->_scenery->freeAnim(-1); break; case 18: - scen_interUpdateAnim(); + _vm->_scenery->interUpdateAnim(); break; case 19: @@ -375,50 +377,50 @@ void inter_drawOperations(void) { break; case 20: - mult_interInitMult(); + _vm->_mult->interInitMult(); break; case 21: - mult_freeMult(); + _vm->_mult->freeMult(); break; case 22: - mult_animate(); + _vm->_mult->animate(); break; case 23: - mult_interLoadMult(); + _vm->_mult->interLoadMult(); break; case 24: - scen_interStoreParams(); + _vm->_scenery->interStoreParams(); break; case 25: - mult_interGetObjAnimSize(); + _vm->_mult->interGetObjAnimSize(); break; case 26: - scen_loadStatic(0); + _vm->_scenery->loadStatic(0); break; case 27: - scen_freeStatic(-1); + _vm->_scenery->freeStatic(-1); break; case 28: - scen_interRenderStatic(); + _vm->_scenery->interRenderStatic(); break; case 29: - scen_interLoadCurLayer(); + _vm->_scenery->interLoadCurLayer(); break; case 32: if (_vm->_features & GF_GOB1) { // Used in gob1 CD - inter_evalExpr(0); - cd_startTrack(inter_resStr); + evalExpr(0); + _vm->_cdrom->startTrack(_vm->_global->inter_resStr); } else { } break; @@ -431,9 +433,9 @@ void inter_drawOperations(void) { // This is a very nasty thing to do, so let's add a // short delay here. It's probably a safe thing to do. - util_longDelay(1); + _vm->_util->longDelay(1); - int pos = cd_getTrackPos(); + int pos = _vm->_cdrom->getTrackPos(); if (pos == -1) pos = 32767; WRITE_VAR(5, pos); @@ -444,7 +446,7 @@ void inter_drawOperations(void) { case 34: if (_vm->_features & GF_GOB1) { // Used in gob1 CD - cd_stopPlaying(); + _vm->_cdrom->stopPlaying(); } else { } break; @@ -465,19 +467,19 @@ void inter_drawOperations(void) { break; case 48: - i = inter_load16(); - draw_fontToSprite[i].sprite = inter_load16(); - draw_fontToSprite[i].base = inter_load16(); - draw_fontToSprite[i].width = inter_load16(); - draw_fontToSprite[i].height = inter_load16(); + i = load16(); + _vm->_draw->fontToSprite[i].sprite = load16(); + _vm->_draw->fontToSprite[i].base = load16(); + _vm->_draw->fontToSprite[i].width = load16(); + _vm->_draw->fontToSprite[i].height = load16(); break; case 49: - i = inter_load16(); - draw_fontToSprite[i].sprite = -1; - draw_fontToSprite[i].base = -1; - draw_fontToSprite[i].width = -1; - draw_fontToSprite[i].height = -1; + i = load16(); + _vm->_draw->fontToSprite[i].sprite = -1; + _vm->_draw->fontToSprite[i].base = -1; + _vm->_draw->fontToSprite[i].width = -1; + _vm->_draw->fontToSprite[i].height = -1; break; case 64: @@ -585,309 +587,309 @@ void inter_drawOperations(void) { } } -void inter_getFreeMem(void) { +void Inter::getFreeMem(void) { int16 freeVar; int16 maxFreeVar; - freeVar = parse_parseVarIndex(); - maxFreeVar = parse_parseVarIndex(); + freeVar = _vm->_parse->parseVarIndex(); + maxFreeVar = _vm->_parse->parseVarIndex(); // HACK WRITE_VAR_OFFSET(freeVar, 1000000); WRITE_VAR_OFFSET(maxFreeVar, 1000000); } -void inter_manageDataFile(void) { - inter_evalExpr(0); +void Inter::manageDataFile(void) { + evalExpr(0); - if (inter_resStr[0] != 0) - data_openDataFile(inter_resStr); + if (_vm->_global->inter_resStr[0] != 0) + _vm->_dataio->openDataFile(_vm->_global->inter_resStr); else - data_closeDataFile(); + _vm->_dataio->closeDataFile(); } -void inter_writeData(void) { +void Inter::writeData(void) { int16 offset; int16 handle; int16 size; int16 dataVar; int16 retSize; - debug(4, "inter_writeData"); - inter_evalExpr(0); - dataVar = parse_parseVarIndex(); - size = parse_parseValExpr(); - offset = parse_parseValExpr(); + debug(4, "writeData"); + evalExpr(0); + dataVar = _vm->_parse->parseVarIndex(); + size = _vm->_parse->parseValExpr(); + offset = _vm->_parse->parseValExpr(); WRITE_VAR(1, 1); - handle = data_openData(inter_resStr, Common::File::kFileWriteMode); + handle = _vm->_dataio->openData(_vm->_global->inter_resStr, Common::File::kFileWriteMode); if (handle < 0) return; if (offset < 0) { - data_seekData(handle, -offset - 1, 2); + _vm->_dataio->seekData(handle, -offset - 1, 2); } else { - data_seekData(handle, offset, 0); + _vm->_dataio->seekData(handle, offset, 0); } - retSize = file_getHandle(handle)->write(inter_variables + dataVar, size); + retSize = _vm->_dataio->file_getHandle(handle)->write(_vm->_global->inter_variables + dataVar, size); if (retSize == size) WRITE_VAR(1, 0); - data_closeData(handle); + _vm->_dataio->closeData(handle); } -void inter_checkData(void) { +void Inter::checkData(void) { int16 handle; int16 varOff; - debug(4, "data_cheackData"); - inter_evalExpr(0); - varOff = parse_parseVarIndex(); - handle = data_openData(inter_resStr); + debug(4, "_vm->_dataio->cheackData"); + evalExpr(0); + varOff = _vm->_parse->parseVarIndex(); + handle = _vm->_dataio->openData(_vm->_global->inter_resStr); WRITE_VAR_OFFSET(varOff, handle); if (handle >= 0) - data_closeData(handle); + _vm->_dataio->closeData(handle); } -void inter_readData(void) { +void Inter::readData(void) { int16 retSize; int16 size; int16 dataVar; int16 offset; int16 handle; - debug(4, "inter_readData"); - inter_evalExpr(0); - dataVar = parse_parseVarIndex(); - size = parse_parseValExpr(); - offset = parse_parseValExpr(); + debug(4, "readData"); + evalExpr(0); + dataVar = _vm->_parse->parseVarIndex(); + size = _vm->_parse->parseValExpr(); + offset = _vm->_parse->parseValExpr(); - if (game_extHandle >= 0) - data_closeData(game_extHandle); + if (_vm->_game->extHandle >= 0) + _vm->_dataio->closeData(_vm->_game->extHandle); WRITE_VAR(1, 1); - handle = data_openData(inter_resStr); + handle = _vm->_dataio->openData(_vm->_global->inter_resStr); if (handle >= 0) { - draw_animateCursor(4); + _vm->_draw->animateCursor(4); if (offset < 0) - data_seekData(handle, -offset - 1, 2); + _vm->_dataio->seekData(handle, -offset - 1, 2); else - data_seekData(handle, offset, 0); + _vm->_dataio->seekData(handle, offset, 0); - retSize = data_readData(handle, inter_variables + dataVar, size); - data_closeData(handle); + retSize = _vm->_dataio->readData(handle, _vm->_global->inter_variables + dataVar, size); + _vm->_dataio->closeData(handle); if (retSize == size) WRITE_VAR(1, 0); } - if (game_extHandle >= 0) - game_extHandle = data_openData(game_curExtFile); + if (_vm->_game->extHandle >= 0) + _vm->_game->extHandle = _vm->_dataio->openData(_vm->_game->curExtFile); } -void inter_loadFont(void) { +void Inter::loadFont(void) { int16 index; - debug(4, "inter_loadFont"); - inter_evalExpr(0); - index = inter_load16(); + debug(4, "loadFont"); + evalExpr(0); + index = load16(); - if (draw_fonts[index] != 0) - util_freeFont(draw_fonts[index]); + if (_vm->_draw->fonts[index] != 0) + _vm->_util->freeFont(_vm->_draw->fonts[index]); - draw_animateCursor(4); - if (game_extHandle >= 0) - data_closeData(game_extHandle); + _vm->_draw->animateCursor(4); + if (_vm->_game->extHandle >= 0) + _vm->_dataio->closeData(_vm->_game->extHandle); - draw_fonts[index] = util_loadFont(inter_resStr); + _vm->_draw->fonts[index] = _vm->_util->loadFont(_vm->_global->inter_resStr); - if (game_extHandle >= 0) - game_extHandle = data_openData(game_curExtFile); + if (_vm->_game->extHandle >= 0) + _vm->_game->extHandle = _vm->_dataio->openData(_vm->_game->curExtFile); } -void inter_freeFont(void) { +void Inter::freeFont(void) { int16 index; - index = inter_load16(); - if (draw_fonts[index] != 0) - util_freeFont(draw_fonts[index]); + index = load16(); + if (_vm->_draw->fonts[index] != 0) + _vm->_util->freeFont(_vm->_draw->fonts[index]); - draw_fonts[index] = 0; + _vm->_draw->fonts[index] = 0; } -void inter_prepareStr(void) { +void Inter::prepareStr(void) { int16 var; - var = parse_parseVarIndex(); - util_prepareStr(inter_variables + var); + var = _vm->_parse->parseVarIndex(); + _vm->_util->prepareStr(_vm->_global->inter_variables + var); } -void inter_insertStr(void) { +void Inter::insertStr(void) { int16 pos; int16 strVar; - strVar = parse_parseVarIndex(); - inter_evalExpr(0); - pos = parse_parseValExpr(); - util_insertStr(inter_resStr, inter_variables + strVar, pos); + strVar = _vm->_parse->parseVarIndex(); + evalExpr(0); + pos = _vm->_parse->parseValExpr(); + _vm->_util->insertStr(_vm->_global->inter_resStr, _vm->_global->inter_variables + strVar, pos); } -void inter_cutStr(void) { +void Inter::cutStr(void) { int16 var; int16 pos; int16 size; - var = parse_parseVarIndex(); - pos = parse_parseValExpr(); - size = parse_parseValExpr(); - util_cutFromStr(inter_variables + var, pos, size); + var = _vm->_parse->parseVarIndex(); + pos = _vm->_parse->parseValExpr(); + size = _vm->_parse->parseValExpr(); + _vm->_util->cutFromStr(_vm->_global->inter_variables + var, pos, size); } -void inter_strstr(void) { +void Inter::strstr(void) { int16 strVar; int16 resVar; int16 pos; - strVar = parse_parseVarIndex(); - inter_evalExpr(0); - resVar = parse_parseVarIndex(); + strVar = _vm->_parse->parseVarIndex(); + evalExpr(0); + resVar = _vm->_parse->parseVarIndex(); - pos = util_strstr(inter_resStr, inter_variables + strVar); + pos = _vm->_util->strstr(_vm->_global->inter_resStr, _vm->_global->inter_variables + strVar); WRITE_VAR_OFFSET(resVar, pos - 1); } -void inter_setFrameRate(void) { - util_setFrameRate(parse_parseValExpr()); +void Inter::setFrameRate(void) { + _vm->_util->setFrameRate(_vm->_parse->parseValExpr()); } -void inter_strlen(void) { +void Inter::istrlen(void) { int16 len; int16 var; - var = parse_parseVarIndex(); - len = strlen(inter_variables + var); - var = parse_parseVarIndex(); + var = _vm->_parse->parseVarIndex(); + len = strlen(_vm->_global->inter_variables + var); + var = _vm->_parse->parseVarIndex(); WRITE_VAR_OFFSET(var, len); } -void inter_strToLong(void) { +void Inter::strToLong(void) { char str[20]; int16 strVar; int16 destVar; int32 res; - strVar = parse_parseVarIndex(); - strcpy(str, inter_variables + strVar); + strVar = _vm->_parse->parseVarIndex(); + strcpy(str, _vm->_global->inter_variables + strVar); res = atol(str); - destVar = parse_parseVarIndex(); + destVar = _vm->_parse->parseVarIndex(); WRITE_VAR_OFFSET(destVar, res); } -void inter_invalidate(void) { - warning("inter_invalidate: 'bugged' function!"); - draw_destSurface = inter_load16(); - draw_destSpriteX = parse_parseValExpr(); - draw_destSpriteY = parse_parseValExpr(); - draw_spriteRight = parse_parseValExpr(); - draw_frontColor = parse_parseValExpr(); - draw_spriteOperation(DRAW_INVALIDATE); +void Inter::invalidate(void) { + warning("invalidate: 'bugged' function!"); + _vm->_draw->destSurface = load16(); + _vm->_draw->destSpriteX = _vm->_parse->parseValExpr(); + _vm->_draw->destSpriteY = _vm->_parse->parseValExpr(); + _vm->_draw->spriteRight = _vm->_parse->parseValExpr(); + _vm->_draw->frontColor = _vm->_parse->parseValExpr(); + _vm->_draw->spriteOperation(DRAW_INVALIDATE); } -void inter_loadSpriteContent(void) { - draw_spriteLeft = inter_load16(); - draw_destSurface = inter_load16(); - draw_transparency = inter_load16(); - draw_destSpriteX = 0; - draw_destSpriteY = 0; - draw_spriteOperation(DRAW_LOADSPRITE); +void Inter::loadSpriteContent(void) { + _vm->_draw->spriteLeft = load16(); + _vm->_draw->destSurface = load16(); + _vm->_draw->transparency = load16(); + _vm->_draw->destSpriteX = 0; + _vm->_draw->destSpriteY = 0; + _vm->_draw->spriteOperation(DRAW_LOADSPRITE); } -void inter_copySprite(void) { - draw_sourceSurface = inter_load16(); - draw_destSurface = inter_load16(); +void Inter::copySprite(void) { + _vm->_draw->sourceSurface = load16(); + _vm->_draw->destSurface = load16(); - draw_spriteLeft = parse_parseValExpr(); - draw_spriteTop = parse_parseValExpr(); - draw_spriteRight = parse_parseValExpr(); - draw_spriteBottom = parse_parseValExpr(); + _vm->_draw->spriteLeft = _vm->_parse->parseValExpr(); + _vm->_draw->spriteTop = _vm->_parse->parseValExpr(); + _vm->_draw->spriteRight = _vm->_parse->parseValExpr(); + _vm->_draw->spriteBottom = _vm->_parse->parseValExpr(); - draw_destSpriteX = parse_parseValExpr(); - draw_destSpriteY = parse_parseValExpr(); + _vm->_draw->destSpriteX = _vm->_parse->parseValExpr(); + _vm->_draw->destSpriteY = _vm->_parse->parseValExpr(); - draw_transparency = inter_load16(); - draw_spriteOperation(DRAW_BLITSURF); + _vm->_draw->transparency = load16(); + _vm->_draw->spriteOperation(DRAW_BLITSURF); } -void inter_putPixel(void) { - draw_destSurface = inter_load16(); +void Inter::putPixel(void) { + _vm->_draw->destSurface = load16(); - draw_destSpriteX = parse_parseValExpr(); - draw_destSpriteY = parse_parseValExpr(); - draw_frontColor = parse_parseValExpr(); - draw_spriteOperation(DRAW_PUTPIXEL); + _vm->_draw->destSpriteX = _vm->_parse->parseValExpr(); + _vm->_draw->destSpriteY = _vm->_parse->parseValExpr(); + _vm->_draw->frontColor = _vm->_parse->parseValExpr(); + _vm->_draw->spriteOperation(DRAW_PUTPIXEL); } -void inter_fillRect(void) { - draw_destSurface = inter_load16(); +void Inter::fillRect(void) { + _vm->_draw->destSurface = load16(); - draw_destSpriteX = parse_parseValExpr(); - draw_destSpriteY = parse_parseValExpr(); - draw_spriteRight = parse_parseValExpr(); - draw_spriteBottom = parse_parseValExpr(); + _vm->_draw->destSpriteX = _vm->_parse->parseValExpr(); + _vm->_draw->destSpriteY = _vm->_parse->parseValExpr(); + _vm->_draw->spriteRight = _vm->_parse->parseValExpr(); + _vm->_draw->spriteBottom = _vm->_parse->parseValExpr(); - draw_backColor = parse_parseValExpr(); - draw_spriteOperation(DRAW_FILLRECT); + _vm->_draw->backColor = _vm->_parse->parseValExpr(); + _vm->_draw->spriteOperation(DRAW_FILLRECT); } -void inter_drawLine(void) { - draw_destSurface = inter_load16(); +void Inter::drawLine(void) { + _vm->_draw->destSurface = load16(); - draw_destSpriteX = parse_parseValExpr(); - draw_destSpriteY = parse_parseValExpr(); - draw_spriteRight = parse_parseValExpr(); - draw_spriteBottom = parse_parseValExpr(); + _vm->_draw->destSpriteX = _vm->_parse->parseValExpr(); + _vm->_draw->destSpriteY = _vm->_parse->parseValExpr(); + _vm->_draw->spriteRight = _vm->_parse->parseValExpr(); + _vm->_draw->spriteBottom = _vm->_parse->parseValExpr(); - draw_frontColor = parse_parseValExpr(); - draw_spriteOperation(DRAW_DRAWLINE); + _vm->_draw->frontColor = _vm->_parse->parseValExpr(); + _vm->_draw->spriteOperation(DRAW_DRAWLINE); } -void inter_createSprite(void) { +void Inter::createSprite(void) { int16 index; int16 height; int16 width; int16 flag; - index = inter_load16(); - width = inter_load16(); - height = inter_load16(); + index = load16(); + width = load16(); + height = load16(); - flag = inter_load16(); + flag = load16(); if (flag == 1) - draw_spritesArray[index] = vid_initSurfDesc(videoMode, width, height, 2); + _vm->_draw->spritesArray[index] = _vm->_video->initSurfDesc(_vm->_global->videoMode, width, height, 2); else - draw_spritesArray[index] = vid_initSurfDesc(videoMode, width, height, 0); + _vm->_draw->spritesArray[index] = _vm->_video->initSurfDesc(_vm->_global->videoMode, width, height, 0); - vid_clearSurf(draw_spritesArray[index]); + _vm->_video->clearSurf(_vm->_draw->spritesArray[index]); } -void inter_freeSprite(void) { +void Inter::freeSprite(void) { int16 index; - index = inter_load16(); - if (draw_spritesArray[index] == 0) + index = load16(); + if (_vm->_draw->spritesArray[index] == 0) return; - vid_freeSurfDesc(draw_spritesArray[index]); - draw_spritesArray[index] = 0; + _vm->_video->freeSurfDesc(_vm->_draw->spritesArray[index]); + _vm->_draw->spritesArray[index] = 0; } -void inter_renewTimeInVars(void) { +void Inter::renewTimeInVars(void) { struct tm *t; time_t now = time(NULL); @@ -902,63 +904,63 @@ void inter_renewTimeInVars(void) { WRITE_VAR(11, t->tm_sec); } -void inter_playComposition(void) { - static int16 inter_composition[50]; +void Inter::playComposition(void) { + static int16 composition[50]; int16 i; int16 dataVar; int16 freqVal; - dataVar = parse_parseVarIndex(); - freqVal = parse_parseValExpr(); + dataVar = _vm->_parse->parseVarIndex(); + freqVal = _vm->_parse->parseValExpr(); for (i = 0; i < 50; i++) - inter_composition[i] = (int16)VAR_OFFSET(dataVar + i * 4); + composition[i] = (int16)VAR_OFFSET(dataVar + i * 4); - snd_playComposition(game_soundSamples, inter_composition, freqVal); + _vm->_snd->playComposition(_vm->_game->soundSamples, composition, freqVal); } -void inter_stopSound(void) { - snd_stopSound(parse_parseValExpr()); - inter_soundEndTimeKey = 0; +void Inter::stopSound(void) { + _vm->_snd->stopSound(_vm->_parse->parseValExpr()); + soundEndTimeKey = 0; } -void inter_playSound(void) { +void Inter::playSound(void) { int16 frequency; int16 freq2; int16 repCount; int16 index; - index = parse_parseValExpr(); - repCount = parse_parseValExpr(); - frequency = parse_parseValExpr(); + index = _vm->_parse->parseValExpr(); + repCount = _vm->_parse->parseValExpr(); + frequency = _vm->_parse->parseValExpr(); - snd_stopSound(0); - inter_soundEndTimeKey = 0; - if (game_soundSamples[index] == 0) + _vm->_snd->stopSound(0); + soundEndTimeKey = 0; + if (_vm->_game->soundSamples[index] == 0) return; if (repCount < 0) { - if (soundFlags < 2) + if (_vm->_global->soundFlags < 2) return; repCount = -repCount; - inter_soundEndTimeKey = util_getTimeKey(); + soundEndTimeKey = _vm->_util->getTimeKey(); if (frequency == 0) { - freq2 = game_soundSamples[index]->frequency; + freq2 = _vm->_game->soundSamples[index]->frequency; } else { freq2 = frequency; } - inter_soundStopVal = - (10 * (game_soundSamples[index]->size / 2)) / freq2; - inter_soundEndTimeKey += - ((game_soundSamples[index]->size * repCount - - game_soundSamples[index]->size / 2) * 1000) / freq2; + soundStopVal = + (10 * (_vm->_game->soundSamples[index]->size / 2)) / freq2; + soundEndTimeKey += + ((_vm->_game->soundSamples[index]->size * repCount - + _vm->_game->soundSamples[index]->size / 2) * 1000) / freq2; } - snd_playSample(game_soundSamples[index], repCount, frequency); + _vm->_snd->playSample(_vm->_game->soundSamples[index], repCount, frequency); } -void inter_loadCursor(void) { - Game_TotResItem *itemPtr; +void Inter::loadCursor(void) { + Game::TotResItem *itemPtr; int16 width; int16 height; int32 offset; @@ -966,78 +968,78 @@ void inter_loadCursor(void) { int16 id; int8 index; - id = inter_load16(); - index = *inter_execPtr++; - itemPtr = &game_totResourceTable->items[id]; + id = load16(); + index = *_vm->_global->inter_execPtr++; + itemPtr = &_vm->_game->totResourceTable->items[id]; offset = itemPtr->offset; if (offset >= 0) { dataBuf = - ((char *)game_totResourceTable) + szGame_TotResTable + - szGame_TotResItem * game_totResourceTable->itemsCount + offset; + ((char *)_vm->_game->totResourceTable) + szGame_TotResTable + + szGame_TotResItem * _vm->_game->totResourceTable->itemsCount + offset; } else { - dataBuf = game_imFileData + (int32)READ_LE_UINT32(&((int32 *)game_imFileData)[-offset - 1]); + dataBuf = _vm->_game->imFileData + (int32)READ_LE_UINT32(&((int32 *)_vm->_game->imFileData)[-offset - 1]); } width = itemPtr->width; height = itemPtr->height; - vid_fillRect(draw_cursorSprites, index * draw_cursorWidth, 0, - index * draw_cursorWidth + draw_cursorWidth - 1, - draw_cursorHeight - 1, 0); + _vm->_video->fillRect(_vm->_draw->cursorSprites, index * _vm->_draw->cursorWidth, 0, + index * _vm->_draw->cursorWidth + _vm->_draw->cursorWidth - 1, + _vm->_draw->cursorHeight - 1, 0); - vid_drawPackedSprite((byte*)dataBuf, width, height, - index * draw_cursorWidth, 0, 0, draw_cursorSprites); - draw_cursorAnimLow[index] = 0; + _vm->_video->drawPackedSprite((byte*)dataBuf, width, height, + index * _vm->_draw->cursorWidth, 0, 0, _vm->_draw->cursorSprites); + _vm->_draw->cursorAnimLow[index] = 0; } -void inter_loadSpriteToPos(void) { - debug(4, "inter_loadSpriteToPos"); - draw_spriteLeft = inter_load16(); +void Inter::loadSpriteToPos(void) { + debug(4, "loadSpriteToPos"); + _vm->_draw->spriteLeft = load16(); - draw_destSpriteX = parse_parseValExpr(); - draw_destSpriteY = parse_parseValExpr(); + _vm->_draw->destSpriteX = _vm->_parse->parseValExpr(); + _vm->_draw->destSpriteY = _vm->_parse->parseValExpr(); - draw_transparency = inter_execPtr[0]; - draw_destSurface = (inter_execPtr[0] / 2) - 1; + _vm->_draw->transparency = _vm->_global->inter_execPtr[0]; + _vm->_draw->destSurface = (_vm->_global->inter_execPtr[0] / 2) - 1; - if (draw_destSurface < 0) - draw_destSurface = 101; - draw_transparency &= 1; - inter_execPtr += 2; - draw_spriteOperation(DRAW_LOADSPRITE); + if (_vm->_draw->destSurface < 0) + _vm->_draw->destSurface = 101; + _vm->_draw->transparency &= 1; + _vm->_global->inter_execPtr += 2; + _vm->_draw->spriteOperation(DRAW_LOADSPRITE); } -void inter_loadTot(void) { +void Inter::loadTot(void) { char buf[20]; int8 size; int16 i; - debug(4, "inter_loadTot"); - if ((*inter_execPtr & 0x80) != 0) { - inter_execPtr++; - inter_evalExpr(0); - strcpy(buf, inter_resStr); + debug(4, "loadTot"); + if ((*_vm->_global->inter_execPtr & 0x80) != 0) { + _vm->_global->inter_execPtr++; + evalExpr(0); + strcpy(buf, _vm->_global->inter_resStr); } else { - size = *inter_execPtr++; + size = *_vm->_global->inter_execPtr++; for (i = 0; i < size; i++) - buf[i] = *inter_execPtr++; + buf[i] = *_vm->_global->inter_execPtr++; buf[size] = 0; } strcat(buf, ".tot"); - inter_terminate = 1; - strcpy(game_totToLoad, buf); + terminate = 1; + strcpy(_vm->_game->totToLoad, buf); } -void inter_storeKey(int16 key) { - WRITE_VAR(12, util_getTimeKey() - game_startTimeKey); +void Inter::storeKey(int16 key) { + WRITE_VAR(12, _vm->_util->getTimeKey() - _vm->_game->startTimeKey); - WRITE_VAR(2, inter_mouseX); - WRITE_VAR(3, inter_mouseY); - WRITE_VAR(4, game_mouseButtons); - WRITE_VAR(1, snd_playingSound); + WRITE_VAR(2, _vm->_global->inter_mouseX); + WRITE_VAR(3, _vm->_global->inter_mouseY); + WRITE_VAR(4, _vm->_game->mouseButtons); + WRITE_VAR(1, _vm->_snd->playingSound); if (key == 0x4800) key = 0x0b; @@ -1055,93 +1057,93 @@ void inter_storeKey(int16 key) { WRITE_VAR(0, key); if (key != 0) - util_waitKey(); + _vm->_util->waitKey(); } -void inter_keyFunc(void) { +void Inter::keyFunc(void) { int16 flag; int16 key; - debug(4, "inter_keyFunc"); - flag = inter_load16(); - inter_animPalette(); - draw_blitInvalidated(); + debug(4, "keyFunc"); + flag = load16(); + animPalette(); + _vm->_draw->blitInvalidated(); if (flag != 0) { if (flag != 1) { if (flag != 2) { - util_longDelay(flag); + _vm->_util->longDelay(flag); return; } key = 0; - if (pressedKeys[0x48]) + if (_vm->_global->pressedKeys[0x48]) key |= 1; - if (pressedKeys[0x50]) + if (_vm->_global->pressedKeys[0x50]) key |= 2; - if (pressedKeys[0x4d]) + if (_vm->_global->pressedKeys[0x4d]) key |= 4; - if (pressedKeys[0x4b]) + if (_vm->_global->pressedKeys[0x4b]) key |= 8; - if (pressedKeys[0x1c]) + if (_vm->_global->pressedKeys[0x1c]) key |= 0x10; - if (pressedKeys[0x39]) + if (_vm->_global->pressedKeys[0x39]) key |= 0x20; - if (pressedKeys[1]) + if (_vm->_global->pressedKeys[1]) key |= 0x40; - if (pressedKeys[0x1d]) + if (_vm->_global->pressedKeys[0x1d]) key |= 0x80; - if (pressedKeys[0x2a]) + if (_vm->_global->pressedKeys[0x2a]) key |= 0x100; - if (pressedKeys[0x36]) + if (_vm->_global->pressedKeys[0x36]) key |= 0x200; - if (pressedKeys[0x38]) + if (_vm->_global->pressedKeys[0x38]) key |= 0x400; - if (pressedKeys[0x3b]) + if (_vm->_global->pressedKeys[0x3b]) key |= 0x800; - if (pressedKeys[0x3c]) + if (_vm->_global->pressedKeys[0x3c]) key |= 0x1000; - if (pressedKeys[0x3d]) + if (_vm->_global->pressedKeys[0x3d]) key |= 0x2000; - if (pressedKeys[0x3e]) + if (_vm->_global->pressedKeys[0x3e]) key |= 0x4000; WRITE_VAR(0, key); - util_waitKey(); + _vm->_util->waitKey(); return; } - key = game_checkKeys(&inter_mouseX, &inter_mouseY, &game_mouseButtons, 0); + key = _vm->_game->checkKeys(&_vm->_global->inter_mouseX, &_vm->_global->inter_mouseY, &_vm->_game->mouseButtons, 0); - inter_storeKey(key); + storeKey(key); return; } else { - key = game_checkCollisions(0, 0, 0, 0); - inter_storeKey(key); + key = _vm->_game->checkCollisions(0, 0, 0, 0); + storeKey(key); if (flag == 1) return; - util_waitKey(); + _vm->_util->waitKey(); } } -void inter_checkSwitchTable(char **ppExec) { +void Inter::checkSwitchTable(char **ppExec) { int16 i; int16 len; char found; @@ -1152,116 +1154,116 @@ void inter_checkSwitchTable(char **ppExec) { found = 0; notFound = 1; *ppExec = 0; - value = parse_parseVarIndex(); + value = _vm->_parse->parseVarIndex(); value = VAR_OFFSET(value); do { - len = *(int8*)inter_execPtr++; // must be a signed char typ and char is not default signed on all platforms. + len = *(int8*)_vm->_global->inter_execPtr++; // must be a signed char typ and char is not default signed on all platforms. if (len == -5) break; for (i = 0; i < len; i++) { - inter_evalExpr(0); + evalExpr(0); - if (inter_terminate != 0) + if (terminate != 0) return; - if (inter_resVal == value) { + if (_vm->_global->inter_resVal == value) { found = 1; notFound = 0; } } if (found != 0) - *ppExec = inter_execPtr; + *ppExec = _vm->_global->inter_execPtr; - inter_execPtr += READ_LE_UINT16(inter_execPtr + 2) + 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr + 2) + 2; found = 0; } while (len != -5); if (len != -5) - inter_execPtr++; + _vm->_global->inter_execPtr++; - defFlag = *inter_execPtr; + defFlag = *_vm->_global->inter_execPtr; defFlag >>= 4; if (defFlag != 4) return; - inter_execPtr++; + _vm->_global->inter_execPtr++; if (notFound) - *ppExec = inter_execPtr; + *ppExec = _vm->_global->inter_execPtr; - inter_execPtr += READ_LE_UINT16(inter_execPtr + 2) + 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr + 2) + 2; } -void inter_repeatUntil(void) { +void Inter::repeatUntil(void) { char *blockPtr; int16 size; char flag; - debug(4, "inter_repeatUntil"); - inter_nestLevel[0]++; - blockPtr = inter_execPtr; + debug(4, "repeatUntil"); + nestLevel[0]++; + blockPtr = _vm->_global->inter_execPtr; do { - inter_execPtr = blockPtr; - size = READ_LE_UINT16(inter_execPtr + 2) + 2; + _vm->_global->inter_execPtr = blockPtr; + size = READ_LE_UINT16(_vm->_global->inter_execPtr + 2) + 2; - inter_funcBlock(1); - inter_execPtr = blockPtr + size + 1; - flag = inter_evalBoolResult(); - } while (flag == 0 && inter_breakFlag == 0 && inter_terminate == 0); + funcBlock(1); + _vm->_global->inter_execPtr = blockPtr + size + 1; + flag = evalBoolResult(); + } while (flag == 0 && breakFlag == 0 && terminate == 0); - inter_nestLevel[0]--; + nestLevel[0]--; - if (*inter_breakFromLevel > -1) { - inter_breakFlag = 0; - *inter_breakFromLevel = -1; + if (*breakFromLevel > -1) { + breakFlag = 0; + *breakFromLevel = -1; } } -void inter_whileDo(void) { +void Inter::whileDo(void) { char *blockPtr; char *savedIP; char flag; int16 size; - debug(4, "inter_whileDo"); - inter_nestLevel[0]++; + debug(4, "whileDo"); + nestLevel[0]++; do { - savedIP = inter_execPtr; - flag = inter_evalBoolResult(); + savedIP = _vm->_global->inter_execPtr; + flag = evalBoolResult(); - if (inter_terminate != 0) + if (terminate != 0) return; - blockPtr = inter_execPtr; + blockPtr = _vm->_global->inter_execPtr; - size = READ_LE_UINT16(inter_execPtr + 2) + 2; + size = READ_LE_UINT16(_vm->_global->inter_execPtr + 2) + 2; if (flag != 0) { - inter_funcBlock(1); - inter_execPtr = savedIP; + funcBlock(1); + _vm->_global->inter_execPtr = savedIP; } else { - inter_execPtr += size; + _vm->_global->inter_execPtr += size; } - if (inter_breakFlag != 0 || inter_terminate != 0) { - inter_execPtr = blockPtr; - inter_execPtr += size; + if (breakFlag != 0 || terminate != 0) { + _vm->_global->inter_execPtr = blockPtr; + _vm->_global->inter_execPtr += size; break; } } while (flag != 0); - inter_nestLevel[0]--; - if (*inter_breakFromLevel > -1) { - inter_breakFlag = 0; - *inter_breakFromLevel = -1; + nestLevel[0]--; + if (*breakFromLevel > -1) { + breakFlag = 0; + *breakFromLevel = -1; } } -void inter_funcBlock(int16 retFlag) { +void Inter::funcBlock(int16 retFlag) { char cmdCount; int16 counter; byte cmd; @@ -1270,124 +1272,124 @@ void inter_funcBlock(int16 retFlag) { char *callAddr; char boolRes; - if (inter_execPtr == 0) + if (_vm->_global->inter_execPtr == 0) return; - inter_breakFlag = 0; - inter_execPtr++; - cmdCount = *inter_execPtr++; - inter_execPtr += 2; + breakFlag = 0; + _vm->_global->inter_execPtr++; + cmdCount = *_vm->_global->inter_execPtr++; + _vm->_global->inter_execPtr += 2; if (cmdCount == 0) { - inter_execPtr = 0; + _vm->_global->inter_execPtr = 0; return; } counter = 0; do { - if (inter_terminate != 0) + if (terminate != 0) break; - cmd = (byte)*inter_execPtr; + cmd = (byte)*_vm->_global->inter_execPtr; if ((cmd >> 4) >= 12) { cmd2 = 16 - (cmd >> 4); cmd &= 0xf; } else cmd2 = 0; - inter_execPtr++; + _vm->_global->inter_execPtr++; counter++; - debug(4, "inter_funcBlock(%d, %d)", cmd2, cmd); + debug(4, "funcBlock(%d, %d)", cmd2, cmd); switch (cmd2) { case 0: switch (cmd >> 4) { case 0: case 1: - storedIP = inter_execPtr; - inter_execPtr = (char *)game_totFileData + READ_LE_UINT16(inter_execPtr); + storedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = (char *)_vm->_game->totFileData + READ_LE_UINT16(_vm->_global->inter_execPtr); if (counter == cmdCount && retFlag == 2) return; - inter_callSub(2); - inter_execPtr = storedIP + 2; + callSub(2); + _vm->_global->inter_execPtr = storedIP + 2; break; case 2: - draw_printText(); + _vm->_draw->printText(); break; case 3: - inter_loadCursor(); + loadCursor(); break; case 5: - inter_checkSwitchTable(&callAddr); - storedIP = inter_execPtr; - inter_execPtr = callAddr; + checkSwitchTable(&callAddr); + storedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = callAddr; if (counter == cmdCount && retFlag == 2) return; - inter_funcBlock(0); - inter_execPtr = storedIP; + funcBlock(0); + _vm->_global->inter_execPtr = storedIP; break; case 6: - inter_repeatUntil(); + repeatUntil(); break; case 7: - inter_whileDo(); + whileDo(); break; case 8: - boolRes = inter_evalBoolResult(); + boolRes = evalBoolResult(); if (boolRes != 0) { if (counter == cmdCount && retFlag == 2) return; - storedIP = inter_execPtr; - inter_funcBlock(0); - inter_execPtr = storedIP; + storedIP = _vm->_global->inter_execPtr; + funcBlock(0); + _vm->_global->inter_execPtr = storedIP; - inter_execPtr += READ_LE_UINT16(inter_execPtr + 2) + 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr + 2) + 2; - debug(5, "cmd = %d", (int16)*inter_execPtr); - cmd = (byte)(*inter_execPtr) >> 4; - inter_execPtr++; + debug(5, "cmd = %d", (int16)*_vm->_global->inter_execPtr); + cmd = (byte)(*_vm->_global->inter_execPtr) >> 4; + _vm->_global->inter_execPtr++; if (cmd != 12) break; - inter_execPtr += READ_LE_UINT16(inter_execPtr + 2) + 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr + 2) + 2; } else { - inter_execPtr += READ_LE_UINT16(inter_execPtr + 2) + 2; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr + 2) + 2; - debug(5, "cmd = %d", (int16)*inter_execPtr); - cmd = (byte)(*inter_execPtr) >> 4; - inter_execPtr++; + debug(5, "cmd = %d", (int16)*_vm->_global->inter_execPtr); + cmd = (byte)(*_vm->_global->inter_execPtr) >> 4; + _vm->_global->inter_execPtr++; if (cmd != 12) break; if (counter == cmdCount && retFlag == 2) return; - storedIP = inter_execPtr; - inter_funcBlock(0); - inter_execPtr = storedIP; - inter_execPtr += READ_LE_UINT16(inter_execPtr + 2) + 2; + storedIP = _vm->_global->inter_execPtr; + funcBlock(0); + _vm->_global->inter_execPtr = storedIP; + _vm->_global->inter_execPtr += READ_LE_UINT16(_vm->_global->inter_execPtr + 2) + 2; } break; case 9: - inter_evaluateStore(); + evaluateStore(); break; case 10: - inter_loadSpriteToPos(); + loadSpriteToPos(); break; } break; @@ -1395,39 +1397,39 @@ void inter_funcBlock(int16 retFlag) { case 1: switch (cmd) { case 1: - inter_printText(); + printText(); break; case 2: - inter_loadTot(); + loadTot(); break; case 3: - draw_interPalLoad(); + _vm->_draw->interPalLoad(); break; case 4: - inter_keyFunc(); + keyFunc(); break; case 5: - inter_capturePush(); + capturePush(); break; case 6: - inter_capturePop(); + capturePop(); break; case 7: - inter_animPalInit(); + animPalInit(); break; case 14: - inter_drawOperations(); + drawOperations(); break; case 15: - cmdCount = *inter_execPtr++; + cmdCount = *_vm->_global->inter_execPtr++; counter = 0; break; } @@ -1438,37 +1440,37 @@ void inter_funcBlock(int16 retFlag) { switch (cmd) { case 0: if (retFlag != 2) - inter_breakFlag = 1; + breakFlag = 1; - inter_execPtr = 0; + _vm->_global->inter_execPtr = 0; return; case 1: - inter_renewTimeInVars(); + renewTimeInVars(); break; case 2: - snd_speakerOn(parse_parseValExpr(), -1); + _vm->_snd->speakerOn(_vm->_parse->parseValExpr(), -1); break; case 3: - snd_speakerOff(); + _vm->_snd->speakerOff(); break; case 4: - inter_putPixel(); + putPixel(); break; case 5: - gob_interFunc(); + _vm->_goblin->interFunc(); break; case 6: - inter_createSprite(); + createSprite(); break; case 7: - inter_freeSprite(); + freeSprite(); break; } break; @@ -1477,78 +1479,78 @@ void inter_funcBlock(int16 retFlag) { switch (cmd) { case 0: if (retFlag == 1) { - inter_breakFlag = 1; - inter_execPtr = 0; + breakFlag = 1; + _vm->_global->inter_execPtr = 0; return; } - if (*inter_nestLevel == 0) + if (*nestLevel == 0) break; - *inter_breakFromLevel = *inter_nestLevel; - inter_breakFlag = 1; - inter_execPtr = 0; + *breakFromLevel = *nestLevel; + breakFlag = 1; + _vm->_global->inter_execPtr = 0; return; case 1: - inter_loadSpriteContent(); + loadSpriteContent(); break; case 2: - inter_copySprite(); + copySprite(); break; case 3: - inter_fillRect(); + fillRect(); break; case 4: - inter_drawLine(); + drawLine(); break; case 5: - inter_strToLong(); + strToLong(); break; case 6: - inter_invalidate(); + invalidate(); break; case 7: - draw_backDeltaX = parse_parseValExpr(); - draw_backDeltaY = parse_parseValExpr(); + _vm->_draw->backDeltaX = _vm->_parse->parseValExpr(); + _vm->_draw->backDeltaY = _vm->_parse->parseValExpr(); break; case 8: - inter_playSound(); + playSound(); break; case 9: - inter_stopSound(); + stopSound(); break; case 10: - game_interLoadSound(-1); + _vm->_game->interLoadSound(-1); break; case 11: - game_freeSoundSlot(-1); + _vm->_game->freeSoundSlot(-1); break; case 12: - snd_waitEndPlay(); + _vm->_snd->waitEndPlay(); break; case 13: - inter_playComposition(); + playComposition(); break; case 14: - inter_getFreeMem(); + getFreeMem(); break; case 15: - inter_checkData(); + checkData(); break; } break; @@ -1557,112 +1559,112 @@ void inter_funcBlock(int16 retFlag) { switch (cmd) { case 1: - inter_prepareStr(); + prepareStr(); break; case 2: - inter_insertStr(); + insertStr(); break; case 3: - inter_cutStr(); + cutStr(); break; case 4: - inter_strstr(); + strstr(); break; case 5: - inter_strlen(); + istrlen(); break; case 6: - inter_setMousePos(); + setMousePos(); break; case 7: - inter_setFrameRate(); + setFrameRate(); break; case 8: - draw_blitInvalidated(); - util_waitEndFrame(); - inter_animPalette(); - inter_storeKey(game_checkKeys(&inter_mouseX, - &inter_mouseY, &game_mouseButtons, 0)); + _vm->_draw->blitInvalidated(); + _vm->_util->waitEndFrame(); + animPalette(); + storeKey(_vm->_game->checkKeys(&_vm->_global->inter_mouseX, + &_vm->_global->inter_mouseY, &_vm->_game->mouseButtons, 0)); break; case 9: - draw_animateCursor(1); + _vm->_draw->animateCursor(1); break; case 10: - draw_blitCursor(); + _vm->_draw->blitCursor(); break; case 11: - inter_loadFont(); + loadFont(); break; case 12: - inter_freeFont(); + freeFont(); break; case 13: - inter_readData(); + readData(); break; case 14: - inter_writeData(); + writeData(); break; case 15: - inter_manageDataFile(); + manageDataFile(); break; } break; } - if (inter_breakFlag != 0) { + if (breakFlag != 0) { if (retFlag != 2) break; - if (*inter_breakFromLevel == -1) - inter_breakFlag = 0; + if (*breakFromLevel == -1) + breakFlag = 0; break; } } while (counter != cmdCount); - inter_execPtr = 0; + _vm->_global->inter_execPtr = 0; return; } -void inter_initControlVars(void) { - *inter_nestLevel = 0; - *inter_breakFromLevel = -1; +void Inter::initControlVars(void) { + *nestLevel = 0; + *breakFromLevel = -1; - *scen_pCaptureCounter = 0; + *_vm->_scenery->pCaptureCounter = 0; - inter_breakFlag = 0; - inter_terminate = 0; - inter_animPalDir = 0; - inter_soundEndTimeKey = 0; + breakFlag = 0; + terminate = 0; + animPalDir = 0; + soundEndTimeKey = 0; } -void inter_callSub(int16 retFlag) { +void Inter::callSub(int16 retFlag) { int16 block; - while (inter_execPtr != 0 && (char *)inter_execPtr != game_totFileData) { - block = *inter_execPtr; + while (_vm->_global->inter_execPtr != 0 && (char *)_vm->_global->inter_execPtr != _vm->_game->totFileData) { + block = *_vm->_global->inter_execPtr; if (block == 1) { - inter_funcBlock(retFlag); + funcBlock(retFlag); } else if (block == 2) { - game_collisionsBlock(); + _vm->_game->collisionsBlock(); } } - if ((char *)inter_execPtr == game_totFileData) - inter_terminate = 1; + if ((char *)_vm->_global->inter_execPtr == _vm->_game->totFileData) + terminate = 1; } } // End of namespace Gob diff --git a/gob/inter.h b/gob/inter.h index 3464072d07..f74c6a81f6 100644 --- a/gob/inter.h +++ b/gob/inter.h @@ -24,75 +24,83 @@ namespace Gob { -extern int16 inter_animPalLowIndex; -extern int16 inter_animPalHighIndex; -extern int16 inter_animPalDir; -extern uint32 inter_soundEndTimeKey; -extern int16 inter_soundStopVal; -extern char inter_terminate; -extern char inter_breakFlag; -extern int16 *inter_breakFromLevel; -extern int16 *inter_nestLevel; +class Inter { +public: + int16 animPalLowIndex; + int16 animPalHighIndex; + int16 animPalDir; + uint32 soundEndTimeKey; + int16 soundStopVal; + char terminate; + char breakFlag; + int16 *breakFromLevel; + int16 *nestLevel; -int16 inter_load16(void); -int16 inter_peek16(char *ptr); -int32 inter_peek32(char *ptr); + int16 load16(void); + int16 peek16(char *ptr); + int32 peek32(char *ptr); -void inter_setMousePos(void); -char inter_evalExpr(int16 *pRes); -char inter_evalBoolResult(void); -void inter_storeResult(void); -void inter_printText(void); -void inter_animPalette(void); -void inter_animPalInit(void); -void inter_loadMult(void); -void inter_playMult(void); -void inter_freeMult(void); -void inter_initCursor(void); -void inter_initCursorAnim(void); -void inter_clearCursorAnim(void); -void inter_drawOperations(void); -void inter_getFreeMem(void); -void inter_manageDataFile(void); -void inter_getFreeMem(void); -void inter_manageDataFile(void); -void inter_writeData(void); -void inter_checkData(void); -void inter_readData(void); -void inter_loadFont(void); -void inter_freeFont(void); -void inter_prepareStr(void); -void inter_insertStr(void); -void inter_cutStr(void); -void inter_strstr(void); -void inter_setFrameRate(void); -void inter_strlen(void); -void inter_strToLong(void); -void inter_invalidate(void); -void inter_loadSpriteContent(void); -void inter_copySprite(void); -void inter_putPixel(void); -void inter_fillRect(void); -void inter_drawLine(void); -void inter_createSprite(void); -void inter_freeSprite(void); -void inter_renewTimeInVars(void); -void inter_playComposition(void); -void inter_stopSound(void); -void inter_playSound(void); -void inter_loadCursor(void); -void inter_loadSpriteToPos(void); -void inter_funcBlock(int16 retFlag); -void inter_loadTot(void); -void inter_storeKey(int16 key); -void inter_keyFunc(void); -void inter_checkSwitchTable(char **ppExec); -void inter_repeatUntil(void); -void inter_whileDo(void); -void inter_funcBlock(int16 retFlag); -void inter_callSub(int16 retFlag); -void inter_initControlVars(void); -void inter_callSub(int16 retFlag); + void setMousePos(void); + char evalExpr(int16 *pRes); + char evalBoolResult(void); + void storeResult(void); + void printText(void); + void animPalette(void); + void animPalInit(void); + void loadMult(void); + void playMult(void); + void freeMult(void); + void initCursor(void); + void initCursorAnim(void); + void clearCursorAnim(void); + void drawOperations(void); + void getFreeMem(void); + void manageDataFile(void); + void writeData(void); + void checkData(void); + void readData(void); + void loadFont(void); + void freeFont(void); + void prepareStr(void); + void insertStr(void); + void cutStr(void); + void strstr(void); + void setFrameRate(void); + void istrlen(void); + void strToLong(void); + void invalidate(void); + void loadSpriteContent(void); + void copySprite(void); + void putPixel(void); + void fillRect(void); + void drawLine(void); + void createSprite(void); + void freeSprite(void); + void renewTimeInVars(void); + void playComposition(void); + void stopSound(void); + void playSound(void); + void loadCursor(void); + void loadSpriteToPos(void); + void funcBlock(int16 retFlag); + void loadTot(void); + void storeKey(int16 key); + void keyFunc(void); + void checkSwitchTable(char **ppExec); + void repeatUntil(void); + void whileDo(void); + void callSub(int16 retFlag); + void initControlVars(void); + + Inter(GobEngine *vm); + +protected: + GobEngine *_vm; + + void evaluateStore(void); + void capturePush(void); + void capturePop(void); +}; } // End of namespace Gob diff --git a/gob/map.cpp b/gob/map.cpp index 955742503a..85983a72de 100644 --- a/gob/map.cpp +++ b/gob/map.cpp @@ -31,28 +31,38 @@ namespace Gob { -int8 map_passMap[kMapHeight][kMapWidth]; // [y][x] -int16 map_itemsMap[kMapHeight][kMapWidth]; // [y][x] - -Map_Point map_wayPoints[40]; -int16 map_nearestWayPoint = 0; -int16 map_nearestDest = 0; - -int16 map_curGoblinX; -int16 map_curGoblinY; -int16 map_destX; -int16 map_destY; - -Map_ItemPos map_itemPoses[40]; -int8 map_loadFromAvo; -char map_sourceFile[15]; -static char *map_avoDataPtr; - -void map_placeItem(int16 x, int16 y, int16 id) { - if ((map_itemsMap[y][x] & 0xff00) != 0) - map_itemsMap[y][x] = (map_itemsMap[y][x] & 0xff00) | id; +Map::Map(GobEngine *vm) : _vm(vm) { + for (int i = 0; i < kMapHeight; i++) + for (int j = 0; j < kMapWidth; j++) { + passMap[i][j] = 0; + itemsMap[i][j] = 0; + } + for (int i = 0; i < 40; i++) { + wayPoints[i].x = 0; + wayPoints[i].y = 0; + } + for (int i = 0; i < 40; i++) { + itemPoses[i].x = 0; + itemPoses[i].y = 0; + itemPoses[i].orient = 0; + } + + nearestWayPoint = 0; + nearestDest = 0; + curGoblinX = 0; + curGoblinY = 0; + destX = 0; + destY = 0; + loadFromAvo = 0; + sourceFile[0] = 0; + avoDataPtr = 0; +} + +void Map::placeItem(int16 x, int16 y, int16 id) { + if ((itemsMap[y][x] & 0xff00) != 0) + itemsMap[y][x] = (itemsMap[y][x] & 0xff00) | id; else - map_itemsMap[y][x] = (map_itemsMap[y][x] & 0x00ff) | (id << 8); + itemsMap[y][x] = (itemsMap[y][x] & 0x00ff) | (id << 8); } enum { @@ -62,7 +72,7 @@ enum { kDown = (1 << 3) }; -int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { +int16 Map::getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { int16 dir = 0; if (x0 == x1 && y0 == y1) @@ -81,63 +91,63 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { else if (x1 < x0) dir |= kLeft; - if (map_passMap[y0][x0] == 3 && (dir & kUp)) { - if (map_passMap[y0 - 1][x0] != 0) + if (passMap[y0][x0] == 3 && (dir & kUp)) { + if (passMap[y0 - 1][x0] != 0) return kDirN; } - if (map_passMap[y0][x0] == 3 && (dir & kDown)) { - if (map_passMap[y0 + 1][x0] != 0) + if (passMap[y0][x0] == 3 && (dir & kDown)) { + if (passMap[y0 + 1][x0] != 0) return kDirS; } - if (map_passMap[y0][x0] == 6 && (dir & kUp)) { - if (map_passMap[y0 - 1][x0] != 0) + if (passMap[y0][x0] == 6 && (dir & kUp)) { + if (passMap[y0 - 1][x0] != 0) return kDirN; } - if (map_passMap[y0][x0] == 6 && (dir & kDown)) { - if (map_passMap[y0 + 1][x0] != 0) + if (passMap[y0][x0] == 6 && (dir & kDown)) { + if (passMap[y0 + 1][x0] != 0) return kDirS; } if (dir == kLeft) { - if (x0 - 1 >= 0 && map_passMap[y0][x0 - 1] != 0) + if (x0 - 1 >= 0 && passMap[y0][x0 - 1] != 0) return kDirW; return 0; } if (dir == kRight) { - if (x0 + 1 < kMapWidth && map_passMap[y0][x0 + 1] != 0) + if (x0 + 1 < kMapWidth && passMap[y0][x0 + 1] != 0) return kDirE; return 0; } if (dir == kUp) { - if (y0 - 1 >= 0 && map_passMap[y0 - 1][x0] != 0) + if (y0 - 1 >= 0 && passMap[y0 - 1][x0] != 0) return kDirN; if (y0 - 1 >= 0 && x0 - 1 >= 0 - && map_passMap[y0 - 1][x0 - 1] != 0) + && passMap[y0 - 1][x0 - 1] != 0) return kDirNW; if (y0 - 1 >= 0 && x0 + 1 < kMapWidth - && map_passMap[y0 - 1][x0 + 1] != 0) + && passMap[y0 - 1][x0 + 1] != 0) return kDirNE; return 0; } if (dir == kDown) { - if (y0 + 1 < kMapHeight && map_passMap[y0 + 1][x0] != 0) + if (y0 + 1 < kMapHeight && passMap[y0 + 1][x0] != 0) return kDirS; if (y0 + 1 < kMapHeight && x0 - 1 >= 0 - && map_passMap[y0 + 1][x0 - 1] != 0) + && passMap[y0 + 1][x0 - 1] != 0) return kDirSW; if (y0 + 1 < kMapHeight && x0 + 1 < kMapWidth - && map_passMap[y0 + 1][x0 + 1] != 0) + && passMap[y0 + 1][x0 + 1] != 0) return kDirSE; return 0; @@ -145,13 +155,13 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { if (dir == (kRight | kUp)) { if (y0 - 1 >= 0 && x0 + 1 < kMapWidth - && map_passMap[y0 - 1][x0 + 1] != 0) + && passMap[y0 - 1][x0 + 1] != 0) return kDirNE; - if (y0 - 1 >= 0 && map_passMap[y0 - 1][x0] != 0) + if (y0 - 1 >= 0 && passMap[y0 - 1][x0] != 0) return kDirN; - if (x0 + 1 < kMapWidth && map_passMap[y0][x0 + 1] != 0) + if (x0 + 1 < kMapWidth && passMap[y0][x0 + 1] != 0) return kDirE; return 0; @@ -159,13 +169,13 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { if (dir == (kRight | kDown)) { if (x0 + 1 < kMapWidth && y0 + 1 < kMapHeight - && map_passMap[y0 + 1][x0 + 1] != 0) + && passMap[y0 + 1][x0 + 1] != 0) return kDirSE; - if (y0 + 1 < kMapHeight && map_passMap[y0 + 1][x0] != 0) + if (y0 + 1 < kMapHeight && passMap[y0 + 1][x0] != 0) return kDirS; - if (x0 + 1 < kMapWidth && map_passMap[y0][x0 + 1] != 0) + if (x0 + 1 < kMapWidth && passMap[y0][x0 + 1] != 0) return kDirE; return 0; @@ -173,13 +183,13 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { if (dir == (kLeft | kUp)) { if (x0 - 1 >= 0 && y0 - 1 >= 0 - && map_passMap[y0 - 1][x0 - 1] != 0) + && passMap[y0 - 1][x0 - 1] != 0) return kDirNW; - if (y0 - 1 >= 0 && map_passMap[y0 - 1][x0] != 0) + if (y0 - 1 >= 0 && passMap[y0 - 1][x0] != 0) return kDirN; - if (x0 - 1 >= 0 && map_passMap[y0][x0 - 1] != 0) + if (x0 - 1 >= 0 && passMap[y0][x0 - 1] != 0) return kDirW; return 0; @@ -187,13 +197,13 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { if (dir == (kLeft | kDown)) { if (x0 - 1 >= 0 && y0 + 1 < kMapHeight - && map_passMap[y0 + 1][x0 - 1] != 0) + && passMap[y0 + 1][x0 - 1] != 0) return kDirSW; - if (y0 + 1 < kMapHeight && map_passMap[y0 + 1][x0] != 0) + if (y0 + 1 < kMapHeight && passMap[y0 + 1][x0] != 0) return kDirS; - if (x0 - 1 >= 0 && map_passMap[y0][x0 - 1] != 0) + if (x0 - 1 >= 0 && passMap[y0][x0 - 1] != 0) return kDirW; return 0; @@ -201,8 +211,8 @@ int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1) { return -1; } -int16 map_findNearestWayPoint(int16 x, int16 y) { - int16 nearestWayPoint = -1; +int16 Map::findNearestWayPoint(int16 x, int16 y) { + int16 lnearestWayPoint = -1; int16 length; int16 i; int16 tmp; @@ -210,41 +220,41 @@ int16 map_findNearestWayPoint(int16 x, int16 y) { length = 30000; for (i = 0; i < 40; i++) { - if (map_wayPoints[i].x < 0 || - map_wayPoints[i].x >= kMapWidth || - map_wayPoints[i].y < 0 || map_wayPoints[i].y >= kMapHeight) + if (wayPoints[i].x < 0 || + wayPoints[i].x >= kMapWidth || + wayPoints[i].y < 0 || wayPoints[i].y >= kMapHeight) return -1; - tmp = ABS(x - map_wayPoints[i].x) + ABS(y - map_wayPoints[i].y); + tmp = ABS(x - wayPoints[i].x) + ABS(y - wayPoints[i].y); if (tmp <= length) { - nearestWayPoint = i; + lnearestWayPoint = i; length = tmp; } } - return nearestWayPoint; + return lnearestWayPoint; } -void map_findNearestToGob(void) { - int16 wayPoint = map_findNearestWayPoint(map_curGoblinX, map_curGoblinY); +void Map::findNearestToGob(void) { + int16 wayPoint = findNearestWayPoint(curGoblinX, curGoblinY); if (wayPoint != -1) - map_nearestWayPoint = wayPoint; + nearestWayPoint = wayPoint; } -void map_findNearestToDest(void) { - int16 wayPoint = map_findNearestWayPoint(map_destX, map_destY); +void Map::findNearestToDest(void) { + int16 wayPoint = findNearestWayPoint(destX, destY); if (wayPoint != -1) - map_nearestDest = wayPoint; + nearestDest = wayPoint; } -int16 map_checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1) { +int16 Map::checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1) { uint16 dir; while (1) { - dir = map_getDirection(x0, y0, x1, y1); + dir = getDirection(x0, y0, x1, y1); if (x0 == x1 && y0 == y1) return 1; @@ -292,7 +302,7 @@ int16 map_checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1) { } } -int16 map_checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) { +int16 Map::checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1) { uint16 dir; int16 curX; int16 curY; @@ -309,30 +319,30 @@ int16 map_checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 nextLink = 1; if (nextLink != 0) { - if (map_checkDirectPath(x0, y0, x1, y1) == 1) + if (checkDirectPath(x0, y0, x1, y1) == 1) return 1; nextLink = 0; if (i0 > i1) { - curX = map_wayPoints[i0].x; - curY = map_wayPoints[i0].y; + curX = wayPoints[i0].x; + curY = wayPoints[i0].y; i0--; } else if (i0 < i1) { - curX = map_wayPoints[i0].x; - curY = map_wayPoints[i0].y; + curX = wayPoints[i0].x; + curY = wayPoints[i0].y; i0++; } else if (i0 == i1) { - curX = map_wayPoints[i0].x; - curY = map_wayPoints[i0].y; + curX = wayPoints[i0].x; + curY = wayPoints[i0].y; } } - if (i0 == i1 && map_wayPoints[i0].x == x0 - && map_wayPoints[i0].y == y0) { - if (map_checkDirectPath(x0, y0, x1, y1) == 1) + if (i0 == i1 && wayPoints[i0].x == x0 + && wayPoints[i0].y == y0) { + if (checkDirectPath(x0, y0, x1, y1) == 1) return 1; return 0; } - dir = map_getDirection(x0, y0, curX, curY); + dir = getDirection(x0, y0, curX, curY); switch (dir) { case 0: return 0; @@ -376,54 +386,54 @@ int16 map_checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 } } -void map_optimizePoints(void) { +void Map::optimizePoints(void) { int16 i; - if (map_nearestWayPoint < map_nearestDest) { - for (i = map_nearestWayPoint; i <= map_nearestDest; i++) { - if (map_checkDirectPath(map_curGoblinX, map_curGoblinY, - map_wayPoints[i].x, map_wayPoints[i].y) == 1) - map_nearestWayPoint = i; + if (nearestWayPoint < nearestDest) { + for (i = nearestWayPoint; i <= nearestDest; i++) { + if (checkDirectPath(curGoblinX, curGoblinY, + wayPoints[i].x, wayPoints[i].y) == 1) + nearestWayPoint = i; } - } else if (map_nearestWayPoint > map_nearestDest) { - for (i = map_nearestWayPoint; i >= map_nearestDest; i--) { - if (map_checkDirectPath(map_curGoblinX, map_curGoblinY, - map_wayPoints[i].x, map_wayPoints[i].y) == 1) - map_nearestWayPoint = i; + } else if (nearestWayPoint > nearestDest) { + for (i = nearestWayPoint; i >= nearestDest; i--) { + if (checkDirectPath(curGoblinX, curGoblinY, + wayPoints[i].x, wayPoints[i].y) == 1) + nearestWayPoint = i; } } } -void map_loadDataFromAvo(char *dest, int16 size) { - memcpy(dest, map_avoDataPtr, size); - map_avoDataPtr += size; +void Map::loadDataFromAvo(char *dest, int16 size) { + memcpy(dest, avoDataPtr, size); + avoDataPtr += size; } -uint16 map_loadFromAvo_LE_UINT16() { - uint16 tmp = READ_LE_UINT16(map_avoDataPtr); - map_avoDataPtr += 2; +uint16 Map::loadFromAvo_LE_UINT16() { + uint16 tmp = READ_LE_UINT16(avoDataPtr); + avoDataPtr += 2; return tmp; } -void map_loadItemToObject(void) { +void Map::loadItemToObject(void) { int16 flag; int16 count; int16 i; - flag = map_loadFromAvo_LE_UINT16(); + flag = loadFromAvo_LE_UINT16(); if (flag == 0) return; - map_avoDataPtr += 1456; - count = map_loadFromAvo_LE_UINT16(); + avoDataPtr += 1456; + count = loadFromAvo_LE_UINT16(); for (i = 0; i < count; i++) { - map_avoDataPtr += 20; - gob_itemToObject[i] = map_loadFromAvo_LE_UINT16(); - map_avoDataPtr += 5; + avoDataPtr += 20; + _vm->_goblin->itemToObject[i] = loadFromAvo_LE_UINT16(); + avoDataPtr += 5; } } -void map_loadMapObjects(char *avjFile) { +void Map::loadMapObjects(char *avjFile) { int16 i; char avoName[128]; int16 handle; @@ -436,7 +446,7 @@ void map_loadMapObjects(char *avjFile) { int16 state; int16 col; int32 flag; - Gob_State *pState; + Goblin::Gob_State *pState; char buf[128]; char sndNames[20][14]; char *dataBuf; @@ -445,154 +455,154 @@ void map_loadMapObjects(char *avjFile) { int16 count2; int16 count3; - strcpy(avoName, map_sourceFile); + strcpy(avoName, sourceFile); strcat(avoName, ".avo"); - handle = data_openData(avoName); + handle = _vm->_dataio->openData(avoName); if (handle >= 0) { - map_loadFromAvo = 1; - data_closeData(handle); - map_avoDataPtr = data_getData(avoName); - dataBuf = map_avoDataPtr; - map_loadDataFromAvo((char *)map_passMap, kMapHeight * kMapWidth); + loadFromAvo = 1; + _vm->_dataio->closeData(handle); + avoDataPtr = _vm->_dataio->getData(avoName); + dataBuf = avoDataPtr; + loadDataFromAvo((char *)passMap, kMapHeight * kMapWidth); for (y = 0; y < kMapHeight; y++) { for (x = 0; x < kMapWidth; x++) { - map_loadDataFromAvo(&item, 1); - map_itemsMap[y][x] = item; + loadDataFromAvo(&item, 1); + itemsMap[y][x] = item; } } for (i = 0; i < 40; i++) { - map_wayPoints[i].x = map_loadFromAvo_LE_UINT16(); - map_wayPoints[i].y = map_loadFromAvo_LE_UINT16(); + wayPoints[i].x = loadFromAvo_LE_UINT16(); + wayPoints[i].y = loadFromAvo_LE_UINT16(); } - map_loadDataFromAvo((char *)map_itemPoses, szMap_ItemPos * 20); + loadDataFromAvo((char *)itemPoses, szMap_ItemPos * 20); } else { - map_loadFromAvo = 0; - map_avoDataPtr = data_getData(avjFile); - dataBuf = map_avoDataPtr; + loadFromAvo = 0; + avoDataPtr = _vm->_dataio->getData(avjFile); + dataBuf = avoDataPtr; } - map_avoDataPtr += 32; - map_avoDataPtr += 76; - map_avoDataPtr += 4; - map_avoDataPtr += 20; + avoDataPtr += 32; + avoDataPtr += 76; + avoDataPtr += 4; + avoDataPtr += 20; for (i = 0; i < 3; i++) { - tmp = map_loadFromAvo_LE_UINT16(); - map_avoDataPtr += tmp * 14; + tmp = loadFromAvo_LE_UINT16(); + avoDataPtr += tmp * 14; } - soundCount = map_loadFromAvo_LE_UINT16(); - savedPtr = map_avoDataPtr; + soundCount = loadFromAvo_LE_UINT16(); + savedPtr = avoDataPtr; - map_avoDataPtr += 14 * soundCount; - map_avoDataPtr += 4; - map_avoDataPtr += 24; + avoDataPtr += 14 * soundCount; + avoDataPtr += 4; + avoDataPtr += 24; - count2 = map_loadFromAvo_LE_UINT16(); - count3 = map_loadFromAvo_LE_UINT16(); + count2 = loadFromAvo_LE_UINT16(); + count3 = loadFromAvo_LE_UINT16(); - savedPtr2 = map_avoDataPtr; - map_avoDataPtr += count2 * 8; + savedPtr2 = avoDataPtr; + avoDataPtr += count2 * 8; - savedPtr3 = map_avoDataPtr; - map_avoDataPtr += count3 * 8; + savedPtr3 = avoDataPtr; + avoDataPtr += count3 * 8; - gob_gobsCount = map_loadFromAvo_LE_UINT16(); - for (i = 0; i < gob_gobsCount; i++) { - gob_goblins[i] = (Gob_Object *)malloc(sizeof(Gob_Object)); + _vm->_goblin->gobsCount = loadFromAvo_LE_UINT16(); + for (i = 0; i < _vm->_goblin->gobsCount; i++) { + _vm->_goblin->goblins[i] = (Goblin::Gob_Object *)malloc(sizeof(Goblin::Gob_Object)); - gob_goblins[i]->xPos = READ_LE_UINT16(savedPtr2); + _vm->_goblin->goblins[i]->xPos = READ_LE_UINT16(savedPtr2); savedPtr2 += 2; - gob_goblins[i]->yPos = READ_LE_UINT16(savedPtr2); + _vm->_goblin->goblins[i]->yPos = READ_LE_UINT16(savedPtr2); savedPtr2 += 2; - gob_goblins[i]->order = READ_LE_UINT16(savedPtr2); + _vm->_goblin->goblins[i]->order = READ_LE_UINT16(savedPtr2); savedPtr2 += 2; - gob_goblins[i]->state = READ_LE_UINT16(savedPtr2); + _vm->_goblin->goblins[i]->state = READ_LE_UINT16(savedPtr2); savedPtr2 += 2; if (i == 3) - gob_goblins[i]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 70); + _vm->_goblin->goblins[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 70); else - gob_goblins[i]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 40); + _vm->_goblin->goblins[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40); - // FIXME: All is wrong further. We should unwind calls to map_loadDataFromAvo() - map_loadDataFromAvo((char *)gob_goblins[i]->stateMach, 40 * szGob_StateLine); - map_avoDataPtr += 160; - gob_goblins[i]->multObjIndex = *map_avoDataPtr; - map_avoDataPtr += 2; + // FIXME: All is wrong further. We should unwind calls to loadDataFromAvo() + loadDataFromAvo((char *)_vm->_goblin->goblins[i]->stateMach, 40 * szGob_StateLine); + avoDataPtr += 160; + _vm->_goblin->goblins[i]->multObjIndex = *avoDataPtr; + avoDataPtr += 2; - gob_goblins[i]->realStateMach = gob_goblins[i]->stateMach; + _vm->_goblin->goblins[i]->realStateMach = _vm->_goblin->goblins[i]->stateMach; for (state = 0; state < 40; state++) { for (col = 0; col < 6; col++) { - if (gob_goblins[i]->stateMach[state][col] == 0) + if (_vm->_goblin->goblins[i]->stateMach[state][col] == 0) continue; - Gob_State *tmpState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_goblins[i]->stateMach[state][col] = tmpState; + Goblin::Gob_State *tmpState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[i]->stateMach[state][col] = tmpState; - tmpState->animation = map_loadFromAvo_LE_UINT16(); - tmpState->layer = map_loadFromAvo_LE_UINT16(); - map_avoDataPtr += 8; - tmpState->unk0 = map_loadFromAvo_LE_UINT16(); - tmpState->unk1 = map_loadFromAvo_LE_UINT16(); + tmpState->animation = loadFromAvo_LE_UINT16(); + tmpState->layer = loadFromAvo_LE_UINT16(); + avoDataPtr += 8; + tmpState->unk0 = loadFromAvo_LE_UINT16(); + tmpState->unk1 = loadFromAvo_LE_UINT16(); - map_avoDataPtr += 2; - if (READ_LE_UINT32(map_avoDataPtr) != 0) { - map_avoDataPtr += 4; - tmpState->sndItem = map_loadFromAvo_LE_UINT16(); + avoDataPtr += 2; + if (READ_LE_UINT32(avoDataPtr) != 0) { + avoDataPtr += 4; + tmpState->sndItem = loadFromAvo_LE_UINT16(); } else { - map_avoDataPtr += 6; + avoDataPtr += 6; tmpState->sndItem = -1; } - tmpState->freq = map_loadFromAvo_LE_UINT16(); - tmpState->repCount = map_loadFromAvo_LE_UINT16(); - tmpState->sndFrame = map_loadFromAvo_LE_UINT16(); + tmpState->freq = loadFromAvo_LE_UINT16(); + tmpState->repCount = loadFromAvo_LE_UINT16(); + tmpState->sndFrame = loadFromAvo_LE_UINT16(); } } } - pState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_goblins[0]->stateMach[39][0] = pState; + pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[0]->stateMach[39][0] = pState; pState->animation = 0; pState->layer = 98; pState->unk0 = 0; pState->unk1 = 0; pState->sndItem = -1; - pState = (Gob_State *) malloc(sizeof(Gob_State)); - gob_goblins[1]->stateMach[39][0] = pState; + pState = (Goblin::Gob_State *) malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[1]->stateMach[39][0] = pState; pState->animation = 0; pState->layer = 99; pState->unk0 = 0; pState->unk1 = 0; pState->sndItem = -1; - pState = (Gob_State *) malloc(sizeof(Gob_State)); - gob_goblins[2]->stateMach[39][0] = pState; + pState = (Goblin::Gob_State *) malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[2]->stateMach[39][0] = pState; pState->animation = 0; pState->layer = 100; pState->unk0 = 0; pState->unk1 = 0; pState->sndItem = -1; - gob_goblins[2]->stateMach[10][0]->sndFrame = 13; - gob_goblins[2]->stateMach[11][0]->sndFrame = 13; - gob_goblins[2]->stateMach[28][0]->sndFrame = 13; - gob_goblins[2]->stateMach[29][0]->sndFrame = 13; + _vm->_goblin->goblins[2]->stateMach[10][0]->sndFrame = 13; + _vm->_goblin->goblins[2]->stateMach[11][0]->sndFrame = 13; + _vm->_goblin->goblins[2]->stateMach[28][0]->sndFrame = 13; + _vm->_goblin->goblins[2]->stateMach[29][0]->sndFrame = 13; - gob_goblins[1]->stateMach[10][0]->sndFrame = 13; - gob_goblins[1]->stateMach[11][0]->sndFrame = 13; + _vm->_goblin->goblins[1]->stateMach[10][0]->sndFrame = 13; + _vm->_goblin->goblins[1]->stateMach[11][0]->sndFrame = 13; for (state = 40; state < 70; state++) { - pState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_goblins[3]->stateMach[state][0] = pState; - gob_goblins[3]->stateMach[state][1] = 0; + pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->goblins[3]->stateMach[state][0] = pState; + _vm->_goblin->goblins[3]->stateMach[state][1] = 0; pState->animation = 9; pState->layer = state - 40; @@ -600,70 +610,70 @@ void map_loadMapObjects(char *avjFile) { pState->sndFrame = 0; } - gob_objCount = map_loadFromAvo_LE_UINT16(); - for (i = 0; i < gob_objCount; i++) { - gob_objects[i] = - (Gob_Object *) malloc(sizeof(Gob_Object)); + _vm->_goblin->objCount = loadFromAvo_LE_UINT16(); + for (i = 0; i < _vm->_goblin->objCount; i++) { + _vm->_goblin->objects[i] = + (Goblin::Gob_Object *) malloc(sizeof(Goblin::Gob_Object)); - gob_objects[i]->xPos = READ_LE_UINT16(savedPtr3); + _vm->_goblin->objects[i]->xPos = READ_LE_UINT16(savedPtr3); savedPtr3 += 2; - gob_objects[i]->yPos = READ_LE_UINT16(savedPtr3); + _vm->_goblin->objects[i]->yPos = READ_LE_UINT16(savedPtr3); savedPtr3 += 2; - gob_objects[i]->order = READ_LE_UINT16(savedPtr3); + _vm->_goblin->objects[i]->order = READ_LE_UINT16(savedPtr3); savedPtr3 += 2; - gob_objects[i]->state = READ_LE_UINT16(savedPtr3); + _vm->_goblin->objects[i]->state = READ_LE_UINT16(savedPtr3); savedPtr3 += 2; - gob_objects[i]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 40); + _vm->_goblin->objects[i]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40); - map_loadDataFromAvo((char *)gob_objects[i]->stateMach, 40 * szGob_StateLine); - map_avoDataPtr += 160; - gob_objects[i]->multObjIndex = *map_avoDataPtr; - map_avoDataPtr += 2; + loadDataFromAvo((char *)_vm->_goblin->objects[i]->stateMach, 40 * szGob_StateLine); + avoDataPtr += 160; + _vm->_goblin->objects[i]->multObjIndex = *avoDataPtr; + avoDataPtr += 2; - gob_objects[i]->realStateMach = gob_objects[i]->stateMach; + _vm->_goblin->objects[i]->realStateMach = _vm->_goblin->objects[i]->stateMach; for (state = 0; state < 40; state++) { for (col = 0; col < 6; col++) { - if (gob_objects[i]->stateMach[state][col] == 0) + if (_vm->_goblin->objects[i]->stateMach[state][col] == 0) continue; - Gob_State *tmpState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_objects[i]->stateMach[state][col] = tmpState; + Goblin::Gob_State *tmpState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->objects[i]->stateMach[state][col] = tmpState; - tmpState->animation = map_loadFromAvo_LE_UINT16(); - tmpState->layer = map_loadFromAvo_LE_UINT16(); - map_avoDataPtr += 8; - tmpState->unk0 = map_loadFromAvo_LE_UINT16(); - tmpState->unk1 = map_loadFromAvo_LE_UINT16(); + tmpState->animation = loadFromAvo_LE_UINT16(); + tmpState->layer = loadFromAvo_LE_UINT16(); + avoDataPtr += 8; + tmpState->unk0 = loadFromAvo_LE_UINT16(); + tmpState->unk1 = loadFromAvo_LE_UINT16(); - map_avoDataPtr += 2; - if (READ_LE_UINT32(map_avoDataPtr) != 0) { - map_avoDataPtr += 4; - tmpState->sndItem = map_loadFromAvo_LE_UINT16(); + avoDataPtr += 2; + if (READ_LE_UINT32(avoDataPtr) != 0) { + avoDataPtr += 4; + tmpState->sndItem = loadFromAvo_LE_UINT16(); } else { - map_avoDataPtr += 6; + avoDataPtr += 6; tmpState->sndItem = -1; } - tmpState->freq = map_loadFromAvo_LE_UINT16(); - tmpState->repCount = map_loadFromAvo_LE_UINT16(); - tmpState->sndFrame = map_loadFromAvo_LE_UINT16(); + tmpState->freq = loadFromAvo_LE_UINT16(); + tmpState->repCount = loadFromAvo_LE_UINT16(); + tmpState->sndFrame = loadFromAvo_LE_UINT16(); } } } - gob_objects[10] = (Gob_Object *)malloc(sizeof(Gob_Object)); - memset(gob_objects[10], 0, sizeof(Gob_Object)); + _vm->_goblin->objects[10] = (Goblin::Gob_Object *)malloc(sizeof(Goblin::Gob_Object)); + memset(_vm->_goblin->objects[10], 0, sizeof(Goblin::Gob_Object)); - gob_objects[10]->stateMach = (Gob_StateLine *)malloc(szGob_StateLine * 40); - memset(gob_objects[10]->stateMach, 0, szGob_StateLine * 40); + _vm->_goblin->objects[10]->stateMach = (Goblin::Gob_StateLine *)malloc(szGob_StateLine * 40); + memset(_vm->_goblin->objects[10]->stateMach, 0, szGob_StateLine * 40); - pState = (Gob_State *)malloc(sizeof(Gob_State)); - gob_objects[10]->stateMach[0][0] = pState; + pState = (Goblin::Gob_State *)malloc(sizeof(Goblin::Gob_State)); + _vm->_goblin->objects[10]->stateMach[0][0] = pState; - memset(pState, 0, sizeof(Gob_State)); + memset(pState, 0, sizeof(Goblin::Gob_State)); pState->animation = 9; pState->layer = 27; pState->unk0 = 0; @@ -671,84 +681,84 @@ void map_loadMapObjects(char *avjFile) { pState->sndItem = -1; pState->sndFrame = 0; - gob_placeObject(gob_objects[10], 1); + _vm->_goblin->placeObject(_vm->_goblin->objects[10], 1); - gob_objects[10]->realStateMach = gob_objects[10]->stateMach; - gob_objects[10]->type = 1; - gob_objects[10]->unk14 = 1; + _vm->_goblin->objects[10]->realStateMach = _vm->_goblin->objects[10]->stateMach; + _vm->_goblin->objects[10]->type = 1; + _vm->_goblin->objects[10]->unk14 = 1; - state = map_loadFromAvo_LE_UINT16(); + state = loadFromAvo_LE_UINT16(); for (i = 0; i < state; i++) { - map_avoDataPtr += 30; + avoDataPtr += 30; - map_loadDataFromAvo((char *)&flag, 4); - map_avoDataPtr += 56; + loadDataFromAvo((char *)&flag, 4); + avoDataPtr += 56; if (flag != 0) - map_avoDataPtr += 30; + avoDataPtr += 30; } - map_loadDataFromAvo((char *)&tmp, 2); - map_avoDataPtr += 48; - map_loadItemToObject(); - map_avoDataPtr = savedPtr; + loadDataFromAvo((char *)&tmp, 2); + avoDataPtr += 48; + loadItemToObject(); + avoDataPtr = savedPtr; for (i = 0; i < soundCount; i++) { - map_loadDataFromAvo(buf, 14); + loadDataFromAvo(buf, 14); strcat(buf, ".SND"); strcpy(sndNames[i], buf); } free(dataBuf); - gob_soundData[14] = snd_loadSoundData("diamant1.snd"); + _vm->_goblin->soundData[14] = _vm->_snd->loadSoundData("diamant1.snd"); for (i = 0; i < soundCount; i++) { - handle = data_openData(sndNames[i]); + handle = _vm->_dataio->openData(sndNames[i]); if (handle < 0) continue; - data_closeData(handle); - gob_soundData[i] = snd_loadSoundData(sndNames[i]); + _vm->_dataio->closeData(handle); + _vm->_goblin->soundData[i] = _vm->_snd->loadSoundData(sndNames[i]); } } -void map_loadMapsInitGobs(void) { +void Map::loadMapsInitGobs(void) { int16 layer; int16 i; - if (map_loadFromAvo == 0) - error("map_load: Loading .pas/.pos files is not supported!"); + if (loadFromAvo == 0) + error("load: Loading .pas/.pos files is not supported!"); for (i = 0; i < 3; i++) { - gob_nextLayer(gob_goblins[i]); + _vm->_goblin->nextLayer(_vm->_goblin->goblins[i]); } for (i = 0; i < 3; i++) { layer = - gob_goblins[i]->stateMach[gob_goblins[i]->state][0]->layer; + _vm->_goblin->goblins[i]->stateMach[_vm->_goblin->goblins[i]->state][0]->layer; - scen_updateAnim(layer, 0, gob_goblins[i]->animation, 0, - gob_goblins[i]->xPos, gob_goblins[i]->yPos, 0); + _vm->_scenery->updateAnim(layer, 0, _vm->_goblin->goblins[i]->animation, 0, + _vm->_goblin->goblins[i]->xPos, _vm->_goblin->goblins[i]->yPos, 0); - gob_goblins[i]->yPos = (gob_gobPositions[i].y + 1) * 6 - - (scen_toRedrawBottom - scen_animTop); + _vm->_goblin->goblins[i]->yPos = (_vm->_goblin->gobPositions[i].y + 1) * 6 - + (_vm->_scenery->toRedrawBottom - _vm->_scenery->animTop); - gob_goblins[i]->xPos = gob_gobPositions[i].x * 12 - - (scen_toRedrawLeft - scen_animLeft); + _vm->_goblin->goblins[i]->xPos = _vm->_goblin->gobPositions[i].x * 12 - + (_vm->_scenery->toRedrawLeft - _vm->_scenery->animLeft); - gob_goblins[i]->order = scen_toRedrawBottom / 24 + 3; + _vm->_goblin->goblins[i]->order = _vm->_scenery->toRedrawBottom / 24 + 3; } - gob_currentGoblin = 0; - gob_pressedMapX = gob_gobPositions[0].x; - gob_pressedMapY = gob_gobPositions[0].y; - gob_pathExistence = 0; + _vm->_goblin->currentGoblin = 0; + _vm->_goblin->pressedMapX = _vm->_goblin->gobPositions[0].x; + _vm->_goblin->pressedMapY = _vm->_goblin->gobPositions[0].y; + _vm->_goblin->pathExistence = 0; - gob_goblins[0]->doAnim = 0; - gob_goblins[1]->doAnim = 1; - gob_goblins[2]->doAnim = 1; + _vm->_goblin->goblins[0]->doAnim = 0; + _vm->_goblin->goblins[1]->doAnim = 1; + _vm->_goblin->goblins[2]->doAnim = 1; } } // End of namespace Gob @@ -26,67 +26,78 @@ namespace Gob { // The same numeric values are also used for the arrow keys. -enum { - kDirNW = 0x4700, - kDirN = 0x4800, - kDirNE = 0x4900, - kDirW = 0x4b00, - kDirE = 0x4d00, - kDirSW = 0x4f00, - kDirS = 0x5000, - kDirSE = 0x5100 -}; +class Map { +public: + enum { + kDirNW = 0x4700, + kDirN = 0x4800, + kDirNE = 0x4900, + kDirW = 0x4b00, + kDirE = 0x4d00, + kDirSW = 0x4f00, + kDirS = 0x5000, + kDirSE = 0x5100 + }; + enum { + kMapWidth = 26, + kMapHeight = 28 + }; #pragma START_PACK_STRUCTS -typedef struct Map_Point { - int16 x; - int16 y; -} GCC_PACK Map_Point; + typedef struct Point { + int16 x; + int16 y; + } GCC_PACK Point; #define szMap_ItemPos 3 - typedef struct Map_ItemPos { - int8 x; - int8 y; - int8 orient; // ?? -} GCC_PACK Map_ItemPos; + typedef struct ItemPos { + int8 x; + int8 y; + int8 orient; // ?? + } GCC_PACK ItemPos; #pragma END_PACK_STRUCTS -enum { - kMapWidth = 26, - kMapHeight = 28 + int8 passMap[kMapHeight][kMapWidth]; // [y][x] + int16 itemsMap[kMapHeight][kMapWidth]; // [y][x] + Point wayPoints[40]; + int16 nearestWayPoint; + int16 nearestDest; + + int16 curGoblinX; + int16 curGoblinY; + int16 destX; + int16 destY; + int8 loadFromAvo; + + ItemPos itemPoses[40]; + char sourceFile[15]; + + void placeItem(int16 x, int16 y, int16 id); + + int16 getDirection(int16 x0, int16 y0, int16 x1, int16 y1); + void findNearestToGob(void); + void findNearestToDest(void); + int16 checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1); + int16 checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1); + void optimizePoints(void); + void loadItemToObject(void); + void loadMapObjects(char *avjFile); + void loadDataFromAvo(char *dest, int16 size); + void loadMapsInitGobs(void); + + Map(GobEngine *vm); + +protected: + char *avoDataPtr; + GobEngine *_vm; + + int16 findNearestWayPoint(int16 x, int16 y); + uint16 loadFromAvo_LE_UINT16(); }; -extern int8 map_passMap[kMapHeight][kMapWidth]; // [y][x] -extern int16 map_itemsMap[kMapHeight][kMapWidth]; // [y][x] -extern Map_Point map_wayPoints[40]; -extern int16 map_nearestWayPoint; -extern int16 map_nearestDest; - -extern int16 map_curGoblinX; -extern int16 map_curGoblinY; -extern int16 map_destX; -extern int16 map_destY; -extern int8 map_loadFromAvo; - -extern Map_ItemPos map_itemPoses[40]; -extern char map_sourceFile[15]; - -void map_placeItem(int16 x, int16 y, int16 id); - -int16 map_getDirection(int16 x0, int16 y0, int16 x1, int16 y1); -void map_findNearestToGob(void); -void map_findNearestToDest(void); -int16 map_checkDirectPath(int16 x0, int16 y0, int16 x1, int16 y1); -int16 map_checkLongPath(int16 x0, int16 y0, int16 x1, int16 y1, int16 i0, int16 i1); -void map_optimizePoints(void); -void map_loadItemToObject(void); -void map_loadMapObjects(char *avjFile); -void map_loadDataFromAvo(int8 *dest, int16 size); -void map_loadMapsInitGobs(void); - } // End of namespace Gob #endif /* __MAP_H */ diff --git a/gob/mult.cpp b/gob/mult.cpp index c0d7a2264a..e9ff27a20d 100644 --- a/gob/mult.cpp +++ b/gob/mult.cpp @@ -35,73 +35,85 @@ namespace Gob { -Mult_Object *mult_objects; -int16 *mult_renderData; -int16 mult_objCount; -int16 mult_frame; - -char *mult_multData; -char mult_doPalSubst; -int16 mult_counter; -int16 mult_frameRate; - -int32 *mult_animArrayX; -int32 *mult_animArrayY; - -Mult_AnimData *mult_animArrayData; - -int16 mult_index; - -// Static keys -int16 mult_staticKeysCount; -Mult_StaticKey *mult_staticKeys; -int16 mult_staticIndices[10]; - -// Anim keys -Mult_AnimKey *mult_animKeys[4]; -int16 mult_animKeysCount[4]; -int16 mult_animLayer; -int16 mult_animIndices[10]; - -// Text keys -int16 mult_textKeysCount; -Mult_TextKey *mult_textKeys; - -int16 mult_frameStart; - -// Palette keys -int16 mult_palKeyIndex; -int16 mult_palKeysCount; -Mult_PalKey *mult_palKeys; -Color *mult_oldPalette; -Color mult_palAnimPalette[256]; -int16 mult_palAnimKey; -int16 mult_palAnimIndices[4]; -int16 mult_palAnimRed[4]; -int16 mult_palAnimGreen[4]; -int16 mult_palAnimBlue[4]; - -// Palette fading -Mult_PalFadeKey *mult_palFadeKeys; -int16 mult_palFadeKeysCount; -char mult_palFadingRed; -char mult_palFadingGreen; -char mult_palFadingBlue; - -Color mult_fadePal[5][16]; - -// Sounds -int16 mult_sndKeysCount; -Mult_SndKey *mult_sndKeys; - -char mult_animDataAllocated; - -char *mult_dataPtr; -int16 mult_staticLoaded[10]; -int16 mult_animLoaded[10]; -int16 mult_sndSlotsCount; - -void mult_animate(void) { +Mult::Mult(GobEngine *vm) : _vm(vm) { + objects = 0; + renderData = 0; + objCount = 0; + underAnimSurf = 0; + multData = 0; + frame = 0; + doPalSubst = 0; + counter = 0; + frameRate = 0; + + animArrayX = 0; + animArrayY = 0; + animArrayData = 0; + + index = 0; + + staticKeysCount = 0; + staticKeys = 0; + for (int i = 0; i < 10; i++) + staticIndices[i] = 0; + + for (int i = 0; i < 4; i++) { + animKeys[i] = 0; + animKeysCount[i] = 0; + } + animLayer = 0; + for (int i = 0; i < 10; i++) + animIndices[i] = 0; + + textKeysCount = 0; + textKeys = 0; + + frameStart = 0; + + palKeyIndex = 0; + palKeysCount = 0; + palKeys = 0; + oldPalette = 0; + palAnimKey = 0; + for (int i = 0; i < 256; i++) { + palAnimPalette[i].red = 0; + palAnimPalette[i].green = 0; + palAnimPalette[i].blue = 0; + } + for (int i = 0; i < 4; i++) { + palAnimIndices[i] = 0; + palAnimRed[i] = 0; + palAnimGreen[i] = 0; + palAnimBlue[i] = 0; + } + + palFadeKeys = 0; + palFadeKeysCount = 0; + palFadingRed = 0; + palFadingGreen = 0; + palFadingBlue = 0; + + animDataAllocated = 0; + + dataPtr = 0; + for (int i = 0; i < 10; i++) { + staticLoaded[i] = 0; + animLoaded[i] = 0; + } + sndSlotsCount = 0; + + sndKeysCount = 0; + sndKeys = 0; + + for (int i = 0; i < 5; i++) + for (int j = 0; j < 16; j++) { + fadePal[i][j].red = 0; + fadePal[i][j].green = 0; + fadePal[i][j].blue = 0; + } +} + +void Mult::animate(void) { int16 minOrder; int16 maxOrder; int16 *pCurLefts; @@ -117,32 +129,32 @@ void mult_animate(void) { int16 i, j; int16 order; - if (mult_renderData == 0) + if (renderData == 0) return; - pDirtyLefts = mult_renderData; - pDirtyRights = pDirtyLefts + mult_objCount; - pDirtyTops = pDirtyRights + mult_objCount; - pDirtyBottoms = pDirtyTops + mult_objCount; - pNeedRedraw = pDirtyBottoms + mult_objCount; - pCurLefts = pNeedRedraw + mult_objCount; - pCurRights = pCurLefts + mult_objCount; - pCurTops = pCurRights + mult_objCount; - pCurBottoms = pCurTops + mult_objCount; + pDirtyLefts = renderData; + pDirtyRights = pDirtyLefts + objCount; + pDirtyTops = pDirtyRights + objCount; + pDirtyBottoms = pDirtyTops + objCount; + pNeedRedraw = pDirtyBottoms + objCount; + pCurLefts = pNeedRedraw + objCount; + pCurRights = pCurLefts + objCount; + pCurTops = pCurRights + objCount; + pCurBottoms = pCurTops + objCount; minOrder = 100; maxOrder = 0; //Find dirty areas - for (i = 0; i < mult_objCount; i++) { + for (i = 0; i < objCount; i++) { pNeedRedraw[i] = 0; pDirtyTops[i] = 1000; pDirtyLefts[i] = 1000; pDirtyBottoms[i] = 1000; pDirtyRights[i] = 1000; - pAnimData = mult_objects[i].pAnimData; + pAnimData = objects[i].pAnimData; if (pAnimData->isStatic == 0 && pAnimData->isPaused == 0 && - mult_objects[i].tick == pAnimData->maxTick) { + objects[i].tick == pAnimData->maxTick) { if (pAnimData->order < minOrder) minOrder = pAnimData->order; @@ -150,36 +162,36 @@ void mult_animate(void) { maxOrder = pAnimData->order; pNeedRedraw[i] = 1; - scen_updateAnim(pAnimData->layer, pAnimData->frame, + _vm->_scenery->updateAnim(pAnimData->layer, pAnimData->frame, pAnimData->animation, 0, - *(mult_objects[i].pPosX), *(mult_objects[i].pPosY), + *(objects[i].pPosX), *(objects[i].pPosY), 0); - if (mult_objects[i].lastLeft != -1) { + if (objects[i].lastLeft != -1) { pDirtyLefts[i] = - MIN(mult_objects[i].lastLeft, - scen_toRedrawLeft); + MIN(objects[i].lastLeft, + _vm->_scenery->toRedrawLeft); pDirtyTops[i] = - MIN(mult_objects[i].lastTop, - scen_toRedrawTop); + MIN(objects[i].lastTop, + _vm->_scenery->toRedrawTop); pDirtyRights[i] = - MAX(mult_objects[i].lastRight, - scen_toRedrawRight); + MAX(objects[i].lastRight, + _vm->_scenery->toRedrawRight); pDirtyBottoms[i] = - MAX(mult_objects[i].lastBottom, - scen_toRedrawBottom); + MAX(objects[i].lastBottom, + _vm->_scenery->toRedrawBottom); } else { - pDirtyLefts[i] = scen_toRedrawLeft; - pDirtyTops[i] = scen_toRedrawTop; - pDirtyRights[i] = scen_toRedrawRight; - pDirtyBottoms[i] = scen_toRedrawBottom; + pDirtyLefts[i] = _vm->_scenery->toRedrawLeft; + pDirtyTops[i] = _vm->_scenery->toRedrawTop; + pDirtyRights[i] = _vm->_scenery->toRedrawRight; + pDirtyBottoms[i] = _vm->_scenery->toRedrawBottom; } - pCurLefts[i] = scen_toRedrawLeft; - pCurRights[i] = scen_toRedrawRight; - pCurTops[i] = scen_toRedrawTop; - pCurBottoms[i] = scen_toRedrawBottom; + pCurLefts[i] = _vm->_scenery->toRedrawLeft; + pCurRights[i] = _vm->_scenery->toRedrawRight; + pCurTops[i] = _vm->_scenery->toRedrawTop; + pCurBottoms[i] = _vm->_scenery->toRedrawBottom; } else { - if (mult_objects[i].lastLeft != -1) { + if (objects[i].lastLeft != -1) { if (pAnimData->order < minOrder) minOrder = pAnimData->order; @@ -189,34 +201,34 @@ void mult_animate(void) { if (pAnimData->isStatic) *pNeedRedraw = 1; - pCurLefts[i] = mult_objects[i].lastLeft; - pDirtyLefts[i] = mult_objects[i].lastLeft; + pCurLefts[i] = objects[i].lastLeft; + pDirtyLefts[i] = objects[i].lastLeft; - pCurTops[i] = mult_objects[i].lastTop; - pDirtyTops[i] = mult_objects[i].lastTop; + pCurTops[i] = objects[i].lastTop; + pDirtyTops[i] = objects[i].lastTop; - pCurRights[i] = mult_objects[i].lastRight; - pDirtyRights[i] = mult_objects[i].lastRight; + pCurRights[i] = objects[i].lastRight; + pDirtyRights[i] = objects[i].lastRight; - pCurBottoms[i] = mult_objects[i].lastBottom; - pDirtyBottoms[i] = mult_objects[i].lastBottom; + pCurBottoms[i] = objects[i].lastBottom; + pDirtyBottoms[i] = objects[i].lastBottom; } } } // Find intersections - for (i = 0; i < mult_objCount; i++) { - pAnimData = mult_objects[i].pAnimData; + for (i = 0; i < objCount; i++) { + pAnimData = objects[i].pAnimData; pAnimData->intersected = 200; if (pAnimData->isStatic) continue; - for (j = 0; j < mult_objCount; j++) { + for (j = 0; j < objCount; j++) { if (i == j) continue; - if (mult_objects[j].pAnimData->isStatic) + if (objects[j].pAnimData->isStatic) continue; if (pCurRights[i] < pCurLefts[j]) @@ -237,56 +249,56 @@ void mult_animate(void) { } // Restore dirty areas - for (i = 0; i < mult_objCount; i++) { + for (i = 0; i < objCount; i++) { - if (pNeedRedraw[i] == 0 || mult_objects[i].lastLeft == -1) + if (pNeedRedraw[i] == 0 || objects[i].lastLeft == -1) continue; - draw_sourceSurface = 22; - draw_destSurface = 21; - draw_spriteLeft = pDirtyLefts[i] - anim_animAreaLeft; - draw_spriteTop = pDirtyTops[i] - anim_animAreaTop; - draw_spriteRight = pDirtyRights[i] - pDirtyLefts[i] + 1; - draw_spriteBottom = pDirtyBottoms[i] - pDirtyTops[i] + 1; - draw_destSpriteX = pDirtyLefts[i]; - draw_destSpriteY = pDirtyTops[i]; - draw_transparency = 0; - draw_spriteOperation(DRAW_BLITSURF); - mult_objects[i].lastLeft = -1; + _vm->_draw->sourceSurface = 22; + _vm->_draw->destSurface = 21; + _vm->_draw->spriteLeft = pDirtyLefts[i] - _vm->_anim->_areaLeft; + _vm->_draw->spriteTop = pDirtyTops[i] - _vm->_anim->_areaTop; + _vm->_draw->spriteRight = pDirtyRights[i] - pDirtyLefts[i] + 1; + _vm->_draw->spriteBottom = pDirtyBottoms[i] - pDirtyTops[i] + 1; + _vm->_draw->destSpriteX = pDirtyLefts[i]; + _vm->_draw->destSpriteY = pDirtyTops[i]; + _vm->_draw->transparency = 0; + _vm->_draw->spriteOperation(DRAW_BLITSURF); + objects[i].lastLeft = -1; } // Update view for (order = minOrder; order <= maxOrder; order++) { - for (i = 0; i < mult_objCount; i++) { - pAnimData = mult_objects[i].pAnimData; + for (i = 0; i < objCount; i++) { + pAnimData = objects[i].pAnimData; if (pAnimData->order != order) continue; if (pNeedRedraw[i]) { if (pAnimData->isStatic == 0) { - scen_updateAnim(pAnimData->layer, + _vm->_scenery->updateAnim(pAnimData->layer, pAnimData->frame, pAnimData->animation, 2, - *(mult_objects[i].pPosX), - *(mult_objects[i].pPosY), 1); - - if (scen_toRedrawLeft != -12345) { - mult_objects[i].lastLeft = - scen_toRedrawLeft; - mult_objects[i].lastTop = - scen_toRedrawTop; - mult_objects[i].lastRight = - scen_toRedrawRight; - mult_objects[i].lastBottom = - scen_toRedrawBottom; + *(objects[i].pPosX), + *(objects[i].pPosY), 1); + + if (_vm->_scenery->toRedrawLeft != -12345) { + objects[i].lastLeft = + _vm->_scenery->toRedrawLeft; + objects[i].lastTop = + _vm->_scenery->toRedrawTop; + objects[i].lastRight = + _vm->_scenery->toRedrawRight; + objects[i].lastBottom = + _vm->_scenery->toRedrawBottom; } else { - mult_objects[i].lastLeft = -1; + objects[i].lastLeft = -1; } } - scen_updateStatic(order + 1); + _vm->_scenery->updateStatic(order + 1); } else if (pAnimData->isStatic == 0) { - for (j = 0; j < mult_objCount; j++) { + for (j = 0; j < objCount; j++) { if (pNeedRedraw[j] == 0) continue; @@ -302,38 +314,38 @@ void mult_animate(void) { if (pDirtyBottoms[j] < pDirtyTops[i]) continue; - scen_toRedrawLeft = pDirtyLefts[j]; - scen_toRedrawRight = pDirtyRights[j]; - scen_toRedrawTop = pDirtyTops[j]; - scen_toRedrawBottom = pDirtyBottoms[j]; + _vm->_scenery->toRedrawLeft = pDirtyLefts[j]; + _vm->_scenery->toRedrawRight = pDirtyRights[j]; + _vm->_scenery->toRedrawTop = pDirtyTops[j]; + _vm->_scenery->toRedrawBottom = pDirtyBottoms[j]; - scen_updateAnim(pAnimData->layer, + _vm->_scenery->updateAnim(pAnimData->layer, pAnimData->frame, pAnimData->animation, 4, - *(mult_objects[i].pPosX), - *(mult_objects[i].pPosY), 1); + *(objects[i].pPosX), + *(objects[i].pPosY), 1); - scen_updateStatic(order + 1); + _vm->_scenery->updateStatic(order + 1); } } } } // Advance animations - for (i = 0; i < mult_objCount; i++) { - pAnimData = mult_objects[i].pAnimData; + for (i = 0; i < objCount; i++) { + pAnimData = objects[i].pAnimData; if (pAnimData->isStatic || pAnimData->isPaused) continue; - if (mult_objects[i].tick == pAnimData->maxTick) { - mult_objects[i].tick = 0; + if (objects[i].tick == pAnimData->maxTick) { + objects[i].tick = 0; if (pAnimData->animType == 4) { pAnimData->isPaused = 1; pAnimData->frame = 0; } else { pAnimData->frame++; if (pAnimData->frame >= - scen_animations[(int)pAnimData->animation].layers[pAnimData->layer]->framesCount) { + _vm->_scenery->animations[(int)pAnimData->animation].layers[pAnimData->layer]->framesCount) { switch (pAnimData->animType) { case 0: pAnimData->frame = 0; @@ -342,13 +354,13 @@ void mult_animate(void) { case 1: pAnimData->frame = 0; - *(mult_objects[i].pPosX) = - *(mult_objects[i].pPosX) + - scen_animations[(int)pAnimData->animation].layers[pAnimData->layer]->animDeltaX; + *(objects[i].pPosX) = + *(objects[i].pPosX) + + _vm->_scenery->animations[(int)pAnimData->animation].layers[pAnimData->layer]->animDeltaX; - *(mult_objects[i].pPosY) = - *(mult_objects[i].pPosY) + - scen_animations[(int)pAnimData->animation].layers[pAnimData->layer]->animDeltaY; + *(objects[i].pPosY) = + *(objects[i].pPosY) + + _vm->_scenery->animations[(int)pAnimData->animation].layers[pAnimData->layer]->animDeltaY; break; case 2: @@ -380,29 +392,29 @@ void mult_animate(void) { } } } else { - mult_objects[i].tick++; + objects[i].tick++; } } } -void mult_interGetObjAnimSize(void) { +void Mult::interGetObjAnimSize(void) { Mult_AnimData *pAnimData; int16 objIndex; - inter_evalExpr(&objIndex); - pAnimData = mult_objects[objIndex].pAnimData; + _vm->_inter->evalExpr(&objIndex); + pAnimData = objects[objIndex].pAnimData; if (pAnimData->isStatic == 0) { - scen_updateAnim(pAnimData->layer, pAnimData->frame, - pAnimData->animation, 0, *(mult_objects[objIndex].pPosX), - *(mult_objects[objIndex].pPosY), 0); + _vm->_scenery->updateAnim(pAnimData->layer, pAnimData->frame, + pAnimData->animation, 0, *(objects[objIndex].pPosX), + *(objects[objIndex].pPosY), 0); } - WRITE_VAR_OFFSET(parse_parseVarIndex(), scen_toRedrawLeft); - WRITE_VAR_OFFSET(parse_parseVarIndex(), scen_toRedrawTop); - WRITE_VAR_OFFSET(parse_parseVarIndex(), scen_toRedrawRight); - WRITE_VAR_OFFSET(parse_parseVarIndex(), scen_toRedrawBottom); + WRITE_VAR_OFFSET(_vm->_parse->parseVarIndex(), _vm->_scenery->toRedrawLeft); + WRITE_VAR_OFFSET(_vm->_parse->parseVarIndex(), _vm->_scenery->toRedrawTop); + WRITE_VAR_OFFSET(_vm->_parse->parseVarIndex(), _vm->_scenery->toRedrawRight); + WRITE_VAR_OFFSET(_vm->_parse->parseVarIndex(), _vm->_scenery->toRedrawBottom); } -void mult_interInitMult(void) { +void Mult::interInitMult(void) { int16 oldAnimHeight; int16 oldAnimWidth; int16 oldObjCount; @@ -411,177 +423,177 @@ void mult_interInitMult(void) { int16 posYVar; int16 animDataVar; - oldAnimWidth = anim_animAreaWidth; - oldAnimHeight = anim_animAreaHeight; - oldObjCount = mult_objCount; - - anim_animAreaLeft = inter_load16(); - anim_animAreaTop = inter_load16(); - anim_animAreaWidth = inter_load16(); - anim_animAreaHeight = inter_load16(); - mult_objCount = inter_load16(); - posXVar = parse_parseVarIndex(); - posYVar = parse_parseVarIndex(); - animDataVar = parse_parseVarIndex(); - - if (mult_objects == 0) { - mult_renderData = (int16 *)malloc(sizeof(int16) * mult_objCount * 9); - mult_objects = (Mult_Object *)malloc(sizeof(Mult_Object) * mult_objCount); - - for (i = 0; i < mult_objCount; i++) { - mult_objects[i].pPosX = (int32 *)(inter_variables + i * 4 + (posXVar / 4) * 4); - mult_objects[i].pPosY = (int32 *)(inter_variables + i * 4 + (posYVar / 4) * 4); - mult_objects[i].pAnimData = - (Mult_AnimData *) (inter_variables + animDataVar + - i * 4 * inter_animDataSize); - - mult_objects[i].pAnimData->isStatic = 1; - mult_objects[i].tick = 0; - mult_objects[i].lastLeft = -1; - mult_objects[i].lastRight = -1; - mult_objects[i].lastTop = -1; - mult_objects[i].lastBottom = -1; + oldAnimWidth = _vm->_anim->_areaWidth; + oldAnimHeight = _vm->_anim->_areaHeight; + oldObjCount = objCount; + + _vm->_anim->_areaLeft = _vm->_inter->load16(); + _vm->_anim->_areaTop = _vm->_inter->load16(); + _vm->_anim->_areaWidth = _vm->_inter->load16(); + _vm->_anim->_areaHeight = _vm->_inter->load16(); + objCount = _vm->_inter->load16(); + posXVar = _vm->_parse->parseVarIndex(); + posYVar = _vm->_parse->parseVarIndex(); + animDataVar = _vm->_parse->parseVarIndex(); + + if (objects == 0) { + renderData = (int16 *)malloc(sizeof(int16) * objCount * 9); + objects = (Mult_Object *)malloc(sizeof(Mult_Object) * objCount); + + for (i = 0; i < objCount; i++) { + objects[i].pPosX = (int32 *)(_vm->_global->inter_variables + i * 4 + (posXVar / 4) * 4); + objects[i].pPosY = (int32 *)(_vm->_global->inter_variables + i * 4 + (posYVar / 4) * 4); + objects[i].pAnimData = + (Mult_AnimData *) (_vm->_global->inter_variables + animDataVar + + i * 4 * _vm->_global->inter_animDataSize); + + objects[i].pAnimData->isStatic = 1; + objects[i].tick = 0; + objects[i].lastLeft = -1; + objects[i].lastRight = -1; + objects[i].lastTop = -1; + objects[i].lastBottom = -1; } - } else if (oldObjCount != mult_objCount) { - error("mult_interInitMult: Object count changed, but storage didn't (old count = %d, new count = %d)", - oldObjCount, mult_objCount); + } else if (oldObjCount != objCount) { + error("interInitMult: Object count changed, but storage didn't (old count = %d, new count = %d)", + oldObjCount, objCount); } - if (anim_underAnimSurf != 0 && - (oldAnimWidth != anim_animAreaWidth - || oldAnimHeight != anim_animAreaHeight)) { - vid_freeSurfDesc(anim_underAnimSurf); - anim_underAnimSurf = 0; + if (_vm->_anim->_animSurf != 0 && + (oldAnimWidth != _vm->_anim->_areaWidth + || oldAnimHeight != _vm->_anim->_areaHeight)) { + _vm->_video->freeSurfDesc(_vm->_anim->_animSurf); + _vm->_anim->_animSurf = 0; } - if (anim_underAnimSurf == 0) { - anim_underAnimSurf = vid_initSurfDesc(videoMode, - anim_animAreaWidth, anim_animAreaHeight, 0); + if (_vm->_anim->_animSurf == 0) { + _vm->_anim->_animSurf = _vm->_video->initSurfDesc(_vm->_global->videoMode, + _vm->_anim->_areaWidth, _vm->_anim->_areaHeight, 0); - draw_spritesArray[22] = anim_underAnimSurf; + _vm->_draw->spritesArray[22] = _vm->_anim->_animSurf; } - vid_drawSprite(draw_backSurface, anim_underAnimSurf, - anim_animAreaLeft, anim_animAreaTop, - anim_animAreaLeft + anim_animAreaWidth - 1, - anim_animAreaTop + anim_animAreaHeight - 1, 0, 0, 0); + _vm->_video->drawSprite(_vm->_draw->backSurface, _vm->_anim->_animSurf, + _vm->_anim->_areaLeft, _vm->_anim->_areaTop, + _vm->_anim->_areaLeft + _vm->_anim->_areaWidth - 1, + _vm->_anim->_areaTop + _vm->_anim->_areaHeight - 1, 0, 0, 0); - debug(4, "mult_interInitMult: x = %d, y = %d, w = %d, h = %d", - anim_animAreaLeft, anim_animAreaTop, anim_animAreaWidth, anim_animAreaHeight); - debug(4, " objCount = %d, animation data size = %d", mult_objCount, inter_animDataSize); + debug(4, "interInitMult: x = %d, y = %d, w = %d, h = %d", + _vm->_anim->_areaLeft, _vm->_anim->_areaTop, _vm->_anim->_areaWidth, _vm->_anim->_areaHeight); + debug(4, " objCount = %d, animation data size = %d", objCount, _vm->_global->inter_animDataSize); } -void mult_freeMult(void) { - if (anim_underAnimSurf != 0) - vid_freeSurfDesc(anim_underAnimSurf); +void Mult::freeMult(void) { + if (_vm->_anim->_animSurf != 0) + _vm->_video->freeSurfDesc(_vm->_anim->_animSurf); - free(mult_objects); - free(mult_renderData); + free(objects); + free(renderData); - mult_objects = 0; - mult_renderData = 0; - anim_underAnimSurf = 0; + objects = 0; + renderData = 0; + _vm->_anim->_animSurf = 0; } -void mult_interLoadMult(void) { +void Mult::interLoadMult(void) { int16 val; int16 objIndex; int16 i; - char *multData; + char *lmultData; - debug(4, "mult_interLoadMult: Loading..."); + debug(4, "interLoadMult: Loading..."); - inter_evalExpr(&objIndex); - inter_evalExpr(&val); - *mult_objects[objIndex].pPosX = val; - inter_evalExpr(&val); - *mult_objects[objIndex].pPosY = val; + _vm->_inter->evalExpr(&objIndex); + _vm->_inter->evalExpr(&val); + *objects[objIndex].pPosX = val; + _vm->_inter->evalExpr(&val); + *objects[objIndex].pPosY = val; - multData = (char *)mult_objects[objIndex].pAnimData; + lmultData = (char *)objects[objIndex].pAnimData; for (i = 0; i < 11; i++) { - if ((char)READ_LE_UINT16(inter_execPtr) == (char)99) { - inter_evalExpr(&val); - multData[i] = val; + if ((char)READ_LE_UINT16(_vm->_global->inter_execPtr) == (char)99) { + _vm->_inter->evalExpr(&val); + lmultData[i] = val; } else { - inter_execPtr++; + _vm->_global->inter_execPtr++; } } } -void mult_freeAll(void) { +void Mult::freeAll(void) { int16 i; - mult_freeMult(); + freeMult(); for (i = 0; i < 10; i++) - scen_freeAnim(i); + _vm->_scenery->freeAnim(i); for (i = 0; i < 10; i++) - scen_freeStatic(i); + _vm->_scenery->freeStatic(i); } -void mult_initAll(void) { +void Mult::initAll(void) { int16 i; - mult_objects = 0; - anim_underAnimSurf = 0; - mult_renderData = 0; + objects = 0; + _vm->_anim->_animSurf = 0; + renderData = 0; for (i = 0; i < 10; i++) - scen_animPictCount[i] = 0; + _vm->_scenery->animPictCount[i] = 0; for (i = 0; i < 20; i++) { - scen_spriteRefs[i] = 0; - scen_spriteResId[i] = -1; + _vm->_scenery->spriteRefs[i] = 0; + _vm->_scenery->spriteResId[i] = -1; } for (i = 0; i < 10; i++) - scen_staticPictCount[i] = -1; + _vm->_scenery->staticPictCount[i] = -1; - scen_curStaticLayer = -1; - scen_curStatic = -1; + _vm->_scenery->curStaticLayer = -1; + _vm->_scenery->curStatic = -1; } -void mult_playSound(Snd_SoundDesc * soundDesc, int16 repCount, int16 freq, +void Mult::playSound(Snd::SoundDesc * soundDesc, int16 repCount, int16 freq, int16 channel) { - snd_playSample(soundDesc, repCount, freq); + _vm->_snd->playSample(soundDesc, repCount, freq); } -char mult_drawStatics(char stop) { - if (mult_staticKeys[mult_staticKeysCount - 1].frame > mult_frame) +char Mult::drawStatics(char stop) { + if (staticKeys[staticKeysCount - 1].frame > frame) stop = 0; - for (mult_counter = 0; mult_counter < mult_staticKeysCount; - mult_counter++) { - if (mult_staticKeys[mult_counter].frame != mult_frame - || mult_staticKeys[mult_counter].layer == -1) + for (counter = 0; counter < staticKeysCount; + counter++) { + if (staticKeys[counter].frame != frame + || staticKeys[counter].layer == -1) continue; - for (scen_curStatic = 0, scen_curStaticLayer = mult_staticKeys[mult_counter].layer; - scen_curStaticLayer >= scen_statics[mult_staticIndices[scen_curStatic]].layersCount; - scen_curStatic++) { - scen_curStaticLayer -= - scen_statics[mult_staticIndices[scen_curStatic]].layersCount; + for (_vm->_scenery->curStatic = 0, _vm->_scenery->curStaticLayer = staticKeys[counter].layer; + _vm->_scenery->curStaticLayer >= _vm->_scenery->statics[staticIndices[_vm->_scenery->curStatic]].layersCount; + _vm->_scenery->curStatic++) { + _vm->_scenery->curStaticLayer -= + _vm->_scenery->statics[staticIndices[_vm->_scenery->curStatic]].layersCount; } - scen_curStatic = mult_staticIndices[scen_curStatic]; - scen_renderStatic(scen_curStatic, scen_curStaticLayer); - vid_drawSprite(draw_backSurface, anim_underAnimSurf, + _vm->_scenery->curStatic = staticIndices[_vm->_scenery->curStatic]; + _vm->_scenery->renderStatic(_vm->_scenery->curStatic, _vm->_scenery->curStaticLayer); + _vm->_video->drawSprite(_vm->_draw->backSurface, _vm->_anim->_animSurf, 0, 0, 319, 199, 0, 0, 0); } return stop; } -void mult_drawAnims(void) { +void Mult::drawAnims(void) { Mult_AnimKey *key; Mult_Object *animObj; int16 i; int16 count; - for (mult_index = 0; mult_index < 4; mult_index++) { - for (mult_counter = 0; mult_counter < mult_animKeysCount[mult_index]; mult_counter++) { - key = &mult_animKeys[mult_index][mult_counter]; - animObj = &mult_objects[mult_index]; - if (key->frame != mult_frame) + for (index = 0; index < 4; index++) { + for (counter = 0; counter < animKeysCount[index]; counter++) { + key = &animKeys[index][counter]; + animObj = &objects[index]; + if (key->frame != frame) continue; if (key->layer != -1) { @@ -598,15 +610,15 @@ void mult_drawAnims(void) { animObj->tick = 0; animObj->pAnimData->layer = key->layer; - count = scen_animations[mult_animIndices[0]].layersCount; + count = _vm->_scenery->animations[animIndices[0]].layersCount; i = 0; while (animObj->pAnimData->layer >= count) { animObj->pAnimData->layer -= count; i++; - count = scen_animations[mult_animIndices[i]].layersCount; + count = _vm->_scenery->animations[animIndices[i]].layersCount; } - animObj->pAnimData->animation = mult_animIndices[i]; + animObj->pAnimData->animation = animIndices[i]; } else { animObj->pAnimData->isStatic = 1; } @@ -614,255 +626,255 @@ void mult_drawAnims(void) { } } -void mult_drawText(char *pStop, char *pStopNoClear) { +void Mult::drawText(char *pStop, char *pStopNoClear) { char *savedIP; int16 cmd; - for (mult_index = 0; mult_index < mult_textKeysCount; mult_index++) { - if (mult_textKeys[mult_index].frame != mult_frame) + for (index = 0; index < textKeysCount; index++) { + if (textKeys[index].frame != frame) continue; - cmd = mult_textKeys[mult_index].cmd; + cmd = textKeys[index].cmd; if (cmd == 0) { *pStop = 0; } else if (cmd == 1) { *pStopNoClear = 1; - mult_frameStart = 0; + frameStart = 0; } else if (cmd == 3) { *pStop = 0; - savedIP = inter_execPtr; - inter_execPtr = (char *)(&mult_textKeys[mult_index].index); - inter_execPtr = savedIP; + savedIP = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr = (char *)(&textKeys[index].index); + _vm->_global->inter_execPtr = savedIP; } } } -char mult_prepPalAnim(char stop) { - mult_palKeyIndex = -1; +char Mult::prepPalAnim(char stop) { + palKeyIndex = -1; do { - mult_palKeyIndex++; - if (mult_palKeyIndex >= mult_palKeysCount) + palKeyIndex++; + if (palKeyIndex >= palKeysCount) return stop; - } while (mult_palKeys[mult_palKeyIndex].frame != mult_frame); + } while (palKeys[palKeyIndex].frame != frame); - if (mult_palKeys[mult_palKeyIndex].cmd == -1) { + if (palKeys[palKeyIndex].cmd == -1) { stop = 0; - mult_doPalSubst = 0; - pPaletteDesc->vgaPal = mult_oldPalette; + doPalSubst = 0; + _vm->_global->pPaletteDesc->vgaPal = oldPalette; - memcpy((char *)mult_palAnimPalette, (char *)pPaletteDesc->vgaPal, 768); + memcpy((char *)palAnimPalette, (char *)_vm->_global->pPaletteDesc->vgaPal, 768); - vid_setFullPalette(pPaletteDesc); + _vm->_video->setFullPalette(_vm->_global->pPaletteDesc); } else { stop = 0; - mult_doPalSubst = 1; - mult_palAnimKey = mult_palKeyIndex; + doPalSubst = 1; + palAnimKey = palKeyIndex; - mult_palAnimIndices[0] = 0; - mult_palAnimIndices[1] = 0; - mult_palAnimIndices[2] = 0; - mult_palAnimIndices[3] = 0; + palAnimIndices[0] = 0; + palAnimIndices[1] = 0; + palAnimIndices[2] = 0; + palAnimIndices[3] = 0; - pPaletteDesc->vgaPal = mult_palAnimPalette; + _vm->_global->pPaletteDesc->vgaPal = palAnimPalette; } return stop; } -void mult_doPalAnim(void) { +void Mult::doPalAnim(void) { int16 off; int16 off2; - Color *palPtr; + Video::Color *palPtr; Mult_PalKey *palKey; - if (mult_doPalSubst == 0) + if (doPalSubst == 0) return; - for (mult_index = 0; mult_index < 4; mult_index++) { - palKey = &mult_palKeys[mult_palAnimKey]; + for (index = 0; index < 4; index++) { + palKey = &palKeys[palAnimKey]; - if ((mult_frame % palKey->rates[mult_index]) != 0) + if ((frame % palKey->rates[index]) != 0) continue; - mult_palAnimRed[mult_index] = - pPaletteDesc->vgaPal[palKey->subst[0][mult_index] - 1].red; - mult_palAnimGreen[mult_index] = - pPaletteDesc->vgaPal[palKey->subst[0][mult_index] - 1].green; - mult_palAnimBlue[mult_index] = - pPaletteDesc->vgaPal[palKey->subst[0][mult_index] - 1].blue; + palAnimRed[index] = + _vm->_global->pPaletteDesc->vgaPal[palKey->subst[0][index] - 1].red; + palAnimGreen[index] = + _vm->_global->pPaletteDesc->vgaPal[palKey->subst[0][index] - 1].green; + palAnimBlue[index] = + _vm->_global->pPaletteDesc->vgaPal[palKey->subst[0][index] - 1].blue; while (1) { - off = palKey->subst[(mult_palAnimIndices[mult_index] + 1) % 16][mult_index]; + off = palKey->subst[(palAnimIndices[index] + 1) % 16][index]; if (off == 0) { - off = palKey->subst[mult_palAnimIndices[mult_index]][mult_index] - 1; + off = palKey->subst[palAnimIndices[index]][index] - 1; - pPaletteDesc->vgaPal[off].red = mult_palAnimRed[mult_index]; - pPaletteDesc->vgaPal[off].green = mult_palAnimGreen[mult_index]; - pPaletteDesc->vgaPal[off].blue = mult_palAnimBlue[mult_index]; + _vm->_global->pPaletteDesc->vgaPal[off].red = palAnimRed[index]; + _vm->_global->pPaletteDesc->vgaPal[off].green = palAnimGreen[index]; + _vm->_global->pPaletteDesc->vgaPal[off].blue = palAnimBlue[index]; } else { - off = palKey->subst[(mult_palAnimIndices[mult_index] + 1) % 16][mult_index] - 1; - off2 = palKey->subst[mult_palAnimIndices[mult_index]][mult_index] - 1; + off = palKey->subst[(palAnimIndices[index] + 1) % 16][index] - 1; + off2 = palKey->subst[palAnimIndices[index]][index] - 1; - pPaletteDesc->vgaPal[off2].red = pPaletteDesc->vgaPal[off].red; - pPaletteDesc->vgaPal[off2].green = pPaletteDesc->vgaPal[off].green; - pPaletteDesc->vgaPal[off2].blue = pPaletteDesc->vgaPal[off].blue; + _vm->_global->pPaletteDesc->vgaPal[off2].red = _vm->_global->pPaletteDesc->vgaPal[off].red; + _vm->_global->pPaletteDesc->vgaPal[off2].green = _vm->_global->pPaletteDesc->vgaPal[off].green; + _vm->_global->pPaletteDesc->vgaPal[off2].blue = _vm->_global->pPaletteDesc->vgaPal[off].blue; } - mult_palAnimIndices[mult_index] = (mult_palAnimIndices[mult_index] + 1) % 16; + palAnimIndices[index] = (palAnimIndices[index] + 1) % 16; - off = palKey->subst[mult_palAnimIndices[mult_index]][mult_index]; + off = palKey->subst[palAnimIndices[index]][index]; if (off == 0) { - mult_palAnimIndices[mult_index] = 0; - off = palKey->subst[0][mult_index] - 1; + palAnimIndices[index] = 0; + off = palKey->subst[0][index] - 1; - mult_palAnimRed[mult_index] = pPaletteDesc->vgaPal[off].red; - mult_palAnimGreen[mult_index] = pPaletteDesc->vgaPal[off].green; - mult_palAnimBlue[mult_index] = pPaletteDesc->vgaPal[off].blue; + palAnimRed[index] = _vm->_global->pPaletteDesc->vgaPal[off].red; + palAnimGreen[index] = _vm->_global->pPaletteDesc->vgaPal[off].green; + palAnimBlue[index] = _vm->_global->pPaletteDesc->vgaPal[off].blue; } - if (mult_palAnimIndices[mult_index] == 0) + if (palAnimIndices[index] == 0) break; } } - if (colorCount == 256) { - vid_waitRetrace(videoMode); + if (_vm->_global->colorCount == 256) { + _vm->_video->waitRetrace(_vm->_global->videoMode); - palPtr = pPaletteDesc->vgaPal; - for (mult_counter = 0; mult_counter < 16; mult_counter++) { - vid_setPalElem(mult_counter, palPtr->red, palPtr->green, palPtr->blue, 0, 0x13); + palPtr = _vm->_global->pPaletteDesc->vgaPal; + for (counter = 0; counter < 16; counter++) { + _vm->_video->setPalElem(counter, palPtr->red, palPtr->green, palPtr->blue, 0, 0x13); palPtr++; } - palPtr = pPaletteDesc->vgaPal; - for (mult_counter = 0; mult_counter < 16; mult_counter++) { - redPalette[mult_counter] = palPtr->red; - greenPalette[mult_counter] = palPtr->green; - bluePalette[mult_counter] = palPtr->blue; + palPtr = _vm->_global->pPaletteDesc->vgaPal; + for (counter = 0; counter < 16; counter++) { + _vm->_global->redPalette[counter] = palPtr->red; + _vm->_global->greenPalette[counter] = palPtr->green; + _vm->_global->bluePalette[counter] = palPtr->blue; palPtr++; } } else { - vid_setFullPalette(pPaletteDesc); + _vm->_video->setFullPalette(_vm->_global->pPaletteDesc); } } -char mult_doFadeAnim(char stop) { +char Mult::doFadeAnim(char stop) { Mult_PalFadeKey *fadeKey; - for (mult_index = 0; mult_index < mult_palFadeKeysCount; mult_index++) { - fadeKey = &mult_palFadeKeys[mult_index]; + for (index = 0; index < palFadeKeysCount; index++) { + fadeKey = &palFadeKeys[index]; - if (fadeKey->frame != mult_frame) + if (fadeKey->frame != frame) continue; stop = 0; if ((fadeKey->flag & 1) == 0) { if (fadeKey->fade == 0) { - pPaletteDesc->vgaPal = mult_fadePal[fadeKey->palIndex]; - vid_setFullPalette(pPaletteDesc); + _vm->_global->pPaletteDesc->vgaPal = fadePal[fadeKey->palIndex]; + _vm->_video->setFullPalette(_vm->_global->pPaletteDesc); } else { - pPaletteDesc->vgaPal = mult_fadePal[fadeKey->palIndex]; - pal_fade(pPaletteDesc, fadeKey->fade, 0); + _vm->_global->pPaletteDesc->vgaPal = fadePal[fadeKey->palIndex]; + _vm->_palanim->fade(_vm->_global->pPaletteDesc, fadeKey->fade, 0); } } else { - pPaletteDesc->vgaPal = mult_fadePal[fadeKey->palIndex]; - pal_fade(pPaletteDesc, fadeKey->fade, -1); + _vm->_global->pPaletteDesc->vgaPal = fadePal[fadeKey->palIndex]; + _vm->_palanim->fade(_vm->_global->pPaletteDesc, fadeKey->fade, -1); - mult_palFadingRed = (fadeKey->flag >> 1) & 1; - mult_palFadingGreen = (fadeKey->flag >> 2) & 1; - mult_palFadingBlue = (fadeKey->flag >> 3) & 1; + palFadingRed = (fadeKey->flag >> 1) & 1; + palFadingGreen = (fadeKey->flag >> 2) & 1; + palFadingBlue = (fadeKey->flag >> 3) & 1; } } - if (mult_palFadingRed) { - mult_palFadingRed = !pal_fadeStep(1); + if (palFadingRed) { + palFadingRed = !_vm->_palanim->fadeStep(1); stop = 0; } - if (mult_palFadingGreen) { - mult_palFadingGreen = !pal_fadeStep(2); + if (palFadingGreen) { + palFadingGreen = !_vm->_palanim->fadeStep(2); stop = 0; } - if (mult_palFadingBlue) { - mult_palFadingBlue = !pal_fadeStep(3); + if (palFadingBlue) { + palFadingBlue = !_vm->_palanim->fadeStep(3); stop = 0; } return stop; } -char mult_doSoundAnim(char stop) { +char Mult::doSoundAnim(char stop) { Mult_SndKey *sndKey; - for (mult_index = 0; mult_index < mult_sndKeysCount; mult_index++) { - sndKey = &mult_sndKeys[mult_index]; - if (sndKey->frame != mult_frame) + for (index = 0; index < sndKeysCount; index++) { + sndKey = &sndKeys[index]; + if (sndKey->frame != frame) continue; if (sndKey->cmd != -1) { if (sndKey->cmd == 1) { - snd_stopSound(0); + _vm->_snd->stopSound(0); stop = 0; - mult_playSound(game_soundSamples[sndKey->soundIndex], sndKey->repCount, + playSound(_vm->_game->soundSamples[sndKey->soundIndex], sndKey->repCount, sndKey->freq, sndKey->channel); } else if (sndKey->cmd == 4) { - snd_stopSound(0); + _vm->_snd->stopSound(0); stop = 0; - mult_playSound(game_soundSamples[sndKey->soundIndex], sndKey->repCount, + playSound(_vm->_game->soundSamples[sndKey->soundIndex], sndKey->repCount, sndKey->freq, sndKey->channel); } } else { - if (snd_playingSound) - snd_stopSound(sndKey->channel); + if (_vm->_snd->playingSound) + _vm->_snd->stopSound(sndKey->channel); } } return stop; } -void mult_playMult(int16 startFrame, int16 endFrame, char checkEscape, +void Mult::playMult(int16 startFrame, int16 endFrame, char checkEscape, char handleMouse) { char stopNoClear; char stop; Mult_Object *multObj; Mult_AnimData *animData; - if (mult_multData == 0) + if (multData == 0) return; stopNoClear = 0; - mult_frame = startFrame; + frame = startFrame; if (endFrame == -1) endFrame = 32767; - if (mult_frame == -1) { - mult_doPalSubst = 0; - mult_palFadingRed = 0; - mult_palFadingGreen = 0; - mult_palFadingBlue = 0; + if (frame == -1) { + doPalSubst = 0; + palFadingRed = 0; + palFadingGreen = 0; + palFadingBlue = 0; - mult_oldPalette = pPaletteDesc->vgaPal; - memcpy((char *)mult_palAnimPalette, (char *)pPaletteDesc->vgaPal, 768); + oldPalette = _vm->_global->pPaletteDesc->vgaPal; + memcpy((char *)palAnimPalette, (char *)_vm->_global->pPaletteDesc->vgaPal, 768); - if (anim_underAnimSurf == 0) { - util_setFrameRate(mult_frameRate); - anim_animAreaTop = 0; - anim_animAreaLeft = 0; - anim_animAreaWidth = 320; - anim_animAreaHeight = 200; - mult_objCount = 4; + if (_vm->_anim->_animSurf == 0) { + _vm->_util->setFrameRate(frameRate); + _vm->_anim->_areaTop = 0; + _vm->_anim->_areaLeft = 0; + _vm->_anim->_areaWidth = 320; + _vm->_anim->_areaHeight = 200; + objCount = 4; - mult_objects = (Mult_Object *)malloc(sizeof(Mult_Object) * mult_objCount); - mult_renderData = (int16 *)malloc(sizeof(int16) * 9 * mult_objCount); + objects = (Mult_Object *)malloc(sizeof(Mult_Object) * objCount); + renderData = (int16 *)malloc(sizeof(int16) * 9 * objCount); - mult_animArrayX = (int32 *)malloc(sizeof(int32) * mult_objCount); - mult_animArrayY = (int32 *)malloc(sizeof(int32) * mult_objCount); + animArrayX = (int32 *)malloc(sizeof(int32) * objCount); + animArrayY = (int32 *)malloc(sizeof(int32) * objCount); - mult_animArrayData = (Mult_AnimData *)malloc(sizeof(Mult_AnimData) * mult_objCount); + animArrayData = (Mult_AnimData *)malloc(sizeof(Mult_AnimData) * objCount); - for (mult_counter = 0; mult_counter < mult_objCount; mult_counter++) { - multObj = &mult_objects[mult_counter]; + for (counter = 0; counter < objCount; counter++) { + multObj = &objects[counter]; - multObj->pPosX = (int32 *)&mult_animArrayX[mult_counter]; - multObj->pPosY = (int32 *)&mult_animArrayY[mult_counter]; + multObj->pPosX = (int32 *)&animArrayX[counter]; + multObj->pPosY = (int32 *)&animArrayY[counter]; - multObj->pAnimData = &mult_animArrayData[mult_counter]; + multObj->pAnimData = &animArrayData[counter]; animData = multObj->pAnimData; animData->isStatic = 1; @@ -874,328 +886,328 @@ void mult_playMult(int16 startFrame, int16 endFrame, char checkEscape, multObj->lastBottom = -1; } - anim_underAnimSurf = - vid_initSurfDesc(videoMode, 320, 200, 0); - draw_spritesArray[22] = anim_underAnimSurf; + _vm->_anim->_animSurf = + _vm->_video->initSurfDesc(_vm->_global->videoMode, 320, 200, 0); + _vm->_draw->spritesArray[22] = _vm->_anim->_animSurf; - vid_drawSprite(draw_backSurface, anim_underAnimSurf, + _vm->_video->drawSprite(_vm->_draw->backSurface, _vm->_anim->_animSurf, 0, 0, 319, 199, 0, 0, 0); - mult_animDataAllocated = 1; + animDataAllocated = 1; } else - mult_animDataAllocated = 0; - mult_frame = 0; + animDataAllocated = 0; + frame = 0; } do { stop = 1; if (VAR(58) == 0) { - stop = mult_drawStatics(stop); - mult_drawAnims(); + stop = drawStatics(stop); + drawAnims(); } - mult_animate(); + animate(); if (handleMouse) { - draw_animateCursor(-1); + _vm->_draw->animateCursor(-1); } else { - draw_blitInvalidated(); + _vm->_draw->blitInvalidated(); } if (VAR(58) == 0) { - mult_drawText(&stop, &stopNoClear); + drawText(&stop, &stopNoClear); } - stop = mult_prepPalAnim(stop); - mult_doPalAnim(); + stop = prepPalAnim(stop); + doPalAnim(); - stop = mult_doFadeAnim(stop); - stop = mult_doSoundAnim(stop); + stop = doFadeAnim(stop); + stop = doSoundAnim(stop); - if (mult_frame >= endFrame) + if (frame >= endFrame) stopNoClear = 1; - if (snd_playingSound) + if (_vm->_snd->playingSound) stop = 0; - util_processInput(); - if (checkEscape && util_checkKey() == 0x11b) // Esc + _vm->_util->processInput(); + if (checkEscape && _vm->_util->checkKey() == 0x11b) // Esc stop = 1; - mult_frame++; - util_waitEndFrame(); + frame++; + _vm->_util->waitEndFrame(); } while (stop == 0 && stopNoClear == 0); if (stopNoClear == 0) { - if (mult_animDataAllocated) { - free(mult_objects); - mult_objects = 0; + if (animDataAllocated) { + free(objects); + objects = 0; - free(mult_renderData); - mult_renderData = 0; + free(renderData); + renderData = 0; - free(mult_animArrayX); - mult_animArrayX = 0; + free(animArrayX); + animArrayX = 0; - free(mult_animArrayY); - mult_animArrayY = 0; + free(animArrayY); + animArrayY = 0; - free(mult_animArrayData); - mult_animArrayData = 0; + free(animArrayData); + animArrayData = 0; - if (anim_underAnimSurf) - vid_freeSurfDesc(anim_underAnimSurf); - anim_underAnimSurf = 0; + if (_vm->_anim->_animSurf) + _vm->_video->freeSurfDesc(_vm->_anim->_animSurf); + _vm->_anim->_animSurf = 0; - mult_animDataAllocated = 0; + animDataAllocated = 0; } - if (snd_playingSound != 0) - snd_stopSound(10); + if (_vm->_snd->playingSound != 0) + _vm->_snd->stopSound(10); WRITE_VAR(57, (uint32)-1); } else { - WRITE_VAR(57, mult_frame - 1 - mult_frameStart); + WRITE_VAR(57, frame - 1 - frameStart); } } -void mult_zeroMultData(void) { - mult_multData = 0; +void Mult::zeroMultData(void) { + multData = 0; } -void mult_loadMult(int16 resId) { +void Mult::loadMult(int16 resId) { char animCount; char staticCount; int16 palIndex; int16 i, j; - mult_sndSlotsCount = 0; - mult_frameStart = 0; - mult_multData = game_loadExtData(resId, 0, 0); - mult_dataPtr = mult_multData; + sndSlotsCount = 0; + frameStart = 0; + multData = _vm->_game->loadExtData(resId, 0, 0); + dataPtr = multData; - staticCount = mult_dataPtr[0]; - animCount = mult_dataPtr[1]; - mult_dataPtr += 2; + staticCount = dataPtr[0]; + animCount = dataPtr[1]; + dataPtr += 2; staticCount++; animCount++; - for (i = 0; i < staticCount; i++, mult_dataPtr += 14) { - mult_staticIndices[i] = scen_loadStatic(1); + for (i = 0; i < staticCount; i++, dataPtr += 14) { + staticIndices[i] = _vm->_scenery->loadStatic(1); - if (mult_staticIndices[i] >= 100) { - mult_staticIndices[i] -= 100; - mult_staticLoaded[i] = 1; + if (staticIndices[i] >= 100) { + staticIndices[i] -= 100; + staticLoaded[i] = 1; } else { - mult_staticLoaded[i] = 0; + staticLoaded[i] = 0; } } - for (i = 0; i < animCount; i++, mult_dataPtr += 14) { - mult_animIndices[i] = scen_loadAnim(1); + for (i = 0; i < animCount; i++, dataPtr += 14) { + animIndices[i] = _vm->_scenery->loadAnim(1); - if (mult_animIndices[i] >= 100) { - mult_animIndices[i] -= 100; - mult_animLoaded[i] = 1; + if (animIndices[i] >= 100) { + animIndices[i] -= 100; + animLoaded[i] = 1; } else { - mult_animLoaded[i] = 0; + animLoaded[i] = 0; } } - mult_frameRate = READ_LE_UINT16(mult_dataPtr); - mult_dataPtr += 2; + frameRate = READ_LE_UINT16(dataPtr); + dataPtr += 2; - mult_staticKeysCount = READ_LE_UINT16(mult_dataPtr); - mult_dataPtr += 2; + staticKeysCount = READ_LE_UINT16(dataPtr); + dataPtr += 2; - mult_staticKeys = (Mult_StaticKey *)malloc(sizeof(Mult_StaticKey) * - mult_staticKeysCount); - for (i = 0; i < mult_staticKeysCount; i++, mult_dataPtr += 4) { - mult_staticKeys[i].frame = (int16)READ_LE_UINT16(mult_dataPtr); - mult_staticKeys[i].layer = (int16)READ_LE_UINT16(mult_dataPtr + 2); + staticKeys = (Mult_StaticKey *)malloc(sizeof(Mult_StaticKey) * + staticKeysCount); + for (i = 0; i < staticKeysCount; i++, dataPtr += 4) { + staticKeys[i].frame = (int16)READ_LE_UINT16(dataPtr); + staticKeys[i].layer = (int16)READ_LE_UINT16(dataPtr + 2); } for (j = 0; j < 4; j++) { - mult_animKeysCount[j] = READ_LE_UINT16(mult_dataPtr); - mult_dataPtr += 2; - - mult_animKeys[j] = (Mult_AnimKey *) malloc(sizeof(Mult_AnimKey) * mult_animKeysCount[j]); - for (i = 0; i < mult_animKeysCount[j]; i++, mult_dataPtr += 10) { - mult_animKeys[j][i].frame = (int16)READ_LE_UINT16(mult_dataPtr); - mult_animKeys[j][i].layer = (int16)READ_LE_UINT16(mult_dataPtr + 2); - mult_animKeys[j][i].posX = (int16)READ_LE_UINT16(mult_dataPtr + 4); - mult_animKeys[j][i].posY = (int16)READ_LE_UINT16(mult_dataPtr + 6); - mult_animKeys[j][i].order = (int16)READ_LE_UINT16(mult_dataPtr + 8); + animKeysCount[j] = READ_LE_UINT16(dataPtr); + dataPtr += 2; + + animKeys[j] = (Mult_AnimKey *) malloc(sizeof(Mult_AnimKey) * animKeysCount[j]); + for (i = 0; i < animKeysCount[j]; i++, dataPtr += 10) { + animKeys[j][i].frame = (int16)READ_LE_UINT16(dataPtr); + animKeys[j][i].layer = (int16)READ_LE_UINT16(dataPtr + 2); + animKeys[j][i].posX = (int16)READ_LE_UINT16(dataPtr + 4); + animKeys[j][i].posY = (int16)READ_LE_UINT16(dataPtr + 6); + animKeys[j][i].order = (int16)READ_LE_UINT16(dataPtr + 8); } } for (palIndex = 0; palIndex < 5; palIndex++) { for (i = 0; i < 16; i++) { - mult_fadePal[palIndex][i].red = mult_dataPtr[0]; - mult_fadePal[palIndex][i].green = mult_dataPtr[1]; - mult_fadePal[palIndex][i].blue = mult_dataPtr[2]; - mult_dataPtr += 3; + fadePal[palIndex][i].red = dataPtr[0]; + fadePal[palIndex][i].green = dataPtr[1]; + fadePal[palIndex][i].blue = dataPtr[2]; + dataPtr += 3; } } - mult_palFadeKeysCount = READ_LE_UINT16(mult_dataPtr); - mult_dataPtr += 2; - mult_palFadeKeys = (Mult_PalFadeKey *)malloc(sizeof(Mult_PalFadeKey) * mult_palFadeKeysCount); + palFadeKeysCount = READ_LE_UINT16(dataPtr); + dataPtr += 2; + palFadeKeys = (Mult_PalFadeKey *)malloc(sizeof(Mult_PalFadeKey) * palFadeKeysCount); - for (i = 0; i < mult_palFadeKeysCount; i++, mult_dataPtr += 7) { - mult_palFadeKeys[i].frame = (int16)READ_LE_UINT16(mult_dataPtr); - mult_palFadeKeys[i].fade = (int16)READ_LE_UINT16(mult_dataPtr + 2); - mult_palFadeKeys[i].palIndex = (int16)READ_LE_UINT16(mult_dataPtr + 4); - mult_palFadeKeys[i].flag = *(mult_dataPtr + 6); + for (i = 0; i < palFadeKeysCount; i++, dataPtr += 7) { + palFadeKeys[i].frame = (int16)READ_LE_UINT16(dataPtr); + palFadeKeys[i].fade = (int16)READ_LE_UINT16(dataPtr + 2); + palFadeKeys[i].palIndex = (int16)READ_LE_UINT16(dataPtr + 4); + palFadeKeys[i].flag = *(dataPtr + 6); } - mult_palKeysCount = READ_LE_UINT16(mult_dataPtr); - mult_dataPtr += 2; - - mult_palKeys = (Mult_PalKey *)malloc(sizeof(Mult_PalKey) * mult_palKeysCount); - for (i = 0; i < mult_palKeysCount; i++, mult_dataPtr += 80) { - mult_palKeys[i].frame = (int16)READ_LE_UINT16(mult_dataPtr); - mult_palKeys[i].cmd = (int16)READ_LE_UINT16(mult_dataPtr + 2); - mult_palKeys[i].rates[0] = (int16)READ_LE_UINT16(mult_dataPtr + 4); - mult_palKeys[i].rates[1] = (int16)READ_LE_UINT16(mult_dataPtr + 6); - mult_palKeys[i].rates[2] = (int16)READ_LE_UINT16(mult_dataPtr + 8); - mult_palKeys[i].rates[3] = (int16)READ_LE_UINT16(mult_dataPtr + 10); - mult_palKeys[i].unknown0 = (int16)READ_LE_UINT16(mult_dataPtr + 12); - mult_palKeys[i].unknown1 = (int16)READ_LE_UINT16(mult_dataPtr + 14); - memcpy(mult_palKeys[i].subst, mult_dataPtr + 16, 64); + palKeysCount = READ_LE_UINT16(dataPtr); + dataPtr += 2; + + palKeys = (Mult_PalKey *)malloc(sizeof(Mult_PalKey) * palKeysCount); + for (i = 0; i < palKeysCount; i++, dataPtr += 80) { + palKeys[i].frame = (int16)READ_LE_UINT16(dataPtr); + palKeys[i].cmd = (int16)READ_LE_UINT16(dataPtr + 2); + palKeys[i].rates[0] = (int16)READ_LE_UINT16(dataPtr + 4); + palKeys[i].rates[1] = (int16)READ_LE_UINT16(dataPtr + 6); + palKeys[i].rates[2] = (int16)READ_LE_UINT16(dataPtr + 8); + palKeys[i].rates[3] = (int16)READ_LE_UINT16(dataPtr + 10); + palKeys[i].unknown0 = (int16)READ_LE_UINT16(dataPtr + 12); + palKeys[i].unknown1 = (int16)READ_LE_UINT16(dataPtr + 14); + memcpy(palKeys[i].subst, dataPtr + 16, 64); } - mult_textKeysCount = READ_LE_UINT16(mult_dataPtr); - mult_dataPtr += 2; - mult_textKeys = (Mult_TextKey *) malloc(sizeof(Mult_TextKey) * mult_textKeysCount); + textKeysCount = READ_LE_UINT16(dataPtr); + dataPtr += 2; + textKeys = (Mult_TextKey *) malloc(sizeof(Mult_TextKey) * textKeysCount); - for (i = 0; i < mult_textKeysCount; i++, mult_dataPtr += 28) { - mult_textKeys[i].frame = (int16)READ_LE_UINT16(mult_dataPtr); - mult_textKeys[i].cmd = (int16)READ_LE_UINT16(mult_dataPtr + 2); + for (i = 0; i < textKeysCount; i++, dataPtr += 28) { + textKeys[i].frame = (int16)READ_LE_UINT16(dataPtr); + textKeys[i].cmd = (int16)READ_LE_UINT16(dataPtr + 2); for (int k = 0; k < 9; ++k) - mult_textKeys[i].unknown0[k] = (int16)READ_LE_UINT16(mult_dataPtr + 4 + (k * 2)); - mult_textKeys[i].index = (int16)READ_LE_UINT16(mult_dataPtr + 22); - mult_textKeys[i].unknown1[0] = (int16)READ_LE_UINT16(mult_dataPtr + 24); - mult_textKeys[i].unknown1[1] = (int16)READ_LE_UINT16(mult_dataPtr + 26); + textKeys[i].unknown0[k] = (int16)READ_LE_UINT16(dataPtr + 4 + (k * 2)); + textKeys[i].index = (int16)READ_LE_UINT16(dataPtr + 22); + textKeys[i].unknown1[0] = (int16)READ_LE_UINT16(dataPtr + 24); + textKeys[i].unknown1[1] = (int16)READ_LE_UINT16(dataPtr + 26); } - mult_sndKeysCount = READ_LE_UINT16(mult_dataPtr); - mult_dataPtr += 2; - - mult_sndKeys = (Mult_SndKey *)malloc(sizeof(Mult_SndKey) * mult_sndKeysCount); - for (i = 0; i < mult_sndKeysCount; i++) { - mult_sndKeys[i].frame = (int16)READ_LE_UINT16(mult_dataPtr); - mult_sndKeys[i].cmd = (int16)READ_LE_UINT16(mult_dataPtr + 2); - mult_sndKeys[i].freq = (int16)READ_LE_UINT16(mult_dataPtr + 4); - mult_sndKeys[i].channel = (int16)READ_LE_UINT16(mult_dataPtr + 6); - mult_sndKeys[i].repCount = (int16)READ_LE_UINT16(mult_dataPtr + 8); - mult_sndKeys[i].resId = (int16)READ_LE_UINT16(mult_dataPtr + 10); - mult_sndKeys[i].soundIndex = (int16)READ_LE_UINT16(mult_dataPtr + 12); - - mult_sndKeys[i].soundIndex = -1; - mult_sndKeys[i].resId = -1; - mult_dataPtr += 36; - switch (mult_sndKeys[i].cmd) { + sndKeysCount = READ_LE_UINT16(dataPtr); + dataPtr += 2; + + sndKeys = (Mult_SndKey *)malloc(sizeof(Mult_SndKey) * sndKeysCount); + for (i = 0; i < sndKeysCount; i++) { + sndKeys[i].frame = (int16)READ_LE_UINT16(dataPtr); + sndKeys[i].cmd = (int16)READ_LE_UINT16(dataPtr + 2); + sndKeys[i].freq = (int16)READ_LE_UINT16(dataPtr + 4); + sndKeys[i].channel = (int16)READ_LE_UINT16(dataPtr + 6); + sndKeys[i].repCount = (int16)READ_LE_UINT16(dataPtr + 8); + sndKeys[i].resId = (int16)READ_LE_UINT16(dataPtr + 10); + sndKeys[i].soundIndex = (int16)READ_LE_UINT16(dataPtr + 12); + + sndKeys[i].soundIndex = -1; + sndKeys[i].resId = -1; + dataPtr += 36; + switch (sndKeys[i].cmd) { case 1: case 4: - mult_sndKeys[i].resId = READ_LE_UINT16(inter_execPtr); + sndKeys[i].resId = READ_LE_UINT16(_vm->_global->inter_execPtr); for (j = 0; j < i; j++) { - if (mult_sndKeys[i].resId == - mult_sndKeys[j].resId) { - mult_sndKeys[i].soundIndex = - mult_sndKeys[j].soundIndex; - inter_execPtr += 2; + if (sndKeys[i].resId == + sndKeys[j].resId) { + sndKeys[i].soundIndex = + sndKeys[j].soundIndex; + _vm->_global->inter_execPtr += 2; break; } } if (i == j) { - game_interLoadSound(19 - mult_sndSlotsCount); - mult_sndKeys[i].soundIndex = - 19 - mult_sndSlotsCount; - mult_sndSlotsCount++; + _vm->_game->interLoadSound(19 - sndSlotsCount); + sndKeys[i].soundIndex = + 19 - sndSlotsCount; + sndSlotsCount++; } break; case 3: - inter_execPtr += 6; + _vm->_global->inter_execPtr += 6; break; case 5: - inter_execPtr += mult_sndKeys[i].freq * 2; + _vm->_global->inter_execPtr += sndKeys[i].freq * 2; break; } } } -void mult_freeMultKeys(void) { +void Mult::freeMultKeys(void) { int i; char animCount; char staticCount; - mult_dataPtr = mult_multData; - staticCount = mult_dataPtr[0]; - animCount = mult_dataPtr[1]; + dataPtr = multData; + staticCount = dataPtr[0]; + animCount = dataPtr[1]; - free(mult_dataPtr); + free(dataPtr); staticCount++; animCount++; for (i = 0; i < staticCount; i++) { - if (mult_staticLoaded[i] != 0) - scen_freeStatic(mult_staticIndices[i]); + if (staticLoaded[i] != 0) + _vm->_scenery->freeStatic(staticIndices[i]); } for (i = 0; i < animCount; i++) { - if (mult_animLoaded[i] != 0) - scen_freeAnim(mult_animIndices[i]); + if (animLoaded[i] != 0) + _vm->_scenery->freeAnim(animIndices[i]); } - free(mult_staticKeys); + free(staticKeys); for (i = 0; i < 4; i++) - free(mult_animKeys[i]); + free(animKeys[i]); - free(mult_palFadeKeys); - free(mult_palKeys); - free(mult_textKeys); + free(palFadeKeys); + free(palKeys); + free(textKeys); - for (i = 0; i < mult_sndSlotsCount; i++) { - game_freeSoundSlot(19 - i); + for (i = 0; i < sndSlotsCount; i++) { + _vm->_game->freeSoundSlot(19 - i); } - free(mult_sndKeys); + free(sndKeys); - mult_multData = 0; + multData = 0; - if (mult_animDataAllocated != 0) { - free(mult_objects); - mult_objects = 0; + if (animDataAllocated != 0) { + free(objects); + objects = 0; - free(mult_renderData); - mult_renderData = 0; + free(renderData); + renderData = 0; - free(mult_animArrayX); - mult_animArrayX = 0; + free(animArrayX); + animArrayX = 0; - free(mult_animArrayY); - mult_animArrayY = 0; + free(animArrayY); + animArrayY = 0; - free(mult_animArrayData); - mult_animArrayData = 0; + free(animArrayData); + animArrayData = 0; - if (anim_underAnimSurf) - vid_freeSurfDesc(anim_underAnimSurf); - anim_underAnimSurf = 0; + if (_vm->_anim->_animSurf) + _vm->_video->freeSurfDesc(_vm->_anim->_animSurf); + _vm->_anim->_animSurf = 0; - mult_animDataAllocated = 0; + animDataAllocated = 0; } } -void mult_checkFreeMult(void) { - if (mult_multData != 0) - mult_freeMultKeys(); +void Mult::checkFreeMult(void) { + if (multData != 0) + freeMultKeys(); } } // End of namespace Gob diff --git a/gob/mult.h b/gob/mult.h index 5c584514ac..df66011edc 100644 --- a/gob/mult.h +++ b/gob/mult.h @@ -26,171 +26,182 @@ namespace Gob { +class Mult { +public: #pragma START_PACK_STRUCTS -typedef struct Mult_AnimData { - int8 animation; - int8 layer; - int8 frame; - int8 animType; - int8 order; - int8 isPaused; - int8 isStatic; - int8 maxTick; - int8 unknown; - int8 newLayer; - int8 newAnimation; - byte intersected; - int8 newCycle; -} GCC_PACK Mult_AnimData; - -typedef struct Mult_Object { - int32 *pPosX; - int32 *pPosY; - Mult_AnimData *pAnimData; - int16 tick; - int16 lastLeft; - int16 lastRight; - int16 lastTop; - int16 lastBottom; -} Mult_Object; - -// Mult -typedef struct Mult_StaticKey { - int16 frame; - int16 layer; -} GCC_PACK Mult_StaticKey; + typedef struct Mult_AnimData { + int8 animation; + int8 layer; + int8 frame; + int8 animType; + int8 order; + int8 isPaused; + int8 isStatic; + int8 maxTick; + int8 unknown; + int8 newLayer; + int8 newAnimation; + byte intersected; + int8 newCycle; + } GCC_PACK Mult_AnimData; + + typedef struct Mult_Object { + int32 *pPosX; + int32 *pPosY; + Mult_AnimData *pAnimData; + int16 tick; + int16 lastLeft; + int16 lastRight; + int16 lastTop; + int16 lastBottom; + } Mult_Object; + + // Mult + typedef struct Mult_StaticKey { + int16 frame; + int16 layer; + } GCC_PACK Mult_StaticKey; + + typedef struct Mult_AnimKey { + int16 frame; + int16 layer; + int16 posX; + int16 posY; + int16 order; + } GCC_PACK Mult_AnimKey; + + typedef struct Mult_TextKey { + int16 frame; + int16 cmd; + int16 unknown0[9]; + int16 index; + int16 unknown1[2]; + } GCC_PACK Mult_TextKey; + + typedef struct Mult_PalKey { + int16 frame; + int16 cmd; + int16 rates[4]; + int16 unknown0; + int16 unknown1; + int8 subst[16][4]; + } GCC_PACK Mult_PalKey; + + typedef struct Mult_PalFadeKey { + int16 frame; + int16 fade; + int16 palIndex; + int8 flag; + } GCC_PACK Mult_PalFadeKey; + + typedef struct Mult_SndKey { + int16 frame; + int16 cmd; + int16 freq; + int16 channel; + int16 repCount; + int16 resId; + int16 soundIndex; + } GCC_PACK Mult_SndKey; +#pragma END_PACK_STRUCTS -typedef struct Mult_AnimKey { - int16 frame; - int16 layer; - int16 posX; - int16 posY; - int16 order; -} GCC_PACK Mult_AnimKey; + // Globals -typedef struct Mult_TextKey { - int16 frame; - int16 cmd; - int16 unknown0[9]; - int16 index; - int16 unknown1[2]; -} GCC_PACK Mult_TextKey; + Mult_Object *objects; + int16 *renderData; + int16 objCount; + Video::SurfaceDesc *underAnimSurf; -typedef struct Mult_PalKey { - int16 frame; - int16 cmd; - int16 rates[4]; - int16 unknown0; - int16 unknown1; - int8 subst[16][4]; -} GCC_PACK Mult_PalKey; - -typedef struct Mult_PalFadeKey { + char *multData; int16 frame; - int16 fade; - int16 palIndex; - int8 flag; -} GCC_PACK Mult_PalFadeKey; + char doPalSubst; + int16 counter; + int16 frameRate; -typedef struct Mult_SndKey { - int16 frame; - int16 cmd; - int16 freq; - int16 channel; - int16 repCount; - int16 resId; - int16 soundIndex; -} GCC_PACK Mult_SndKey; -#pragma END_PACK_STRUCTS + int32 *animArrayX; + int32 *animArrayY; + + Mult_AnimData *animArrayData; + + int16 index; -// Globals - -extern Mult_Object *mult_objects; -extern int16 *mult_renderData; -extern int16 mult_objCount; -extern SurfaceDesc *mult_underAnimSurf; - -extern char *mult_multData; -extern int16 mult_frame; -extern char mult_doPalSubst; -extern int16 mult_counter; -extern int16 mult_frameRate; - -extern int32 *mult_animArrayX; -extern int32 *mult_animArrayY; - -extern Mult_AnimData *mult_animArrayData; - -extern int16 mult_index; - -// Static keys -extern int16 mult_staticKeysCount; -extern Mult_StaticKey *mult_staticKeys; -extern int16 mult_staticIndices[10]; - -// Anim keys -extern Mult_AnimKey *mult_animKeys[4]; -extern int16 mult_animKeysCount[4]; -extern int16 mult_animLayer; -extern int16 mult_animIndices[10]; - -// Text keys -extern int16 mult_textKeysCount; -extern Mult_TextKey *mult_textKeys; - -extern int16 mult_frameStart; - -// Palette keys -extern int16 mult_palKeyIndex; -extern int16 mult_palKeysCount; -extern Mult_PalKey *mult_palKeys; -extern Color *mult_oldPalette; -extern Color mult_palAnimPalette[256]; -extern int16 mult_palAnimKey; -extern int16 mult_palAnimIndices[4]; -extern int16 mult_palAnimRed[4]; -extern int16 mult_palAnimGreen[4]; -extern int16 mult_palAnimBlue[4]; - -// Palette fading -extern Mult_PalFadeKey *mult_palFadeKeys; -extern int16 mult_palFadeKeysCount; -extern char mult_palFadingRed; -extern char mult_palFadingGreen; -extern char mult_palFadingBlue; - -extern char mult_animDataAllocated; - -extern char *mult_dataPtr; -extern int16 mult_staticLoaded[10]; -extern int16 mult_animLoaded[10]; -extern int16 mult_sndSlotsCount; - -// Sound keys -extern int16 mult_sndKeysCount; -extern Mult_SndKey *mult_sndKeys; - -void mult_zeroMultData(void); -void mult_loadMult(int16 resId); -void mult_freeMultKeys(void); -void mult_checkFreeMult(void); -void mult_playMult(int16 startFrame, int16 endFrame, char checkEscape, - char handleMouse); -void mult_animate(void); -void mult_interGetObjAnimSize(void); -void mult_interInitMult(void); -void mult_freeMult(void); -void mult_interLoadMult(void); -void mult_freeAll(void); -void mult_initAll(void); -void mult_playSound(Snd_SoundDesc * soundDesc, int16 repCount, int16 freq, - int16 channel); -void mult_playMult(int16 startFrame, int16 endFrame, char checkEscape, - char handleMouse); -void mult_zeroMultData(void); -void mult_loadMult(int16 resId); -void mult_freeMultKeys(void); -void mult_checkFreeMult(void); + // Static keys + int16 staticKeysCount; + Mult_StaticKey *staticKeys; + int16 staticIndices[10]; + + // Anim keys + Mult_AnimKey *animKeys[4]; + int16 animKeysCount[4]; + int16 animLayer; + int16 animIndices[10]; + + // Text keys + int16 textKeysCount; + Mult_TextKey *textKeys; + + int16 frameStart; + + // Palette keys + int16 palKeyIndex; + int16 palKeysCount; + Mult_PalKey *palKeys; + Video::Color *oldPalette; + Video::Color palAnimPalette[256]; + int16 palAnimKey; + int16 palAnimIndices[4]; + int16 palAnimRed[4]; + int16 palAnimGreen[4]; + int16 palAnimBlue[4]; + + // Palette fading + Mult_PalFadeKey *palFadeKeys; + int16 palFadeKeysCount; + char palFadingRed; + char palFadingGreen; + char palFadingBlue; + + char animDataAllocated; + + char *dataPtr; + int16 staticLoaded[10]; + int16 animLoaded[10]; + int16 sndSlotsCount; + + // Sound keys + int16 sndKeysCount; + Mult_SndKey *sndKeys; + + void zeroMultData(void); + void loadMult(int16 resId); + void freeMultKeys(void); + void checkFreeMult(void); + void playMult(int16 startFrame, int16 endFrame, char checkEscape, + char handleMouse); + void animate(void); + void interGetObjAnimSize(void); + void interInitMult(void); + void freeMult(void); + void interLoadMult(void); + void freeAll(void); + void initAll(void); + void playSound(Snd::SoundDesc * soundDesc, int16 repCount, int16 freq, + int16 channel); + + Mult(GobEngine *vm); + +protected: + Video::Color fadePal[5][16]; + GobEngine *_vm; + + char drawStatics(char stop); + void drawAnims(void); + void drawText(char *pStop, char *pStopNoClear); + char prepPalAnim(char stop); + void doPalAnim(void); + char doFadeAnim(char stop); + char doSoundAnim(char stop); +}; } // End of namespace Gob diff --git a/gob/pack.cpp b/gob/pack.cpp index 92563b204b..e2091fa2b3 100644 --- a/gob/pack.cpp +++ b/gob/pack.cpp @@ -24,7 +24,7 @@ namespace Gob { -int32 unpackData(char *sourceBuf, char *destBuf) { +int32 Pack::unpackData(char *sourceBuf, char *destBuf) { uint32 realSize; uint32 counter; uint16 cmd; diff --git a/gob/pack.h b/gob/pack.h index 9cbba5b90b..69c53c9a83 100644 --- a/gob/pack.h +++ b/gob/pack.h @@ -24,8 +24,11 @@ namespace Gob { -int32 asm_unpackData(char *source, char *dest, char *temp); -int32 unpackData(char *source, char *dest); +class Pack { +public: + int32 asm_unpackData(char *source, char *dest, char *temp); + int32 unpackData(char *source, char *dest); +}; } // End of namespace Gob diff --git a/gob/palanim.cpp b/gob/palanim.cpp index ed5a37f274..62b4897c2c 100644 --- a/gob/palanim.cpp +++ b/gob/palanim.cpp @@ -27,74 +27,77 @@ namespace Gob { -int16 pal_fadeValue = 1; - -byte pal_toFadeRed[256]; -byte pal_toFadeGreen[256]; -byte pal_toFadeBlue[256]; +PalAnim::PalAnim(GobEngine *vm) : _vm(vm) { + fadeValue = 1; + for (int i = 0; i < 256; i++) { + toFadeRed[i] = 0; + toFadeGreen[i] = 0; + toFadeBlue[i] = 0; + } +} -char pal_fadeColor(char from, char to) { - if ((int16)from - pal_fadeValue > (int16)to) - return from - pal_fadeValue; - else if ((int16)from + pal_fadeValue < (int16)to) - return from + pal_fadeValue; +char PalAnim::fadeColor(char from, char to) { + if ((int16)from - fadeValue > (int16)to) + return from - fadeValue; + else if ((int16)from + fadeValue < (int16)to) + return from + fadeValue; else return to; } -char pal_fadeStep(int16 oper) { +char PalAnim::fadeStep(int16 oper) { byte newRed; byte newGreen; byte newBlue; char stop; int16 i; - if (colorCount != 256) - error("pal_fadeStep: Only 256 color mode is supported!"); + if (_vm->_global->colorCount != 256) + error("fadeStep: Only 256 color mode is supported!"); if (oper == 0) { stop = 1; - if (setAllPalette) { - if (inVM != 0) - error("pal_fade: inVM != 0 not supported."); + if (_vm->_global->setAllPalette) { + if (_vm->_global->inVM != 0) + error("fade: _vm->_global->inVM != 0 not supported."); for (i = 0; i < 256; i++) { newRed = - pal_fadeColor(redPalette[i], - pal_toFadeRed[i]); + fadeColor(_vm->_global->redPalette[i], + toFadeRed[i]); newGreen = - pal_fadeColor(greenPalette[i], - pal_toFadeGreen[i]); + fadeColor(_vm->_global->greenPalette[i], + toFadeGreen[i]); newBlue = - pal_fadeColor(bluePalette[i], - pal_toFadeBlue[i]); + fadeColor(_vm->_global->bluePalette[i], + toFadeBlue[i]); - if (redPalette[i] != newRed - || greenPalette[i] != newGreen - || bluePalette[i] != newBlue) { + if (_vm->_global->redPalette[i] != newRed + || _vm->_global->greenPalette[i] != newGreen + || _vm->_global->bluePalette[i] != newBlue) { - vid_setPalElem(i, newRed, newGreen, newBlue, 0, 0x13); + _vm->_video->setPalElem(i, newRed, newGreen, newBlue, 0, 0x13); - redPalette[i] = newRed; - greenPalette[i] = newGreen; - bluePalette[i] = newBlue; + _vm->_global->redPalette[i] = newRed; + _vm->_global->greenPalette[i] = newGreen; + _vm->_global->bluePalette[i] = newBlue; stop = 0; } } } else { for (i = 0; i < 16; i++) { - vid_setPalElem(i, - pal_fadeColor(redPalette[i], - pal_toFadeRed[i]), - pal_fadeColor(greenPalette[i], - pal_toFadeGreen[i]), - pal_fadeColor(bluePalette[i], - pal_toFadeBlue[i]), -1, videoMode); - - if (redPalette[i] != pal_toFadeRed[i] || - greenPalette[i] != pal_toFadeGreen[i] || - bluePalette[i] != pal_toFadeBlue[i]) + _vm->_video->setPalElem(i, + fadeColor(_vm->_global->redPalette[i], + toFadeRed[i]), + fadeColor(_vm->_global->greenPalette[i], + toFadeGreen[i]), + fadeColor(_vm->_global->bluePalette[i], + toFadeBlue[i]), -1, _vm->_global->videoMode); + + if (_vm->_global->redPalette[i] != toFadeRed[i] || + _vm->_global->greenPalette[i] != toFadeGreen[i] || + _vm->_global->bluePalette[i] != toFadeBlue[i]) stop = 0; } } @@ -102,36 +105,36 @@ char pal_fadeStep(int16 oper) { } else if (oper == 1) { stop = 1; for (i = 0; i < 16; i++) { - vid_setPalElem(i, - pal_fadeColor(redPalette[i], pal_toFadeRed[i]), - greenPalette[i], bluePalette[i], -1, videoMode); + _vm->_video->setPalElem(i, + fadeColor(_vm->_global->redPalette[i], toFadeRed[i]), + _vm->_global->greenPalette[i], _vm->_global->bluePalette[i], -1, _vm->_global->videoMode); - if (redPalette[i] != pal_toFadeRed[i]) + if (_vm->_global->redPalette[i] != toFadeRed[i]) stop = 0; } return stop; } else if (oper == 2) { stop = 1; for (i = 0; i < 16; i++) { - vid_setPalElem(i, - redPalette[i], - pal_fadeColor(greenPalette[i], pal_toFadeGreen[i]), - bluePalette[i], -1, videoMode); + _vm->_video->setPalElem(i, + _vm->_global->redPalette[i], + fadeColor(_vm->_global->greenPalette[i], toFadeGreen[i]), + _vm->_global->bluePalette[i], -1, _vm->_global->videoMode); - if (greenPalette[i] != pal_toFadeGreen[i]) + if (_vm->_global->greenPalette[i] != toFadeGreen[i]) stop = 0; } return stop; } else if (oper == 3) { stop = 1; for (i = 0; i < 16; i++) { - vid_setPalElem(i, - redPalette[i], - greenPalette[i], - pal_fadeColor(bluePalette[i], pal_toFadeBlue[i]), - -1, videoMode); + _vm->_video->setPalElem(i, + _vm->_global->redPalette[i], + _vm->_global->greenPalette[i], + fadeColor(_vm->_global->bluePalette[i], toFadeBlue[i]), + -1, _vm->_global->videoMode); - if (bluePalette[i] != pal_toFadeBlue[i]) + if (_vm->_global->bluePalette[i] != toFadeBlue[i]) stop = 0; } return stop; @@ -139,95 +142,95 @@ char pal_fadeStep(int16 oper) { return 1; } -void pal_fade(PalDesc *palDesc, int16 fade, int16 allColors) { +void PalAnim::fade(Video::PalDesc *palDesc, int16 fadeV, int16 allColors) { char stop; int16 i; - if (fade < 0) - pal_fadeValue = -fade; + if (fadeV < 0) + fadeValue = -fadeV; else - pal_fadeValue = 2; + fadeValue = 2; - if (colorCount < 256) { + if (_vm->_global->colorCount < 256) { if (palDesc != 0) - vid_setFullPalette(palDesc); + _vm->_video->setFullPalette(palDesc); return; } - if (setAllPalette == 0) { + if (_vm->_global->setAllPalette == 0) { if (palDesc == 0) { for (i = 0; i < 16; i++) { - pal_toFadeRed[i] = 0; - pal_toFadeGreen[i] = 0; - pal_toFadeBlue[i] = 0; + toFadeRed[i] = 0; + toFadeGreen[i] = 0; + toFadeBlue[i] = 0; } } else { for (i = 0; i < 16; i++) { - pal_toFadeRed[i] = palDesc->vgaPal[i].red; - pal_toFadeGreen[i] = palDesc->vgaPal[i].green; - pal_toFadeBlue[i] = palDesc->vgaPal[i].blue; + toFadeRed[i] = palDesc->vgaPal[i].red; + toFadeGreen[i] = palDesc->vgaPal[i].green; + toFadeBlue[i] = palDesc->vgaPal[i].blue; } } } else { - if (inVM != 0) - error("pal_fade: inVM != 0 is not supported"); + if (_vm->_global->inVM != 0) + error("fade: _vm->_global->inVM != 0 is not supported"); if (palDesc == 0) { for (i = 0; i < 256; i++) { - pal_toFadeRed[i] = 0; - pal_toFadeGreen[i] = 0; - pal_toFadeBlue[i] = 0; + toFadeRed[i] = 0; + toFadeGreen[i] = 0; + toFadeBlue[i] = 0; } } else { for (i = 0; i < 256; i++) { - pal_toFadeRed[i] = palDesc->vgaPal[i].red; - pal_toFadeGreen[i] = palDesc->vgaPal[i].green; - pal_toFadeBlue[i] = palDesc->vgaPal[i].blue; + toFadeRed[i] = palDesc->vgaPal[i].red; + toFadeGreen[i] = palDesc->vgaPal[i].green; + toFadeBlue[i] = palDesc->vgaPal[i].blue; } } } if (allColors == 0) { do { - if (tmpPalBuffer == 0) - vid_waitRetrace(videoMode); + if (_vm->_global->tmpPalBuffer == 0) + _vm->_video->waitRetrace(_vm->_global->videoMode); - stop = pal_fadeStep(0); + stop = fadeStep(0); - if (fade > 0) - util_delay(fade); + if (fadeV > 0) + _vm->_util->delay(fadeV); } while (stop == 0); if (palDesc != 0) - vid_setFullPalette(palDesc); + _vm->_video->setFullPalette(palDesc); else - util_clearPalette(); + _vm->_util->clearPalette(); } if (allColors == 1) { do { - vid_waitRetrace(videoMode); - stop = pal_fadeStep(1); + _vm->_video->waitRetrace(_vm->_global->videoMode); + stop = fadeStep(1); } while (stop == 0); do { - vid_waitRetrace(videoMode); - stop = pal_fadeStep(2); + _vm->_video->waitRetrace(_vm->_global->videoMode); + stop = fadeStep(2); } while (stop == 0); do { - vid_waitRetrace(videoMode); - stop = pal_fadeStep(3); + _vm->_video->waitRetrace(_vm->_global->videoMode); + stop = fadeStep(3); } while (stop == 0); if (palDesc != 0) - vid_setFullPalette(palDesc); + _vm->_video->setFullPalette(palDesc); else - util_clearPalette(); + _vm->_util->clearPalette(); } - free(tmpPalBuffer); - tmpPalBuffer = 0; + free(_vm->_global->tmpPalBuffer); + _vm->_global->tmpPalBuffer = 0; } } // End of namespace Gob diff --git a/gob/palanim.h b/gob/palanim.h index 9bc4ff6641..0f2cfcc3c4 100644 --- a/gob/palanim.h +++ b/gob/palanim.h @@ -24,11 +24,22 @@ namespace Gob { -extern int16 pal_fadeValue; +class PalAnim { +public: + int16 fadeValue; -char pal_fadeColor(char from, char to); -char pal_fadeStep(int16 oper); // oper == 0 - fade all colors, 1, 2, 3 - red,green, blue -void pal_fade(PalDesc * palDesc, int16 fade, int16 all); + char fadeColor(char from, char to); + char fadeStep(int16 oper); // oper == 0 - fade all colors, 1, 2, 3 - red,green, blue + void fade(Video::PalDesc * palDesc, int16 fade, int16 all); + + PalAnim(GobEngine *vm); + +protected: + byte toFadeRed[256]; + byte toFadeGreen[256]; + byte toFadeBlue[256]; + GobEngine *_vm; +}; } // End of namespace Gob diff --git a/gob/parse.cpp b/gob/parse.cpp index a05783ab14..9d7134a4a1 100644 --- a/gob/parse.cpp +++ b/gob/parse.cpp @@ -28,24 +28,21 @@ namespace Gob { -enum PointerType { - kExecPtr = 0, - kInterVar = 1, - kResStr = 2 -}; +Parse::Parse(GobEngine *vm) : _vm(vm) { +} -int32 encodePtr(char *ptr, int type) { +int32 Parse::encodePtr(char *ptr, int type) { int32 offset; switch (type) { case kExecPtr: - offset = ptr - game_totFileData; + offset = ptr - _vm->_game->totFileData; break; case kInterVar: - offset = ptr - inter_variables; + offset = ptr - _vm->_global->inter_variables; break; case kResStr: - offset = ptr - inter_resStr; + offset = ptr - _vm->_global->inter_resStr; break; default: error("encodePtr: Unknown pointer type"); @@ -54,18 +51,18 @@ int32 encodePtr(char *ptr, int type) { return (type << 28) | offset; } -char *decodePtr(int32 n) { +char *Parse::decodePtr(int32 n) { char *ptr; switch (n >> 28) { case kExecPtr: - ptr = game_totFileData; + ptr = _vm->_game->totFileData; break; case kInterVar: - ptr = inter_variables; + ptr = _vm->_global->inter_variables; break; case kResStr: - ptr = inter_resStr; + ptr = _vm->_global->inter_resStr; break; default: error("decodePtr: Unknown pointer type"); @@ -73,7 +70,7 @@ char *decodePtr(int32 n) { return ptr + (n & 0x0FFFFFFF); } -int16 parse_parseExpr(char arg_0, byte *arg_2) { +int16 Parse::parseExpr(char arg_0, byte *arg_2) { int32 values[20]; byte operStack[20]; int32 prevPrevVal; @@ -101,54 +98,54 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { stkPos++; operPtr++; valPtr++; - operation = *inter_execPtr++; + operation = *_vm->_global->inter_execPtr++; if (operation >= 19 && operation <= 29) { switch (operation) { case 19: *operPtr = 20; - *valPtr = READ_LE_UINT32(inter_execPtr); - inter_execPtr += 4; + *valPtr = READ_LE_UINT32(_vm->_global->inter_execPtr); + _vm->_global->inter_execPtr += 4; break; case 20: *operPtr = 20; - *valPtr = inter_load16(); + *valPtr = _vm->_inter->load16(); break; case 22: *operPtr = 22; - *valPtr = encodePtr(inter_execPtr, kExecPtr); - inter_execPtr += strlen(inter_execPtr) + 1; + *valPtr = encodePtr(_vm->_global->inter_execPtr, kExecPtr); + _vm->_global->inter_execPtr += strlen(_vm->_global->inter_execPtr) + 1; break; case 23: *operPtr = 20; - *valPtr = VAR(inter_load16()); + *valPtr = VAR(_vm->_inter->load16()); break; case 25: *operPtr = 22; - temp = inter_load16() * 4; - *valPtr = encodePtr(inter_variables + temp, kInterVar); - if (*inter_execPtr == 13) { - inter_execPtr++; - temp += parse_parseValExpr(); + temp = _vm->_inter->load16() * 4; + *valPtr = encodePtr(_vm->_global->inter_variables + temp, kInterVar); + if (*_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; + temp += parseValExpr(); *operPtr = 20; - *valPtr = (uint8)*(inter_variables + temp); + *valPtr = (uint8)*(_vm->_global->inter_variables + temp); } break; case 26: case 28: *operPtr = operation - 6; - temp = inter_load16(); - dimCount = *inter_execPtr++; - arrDescPtr = (byte *)inter_execPtr; - inter_execPtr += dimCount; + temp = _vm->_inter->load16(); + dimCount = *_vm->_global->inter_execPtr++; + arrDescPtr = (byte *)_vm->_global->inter_execPtr; + _vm->_global->inter_execPtr += dimCount; offset = 0; dim = 0; for (dim = 0; dim < dimCount; dim++) { - temp2 = parse_parseValExpr(); + temp2 = parseValExpr(); offset = offset * arrDescPtr[dim] + temp2; } @@ -156,22 +153,22 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { *valPtr = VAR(temp + offset); break; } - *valPtr = encodePtr(inter_variables + temp * 4 + offset * inter_animDataSize * 4, kInterVar); - if (*inter_execPtr == 13) { - inter_execPtr++; - temp2 = parse_parseValExpr(); + *valPtr = encodePtr(_vm->_global->inter_variables + temp * 4 + offset * _vm->_global->inter_animDataSize * 4, kInterVar); + if (*_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; + temp2 = parseValExpr(); *operPtr = 20; - *valPtr = (uint8)*(inter_variables + temp * 4 + offset * 4 * inter_animDataSize + temp2); + *valPtr = (uint8)*(_vm->_global->inter_variables + temp * 4 + offset * 4 * _vm->_global->inter_animDataSize + temp2); } break; case 29: - operation = *inter_execPtr++; - parse_parseExpr(10, 0); + operation = *_vm->_global->inter_execPtr++; + parseExpr(10, 0); switch (operation) { case 5: - inter_resVal = inter_resVal * inter_resVal; + _vm->_global->inter_resVal = _vm->_global->inter_resVal * _vm->_global->inter_resVal; break; case 0: @@ -183,22 +180,22 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { do { prevPrevVal = prevVal; prevVal = curVal; - curVal = (curVal + inter_resVal / curVal) / 2; + curVal = (curVal + _vm->_global->inter_resVal / curVal) / 2; } while (curVal != prevVal && curVal != prevPrevVal); - inter_resVal = curVal; + _vm->_global->inter_resVal = curVal; break; case 10: - inter_resVal = util_getRandom(inter_resVal); + _vm->_global->inter_resVal = _vm->_util->getRandom(_vm->_global->inter_resVal); break; case 7: - if (inter_resVal < 0) - inter_resVal = -inter_resVal; + if (_vm->_global->inter_resVal < 0) + _vm->_global->inter_resVal = -_vm->_global->inter_resVal; break; } *operPtr = 20; - *valPtr = inter_resVal; + *valPtr = _vm->_global->inter_resVal; } if (stkPos > 0 && (operPtr[-1] == 1 || operPtr[-1] == 11)) { @@ -223,11 +220,11 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { switch (operPtr[-1]) { case 2: if (operPtr[-2] == 22) { - if (decodePtr(valPtr[-2]) != inter_resStr) { - strcpy(inter_resStr, decodePtr(valPtr[-2])); - valPtr[-2] = encodePtr(inter_resStr, kResStr); + if (decodePtr(valPtr[-2]) != _vm->_global->inter_resStr) { + strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-2])); + valPtr[-2] = encodePtr(_vm->_global->inter_resStr, kResStr); } - strcat(inter_resStr, decodePtr(valPtr[0])); + strcat(_vm->_global->inter_resStr, decodePtr(valPtr[0])); stkPos -= 2; operPtr -= 2; valPtr -= 2; @@ -343,11 +340,11 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { if (operStack[brackStart] == 20) { values[brackStart] += valPtr[-1]; } else if (operStack[brackStart] == 22) { - if (decodePtr(values[brackStart]) != inter_resStr) { - strcpy(inter_resStr, decodePtr(values[brackStart])); - values[brackStart] = encodePtr(inter_resStr, kResStr); + if (decodePtr(values[brackStart]) != _vm->_global->inter_resStr) { + strcpy(_vm->_global->inter_resStr, decodePtr(values[brackStart])); + values[brackStart] = encodePtr(_vm->_global->inter_resStr, kResStr); } - strcat(inter_resStr, decodePtr(valPtr[-1])); + strcat(_vm->_global->inter_resStr, decodePtr(valPtr[-1])); } stkPos -= 2; operPtr -= 2; @@ -419,11 +416,11 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { if (valPtr[-3] < valPtr[-1]) operPtr[-3] = 24; } else if (var_C == 22) { - if (decodePtr(valPtr[-3]) != inter_resStr) { - strcpy(inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(inter_resStr, kResStr); + if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) { + strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3])); + valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr); } - if (strcmp(inter_resStr, decodePtr(valPtr[-1])) < 0) + if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) < 0) operPtr[-3] = 24; } stkPos -= 2; @@ -438,11 +435,11 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { if (valPtr[-3] <= valPtr[-1]) operPtr[-3] = 24; } else if (var_C == 22) { - if (decodePtr(valPtr[-3]) != inter_resStr) { - strcpy(inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(inter_resStr, kResStr); + if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) { + strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3])); + valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr); } - if (strcmp(inter_resStr, decodePtr(valPtr[-1])) <= 0) + if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) <= 0) operPtr[-3] = 24; } stkPos -= 2; @@ -457,11 +454,11 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { if (valPtr[-3] > valPtr[-1]) operPtr[-3] = 24; } else if (var_C == 22) { - if (decodePtr(valPtr[-3]) != inter_resStr) { - strcpy(inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(inter_resStr, kResStr); + if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) { + strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3])); + valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr); } - if (strcmp(inter_resStr, decodePtr(valPtr[-1])) > 0) + if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) > 0) operPtr[-3] = 24; } stkPos -= 2; @@ -476,11 +473,11 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { if (valPtr[-3] >= valPtr[-1]) operPtr[-3] = 24; } else if (var_C == 22) { - if (decodePtr(valPtr[-3]) != inter_resStr) { - strcpy(inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(inter_resStr, kResStr); + if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) { + strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3])); + valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr); } - if (strcmp(inter_resStr, decodePtr(valPtr[-1])) >= 0) + if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) >= 0) operPtr[-3] = 24; } stkPos -= 2; @@ -495,11 +492,11 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { if (valPtr[-3] == valPtr[-1]) operPtr[-3] = 24; } else if (var_C == 22) { - if (decodePtr(valPtr[-3]) != inter_resStr) { - strcpy(inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(inter_resStr, kResStr); + if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) { + strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3])); + valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr); } - if (strcmp(inter_resStr, decodePtr(valPtr[-1])) == 0) + if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) == 0) operPtr[-3] = 24; } stkPos -= 2; @@ -514,11 +511,11 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { if (valPtr[-3] != valPtr[-1]) operPtr[-3] = 24; } else if (var_C == 22) { - if (decodePtr(valPtr[-3]) != inter_resStr) { - strcpy(inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(inter_resStr, kResStr); + if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) { + strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3])); + valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr); } - if (strcmp(inter_resStr, decodePtr(valPtr[-1])) != 0) + if (strcmp(_vm->_global->inter_resStr, decodePtr(valPtr[-1])) != 0) operPtr[-3] = 24; } stkPos -= 2; @@ -546,15 +543,15 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { if ((operation == 30 && operPtr[-1] == 24) || (operation == 31 && operPtr[-1] == 23)) { if (stkPos > 1 && operPtr[-2] == 9) { - parse_skipExpr(10); + skipExpr(10); operPtr[-2] = operPtr[-1]; stkPos -= 2; operPtr -= 2; valPtr -= 2; } else { - parse_skipExpr(arg_0); + skipExpr(arg_0); } - operation = inter_execPtr[-1]; + operation = _vm->_global->inter_execPtr[-1]; if (stkPos > 0 && operPtr[-1] == 11) { if (operPtr[0] == 23) operPtr[-1] = 24; @@ -581,12 +578,12 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { switch (operStack[0]) { case 20: - inter_resVal = values[0]; + _vm->_global->inter_resVal = values[0]; break; case 22: - if (decodePtr(values[0]) != inter_resStr) - strcpy(inter_resStr, decodePtr(values[0])); + if (decodePtr(values[0]) != _vm->_global->inter_resStr) + strcpy(_vm->_global->inter_resStr, decodePtr(values[0])); break; case 11: @@ -599,7 +596,7 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { break; default: - inter_resVal = 0; + _vm->_global->inter_resVal = 0; if (arg_2 != 0) *arg_2 = 20; break; @@ -616,11 +613,11 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { if (operPtr[-3] == 20) { valPtr[-3] += valPtr[-1]; } else if (operPtr[-3] == 22) { - if (decodePtr(valPtr[-3]) != inter_resStr) { - strcpy(inter_resStr, decodePtr(valPtr[-3])); - valPtr[-3] = encodePtr(inter_resStr, kResStr); + if (decodePtr(valPtr[-3]) != _vm->_global->inter_resStr) { + strcpy(_vm->_global->inter_resStr, decodePtr(valPtr[-3])); + valPtr[-3] = encodePtr(_vm->_global->inter_resStr, kResStr); } - strcat(inter_resStr, decodePtr(valPtr[-1])); + strcat(_vm->_global->inter_resStr, decodePtr(valPtr[-1])); } stkPos -= 2; operPtr -= 2; @@ -643,7 +640,7 @@ int16 parse_parseExpr(char arg_0, byte *arg_2) { } } -void parse_skipExpr(char arg_0) { +void Parse::skipExpr(char arg_0) { int16 dimCount; char operation; int16 num; @@ -651,47 +648,47 @@ void parse_skipExpr(char arg_0) { num = 0; while (1) { - operation = *inter_execPtr++; + operation = *_vm->_global->inter_execPtr++; if (operation >= 19 && operation <= 29) { switch (operation) { case 20: case 23: - inter_execPtr += 2; + _vm->_global->inter_execPtr += 2; break; case 19: - inter_execPtr += 4; + _vm->_global->inter_execPtr += 4; break; case 22: - inter_execPtr += strlen(inter_execPtr) + 1; + _vm->_global->inter_execPtr += strlen(_vm->_global->inter_execPtr) + 1; break; case 25: - inter_execPtr += 2; - if (*inter_execPtr == 13) { - inter_execPtr++; - parse_skipExpr(12); + _vm->_global->inter_execPtr += 2; + if (*_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; + skipExpr(12); } break; case 26: case 28: - dimCount = inter_execPtr[2]; - inter_execPtr += 3 + dimCount; // ??? + dimCount = _vm->_global->inter_execPtr[2]; + _vm->_global->inter_execPtr += 3 + dimCount; // ??? for (dim = 0; dim < dimCount; dim++) - parse_skipExpr(12); + skipExpr(12); - if (operation == 28 && *inter_execPtr == 13) { - inter_execPtr++; - parse_skipExpr(12); + if (operation == 28 && *_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; + skipExpr(12); } break; case 29: - inter_execPtr++; - parse_skipExpr(10); + _vm->_global->inter_execPtr++; + skipExpr(10); } continue; } // if (operation >= 19 && operation <= 29) @@ -718,7 +715,7 @@ void parse_skipExpr(char arg_0) { } } -int16 parse_parseValExpr() { +int16 Parse::parseValExpr() { int16 values[20]; byte operStack[20]; int16 *valPtr; @@ -738,7 +735,7 @@ int16 parse_parseValExpr() { oldflag = flag; if (flag == 0) { flag = 1; - parse_printExpr(99); + printExpr(99); } stkPos = -1; @@ -750,63 +747,63 @@ int16 parse_parseValExpr() { operPtr++; valPtr++; - operation = *inter_execPtr++; + operation = *_vm->_global->inter_execPtr++; if (operation >= 19 && operation <= 29) { *operPtr = 20; switch (operation) { case 19: - *valPtr = READ_LE_UINT32(inter_execPtr); - inter_execPtr += 4; + *valPtr = READ_LE_UINT32(_vm->_global->inter_execPtr); + _vm->_global->inter_execPtr += 4; break; case 20: - *valPtr = inter_load16(); + *valPtr = _vm->_inter->load16(); break; case 23: - *valPtr = (uint16)VAR(inter_load16()); + *valPtr = (uint16)VAR(_vm->_inter->load16()); break; case 25: - temp = inter_load16() * 4; - inter_execPtr++; - temp += parse_parseValExpr(); - *valPtr = (uint8)*(inter_variables + temp); + temp = _vm->_inter->load16() * 4; + _vm->_global->inter_execPtr++; + temp += parseValExpr(); + *valPtr = (uint8)*(_vm->_global->inter_variables + temp); break; case 26: case 28: - temp = inter_load16(); - dimCount = *inter_execPtr++; - arrDesc = (byte*)inter_execPtr; - inter_execPtr += dimCount; + temp = _vm->_inter->load16(); + dimCount = *_vm->_global->inter_execPtr++; + arrDesc = (byte*)_vm->_global->inter_execPtr; + _vm->_global->inter_execPtr += dimCount; offset = 0; for (dim = 0; dim < dimCount; dim++) { - temp2 = parse_parseValExpr(); + temp2 = parseValExpr(); offset = arrDesc[dim] * offset + temp2; } if (operation == 26) { *valPtr = (uint16)VAR(temp + offset); } else { - inter_execPtr++; - temp2 = parse_parseValExpr(); - *valPtr = (uint8)*(inter_variables + temp * 4 + offset * 4 * inter_animDataSize + temp2); + _vm->_global->inter_execPtr++; + temp2 = parseValExpr(); + *valPtr = (uint8)*(_vm->_global->inter_variables + temp * 4 + offset * 4 * _vm->_global->inter_animDataSize + temp2); } break; case 29: - operation = *inter_execPtr++; - parse_parseExpr(10, 0); + operation = *_vm->_global->inter_execPtr++; + parseExpr(10, 0); if (operation == 5) { - inter_resVal = inter_resVal * inter_resVal; + _vm->_global->inter_resVal = _vm->_global->inter_resVal * _vm->_global->inter_resVal; } else if (operation == 7) { - if (inter_resVal < 0) - inter_resVal = -inter_resVal; + if (_vm->_global->inter_resVal < 0) + _vm->_global->inter_resVal = -_vm->_global->inter_resVal; } else if (operation == 10) { - inter_resVal = util_getRandom(inter_resVal); + _vm->_global->inter_resVal = _vm->_util->getRandom(_vm->_global->inter_resVal); } - *valPtr = inter_resVal; + *valPtr = _vm->_global->inter_resVal; break; } // switch @@ -943,7 +940,7 @@ int16 parse_parseValExpr() { } } -int16 parse_parseVarIndex() { +int16 Parse::parseVarIndex() { int16 temp2; char *arrDesc; int16 dim; @@ -953,16 +950,16 @@ int16 parse_parseVarIndex() { int16 offset; int16 val; - operation = *inter_execPtr++; + operation = *_vm->_global->inter_execPtr++; debug(5, "var parse = %d", operation); switch (operation) { case 23: case 25: - temp = inter_load16() * 4; - debug(5, "oper = %d", (int16)*inter_execPtr); - if (operation == 25 && *inter_execPtr == 13) { - inter_execPtr++; - val = parse_parseValExpr(); + temp = _vm->_inter->load16() * 4; + debug(5, "oper = %d", (int16)*_vm->_global->inter_execPtr); + if (operation == 25 && *_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; + val = parseValExpr(); temp += val; debug(5, "parse subscript = %d", val); } @@ -970,31 +967,31 @@ int16 parse_parseVarIndex() { case 26: case 28: - temp = inter_load16() * 4; - dimCount = *inter_execPtr++; - arrDesc = inter_execPtr; - inter_execPtr += dimCount; + temp = _vm->_inter->load16() * 4; + dimCount = *_vm->_global->inter_execPtr++; + arrDesc = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr += dimCount; offset = 0; for (dim = 0; dim < dimCount; dim++) { - temp2 = parse_parseValExpr(); + temp2 = parseValExpr(); offset = arrDesc[dim] * offset + temp2; } offset *= 4; if (operation != 28) return temp + offset; - if (*inter_execPtr == 13) { - inter_execPtr++; - temp += parse_parseValExpr(); + if (*_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; + temp += parseValExpr(); } - return offset * inter_animDataSize + temp; + return offset * _vm->_global->inter_animDataSize + temp; default: return 0; } } -void parse_printExpr(char arg_0) { +void Parse::printExpr(char arg_0) { int16 dimCount; char operation; int16 num; @@ -1009,40 +1006,40 @@ void parse_printExpr(char arg_0) { return; if (savedPos == 0) { - savedPos = inter_execPtr; + savedPos = _vm->_global->inter_execPtr; saved = 1; } num = 0; while (1) { - operation = *inter_execPtr++; + operation = *_vm->_global->inter_execPtr++; if (operation >= 19 && operation <= 29) { switch (operation) { case 19: - debug(5, "%l", READ_LE_UINT32(inter_execPtr)); - inter_execPtr += 4; + debug(5, "%l", READ_LE_UINT32(_vm->_global->inter_execPtr)); + _vm->_global->inter_execPtr += 4; break; case 20: - debug(5, "%d", inter_load16()); + debug(5, "%d", _vm->_inter->load16()); break; case 22: - debug(5, "\42%s\42", inter_execPtr); - inter_execPtr += strlen(inter_execPtr) + 1; + debug(5, "\42%s\42", _vm->_global->inter_execPtr); + _vm->_global->inter_execPtr += strlen(_vm->_global->inter_execPtr) + 1; break; case 23: - debug(5, "var_%d", inter_load16()); + debug(5, "var_%d", _vm->_inter->load16()); break; case 25: - debug(5, "(&var_%d)", inter_load16()); - if (*inter_execPtr == 13) { - inter_execPtr++; + debug(5, "(&var_%d)", _vm->_inter->load16()); + if (*_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; debug(5, "{"); - parse_printExpr(12); + printExpr(12); // debug(5, "}"); } break; @@ -1052,12 +1049,12 @@ void parse_printExpr(char arg_0) { if (operation == 28) debug(5, "(&"); - debug(5, "var_%d[", inter_load16()); - dimCount = *inter_execPtr++; - arrDesc = inter_execPtr; - inter_execPtr += dimCount; + debug(5, "var_%d[", _vm->_inter->load16()); + dimCount = *_vm->_global->inter_execPtr++; + arrDesc = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr += dimCount; for (dim = 0; dim < dimCount; dim++) { - parse_printExpr(12); + printExpr(12); debug(5, " of %d", (int16)arrDesc[dim]); if (dim != dimCount - 1) debug(5, ","); @@ -1066,16 +1063,16 @@ void parse_printExpr(char arg_0) { if (operation == 28) debug(5, ")"); - if (operation == 28 && *inter_execPtr == 13) { - inter_execPtr++; + if (operation == 28 && *_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; debug(5, "{"); - parse_printExpr(12); + printExpr(12); // debug(5, "}"); } break; case 29: - func = *inter_execPtr++; + func = *_vm->_global->inter_execPtr++; if (func == 5) debug(5, "sqr("); else if (func == 10) @@ -1086,7 +1083,7 @@ void parse_printExpr(char arg_0) { debug(5, "sqrt("); else debug(5, "id("); - parse_printExpr(10); + printExpr(10); break; case 12: @@ -1207,7 +1204,7 @@ void parse_printExpr(char arg_0) { if (arg_0 != 10 || num < 0) { if (saved != 0) { - inter_execPtr = savedPos; + _vm->_global->inter_execPtr = savedPos; savedPos = 0; } return; @@ -1216,46 +1213,46 @@ void parse_printExpr(char arg_0) { } } -void parse_printVarIndex() { +void Parse::printVarIndex() { char *arrDesc; int16 dim; int16 dimCount; int16 operation; int16 temp; - char *pos = inter_execPtr; + char *pos = _vm->_global->inter_execPtr; - operation = *inter_execPtr++; + operation = *_vm->_global->inter_execPtr++; switch (operation) { case 23: case 25: - temp = inter_load16() * 4; + temp = _vm->_inter->load16() * 4; debug(5, "&var_%d", temp); - if (operation == 25 && *inter_execPtr == 13) { - inter_execPtr++; + if (operation == 25 && *_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; debug(5, "+"); - parse_printExpr(99); + printExpr(99); } break; case 26: case 28: - debug(5, "&var_%d[", inter_load16()); - dimCount = *inter_execPtr++; - arrDesc = inter_execPtr; - inter_execPtr += dimCount; + debug(5, "&var_%d[", _vm->_inter->load16()); + dimCount = *_vm->_global->inter_execPtr++; + arrDesc = _vm->_global->inter_execPtr; + _vm->_global->inter_execPtr += dimCount; for (dim = 0; dim < dimCount; dim++) { - parse_printExpr(12); + printExpr(12); debug(5, " of %d", (int16)arrDesc[dim]); if (dim != dimCount - 1) debug(5, ","); } debug(5, "]"); - if (operation == 28 && *inter_execPtr == 13) { - inter_execPtr++; + if (operation == 28 && *_vm->_global->inter_execPtr == 13) { + _vm->_global->inter_execPtr++; debug(5, "+"); - parse_printExpr(99); + printExpr(99); } break; @@ -1264,7 +1261,7 @@ void parse_printVarIndex() { break; } debug(5, "\n"); - inter_execPtr = pos; + _vm->_global->inter_execPtr = pos; return; } diff --git a/gob/parse.h b/gob/parse.h index d86a99ce3f..fae387df88 100644 --- a/gob/parse.h +++ b/gob/parse.h @@ -24,12 +24,29 @@ namespace Gob { -int16 parse_parseExpr(char stopToken, byte *resultPtr); -void parse_skipExpr(char stopToken); -int16 parse_parseValExpr(void); -int16 parse_parseVarIndex(void); -void parse_printExpr(char stopToken); -void parse_printVarIndex(void); +class Parse { +public: + int16 parseExpr(char stopToken, byte *resultPtr); + void skipExpr(char stopToken); + int16 parseValExpr(void); + int16 parseVarIndex(void); + void printExpr(char stopToken); + void printVarIndex(void); + + Parse(GobEngine *vm); + +protected: + enum PointerType { + kExecPtr = 0, + kInterVar = 1, + kResStr = 2 + }; + + GobEngine *_vm; + + int32 encodePtr(char *ptr, int type); + char *decodePtr(int32 n); +}; } // End of namespace Gob diff --git a/gob/scenery.cpp b/gob/scenery.cpp index b373e2178c..0cd6971c25 100644 --- a/gob/scenery.cpp +++ b/gob/scenery.cpp @@ -33,35 +33,39 @@ namespace Gob { -int16 scen_spriteResId[20]; -char scen_spriteRefs[20]; - -Scen_Static scen_statics[10]; -int16 scen_staticPictCount[10]; -char scen_staticFromExt[10]; -int16 scen_staticResId[10]; -char scen_staticPictToSprite[70]; - -Scen_Animation scen_animations[10]; -int16 scen_animPictCount[10]; -char scen_animFromExt[10]; -int16 scen_animResId[10]; -char scen_animPictToSprite[70]; +Scenery::Scenery(GobEngine *vm) : _vm(vm) { + for (int i = 0; i < 20; i++) { + spriteRefs[i] = 0; + spriteResId[i] = 0; + } + for (int i = 0; i < 70; i++ ) { + staticPictToSprite[i] = 0; + animPictToSprite[i] = 0; + } + for (int i = 0; i < 10; i++) { + staticPictCount[i] = 0; + staticFromExt[i] = 0; + staticResId[i] = 0; + animPictCount[i] = 0; + animFromExt[i] = 0; + animResId[i] = 0; + } -int16 scen_curStatic; -int16 scen_curStaticLayer; + curStatic = 0; + curStaticLayer = 0; -int16 scen_toRedrawLeft; -int16 scen_toRedrawRight; -int16 scen_toRedrawTop; -int16 scen_toRedrawBottom; + toRedrawLeft = 0; + toRedrawRight = 0; + toRedrawTop = 0; + toRedrawBottom = 0; -int16 scen_animTop; -int16 scen_animLeft; + animTop = 0; + animLeft = 0; -int16 *scen_pCaptureCounter; + pCaptureCounter = 0; +} -int16 scen_loadStatic(char search) { +int16 Scenery::loadStatic(char search) { int16 tmp; int16 *backsPtr; int16 picsCount; @@ -69,7 +73,7 @@ int16 scen_loadStatic(char search) { int16 i; int16 sceneryIndex; char *dataPtr; - Scen_Static *ptr; + Static *ptr; int16 offset; int16 pictDescId; int16 width; @@ -77,48 +81,48 @@ int16 scen_loadStatic(char search) { int16 sprResId; int16 sprIndex; - inter_evalExpr(&sceneryIndex); - tmp = inter_load16(); - backsPtr = (int16 *)inter_execPtr; - inter_execPtr += tmp * 2; - picsCount = inter_load16(); - resId = inter_load16(); + _vm->_inter->evalExpr(&sceneryIndex); + tmp = _vm->_inter->load16(); + backsPtr = (int16 *)_vm->_global->inter_execPtr; + _vm->_global->inter_execPtr += tmp * 2; + picsCount = _vm->_inter->load16(); + resId = _vm->_inter->load16(); if (search) { for (i = 0; i < 10; i++) { - if (scen_staticPictCount[i] != -1 && scen_staticResId[i] == resId) { - inter_execPtr += 8 * scen_staticPictCount[i]; + if (staticPictCount[i] != -1 && staticResId[i] == resId) { + _vm->_global->inter_execPtr += 8 * staticPictCount[i]; return i; } - if (scen_staticPictCount[i] == -1 && i < sceneryIndex) + if (staticPictCount[i] == -1 && i < sceneryIndex) sceneryIndex = i; } } - scen_staticPictCount[sceneryIndex] = picsCount; - scen_staticResId[sceneryIndex] = resId; + staticPictCount[sceneryIndex] = picsCount; + staticResId[sceneryIndex] = resId; if (resId >= 30000) { - scen_staticFromExt[sceneryIndex] = 1; - dataPtr = game_loadExtData(resId, 0, 0); + staticFromExt[sceneryIndex] = 1; + dataPtr = _vm->_game->loadExtData(resId, 0, 0); } else { - scen_staticFromExt[sceneryIndex] = 0; - dataPtr = game_loadTotResource(resId); + staticFromExt[sceneryIndex] = 0; + dataPtr = _vm->_game->loadTotResource(resId); } - ptr = &scen_statics[sceneryIndex]; + ptr = &statics[sceneryIndex]; ptr->dataPtr = dataPtr; ptr->layersCount = (int16)READ_LE_UINT16(dataPtr); dataPtr += 2; - ptr->layers = (Scen_StaticLayer **)malloc(sizeof(Scen_StaticLayer *) * ptr->layersCount); - ptr->pieces = (Scen_PieceDesc **)malloc(sizeof(Scen_PieceDesc *) * picsCount); + ptr->layers = (StaticLayer **)malloc(sizeof(StaticLayer *) * ptr->layersCount); + ptr->pieces = (PieceDesc **)malloc(sizeof(PieceDesc *) * picsCount); ptr->piecesFromExt = (int8 *)malloc(picsCount); for (i = 0; i < ptr->layersCount; i++) { offset = (int16)READ_LE_UINT16(&((int16 *)dataPtr)[i]); - ptr->layers[i] = (Scen_StaticLayer *)(dataPtr + offset - 2); + ptr->layers[i] = (StaticLayer *)(dataPtr + offset - 2); ptr->layers[i]->planeCount = (int16)READ_LE_UINT16(&ptr->layers[i]->planeCount); @@ -132,91 +136,91 @@ int16 scen_loadStatic(char search) { } for (i = 0; i < picsCount; i++) { - pictDescId = inter_load16(); + pictDescId = _vm->_inter->load16(); if (pictDescId >= 30000) { ptr->pieces[i] = - (Scen_PieceDesc *) game_loadExtData(pictDescId, 0, + (PieceDesc *) _vm->_game->loadExtData(pictDescId, 0, 0); ptr->piecesFromExt[i] = 1; } else { ptr->pieces[i] = - (Scen_PieceDesc *) - game_loadTotResource(pictDescId); + (PieceDesc *) + _vm->_game->loadTotResource(pictDescId); ptr->piecesFromExt[i] = 0; } - width = inter_load16(); - height = inter_load16(); - sprResId = inter_load16(); + width = _vm->_inter->load16(); + height = _vm->_inter->load16(); + sprResId = _vm->_inter->load16(); for (sprIndex = 0; sprIndex < 20; sprIndex++) { - if (scen_spriteResId[sprIndex] == sprResId) + if (spriteResId[sprIndex] == sprResId) break; } if (sprIndex < 20) { - scen_staticPictToSprite[7 * sceneryIndex + i] = + staticPictToSprite[7 * sceneryIndex + i] = sprIndex; - scen_spriteRefs[sprIndex]++; + spriteRefs[sprIndex]++; } else { - for (sprIndex = 19; draw_spritesArray[sprIndex] != 0; + for (sprIndex = 19; _vm->_draw->spritesArray[sprIndex] != 0; sprIndex--); - scen_staticPictToSprite[7 * sceneryIndex + i] = + staticPictToSprite[7 * sceneryIndex + i] = sprIndex; - scen_spriteRefs[sprIndex] = 1; - scen_spriteResId[sprIndex] = sprResId; - draw_spritesArray[sprIndex] = - vid_initSurfDesc(videoMode, width, height, 2); - - vid_clearSurf(draw_spritesArray[sprIndex]); - draw_destSurface = sprIndex; - draw_spriteLeft = sprResId; - draw_transparency = 0; - draw_destSpriteX = 0; - draw_destSpriteY = 0; - draw_spriteOperation(DRAW_LOADSPRITE); + spriteRefs[sprIndex] = 1; + spriteResId[sprIndex] = sprResId; + _vm->_draw->spritesArray[sprIndex] = + _vm->_video->initSurfDesc(_vm->_global->videoMode, width, height, 2); + + _vm->_video->clearSurf(_vm->_draw->spritesArray[sprIndex]); + _vm->_draw->destSurface = sprIndex; + _vm->_draw->spriteLeft = sprResId; + _vm->_draw->transparency = 0; + _vm->_draw->destSpriteX = 0; + _vm->_draw->destSpriteY = 0; + _vm->_draw->spriteOperation(DRAW_LOADSPRITE); } } return sceneryIndex + 100; } -void scen_freeStatic(int16 index) { +void Scenery::freeStatic(int16 index) { int16 i; int16 spr; if (index == -1) - inter_evalExpr(&index); + _vm->_inter->evalExpr(&index); - if (scen_staticPictCount[index] == -1) + if (staticPictCount[index] == -1) return; - for (i = 0; i < scen_staticPictCount[index]; i++) { - if (scen_statics[index].piecesFromExt[i] == 1) - free(scen_statics[index].pieces[i]); + for (i = 0; i < staticPictCount[index]; i++) { + if (statics[index].piecesFromExt[i] == 1) + free(statics[index].pieces[i]); - spr = scen_staticPictToSprite[index * 7 + i]; - scen_spriteRefs[spr]--; - if (scen_spriteRefs[spr] == 0) { - vid_freeSurfDesc(draw_spritesArray[spr]); - draw_spritesArray[spr] = 0; - scen_spriteResId[spr] = -1; + spr = staticPictToSprite[index * 7 + i]; + spriteRefs[spr]--; + if (spriteRefs[spr] == 0) { + _vm->_video->freeSurfDesc(_vm->_draw->spritesArray[spr]); + _vm->_draw->spritesArray[spr] = 0; + spriteResId[spr] = -1; } } - free(scen_statics[index].layers); - free(scen_statics[index].pieces); - free(scen_statics[index].piecesFromExt); - if (scen_staticFromExt[index] == 1) - free(scen_statics[index].dataPtr); + free(statics[index].layers); + free(statics[index].pieces); + free(statics[index].piecesFromExt); + if (staticFromExt[index] == 1) + free(statics[index].dataPtr); - scen_staticFromExt[index] = 0; - scen_staticPictCount[index] = -1; + staticFromExt[index] = 0; + staticPictCount[index] = -1; } -void scen_renderStatic(int16 scenery, int16 layer) { - Scen_Static *ptr; - Scen_StaticLayer *layerPtr; - Scen_StaticPlane *planePtr; +void Scenery::renderStatic(int16 scenery, int16 layer) { + Static *ptr; + StaticLayer *layerPtr; + StaticPlane *planePtr; int16 planeCount; int16 order; int16 plane; @@ -229,19 +233,19 @@ void scen_renderStatic(int16 scenery, int16 layer) { int16 top; int16 bottom; - ptr = &scen_statics[scenery]; + ptr = &statics[scenery]; if (layer >= ptr->layersCount) return; layerPtr = ptr->layers[layer]; - draw_spriteLeft = layerPtr->backResId; - if (draw_spriteLeft != -1) { - draw_destSpriteX = 0; - draw_destSpriteY = 0; - draw_destSurface = 21; - draw_transparency = 0; - draw_spriteOperation(DRAW_LOADSPRITE); + _vm->_draw->spriteLeft = layerPtr->backResId; + if (_vm->_draw->spriteLeft != -1) { + _vm->_draw->destSpriteX = 0; + _vm->_draw->destSpriteY = 0; + _vm->_draw->destSurface = 21; + _vm->_draw->transparency = 0; + _vm->_draw->spriteOperation(DRAW_LOADSPRITE); } planeCount = layerPtr->planeCount; @@ -254,44 +258,44 @@ void scen_renderStatic(int16 scenery, int16 layer) { pieceIndex = planePtr->pieceIndex; pictIndex = planePtr->pictIndex - 1; - draw_destSpriteX = planePtr->destX; - draw_destSpriteY = planePtr->destY; + _vm->_draw->destSpriteX = planePtr->destX; + _vm->_draw->destSpriteY = planePtr->destY; left = FROM_LE_16(ptr->pieces[pictIndex][pieceIndex].left); right = FROM_LE_16(ptr->pieces[pictIndex][pieceIndex].right); top = FROM_LE_16(ptr->pieces[pictIndex][pieceIndex].top); bottom = FROM_LE_16(ptr->pieces[pictIndex][pieceIndex].bottom); - draw_sourceSurface = - scen_staticPictToSprite[scenery * 7 + pictIndex]; - draw_destSurface = 21; - draw_spriteLeft = left; - draw_spriteTop = top; - draw_spriteRight = right - left + 1; - draw_spriteBottom = bottom - top + 1; - draw_transparency = planePtr->transp ? 3 : 0; - draw_spriteOperation(DRAW_BLITSURF); + _vm->_draw->sourceSurface = + staticPictToSprite[scenery * 7 + pictIndex]; + _vm->_draw->destSurface = 21; + _vm->_draw->spriteLeft = left; + _vm->_draw->spriteTop = top; + _vm->_draw->spriteRight = right - left + 1; + _vm->_draw->spriteBottom = bottom - top + 1; + _vm->_draw->transparency = planePtr->transp ? 3 : 0; + _vm->_draw->spriteOperation(DRAW_BLITSURF); } } } -void scen_interRenderStatic(void) { +void Scenery::interRenderStatic(void) { int16 layer; int16 index; - inter_evalExpr(&index); - inter_evalExpr(&layer); - scen_renderStatic(index, layer); + _vm->_inter->evalExpr(&index); + _vm->_inter->evalExpr(&layer); + renderStatic(index, layer); } -void scen_interLoadCurLayer(void) { - inter_evalExpr(&scen_curStatic); - inter_evalExpr(&scen_curStaticLayer); +void Scenery::interLoadCurLayer(void) { + _vm->_inter->evalExpr(&curStatic); + _vm->_inter->evalExpr(&curStaticLayer); } -void scen_updateStatic(int16 orderFrom) { - Scen_StaticLayer *layerPtr; - Scen_PieceDesc **pictPtr; - Scen_StaticPlane *planePtr; +void Scenery::updateStatic(int16 orderFrom) { + StaticLayer *layerPtr; + PieceDesc **pictPtr; + StaticPlane *planePtr; int16 planeCount; int16 order; int16 plane; @@ -303,14 +307,14 @@ void scen_updateStatic(int16 orderFrom) { int16 top; int16 bottom; - if (scen_curStatic == -1) + if (curStatic == -1) return; - if (scen_curStaticLayer >= scen_statics[scen_curStatic].layersCount) + if (curStaticLayer >= statics[curStatic].layersCount) return; - layerPtr = scen_statics[scen_curStatic].layers[scen_curStaticLayer]; - pictPtr = scen_statics[scen_curStatic].pieces; + layerPtr = statics[curStatic].layers[curStaticLayer]; + pictPtr = statics[curStatic].pieces; planeCount = layerPtr->planeCount; @@ -322,65 +326,65 @@ void scen_updateStatic(int16 orderFrom) { pieceIndex = planePtr->pieceIndex; pictIndex = planePtr->pictIndex - 1; - draw_destSpriteX = planePtr->destX; - draw_destSpriteY = planePtr->destY; + _vm->_draw->destSpriteX = planePtr->destX; + _vm->_draw->destSpriteY = planePtr->destY; left = FROM_LE_16(pictPtr[pictIndex][pieceIndex].left); right = FROM_LE_16(pictPtr[pictIndex][pieceIndex].right); top = FROM_LE_16(pictPtr[pictIndex][pieceIndex].top); bottom = FROM_LE_16(pictPtr[pictIndex][pieceIndex].bottom); - if (draw_destSpriteX > scen_toRedrawRight) + if (_vm->_draw->destSpriteX > toRedrawRight) continue; - if (draw_destSpriteY > scen_toRedrawBottom) + if (_vm->_draw->destSpriteY > toRedrawBottom) continue; - if (draw_destSpriteX < scen_toRedrawLeft) { - left += scen_toRedrawLeft - draw_destSpriteX; - draw_destSpriteX = scen_toRedrawLeft; + if (_vm->_draw->destSpriteX < toRedrawLeft) { + left += toRedrawLeft - _vm->_draw->destSpriteX; + _vm->_draw->destSpriteX = toRedrawLeft; } - if (draw_destSpriteY < scen_toRedrawTop) { - top += scen_toRedrawTop - draw_destSpriteY; - draw_destSpriteY = scen_toRedrawTop; + if (_vm->_draw->destSpriteY < toRedrawTop) { + top += toRedrawTop - _vm->_draw->destSpriteY; + _vm->_draw->destSpriteY = toRedrawTop; } - draw_spriteLeft = left; - draw_spriteTop = top; - draw_spriteRight = right - left + 1; - draw_spriteBottom = bottom - top + 1; + _vm->_draw->spriteLeft = left; + _vm->_draw->spriteTop = top; + _vm->_draw->spriteRight = right - left + 1; + _vm->_draw->spriteBottom = bottom - top + 1; - if (draw_spriteRight <= 0 || draw_spriteBottom <= 0) + if (_vm->_draw->spriteRight <= 0 || _vm->_draw->spriteBottom <= 0) continue; - if (draw_destSpriteX + draw_spriteRight - 1 > - scen_toRedrawRight) - draw_spriteRight = - scen_toRedrawRight - draw_destSpriteX + 1; + if (_vm->_draw->destSpriteX + _vm->_draw->spriteRight - 1 > + toRedrawRight) + _vm->_draw->spriteRight = + toRedrawRight - _vm->_draw->destSpriteX + 1; - if (draw_destSpriteY + draw_spriteBottom - 1 > - scen_toRedrawBottom) - draw_spriteBottom = - scen_toRedrawBottom - draw_destSpriteY + 1; + if (_vm->_draw->destSpriteY + _vm->_draw->spriteBottom - 1 > + toRedrawBottom) + _vm->_draw->spriteBottom = + toRedrawBottom - _vm->_draw->destSpriteY + 1; - draw_sourceSurface = - scen_staticPictToSprite[scen_curStatic * 7 + + _vm->_draw->sourceSurface = + staticPictToSprite[curStatic * 7 + pictIndex]; - draw_destSurface = 21; - draw_transparency = planePtr->transp ? 3 : 0; - draw_spriteOperation(DRAW_BLITSURF); + _vm->_draw->destSurface = 21; + _vm->_draw->transparency = planePtr->transp ? 3 : 0; + _vm->_draw->spriteOperation(DRAW_BLITSURF); } } } -int16 scen_loadAnim(char search) { +int16 Scenery::loadAnim(char search) { int16 picsCount; int16 resId; int16 i; int16 sceneryIndex; char *dataPtr; - Scen_Animation *ptr; + Animation *ptr; int16 offset; int16 pictDescId; int16 width; @@ -388,58 +392,58 @@ int16 scen_loadAnim(char search) { int16 sprResId; int16 sprIndex; - if (cd_globFlag) { - while (cd_getTrackPos() != -1) - util_longDelay(50); + if (_vm->_cdrom->_cdPlaying) { + while (_vm->_cdrom->getTrackPos() != -1) + _vm->_util->longDelay(50); - cd_globFlag = false; + _vm->_cdrom->_cdPlaying = false; } - inter_evalExpr(&sceneryIndex); - picsCount = inter_load16(); - resId = inter_load16(); + _vm->_inter->evalExpr(&sceneryIndex); + picsCount = _vm->_inter->load16(); + resId = _vm->_inter->load16(); if (search) { for (i = 0; i < 10; i++) { - if (scen_animPictCount[i] != 0 - && scen_animResId[i] == resId) { - inter_execPtr += 8 * scen_animPictCount[i]; + if (animPictCount[i] != 0 + && animResId[i] == resId) { + _vm->_global->inter_execPtr += 8 * animPictCount[i]; return i; } - if (scen_animPictCount[i] == 0 && i < sceneryIndex) + if (animPictCount[i] == 0 && i < sceneryIndex) sceneryIndex = i; } } - scen_animPictCount[sceneryIndex] = picsCount; - scen_animResId[sceneryIndex] = resId; + animPictCount[sceneryIndex] = picsCount; + animResId[sceneryIndex] = resId; if (resId >= 30000) { - scen_animFromExt[sceneryIndex] = 1; - dataPtr = game_loadExtData(resId, 0, 0); + animFromExt[sceneryIndex] = 1; + dataPtr = _vm->_game->loadExtData(resId, 0, 0); } else { - scen_animFromExt[sceneryIndex] = 0; - dataPtr = game_loadTotResource(resId); + animFromExt[sceneryIndex] = 0; + dataPtr = _vm->_game->loadTotResource(resId); } - ptr = &scen_animations[sceneryIndex]; + ptr = &animations[sceneryIndex]; ptr->dataPtr = dataPtr; ptr->layersCount = READ_LE_UINT16(dataPtr); dataPtr += 2; ptr->layers = - (Scen_AnimLayer **) malloc(sizeof(Scen_AnimLayer *) * + (AnimLayer **) malloc(sizeof(AnimLayer *) * ptr->layersCount); ptr->pieces = - (Scen_PieceDesc **) malloc(sizeof(Scen_PieceDesc *) * + (PieceDesc **) malloc(sizeof(PieceDesc *) * picsCount); ptr->piecesFromExt = (int8 *) malloc(picsCount); for (i = 0; i < ptr->layersCount; i++) { offset = (int16)READ_LE_UINT16(&((int16 *)dataPtr)[i]); - ptr->layers[i] = (Scen_AnimLayer *) (dataPtr + offset - 2); + ptr->layers[i] = (AnimLayer *) (dataPtr + offset - 2); ptr->layers[i]->unknown0 = (int16)READ_LE_UINT16(&ptr->layers[i]->unknown0); ptr->layers[i]->posX = (int16)READ_LE_UINT16(&ptr->layers[i]->posX); @@ -450,47 +454,47 @@ int16 scen_loadAnim(char search) { } for (i = 0; i < picsCount; i++) { - pictDescId = inter_load16(); + pictDescId = _vm->_inter->load16(); if (pictDescId >= 30000) { ptr->pieces[i] = - (Scen_PieceDesc *) game_loadExtData(pictDescId, 0, + (PieceDesc *) _vm->_game->loadExtData(pictDescId, 0, 0); ptr->piecesFromExt[i] = 1; } else { ptr->pieces[i] = - (Scen_PieceDesc *) - game_loadTotResource(pictDescId); + (PieceDesc *) + _vm->_game->loadTotResource(pictDescId); ptr->piecesFromExt[i] = 0; } - width = inter_load16(); - height = inter_load16(); - sprResId = inter_load16(); + width = _vm->_inter->load16(); + height = _vm->_inter->load16(); + sprResId = _vm->_inter->load16(); for (sprIndex = 0; sprIndex < 20; sprIndex++) { - if (scen_spriteResId[sprIndex] == sprResId) + if (spriteResId[sprIndex] == sprResId) break; } if (sprIndex < 20) { - scen_animPictToSprite[7 * sceneryIndex + i] = sprIndex; - scen_spriteRefs[sprIndex]++; + animPictToSprite[7 * sceneryIndex + i] = sprIndex; + spriteRefs[sprIndex]++; } else { - for (sprIndex = 19; draw_spritesArray[sprIndex] != 0; + for (sprIndex = 19; _vm->_draw->spritesArray[sprIndex] != 0; sprIndex--); - scen_animPictToSprite[7 * sceneryIndex + i] = sprIndex; - scen_spriteRefs[sprIndex] = 1; - scen_spriteResId[sprIndex] = sprResId; - draw_spritesArray[sprIndex] = - vid_initSurfDesc(videoMode, width, height, 2); - - vid_clearSurf(draw_spritesArray[sprIndex]); - draw_destSurface = sprIndex; - draw_spriteLeft = sprResId; - draw_transparency = 0; - draw_destSpriteX = 0; - draw_destSpriteY = 0; - draw_spriteOperation(DRAW_LOADSPRITE); + animPictToSprite[7 * sceneryIndex + i] = sprIndex; + spriteRefs[sprIndex] = 1; + spriteResId[sprIndex] = sprResId; + _vm->_draw->spritesArray[sprIndex] = + _vm->_video->initSurfDesc(_vm->_global->videoMode, width, height, 2); + + _vm->_video->clearSurf(_vm->_draw->spritesArray[sprIndex]); + _vm->_draw->destSurface = sprIndex; + _vm->_draw->spriteLeft = sprResId; + _vm->_draw->transparency = 0; + _vm->_draw->destSpriteX = 0; + _vm->_draw->destSpriteY = 0; + _vm->_draw->spriteOperation(DRAW_LOADSPRITE); } } return sceneryIndex + 100; @@ -500,11 +504,11 @@ int16 scen_loadAnim(char search) { // flags & 4 == 0 - calculate animation final size // flags & 2 != 0 - don't check with "toRedraw"'s // flags & 4 != 0 - checkk view toRedraw -void scen_updateAnim(int16 layer, int16 frame, int16 animation, int16 flags, +void Scenery::updateAnim(int16 layer, int16 frame, int16 animation, int16 flags, int16 drawDeltaX, int16 drawDeltaY, char doDraw) { - Scen_AnimLayer *layerPtr; - Scen_PieceDesc **pictPtr; - Scen_AnimFramePiece *framePtr; + AnimLayer *layerPtr; + PieceDesc **pictPtr; + AnimFramePiece *framePtr; uint16 pieceIndex; uint16 pictIndex; @@ -523,29 +527,29 @@ void scen_updateAnim(int16 layer, int16 frame, int16 animation, int16 flags, int16 destX; int16 destY; - if (layer >= scen_animations[animation].layersCount) + if (layer >= animations[animation].layersCount) return; - layerPtr = scen_animations[animation].layers[layer]; + layerPtr = animations[animation].layers[layer]; if (frame >= layerPtr->framesCount) return; if (flags & 1) // Do capture { - scen_updateAnim(layer, frame, animation, 0, drawDeltaX, + updateAnim(layer, frame, animation, 0, drawDeltaX, drawDeltaY, 0); - if (scen_toRedrawLeft == -12345) // Some magic number? + if (toRedrawLeft == -12345) // Some magic number? return; - game_capturePush(scen_toRedrawLeft, scen_toRedrawTop, - scen_toRedrawRight - scen_toRedrawLeft + 1, - scen_toRedrawBottom - scen_toRedrawTop + 1); + _vm->_game->capturePush(toRedrawLeft, toRedrawTop, + toRedrawRight - toRedrawLeft + 1, + toRedrawBottom - toRedrawTop + 1); - *scen_pCaptureCounter = *scen_pCaptureCounter + 1; + *pCaptureCounter = *pCaptureCounter + 1; } - pictPtr = scen_animations[animation].pieces; + pictPtr = animations[animation].pieces; framePtr = layerPtr->frames; for (i = 0; i < frame; i++, framePtr++) { @@ -554,18 +558,18 @@ void scen_updateAnim(int16 layer, int16 frame, int16 animation, int16 flags, } if ((flags & 4) == 0) { - scen_toRedrawLeft = -12345; + toRedrawLeft = -12345; } else { - scen_toRedrawLeft = - MAX(scen_toRedrawLeft, anim_animAreaLeft); - scen_toRedrawTop = - MAX(scen_toRedrawTop, anim_animAreaTop); - scen_toRedrawRight = - MIN(scen_toRedrawRight, - (int16)(anim_animAreaLeft + anim_animAreaWidth - 1)); - scen_toRedrawBottom = - MIN(scen_toRedrawBottom, - (int16)(anim_animAreaTop + anim_animAreaHeight - 1)); + toRedrawLeft = + MAX(toRedrawLeft, _vm->_anim->_areaLeft); + toRedrawTop = + MAX(toRedrawTop, _vm->_anim->_areaTop); + toRedrawRight = + MIN(toRedrawRight, + (int16)(_vm->_anim->_areaLeft + _vm->_anim->_areaWidth - 1)); + toRedrawBottom = + MIN(toRedrawBottom, + (int16)(_vm->_anim->_areaTop + _vm->_anim->_areaHeight - 1)); } transp = layerPtr->transp ? 3 : 0; @@ -612,131 +616,131 @@ void scen_updateAnim(int16 layer, int16 frame, int16 animation, int16 flags, bottom = FROM_LE_16(pictPtr[pictIndex][pieceIndex].bottom); if (flags & 2) { - if (destX < anim_animAreaLeft) { - left += anim_animAreaLeft - destX; - destX = anim_animAreaLeft; + if (destX < _vm->_anim->_areaLeft) { + left += _vm->_anim->_areaLeft - destX; + destX = _vm->_anim->_areaLeft; } if (left <= right && destX + right - left >= - anim_animAreaLeft + anim_animAreaWidth) + _vm->_anim->_areaLeft + _vm->_anim->_areaWidth) right -= (destX + right - left) - - (anim_animAreaLeft + anim_animAreaWidth) + + (_vm->_anim->_areaLeft + _vm->_anim->_areaWidth) + 1; - if (destY < anim_animAreaTop) { - top += anim_animAreaTop - destY; - destY = anim_animAreaTop; + if (destY < _vm->_anim->_areaTop) { + top += _vm->_anim->_areaTop - destY; + destY = _vm->_anim->_areaTop; } if (top <= bottom && destY + bottom - top >= - anim_animAreaTop + anim_animAreaHeight) + _vm->_anim->_areaTop + _vm->_anim->_areaHeight) bottom -= (destY + bottom - top) - - (anim_animAreaTop + anim_animAreaHeight) + + (_vm->_anim->_areaTop + _vm->_anim->_areaHeight) + 1; } else if (flags & 4) { - if (destX < scen_toRedrawLeft) { - left += scen_toRedrawLeft - destX; - destX = scen_toRedrawLeft; + if (destX < toRedrawLeft) { + left += toRedrawLeft - destX; + destX = toRedrawLeft; } if (left <= right - && destX + right - left > scen_toRedrawRight) + && destX + right - left > toRedrawRight) right -= - destX + right - left - scen_toRedrawRight; + destX + right - left - toRedrawRight; - if (destY < scen_toRedrawTop) { - top += scen_toRedrawTop - destY; - destY = scen_toRedrawTop; + if (destY < toRedrawTop) { + top += toRedrawTop - destY; + destY = toRedrawTop; } if (top <= bottom - && destY + bottom - top > scen_toRedrawBottom) + && destY + bottom - top > toRedrawBottom) bottom -= - destY + bottom - top - scen_toRedrawBottom; + destY + bottom - top - toRedrawBottom; } if (left > right || top > bottom) continue; if (doDraw) { - draw_sourceSurface = - scen_animPictToSprite[animation * 7 + pictIndex]; - draw_destSurface = 21; - - draw_spriteLeft = left; - draw_spriteTop = top; - draw_spriteRight = right - left + 1; - draw_spriteBottom = bottom - top + 1; - draw_destSpriteX = destX; - draw_destSpriteY = destY; - draw_transparency = transp; - draw_spriteOperation(DRAW_BLITSURF); + _vm->_draw->sourceSurface = + animPictToSprite[animation * 7 + pictIndex]; + _vm->_draw->destSurface = 21; + + _vm->_draw->spriteLeft = left; + _vm->_draw->spriteTop = top; + _vm->_draw->spriteRight = right - left + 1; + _vm->_draw->spriteBottom = bottom - top + 1; + _vm->_draw->destSpriteX = destX; + _vm->_draw->destSpriteY = destY; + _vm->_draw->transparency = transp; + _vm->_draw->spriteOperation(DRAW_BLITSURF); } if ((flags & 4) == 0) { - if (scen_toRedrawLeft == -12345) { - scen_toRedrawLeft = destX; - scen_animLeft = destX; - scen_toRedrawTop = destY; - scen_animTop = destY; - scen_toRedrawRight = destX + right - left; - scen_toRedrawBottom = destY + bottom - top; + if (toRedrawLeft == -12345) { + toRedrawLeft = destX; + animLeft = destX; + toRedrawTop = destY; + animTop = destY; + toRedrawRight = destX + right - left; + toRedrawBottom = destY + bottom - top; } else { - scen_toRedrawLeft = - MIN(scen_toRedrawLeft, destX); - scen_toRedrawTop = - MIN(scen_toRedrawTop, destY); - scen_toRedrawRight = - MAX(scen_toRedrawRight, + toRedrawLeft = + MIN(toRedrawLeft, destX); + toRedrawTop = + MIN(toRedrawTop, destY); + toRedrawRight = + MAX(toRedrawRight, (int16)(destX + right - left)); - scen_toRedrawBottom = - MAX(scen_toRedrawBottom, + toRedrawBottom = + MAX(toRedrawBottom, (int16)(destY + bottom - top)); } } } while (framePtr->notFinal == 1); } -void scen_freeAnim(int16 animation) { +void Scenery::freeAnim(int16 animation) { int16 i; int16 spr; if (animation == -1) - inter_evalExpr(&animation); + _vm->_inter->evalExpr(&animation); - if (scen_animPictCount[animation] == 0) + if (animPictCount[animation] == 0) return; - for (i = 0; i < scen_animPictCount[animation]; i++) { - if (scen_animations[animation].piecesFromExt[i] == 1) - free(scen_animations[animation].pieces[i]); + for (i = 0; i < animPictCount[animation]; i++) { + if (animations[animation].piecesFromExt[i] == 1) + free(animations[animation].pieces[i]); - spr = scen_animPictToSprite[animation * 7 + i]; - scen_spriteRefs[spr]--; - if (scen_spriteRefs[spr] == 0) { - vid_freeSurfDesc(draw_spritesArray[spr]); + spr = animPictToSprite[animation * 7 + i]; + spriteRefs[spr]--; + if (spriteRefs[spr] == 0) { + _vm->_video->freeSurfDesc(_vm->_draw->spritesArray[spr]); - draw_spritesArray[spr] = 0; - scen_spriteResId[spr] = -1; + _vm->_draw->spritesArray[spr] = 0; + spriteResId[spr] = -1; } } - free(scen_animations[animation].layers); - free(scen_animations[animation].pieces); - free(scen_animations[animation].piecesFromExt); - if (scen_animFromExt[animation] == 1) - free(scen_animations[animation].dataPtr); + free(animations[animation].layers); + free(animations[animation].pieces); + free(animations[animation].piecesFromExt); + if (animFromExt[animation] == 1) + free(animations[animation].dataPtr); - scen_animFromExt[animation] = 0; - scen_animPictCount[animation] = 0; + animFromExt[animation] = 0; + animPictCount[animation] = 0; } -void scen_interUpdateAnim(void) { +void Scenery::interUpdateAnim(void) { int16 deltaX; int16 deltaY; int16 flags; @@ -744,37 +748,37 @@ void scen_interUpdateAnim(void) { int16 layer; int16 animation; - inter_evalExpr(&deltaX); - inter_evalExpr(&deltaY); - inter_evalExpr(&animation); - inter_evalExpr(&layer); - inter_evalExpr(&frame); - flags = inter_load16(); - scen_updateAnim(layer, frame, animation, flags, deltaX, deltaY, 1); + _vm->_inter->evalExpr(&deltaX); + _vm->_inter->evalExpr(&deltaY); + _vm->_inter->evalExpr(&animation); + _vm->_inter->evalExpr(&layer); + _vm->_inter->evalExpr(&frame); + flags = _vm->_inter->load16(); + updateAnim(layer, frame, animation, flags, deltaX, deltaY, 1); } -void scen_interStoreParams(void) { - Scen_AnimLayer *layerPtr; +void Scenery::interStoreParams(void) { + AnimLayer *layerPtr; int16 animation; int16 layer; int16 var; - warning("scen_interStoreParams: Storing..."); + warning("interStoreParams: Storing..."); - inter_evalExpr(&animation); - inter_evalExpr(&layer); - layerPtr = scen_animations[animation].layers[layer]; + _vm->_inter->evalExpr(&animation); + _vm->_inter->evalExpr(&layer); + layerPtr = animations[animation].layers[layer]; - var = parse_parseVarIndex(); + var = _vm->_parse->parseVarIndex(); WRITE_VAR_OFFSET(var, layerPtr->animDeltaX); - var = parse_parseVarIndex(); + var = _vm->_parse->parseVarIndex(); WRITE_VAR_OFFSET(var, layerPtr->animDeltaY); - var = parse_parseVarIndex(); + var = _vm->_parse->parseVarIndex(); WRITE_VAR_OFFSET(var, layerPtr->unknown0); - var = parse_parseVarIndex(); + var = _vm->_parse->parseVarIndex(); WRITE_VAR_OFFSET(var, layerPtr->framesCount); } diff --git a/gob/scenery.h b/gob/scenery.h index 8b9b50d7ba..b80ed118cb 100644 --- a/gob/scenery.h +++ b/gob/scenery.h @@ -24,112 +24,124 @@ namespace Gob { +class Scenery { +public: #pragma START_PACK_STRUCTS -typedef struct Scen_PieceDesc { - int16 left; //NOTE: - int16 right; //These are stored in Little Endian format - int16 top; //And should be converted by client code when accessed - int16 bottom; //i.e. use FROM_LE_16() -} GCC_PACK Scen_PieceDesc; - -typedef struct Scen_StaticPlane { - int8 pictIndex; - int8 pieceIndex; - int8 drawOrder; - int16 destX; - int16 destY; - int8 transp; -} GCC_PACK Scen_StaticPlane; - -typedef struct Scen_StaticLayer { - int16 backResId; - int16 planeCount; - Scen_StaticPlane planes[1]; -} GCC_PACK Scen_StaticLayer; - -// Animations - -typedef struct Scen_AnimFramePiece { - byte pictIndex; - byte pieceIndex; - int8 destX; - int8 destY; - int8 notFinal; -} GCC_PACK Scen_AnimFramePiece; - -typedef struct Scen_AnimLayer { - int16 unknown0; - int16 posX; - int16 posY; - int16 animDeltaX; - int16 animDeltaY; - int8 transp; - int16 framesCount; - Scen_AnimFramePiece frames[1]; -} GCC_PACK Scen_AnimLayer; + typedef struct PieceDesc { + int16 left; //NOTE: + int16 right; //These are stored in Little Endian format + int16 top; //And should be converted by client code when accessed + int16 bottom; //i.e. use FROM_LE_16() + } GCC_PACK PieceDesc; + + typedef struct StaticPlane { + int8 pictIndex; + int8 pieceIndex; + int8 drawOrder; + int16 destX; + int16 destY; + int8 transp; + } GCC_PACK StaticPlane; + + typedef struct StaticLayer { + int16 backResId; + int16 planeCount; + StaticPlane planes[1]; + } GCC_PACK StaticLayer; + + // Animations + + typedef struct AnimFramePiece { + byte pictIndex; + byte pieceIndex; + int8 destX; + int8 destY; + int8 notFinal; + } GCC_PACK AnimFramePiece; + + typedef struct AnimLayer { + int16 unknown0; + int16 posX; + int16 posY; + int16 animDeltaX; + int16 animDeltaY; + int8 transp; + int16 framesCount; + AnimFramePiece frames[1]; + } GCC_PACK AnimLayer; #pragma END_PACK_STRUCTS -typedef struct Scen_Static { - int16 layersCount; - Scen_StaticLayer **layers; - Scen_PieceDesc **pieces; - int8 *piecesFromExt; - char *dataPtr; -} Scen_Static; - -struct Scen_Animation { - int16 layersCount; - Scen_AnimLayer **layers; - Scen_PieceDesc **pieces; - int8 *piecesFromExt; - char *dataPtr; + typedef struct Static { + int16 layersCount; + StaticLayer **layers; + PieceDesc **pieces; + int8 *piecesFromExt; + char *dataPtr; + Static() : layersCount(0), layers(0), pieces(0), + piecesFromExt(0), dataPtr(0) {} + } Static; + + struct Animation { + int16 layersCount; + AnimLayer **layers; + PieceDesc **pieces; + int8 *piecesFromExt; + char *dataPtr; + Animation() : layersCount(0), layers(0), pieces(0), + piecesFromExt(0), dataPtr(0) {} + }; + + // Global variables + + char spriteRefs[20]; + int16 spriteResId[20]; + + char staticPictToSprite[70]; + int16 staticPictCount[10]; + Static statics[10]; + char staticFromExt[10]; + int16 staticResId[10]; + + char animPictToSprite[70]; + int16 animPictCount[10]; + char animFromExt[10]; + Animation animations[10]; + int16 animResId[10]; + + int16 curStatic; + int16 curStaticLayer; + + int16 toRedrawLeft; + int16 toRedrawRight; + int16 toRedrawTop; + int16 toRedrawBottom; + + int16 animTop; + int16 animLeft; + + int16 *pCaptureCounter; + + // Functions + + int16 loadStatic(char search); + void freeStatic(int16 index); + void renderStatic(int16 scenery, int16 layer); + void interRenderStatic(void); + void interLoadCurLayer(void); + void updateStatic(int16 orderFrom); + int16 loadAnim(char search); + void updateAnim(int16 layer, int16 frame, int16 animation, int16 flags, + int16 drawDeltaX, int16 drawDeltaY, char doDraw); + void freeAnim(int16 animation); + void interUpdateAnim(void); + void interStoreParams(void); + + Scenery(GobEngine *vm); + +protected: + GobEngine *_vm; }; -// Global variables - -extern char scen_spriteRefs[20]; -extern int16 scen_spriteResId[20]; - -extern char scen_staticPictToSprite[70]; -extern int16 scen_staticPictCount[10]; -extern Scen_Static scen_statics[10]; -extern char scen_staticFromExt[10]; -extern int16 scen_staticResId[10]; - -extern char scen_animPictToSprite[70]; -extern int16 scen_animPictCount[10]; -extern char scen_animFromExt[10]; -extern Scen_Animation scen_animations[10]; -extern int16 scen_animResId[10]; - -extern int16 scen_curStatic; -extern int16 scen_curStaticLayer; - -extern int16 scen_toRedrawLeft; -extern int16 scen_toRedrawRight; -extern int16 scen_toRedrawTop; -extern int16 scen_toRedrawBottom; - -extern int16 scen_animTop; -extern int16 scen_animLeft; - -extern int16 *scen_pCaptureCounter; - -// Functions - -int16 scen_loadStatic(char search); -void scen_freeStatic(int16 index); -void scen_renderStatic(int16 scenery, int16 layer); -void scen_interRenderStatic(void); -void scen_interLoadCurLayer(void); -void scen_updateStatic(int16 orderFrom); -int16 scen_loadAnim(char search); -void scen_updateAnim(int16 layer, int16 frame, int16 animation, int16 flags, - int16 drawDeltaX, int16 drawDeltaY, char doDraw); -void scen_freeAnim(int16 animation); -void scen_interUpdateAnim(void); -void scen_interStoreParams(void); - } // End of namespace Gob #endif /* __SCENERY_H */ diff --git a/gob/sound.cpp b/gob/sound.cpp index bd6e3ca42f..3b287badf8 100644 --- a/gob/sound.cpp +++ b/gob/sound.cpp @@ -20,41 +20,14 @@ * */ -#include "sound/audiostream.h" - #include "gob/gob.h" #include "gob/global.h" #include "gob/sound.h" namespace Gob { -// TODO: This is a very primitive square wave generator. The only thing is -// has in common with the PC speaker is that it sounds terrible. - -class SquareWaveStream : public AudioStream { -private: - uint _rate; - bool _beepForever; - uint32 _periodLength; - uint32 _periodSamples; - uint32 _remainingSamples; - int16 _sampleValue; - -public: - SquareWaveStream() {} - ~SquareWaveStream() {} - - void playNote(int freq, int32 ms); - - int readBuffer(int16 *buffer, const int numSamples); - - bool endOfData() const { return _remainingSamples == 0; } - bool isStereo() const { return false; } - int getRate() const { return _rate; } -}; - -void SquareWaveStream::playNote(int freq, int32 ms) { - _rate = _vm->_mixer->getOutputRate(); +void Snd::SquareWaveStream::playNote(int freq, int32 ms, uint rate) { + _rate = rate; _periodLength = _rate / (2 * freq); _periodSamples = 0; _sampleValue = 6000; @@ -67,7 +40,7 @@ void SquareWaveStream::playNote(int freq, int32 ms) { } } -int SquareWaveStream::readBuffer(int16 *buffer, const int numSamples) { +int Snd::SquareWaveStream::readBuffer(int16 *buffer, const int numSamples) { int samples = 0; while (samples < numSamples && _remainingSamples > 0) { @@ -84,48 +57,42 @@ int SquareWaveStream::readBuffer(int16 *buffer, const int numSamples) { return samples; } -SquareWaveStream speakerStream; -Audio::SoundHandle speakerHandle; -Snd_SoundDesc *snd_loopingSounds[5]; // Should be enough - -void snd_initSound(void) { - for (int i = 0; i < ARRAYSIZE(snd_loopingSounds); i++) - snd_loopingSounds[i] = NULL; +Snd::Snd(GobEngine *vm) : _vm(vm) { + //CleanupFuncPtr cleanupFunc;// = &snd_cleanupFuncCallback(); + cleanupFunc = 0; + for (int i = 0; i < ARRAYSIZE(loopingSounds); i++) + loopingSounds[i] = NULL; + soundPort = 0; + playingSound = 0; } -void snd_loopSounds(void) { - for (int i = 0; i < ARRAYSIZE(snd_loopingSounds); i++) { - Snd_SoundDesc *snd = snd_loopingSounds[i]; +void Snd::loopSounds(void) { + for (int i = 0; i < ARRAYSIZE(loopingSounds); i++) { + SoundDesc *snd = loopingSounds[i]; if (snd && !_vm->_mixer->isSoundHandleActive(snd->handle)) { if (snd->repCount-- > 0) { _vm->_mixer->playRaw(&snd->handle, snd->data, snd->size, snd->frequency, 0); } else { - snd_loopingSounds[i] = NULL; + loopingSounds[i] = NULL; } } } } -int16 snd_checkProAudio(void) {return 0;} -int16 snd_checkAdlib(void) {return 0;} -int16 snd_checkBlaster(void) {return 0;} -void snd_setBlasterPort(int16 port) {return;} +void Snd::setBlasterPort(int16 port) {return;} -void snd_speakerOn(int16 frequency, int32 length) { - speakerStream.playNote(frequency, length); +void Snd::speakerOn(int16 frequency, int32 length) { + speakerStream.playNote(frequency, length, _vm->_mixer->getOutputRate()); if (!_vm->_mixer->isSoundHandleActive(speakerHandle)) { _vm->_mixer->playInputStream(Audio::Mixer::kSFXSoundType, &speakerHandle, &speakerStream, -1, 255, 0, false); } } -void snd_speakerOff(void) { +void Snd::speakerOff(void) { _vm->_mixer->stopHandle(speakerHandle); } -void snd_stopSound(int16 arg){return;} -void snd_setResetTimerFlag(char flag){return;} - -void snd_playSample(Snd_SoundDesc *sndDesc, int16 repCount, int16 frequency) { +void Snd::playSample(Snd::SoundDesc *sndDesc, int16 repCount, int16 frequency) { assert(frequency > 0); if (!_vm->_mixer->isSoundHandleActive(sndDesc->handle)) { @@ -136,9 +103,9 @@ void snd_playSample(Snd_SoundDesc *sndDesc, int16 repCount, int16 frequency) { sndDesc->frequency = frequency; if (repCount > 1) { - for (int i = 0; i < ARRAYSIZE(snd_loopingSounds); i++) { - if (!snd_loopingSounds[i]) { - snd_loopingSounds[i] = sndDesc; + for (int i = 0; i < ARRAYSIZE(loopingSounds); i++) { + if (!loopingSounds[i]) { + loopingSounds[i] = sndDesc; return; } } @@ -146,44 +113,34 @@ void snd_playSample(Snd_SoundDesc *sndDesc, int16 repCount, int16 frequency) { } } -void snd_cleanupFuncCallback() {;} -CleanupFuncPtr (snd_cleanupFunc); -//CleanupFuncPtr snd_cleanupFunc;// = &snd_cleanupFuncCallback(); - -int16 snd_soundPort; -char snd_playingSound; - -void snd_writeAdlib(int16 port, int16 data) { +void Snd::writeAdlib(int16 port, int16 data) { return; } -Snd_SoundDesc *snd_loadSoundData(const char *path) { - Snd_SoundDesc *sndDesc; +Snd::SoundDesc *Snd::loadSoundData(const char *path) { + Snd::SoundDesc *sndDesc; int32 size; - size = data_getDataSize(path); - sndDesc = (Snd_SoundDesc *)malloc(size); + size = _vm->_dataio->getDataSize(path); + sndDesc = (Snd::SoundDesc *)malloc(size); sndDesc->size = size; - sndDesc->data = data_getData(path); + sndDesc->data = _vm->_dataio->getData(path); return sndDesc; } -void snd_freeSoundData(Snd_SoundDesc *sndDesc) { +void Snd::freeSoundData(Snd::SoundDesc *sndDesc) { _vm->_mixer->stopHandle(sndDesc->handle); - for (int i = 0; i < ARRAYSIZE(snd_loopingSounds); i++) { - if (snd_loopingSounds[i] == sndDesc) - snd_loopingSounds[i] = NULL; + for (int i = 0; i < ARRAYSIZE(loopingSounds); i++) { + if (loopingSounds[i] == sndDesc) + loopingSounds[i] = NULL; } free(sndDesc->data); free(sndDesc); } -void snd_playComposition(Snd_SoundDesc ** samples, int16 *composit, int16 freqVal) {;} -void snd_waitEndPlay(void) {;} - } // End of namespace Gob diff --git a/gob/sound.h b/gob/sound.h index 4b947c5317..60750874f4 100644 --- a/gob/sound.h +++ b/gob/sound.h @@ -22,43 +22,82 @@ #ifndef GOB_SOUND_H #define GOB_SOUND_H +#include "sound/audiostream.h" + namespace Gob { -void snd_initSound(void); -void snd_loopSounds(void); -int16 snd_checkProAudio(void); -int16 snd_checkAdlib(void); -int16 snd_checkBlaster(void); -void snd_setBlasterPort(int16 port); -void snd_speakerOn(int16 frequency, int32 length); -void snd_speakerOff(void); -void snd_stopSound(int16 arg); -void snd_setResetTimerFlag(char flag); - -extern int16 snd_soundPort; -extern char snd_playingSound; - -typedef void (*CleanupFuncPtr) (int16); -extern CleanupFuncPtr snd_cleanupFunc; - -void snd_writeAdlib(int16 port, int16 data); - -typedef struct Snd_SoundDesc { - Audio::SoundHandle handle; - char *data; - int32 size; - int16 repCount; - int16 timerTicks; - int16 inClocks; - int16 frequency; - int16 flag; -} Snd_SoundDesc; - -void snd_playSample(Snd_SoundDesc *sndDesc, int16 repCount, int16 frequency); -Snd_SoundDesc *snd_loadSoundData(const char *path); -void snd_freeSoundData(Snd_SoundDesc *sndDesc); -void snd_playComposition(Snd_SoundDesc **samples, int16 *composit, int16 freqVal); -void snd_waitEndPlay(void); +class Snd { +public: + typedef struct SoundDesc { + Audio::SoundHandle handle; + char *data; + int32 size; + int16 repCount; + int16 timerTicks; + int16 inClocks; + int16 frequency; + int16 flag; + SoundDesc() : data(0), size(0), repCount(0), timerTicks(0), + inClocks(0), frequency(0), flag(0) {} + } SoundDesc; + + typedef void (*CleanupFuncPtr) (int16); + + SoundDesc *loopingSounds[5]; // Should be enough + int16 soundPort; + char playingSound; + CleanupFuncPtr cleanupFunc; + + Snd(GobEngine *vm); + void speakerOn(int16 frequency, int32 length); + void speakerOff(void); + SoundDesc *loadSoundData(const char *path); + void stopSound(int16 arg){return;} + void loopSounds(void); + void playSample(SoundDesc *sndDesc, int16 repCount, int16 frequency); + void playComposition(Snd::SoundDesc ** samples, int16 *composit, int16 freqVal) {;} + void waitEndPlay(void) {;} + void freeSoundData(SoundDesc *sndDesc); + +protected: + // TODO: This is a very primitive square wave generator. The only thing is + // has in common with the PC speaker is that it sounds terrible. + class SquareWaveStream : public AudioStream { + private: + uint _rate; + bool _beepForever; + uint32 _periodLength; + uint32 _periodSamples; + uint32 _remainingSamples; + int16 _sampleValue; + + public: + SquareWaveStream() {} + ~SquareWaveStream() {} + + void playNote(int freq, int32 ms, uint rate); + + int readBuffer(int16 *buffer, const int numSamples); + + bool endOfData() const { return _remainingSamples == 0; } + bool isStereo() const { return false; } + int getRate() const { return _rate; } + }; + + SquareWaveStream speakerStream; + Audio::SoundHandle speakerHandle; + + GobEngine *_vm; + + void cleanupFuncCallback() {;} + int16 checkProAudio(void) {return 0;} + int16 checkAdlib(void) {return 0;} + int16 checkBlaster(void) {return 0;} + + void writeAdlib(int16 port, int16 data); + void setBlasterPort(int16 port); + void setResetTimerFlag(char flag){return;} +}; } // End of namespace Gob diff --git a/gob/timer.cpp b/gob/timer.cpp index 1c5987d2e9..c7487f1156 100644 --- a/gob/timer.cpp +++ b/gob/timer.cpp @@ -22,13 +22,15 @@ #include "gob/gob.h" #include "gob/global.h" #include "gob/sound.h" +#include "gob/timer.h" + namespace Gob { -void timer_enableTimer() { - debug(4, "STUB: timer_enableTimer()"); +void GTimer::enableTimer() { + debug(4, "STUB: GTimer::enableTimer()"); } -void timer_disableTimer() { - debug(4, "STUB: timer_disableTimer()"); +void GTimer::disableTimer() { + debug(4, "STUB: GTimer::disableTimer()"); } } diff --git a/gob/timer.h b/gob/timer.h index ca0a8b49b3..5b7e77c2b4 100644 --- a/gob/timer.h +++ b/gob/timer.h @@ -24,15 +24,18 @@ namespace Gob { -typedef void (* TickHandler) (void); +class GTimer { +public: + typedef void (* TickHandler) (void); -void timer_enableTimer(void); -void timer_disableTimer(void); -void timer_setHandler(void); -void timer_restoreHandler(void); -void timer_addTicks(int16 ticks); -void timer_setTickHandler(TickHandler handler); -int32 timer_getTicks(void); + void enableTimer(void); + void disableTimer(void); + void setHandler(void); + void restoreHandler(void); + void addTicks(int16 ticks); + void setTickHandler(TickHandler handler); + int32 getTicks(void); +}; } // End of namespace Gob diff --git a/gob/util.cpp b/gob/util.cpp index ace32c8fac..7d5b574b97 100644 --- a/gob/util.cpp +++ b/gob/util.cpp @@ -28,47 +28,52 @@ namespace Gob { -static const int kKeyBufSize = 16; - -static int16 _mouseX, _mouseY, _mouseButtons; -static int16 _keyBuffer[kKeyBufSize], _keyBufferHead, _keyBufferTail; - -static void addKeyToBuffer(int16 key) { - if ((_keyBufferHead + 1) % kKeyBufSize == _keyBufferTail) { +Util::Util(GobEngine *vm) : _vm(vm) { + _mouseX = 0; + _mouseY = 0; + _mouseButtons = 0; + for (int i = 0; i < KEYBUFSIZE; i++) + _keyBuffer[i] = 0; + _keyBufferHead = 0; + _keyBufferTail = 0; +} + +void Util::addKeyToBuffer(int16 key) { + if ((_keyBufferHead + 1) % KEYBUFSIZE == _keyBufferTail) { warning("key buffer overflow!"); return; } _keyBuffer[_keyBufferHead] = key; - _keyBufferHead = (_keyBufferHead + 1) % kKeyBufSize; + _keyBufferHead = (_keyBufferHead + 1) % KEYBUFSIZE; } -static bool keyBufferEmpty() { +bool Util::keyBufferEmpty() { return (_keyBufferHead == _keyBufferTail); } -static bool getKeyFromBuffer(int16& key) { +bool Util::getKeyFromBuffer(int16& key) { if (_keyBufferHead == _keyBufferTail) return false; key = _keyBuffer[_keyBufferTail]; - _keyBufferTail = (_keyBufferTail + 1) % kKeyBufSize; + _keyBufferTail = (_keyBufferTail + 1) % KEYBUFSIZE; return true; } -void util_initInput(void) { +void Util::initInput(void) { _mouseX = _mouseY = _mouseButtons = 0; _keyBufferHead = _keyBufferTail = 0; } -void util_waitKey(void) { +void Util::waitKey(void) { // FIXME: wrong function name? This functions clears the keyboard buffer. - util_processInput(); + processInput(); _keyBufferHead = _keyBufferTail = 0; } -int16 util_translateKey(int16 key) { +int16 Util::translateKey(int16 key) { struct keyS { int16 from; int16 to; @@ -104,32 +109,32 @@ int16 util_translateKey(int16 key) { return key; } -int16 util_getKey(void) { +int16 Util::getKey(void) { int16 key; while (!getKeyFromBuffer(key)) { - util_processInput(); + processInput(); if (keyBufferEmpty()) g_system->delayMillis(10); } - return util_translateKey(key); + return translateKey(key); } -int16 util_checkKey(void) { +int16 Util::checkKey(void) { int16 key; if (!getKeyFromBuffer(key)) key = 0; - return util_translateKey(key); + return translateKey(key); } -int16 util_getRandom(int16 max) { +int16 Util::getRandom(int16 max) { return _vm->_rnd.getRandomNumber(max - 1); } -void util_processInput() { +void Util::processInput() { OSystem::Event event; while (g_system->pollEvent(event)) { switch (event.type) { @@ -163,7 +168,7 @@ void util_processInput() { } } -void util_getMouseState(int16 *pX, int16 *pY, int16 *pButtons) { +void Util::getMouseState(int16 *pX, int16 *pY, int16 *pButtons) { *pX = _mouseX; *pY = _mouseY; @@ -171,91 +176,90 @@ void util_getMouseState(int16 *pX, int16 *pY, int16 *pButtons) { *pButtons = _mouseButtons; } -void util_setMousePos(int16 x, int16 y) { +void Util::setMousePos(int16 x, int16 y) { g_system->warpMouse(x, y); } -void util_longDelay(uint16 msecs) -{ +void Util::longDelay(uint16 msecs) { uint32 time = g_system->getMillis() + msecs; do { - vid_waitRetrace(videoMode); - util_processInput(); - util_delay(25); + _vm->_video->waitRetrace(_vm->_global->videoMode); + processInput(); + delay(25); } while (g_system->getMillis() < time); } -void util_delay(uint16 msecs) { +void Util::delay(uint16 msecs) { g_system->delayMillis(msecs); } -void util_beep(int16 freq) { - if (soundFlags == 0) +void Util::beep(int16 freq) { + if (_vm->_global->soundFlags == 0) return; - snd_speakerOn(freq, 50); + _vm->_snd->speakerOn(freq, 50); } -uint32 util_getTimeKey(void) { +uint32 Util::getTimeKey(void) { return g_system->getMillis(); } -void util_waitMouseUp(void) { +void Util::waitMouseUp(void) { int16 x; int16 y; int16 buttons; do { - util_processInput(); - util_getMouseState(&x, &y, &buttons); - if (buttons != 0) util_delay(10); + processInput(); + getMouseState(&x, &y, &buttons); + if (buttons != 0) delay(10); } while (buttons != 0); } -void util_waitMouseDown(void) { +void Util::waitMouseDown(void) { int16 x; int16 y; int16 buttons; do { - util_processInput(); - util_getMouseState(&x, &y, &buttons); - if (buttons == 0) util_delay(10); + processInput(); + getMouseState(&x, &y, &buttons); + if (buttons == 0) delay(10); } while (buttons == 0); } /* NOT IMPLEMENTED */ -int16 util_calcDelayTime() { +int16 Util::calcDelayTime() { return 0; } /* NOT IMPLEMENTED */ -void util_checkJoystick() { - useJoystick = 0; +void Util::checkJoystick() { + _vm->_global->useJoystick = 0; } -void util_setFrameRate(int16 rate) { +void Util::setFrameRate(int16 rate) { if (rate == 0) rate = 1; - frameWaitTime = 1000 / rate; - startFrameTime = util_getTimeKey(); + _vm->_global->frameWaitTime = 1000 / rate; + _vm->_global->startFrameTime = getTimeKey(); } -void util_waitEndFrame() { +void Util::waitEndFrame() { int32 time; - vid_waitRetrace(videoMode); + _vm->_video->waitRetrace(_vm->_global->videoMode); - time = util_getTimeKey() - startFrameTime; + time = getTimeKey() - _vm->_global->startFrameTime; if (time > 1000 || time < 0) { - startFrameTime = util_getTimeKey(); + _vm->_global->startFrameTime = getTimeKey(); return; } - if (frameWaitTime - time > 0) { - util_delay(frameWaitTime - time); + if (_vm->_global->frameWaitTime - time > 0) { + delay(_vm->_global->frameWaitTime - time); } - startFrameTime = util_getTimeKey(); + _vm->_global->startFrameTime = getTimeKey(); } int16 joy_getState() { @@ -266,14 +270,14 @@ int16 joy_calibrate() { return 0; } -FontDesc *util_loadFont(const char *path) { - FontDesc *fontDesc = (FontDesc *) malloc(sizeof(FontDesc)); +Video::FontDesc *Util::loadFont(const char *path) { + Video::FontDesc *fontDesc = (Video::FontDesc *) malloc(sizeof(Video::FontDesc)); char *data; if (fontDesc == 0) return 0; - data = data_getData(path); + data = _vm->_dataio->getData(path); if (data == 0) { free(fontDesc); return 0; @@ -298,20 +302,20 @@ FontDesc *util_loadFont(const char *path) { return fontDesc; } -void util_freeFont(FontDesc * fontDesc) { +void Util::freeFont(Video::FontDesc * fontDesc) { free(fontDesc->dataPtr - 4); free(fontDesc); } -void util_clearPalette(void) { +void Util::clearPalette(void) { int16 i; byte colors[768]; - if (videoMode != 0x13) - error("util_clearPalette: Video mode 0x%x is not supported!", - videoMode); + if (_vm->_global->videoMode != 0x13) + error("clearPalette: Video mode 0x%x is not supported!", + _vm->_global->videoMode); - if (setAllPalette) { + if (_vm->_global->setAllPalette) { for (i = 0; i < 768; i++) colors[i] = 0; g_system->setPalette(colors, 0, 256); @@ -320,10 +324,10 @@ void util_clearPalette(void) { } for (i = 0; i < 16; i++) - vid_setPalElem(i, 0, 0, 0, 0, videoMode); + _vm->_video->setPalElem(i, 0, 0, 0, 0, _vm->_global->videoMode); } -void util_insertStr(const char *str1, char *str2, int16 pos) { +void Util::insertStr(const char *str1, char *str2, int16 pos) { int16 len1; int16 i; int16 from; @@ -342,11 +346,11 @@ void util_insertStr(const char *str1, char *str2, int16 pos) { str2[i + from] = str1[i]; } -void util_cutFromStr(char *str, int16 from, int16 cutlen) { +void Util::cutFromStr(char *str, int16 from, int16 cutlen) { int16 len; int16 i; - //log_write("util_cutFromStr: str = %s, ", str); + //log_write("cutFromStr: str = %s, ", str); len = strlen(str); if (from >= len) return; @@ -364,12 +368,12 @@ void util_cutFromStr(char *str, int16 from, int16 cutlen) { //log_write("res = %s\n", str); } -int16 util_strstr(const char *str1, char *str2) { +int16 Util::strstr(const char *str1, char *str2) { char c; uint16 len1; uint16 i; - //log_write("util_strstr: str1 = %s, str2 = %s\n", str1, str2); + //log_write("strstr: str1 = %s, str2 = %s\n", str1, str2); for (i = 0, len1 = strlen(str1); strlen(str2 + i) >= len1; i++) { c = str2[i + len1]; @@ -383,10 +387,10 @@ int16 util_strstr(const char *str1, char *str2) { return 0; } -void util_listInsertFront(Util_List * list, void *data) { - Util_ListNode *node; +void Util::listInsertFront(List * list, void *data) { + ListNode *node; - node = (Util_ListNode *) malloc(sizeof(Util_ListNode)); + node = (ListNode *) malloc(sizeof(ListNode)); if (list->pHead != 0) { node->pData = data; node->pNext = list->pHead; @@ -402,28 +406,28 @@ void util_listInsertFront(Util_List * list, void *data) { } } -void util_listInsertBack(Util_List * list, void *data) { - Util_ListNode *node; +void Util::listInsertBack(List * list, void *data) { + ListNode *node; if (list->pHead != 0) { if (list->pTail == 0) { list->pTail = list->pHead; - warning("util_listInsertBack: Broken list!"); + warning("listInsertBack: Broken list!"); } node = - (Util_ListNode *) malloc(sizeof(Util_ListNode)); + (ListNode *) malloc(sizeof(ListNode)); node->pData = data; node->pPrev = list->pTail; node->pNext = 0; list->pTail->pNext = node; list->pTail = node; } else { - util_listInsertFront(list, data); + listInsertFront(list, data); } } -void util_listDropFront(Util_List * list) { +void Util::listDropFront(List * list) { if (list->pHead->pNext == 0) { free((list->pHead)); list->pHead = 0; @@ -435,50 +439,50 @@ void util_listDropFront(Util_List * list) { } } -void util_deleteList(Util_List * list) { +void Util::deleteList(List * list) { while (list->pHead != 0) { - util_listDropFront(list); + listDropFront(list); } free(list); } -char util_str1[] = +const char Util::trStr1[] = " ' + - :0123456789: <=> abcdefghijklmnopqrstuvwxyz abcdefghijklmnopqrstuvwxyz "; -char util_str2[] = +const char Util::trStr2[] = " ueaaaaceeeiii ooouu aioun "; -char util_str3[] = " "; +const char Util::trStr3[] = " "; -void util_prepareStr(char *str) { +void Util::prepareStr(char *str) { uint16 i; int16 j; char buf[300]; - strcpy(buf, util_str1); - strcat(buf, util_str2); - strcat(buf, util_str3); + strcpy(buf, trStr1); + strcat(buf, trStr2); + strcat(buf, trStr3); for (i = 0; i < strlen(str); i++) str[i] = buf[str[i] - 32]; while (str[0] == ' ') - util_cutFromStr(str, 0, 1); + cutFromStr(str, 0, 1); while (strlen(str) > 0 && str[strlen(str) - 1] == ' ') - util_cutFromStr(str, strlen(str) - 1, 1); + cutFromStr(str, strlen(str) - 1, 1); - i = util_strstr(" ", str); + i = strstr(" ", str); while (1) { if (i == 0) return; if (str[i] == ' ') { - util_cutFromStr(str, i - 1, 1); + cutFromStr(str, i - 1, 1); continue; } - j = util_strstr(" ", str + i); + j = strstr(" ", str + i); if (j != 0) i += j; else @@ -486,18 +490,18 @@ void util_prepareStr(char *str) { } } -void util_waitMouseRelease(char drawMouse) { +void Util::waitMouseRelease(char drawMouse) { int16 buttons; int16 mouseX; int16 mouseY; do { - game_checkKeys(&mouseX, &mouseY, &buttons, drawMouse); + _vm->_game->checkKeys(&mouseX, &mouseY, &buttons, drawMouse); if (drawMouse != 0) - draw_animateCursor(2); - util_delay(10); + _vm->_draw->animateCursor(2); + delay(10); } while (buttons != 0); } -void keyboard_release(void) {;} +void Util::keyboard_release(void) {;} } // End of namespace Gob diff --git a/gob/util.h b/gob/util.h index 2b63ff0f03..d3d76c47f8 100644 --- a/gob/util.h +++ b/gob/util.h @@ -26,57 +26,80 @@ namespace Gob { -struct Util_ListNode; -typedef struct Util_ListNode { - void *pData; - struct Util_ListNode *pNext; - struct Util_ListNode *pPrev; -} Util_ListNode; - -typedef struct Util_List { - Util_ListNode *pHead; - Util_ListNode *pTail; -} Util_List; - -void util_initInput(void); -void util_processInput(void); -void util_waitKey(void); -int16 util_getKey(void); -int16 util_checkKey(void); -int16 util_getRandom(int16 max); -void util_getMouseState(int16 *pX, int16 *pY, int16 *pButtons); -void util_setMousePos(int16 x, int16 y); -void util_longDelay(uint16 msecs); -void util_delay(uint16 msecs); -void util_beep(int16 freq); -uint32 util_getTimeKey(void); -void util_waitMouseUp(void); -void util_waitMouseDown(void); - -void keyboard_init(void); -void keyboard_release(void); - -void util_clearPalette(void); - -void asm_setPaletteBlock(char *tmpPalBuffer, int16 start, int16 end); - -void vid_waitRetrace(int16 mode); - -FontDesc *util_loadFont(const char *path); -void util_freeFont(FontDesc * fontDesc); -void util_clearPalette(void); -void util_insertStr(const char *str1, char *str2, int16 pos); -void util_cutFromStr(char *str, int16 from, int16 cutlen); -int16 util_strstr(const char *str1, char *str2); -void util_waitEndFrame(); -void util_setFrameRate(int16 rate); - -void util_listInsertBack(Util_List * list, void *data); -void util_listInsertFront(Util_List * list, void *data); -void util_listDropFront(Util_List * list); -void util_deleteList(Util_List * list); -void util_prepareStr(char *str); -void util_waitMouseRelease(char drawMouse); +#define KEYBUFSIZE 16 + +class Util { +public: + struct ListNode; + typedef struct ListNode { + void *pData; + struct ListNode *pNext; + struct ListNode *pPrev; + ListNode() : pData(0), pNext(0), pPrev(0) {} + } ListNode; + + typedef struct List { + ListNode *pHead; + ListNode *pTail; + List() : pHead(0), pTail(0) {} + } List; + + void initInput(void); + void processInput(void); + void waitKey(void); + int16 getKey(void); + int16 checkKey(void); + int16 getRandom(int16 max); + void getMouseState(int16 *pX, int16 *pY, int16 *pButtons); + void setMousePos(int16 x, int16 y); + void longDelay(uint16 msecs); + void delay(uint16 msecs); + void beep(int16 freq); + uint32 getTimeKey(void); + void waitMouseUp(void); + void waitMouseDown(void); + + void keyboard_init(void); + void keyboard_release(void); + + void clearPalette(void); + + void asm_setPaletteBlock(char *tmpPalBuffer, int16 start, int16 end); + + void vid_waitRetrace(int16 mode); + + Video::FontDesc *loadFont(const char *path); + void freeFont(Video::FontDesc * fontDesc); + void insertStr(const char *str1, char *str2, int16 pos); + void cutFromStr(char *str, int16 from, int16 cutlen); + int16 strstr(const char *str1, char *str2); + void waitEndFrame(); + void setFrameRate(int16 rate); + + void listInsertBack(List * list, void *data); + void listInsertFront(List * list, void *data); + void listDropFront(List * list); + void deleteList(List * list); + void prepareStr(char *str); + void waitMouseRelease(char drawMouse); + + static const char trStr1[]; + static const char trStr2[]; + static const char trStr3[]; + Util(GobEngine *vm); + +protected: + int16 _mouseX, _mouseY, _mouseButtons; + int16 _keyBuffer[KEYBUFSIZE], _keyBufferHead, _keyBufferTail; + GobEngine *_vm; + + void addKeyToBuffer(int16 key); + bool keyBufferEmpty(); + bool getKeyFromBuffer(int16& key); + int16 translateKey(int16 key); + int16 calcDelayTime(); + void checkJoystick(); +}; } // End of namespace Gob diff --git a/gob/video.cpp b/gob/video.cpp index 3ecf2962b5..934ef29bbf 100644 --- a/gob/video.cpp +++ b/gob/video.cpp @@ -28,22 +28,22 @@ namespace Gob { -VideoDriver *_videoDriver; - - /* NOT IMPLEMENTED */ +Video::Video(GobEngine *vm) : _vm(vm) { +} + //XXX: Use this function to update the screen for now. // This should be moved to a better location later on. -void vid_waitRetrace(int16) { - if (pPrimarySurfDesc) { - g_system->copyRectToScreen(pPrimarySurfDesc->vidPtr, 320, 0, 0, 320, 200); +void Video::waitRetrace(int16) { + if (_vm->_global->pPrimarySurfDesc) { + g_system->copyRectToScreen(_vm->_global->pPrimarySurfDesc->vidPtr, 320, 0, 0, 320, 200); g_system->updateScreen(); } } -char vid_initDriver(int16 vidMode) { - warning("STUB: vid_initDriver"); +char Video::initDriver(int16 vidMode) { + warning("STUB: Video::initDriver"); // FIXME: Finish all this stuff :) _videoDriver = new VGAVideoDriver(); @@ -51,17 +51,17 @@ char vid_initDriver(int16 vidMode) { return 1; } -void vid_freeDriver() { +void Video::freeDriver() { delete _videoDriver; - warning("STUB: vid_freeDriver"); + warning("STUB: Video::freeDriver"); } -int32 vid_getRectSize(int16 width, int16 height, int16 flag, int16 mode) { +int32 Video::getRectSize(int16 width, int16 height, int16 flag, int16 mode) { int32 size; if ((mode & 0x7f) != 0x13) warning - ("vid_getRectSize: Video mode %d is not fully supported!", + ("Video::getRectSize: Video mode %d is not fully supported!", mode & 0x7f); switch (mode & 0x7f) { case 5: @@ -83,7 +83,7 @@ int32 vid_getRectSize(int16 width, int16 height, int16 flag, int16 mode) { return size; } -SurfaceDesc *vid_initSurfDesc(int16 vidMode, int16 width, int16 height, int16 flags) { +Video::SurfaceDesc *Video::initSurfDesc(int16 vidMode, int16 width, int16 height, int16 flags) { int8 flagsAnd2; byte *vidMem; int32 sprSize; @@ -91,13 +91,13 @@ SurfaceDesc *vid_initSurfDesc(int16 vidMode, int16 width, int16 height, int16 fl SurfaceDesc *descPtr; if (flags != PRIMARY_SURFACE) - sprAllocated++; + _vm->_global->sprAllocated++; if (flags & RETURN_PRIMARY) - return pPrimarySurfDesc; + return _vm->_global->pPrimarySurfDesc; if (vidMode != 0x13) - error("vid_initSurfDesc: Only VGA 0x13 mode is supported!"); + error("Video::initSurfDesc: Only VGA 0x13 mode is supported!"); if ((flags & PRIMARY_SURFACE) == 0) vidMode += 0x80; @@ -109,20 +109,20 @@ SurfaceDesc *vid_initSurfDesc(int16 vidMode, int16 width, int16 height, int16 fl if (flags & PRIMARY_SURFACE) { vidMem = 0; - primaryWidth = width; - mouseMaxCol = width; - primaryHeight = height; - mouseMaxRow = height; + _vm->_global->primaryWidth = width; + _vm->_global->mouseMaxCol = width; + _vm->_global->primaryHeight = height; + _vm->_global->mouseMaxRow = height; sprSize = 0; } else { vidMem = 0; - sprSize = vid_getRectSize(width, height, flagsAnd2, vidMode); + sprSize = Video::getRectSize(width, height, flagsAnd2, vidMode); if (flagsAnd2) someFlags += 0x80; } if (flags & PRIMARY_SURFACE) { - descPtr = pPrimarySurfDesc; + descPtr = _vm->_global->pPrimarySurfDesc; vidMem = (byte *)malloc(320 * 200); } else { if (flags & DISABLE_SPR_ALLOC) @@ -146,15 +146,15 @@ SurfaceDesc *vid_initSurfDesc(int16 vidMode, int16 width, int16 height, int16 fl return descPtr; } -void vid_freeSurfDesc(SurfaceDesc * surfDesc) { - sprAllocated--; - if (surfDesc != pPrimarySurfDesc) +void Video::freeSurfDesc(SurfaceDesc * surfDesc) { + _vm->_global->sprAllocated--; + if (surfDesc != _vm->_global->pPrimarySurfDesc) free(surfDesc); else free(surfDesc->vidPtr); } -int16 vid_clampValue(int16 val, int16 max) { +int16 Video::clampValue(int16 val, int16 max) { if (val >= max) val = max - 1; @@ -164,13 +164,13 @@ int16 vid_clampValue(int16 val, int16 max) { return val; } -void vid_drawSprite(SurfaceDesc *source, SurfaceDesc *dest, +void Video::drawSprite(SurfaceDesc *source, SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) { int16 temp; int16 destRight; int16 destBottom; - if (doRangeClamp) { + if (_vm->_global->doRangeClamp) { if (left > right) { temp = left; left = right; @@ -198,8 +198,8 @@ void vid_drawSprite(SurfaceDesc *source, SurfaceDesc *dest, y -= top; top = 0; } - right = vid_clampValue(right, source->width); - bottom = vid_clampValue(bottom, source->height); + right = Video::clampValue(right, source->width); + bottom = Video::clampValue(bottom, source->height); if (right - left >= source->width) right = left + source->width - 1; if (bottom - top >= source->height) @@ -236,11 +236,11 @@ void vid_drawSprite(SurfaceDesc *source, SurfaceDesc *dest, _videoDriver->drawSprite(source, dest, left, top, right, bottom, x, y, transp); } -void vid_fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, +void Video::fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 color) { int16 temp; - if (doRangeClamp) { + if (_vm->_global->doRangeClamp) { if (left > right) { temp = left; left = right; @@ -260,64 +260,64 @@ void vid_fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 b if (top >= dest->height) return; - left = vid_clampValue(left, dest->width); - top = vid_clampValue(top, dest->height); - right = vid_clampValue(right, dest->width); - bottom = vid_clampValue(bottom, dest->height); + left = Video::clampValue(left, dest->width); + top = Video::clampValue(top, dest->height); + right = Video::clampValue(right, dest->width); + bottom = Video::clampValue(bottom, dest->height); } _videoDriver->fillRect(dest, left, top, right, bottom, color); } -void vid_drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, int16 color) { +void Video::drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, int16 color) { if (x0 == x1 || y0 == y1) { - vid_fillRect(dest, x0, y0, x1, y1, color); + Video::fillRect(dest, x0, y0, x1, y1, color); return; } _videoDriver->drawLine(dest, x0, y0, x1, y1, color); } -void vid_putPixel(int16 x, int16 y, int16 color, SurfaceDesc *dest) { +void Video::putPixel(int16 x, int16 y, int16 color, SurfaceDesc *dest) { if (x < 0 || y < 0 || x >= dest->width || y >= dest->height) return; _videoDriver->putPixel(x, y, color, dest); } -void vid_drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, int16 color1, +void Video::drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, int16 color1, int16 color2, int16 transp, SurfaceDesc *dest) { _videoDriver->drawLetter(item, x, y, fontDesc, color1, color2, transp, dest); } -void vid_clearSurf(SurfaceDesc *dest) { - vid_fillRect(dest, 0, 0, dest->width - 1, dest->height - 1, 0); +void Video::clearSurf(SurfaceDesc *dest) { + Video::fillRect(dest, 0, 0, dest->width - 1, dest->height - 1, 0); } -void vid_drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, +void Video::drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, int16 transp, SurfaceDesc *dest) { - if (vid_spriteUncompressor(sprBuf, width, height, x, y, transp, dest)) + if (Video::spriteUncompressor(sprBuf, width, height, x, y, transp, dest)) return; if ((dest->vidMode & 0x7f) != 0x13) - error("vid_drawPackedSprite: Vide mode 0x%x is not fully supported!", + error("Video::drawPackedSprite: Vide mode 0x%x is not fully supported!", dest->vidMode & 0x7f); _videoDriver->drawPackedSprite(sprBuf, width, height, x, y, transp, dest); } -void vid_setPalElem(int16 index, char red, char green, char blue, int16 unused, +void Video::setPalElem(int16 index, char red, char green, char blue, int16 unused, int16 vidMode) { byte pal[4]; - redPalette[index] = red; - greenPalette[index] = green; - bluePalette[index] = blue; + _vm->_global->redPalette[index] = red; + _vm->_global->greenPalette[index] = green; + _vm->_global->bluePalette[index] = blue; if (vidMode != 0x13) - error("vid_setPalElem: Video mode 0x%x is not supported!", + error("Video::setPalElem: Video mode 0x%x is not supported!", vidMode); pal[0] = (red << 2) | (red >> 4); @@ -327,16 +327,16 @@ void vid_setPalElem(int16 index, char red, char green, char blue, int16 unused, g_system->setPalette(pal, index, 1); } -void vid_setPalette(PalDesc *palDesc) { +void Video::setPalette(PalDesc *palDesc) { int16 i; byte pal[1024]; int16 numcolors; - if (videoMode != 0x13) - error("vid_setPalette: Video mode 0x%x is not supported!", - videoMode); + if (_vm->_global->videoMode != 0x13) + error("Video::setPalette: Video mode 0x%x is not supported!", + _vm->_global->videoMode); - if (setAllPalette) + if (_vm->_global->setAllPalette) numcolors = 256; else numcolors = 16; @@ -351,17 +351,17 @@ void vid_setPalette(PalDesc *palDesc) { g_system->setPalette(pal, 0, numcolors); } -void vid_setFullPalette(PalDesc *palDesc) { +void Video::setFullPalette(PalDesc *palDesc) { Color *colors; int16 i; byte pal[1024]; - if (setAllPalette) { + if (_vm->_global->setAllPalette) { colors = palDesc->vgaPal; for (i = 0; i < 256; i++) { - redPalette[i] = colors[i].red; - greenPalette[i] = colors[i].green; - bluePalette[i] = colors[i].blue; + _vm->_global->redPalette[i] = colors[i].red; + _vm->_global->greenPalette[i] = colors[i].green; + _vm->_global->bluePalette[i] = colors[i].blue; } for (i = 0; i < 256; i++) { @@ -372,46 +372,46 @@ void vid_setFullPalette(PalDesc *palDesc) { } g_system->setPalette(pal, 0, 256); } else { - vid_setPalette(palDesc); + Video::setPalette(palDesc); } } -void vid_initPrimary(int16 mode) { +void Video::initPrimary(int16 mode) { int16 old; - if (curPrimaryDesc) { - vid_freeSurfDesc(curPrimaryDesc); - vid_freeSurfDesc(allocatedPrimary); + if (_vm->_global->curPrimaryDesc) { + Video::freeSurfDesc(_vm->_global->curPrimaryDesc); + Video::freeSurfDesc(_vm->_global->allocatedPrimary); - curPrimaryDesc = 0; - allocatedPrimary = 0; + _vm->_global->curPrimaryDesc = 0; + _vm->_global->allocatedPrimary = 0; } if (mode != 0x13 && mode != 3 && mode != -1) - error("vid_initPrimary: Video mode 0x%x is not supported!", + error("Video::initPrimary: Video mode 0x%x is not supported!", mode); - if (videoMode != 0x13) - error("vid_initPrimary: Video mode 0x%x is not supported!", + if (_vm->_global->videoMode != 0x13) + error("Video::initPrimary: Video mode 0x%x is not supported!", mode); - old = oldMode; + old = _vm->_global->oldMode; if (mode == -1) mode = 3; - oldMode = mode; + _vm->_global->oldMode = mode; if (mode != 3) - vid_initDriver(mode); + Video::initDriver(mode); if (mode != 3) { - vid_initSurfDesc(mode, 320, 200, PRIMARY_SURFACE); + Video::initSurfDesc(mode, 320, 200, PRIMARY_SURFACE); - if (dontSetPalette) + if (_vm->_global->dontSetPalette) return; - vid_setFullPalette(pPaletteDesc); + Video::setFullPalette(_vm->_global->pPaletteDesc); } } -char vid_spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, +char Video::spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, int16 x, int16 y, int16 transp, SurfaceDesc *destDesc) { SurfaceDesc sourceDesc; byte *memBuffer; @@ -432,7 +432,7 @@ char vid_spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, return 1; if ((destDesc->vidMode & 0x7f) != 0x13) - error("vid_spriteUncompressor: Video mode 0x%x is not supported!", + error("Video::spriteUncompressor: Video mode 0x%x is not supported!", destDesc->vidMode & 0x7f); if (sprBuf[0] != 1) @@ -446,7 +446,7 @@ char vid_spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, sourceDesc.height = srcHeight; sourceDesc.vidMode = 0x93; sourceDesc.vidPtr = sprBuf + 3; - vid_drawSprite(&sourceDesc, destDesc, 0, 0, srcWidth - 1, + Video::drawSprite(&sourceDesc, destDesc, 0, 0, srcWidth - 1, srcHeight - 1, x, y, transp); return 1; } else { @@ -540,8 +540,6 @@ char vid_spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, return 1; } -void vid_setHandlers() { - setAllPalette = 1; -} +void Video::setHandlers() { _vm->_global->setAllPalette = 1; } } // End of namespace Gob diff --git a/gob/video.h b/gob/video.h index 3f64b43231..194f552da3 100644 --- a/gob/video.h +++ b/gob/video.h @@ -24,6 +24,7 @@ #include "common/stdafx.h" #include "common/util.h" +#include "gob/gob.h" namespace Gob { @@ -35,40 +36,34 @@ namespace Gob { #define TEXT_COL_COUNT 80 #define TEXT_ROW_COUNT 25 +extern int16 setAllPalette; -typedef struct SurfaceDesc_t { - int16 width; - int16 height; - int8 reserved1; - int8 flag; - int16 vidMode; - byte *vidPtr; - int16 reserved2; -} SurfaceDesc; - -typedef struct FontDesc_t { - char *dataPtr; - int8 itemWidth; - int8 itemHeight; - int8 startItem; - int8 endItem; - int8 itemSize; - int8 bitWidth; - void *extraData; -} FontDesc; - - -class VideoDriver { +class Video { public: - VideoDriver() {} - virtual ~VideoDriver() {} - virtual void drawSprite(SurfaceDesc *source, SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) = 0; - virtual void fillRect(SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color) = 0; - virtual void putPixel(int16 x, int16 y, byte color, SurfaceDesc *dest) = 0; - virtual void drawLetter(unsigned char item, int16 x, int16 y, FontDesc *fontDesc, byte color1, byte color2, byte transp, SurfaceDesc *dest) = 0; - virtual void drawLine(SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color) = 0; - virtual void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, SurfaceDesc *dest) = 0; -}; + typedef struct SurfaceDesc_t { + int16 width; + int16 height; + int8 reserved1; + int8 flag; + int16 vidMode; + byte *vidPtr; + int16 reserved2; + SurfaceDesc_t() : width(0), height(0), reserved1(0), flag(0), + vidMode(0), vidPtr(0), reserved2(0) {} + } SurfaceDesc; + + typedef struct FontDesc_t { + char *dataPtr; + int8 itemWidth; + int8 itemHeight; + int8 startItem; + int8 endItem; + int8 itemSize; + int8 bitWidth; + void *extraData; + FontDesc_t() : dataPtr(0), itemWidth(0), itemHeight(0), startItem(0), + endItem(0), itemSize(0), bitWidth(0) {} + } FontDesc; #define GDR_VERSION 4 @@ -76,52 +71,69 @@ public: #define RETURN_PRIMARY 0x01 #define DISABLE_SPR_ALLOC 0x20 -#if !defined(__GNUC__) - #pragma START_PACK_STRUCTS -#endif - -typedef struct Color { - byte red; - byte green; - byte blue; -} GCC_PACK Color; - -#if !defined(__GNUC__) - #pragma END_PACK_STRUCTS -#endif +#pragma START_PACK_STRUCTS + + typedef struct Color { + byte red; + byte green; + byte blue; + } GCC_PACK Color; + +#pragma END_PACK_STRUCTS + + typedef struct PalDesc { + Color *vgaPal; + int16 *unused1; + int16 *unused2; + PalDesc() : vgaPal(0), unused1(0), unused2(0) {} + } PalDesc; + + Video(class GobEngine *vm); + int32 getRectSize(int16 width, int16 height, int16 flag, int16 mode); + SurfaceDesc *initSurfDesc(int16 vidMode, int16 width, int16 height, int16 flags); + void freeSurfDesc(SurfaceDesc * surfDesc); + int16 clampValue(int16 val, int16 max); + void drawSprite(SurfaceDesc * source, SurfaceDesc * dest, int16 left, + int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp); + void fillRect(SurfaceDesc * dest, int16 left, int16 top, int16 right, int16 bottom, + int16 color); + void drawLine(SurfaceDesc * dest, int16 x0, int16 y0, int16 x1, int16 y1, + int16 color); + void putPixel(int16 x, int16 y, int16 color, SurfaceDesc * dest); + void drawLetter(unsigned char item, int16 x, int16 y, FontDesc * fontDesc, int16 color1, + int16 color2, int16 transp, SurfaceDesc * dest); + void clearSurf(SurfaceDesc * dest); + void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, + int16 transp, SurfaceDesc * dest); + void setPalElem(int16 index, char red, char green, char blue, int16 unused, + int16 vidMode); + void setPalette(PalDesc * palDesc); + void setFullPalette(PalDesc * palDesc); + void initPrimary(int16 mode); + char spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, int16 x, + int16 y, int16 transp, SurfaceDesc * destDesc); + void waitRetrace(int16); + void freeDriver(void); + void setHandlers(); + +protected: + class VideoDriver *_videoDriver; + GobEngine *_vm; + + char initDriver(int16 vidMode); +}; -typedef struct PalDesc { - Color *vgaPal; - int16 *unused1; - int16 *unused2; -} PalDesc; - -char vid_initDriver(int16 vidMode); -void vid_freeDriver(void); -int32 vid_getRectSize(int16 width, int16 height, int16 flag, int16 mode); -SurfaceDesc *vid_initSurfDesc(int16 vidMode, int16 width, int16 height, int16 flags); -void vid_freeSurfDesc(SurfaceDesc * surfDesc); -int16 vid_clampValue(int16 val, int16 max); -void vid_drawSprite(SurfaceDesc * source, SurfaceDesc * dest, int16 left, - int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp); -void vid_fillRect(SurfaceDesc * dest, int16 left, int16 top, int16 right, int16 bottom, - int16 color); -void vid_drawLine(SurfaceDesc * dest, int16 x0, int16 y0, int16 x1, int16 y1, - int16 color); -void vid_putPixel(int16 x, int16 y, int16 color, SurfaceDesc * dest); -void vid_drawLetter(unsigned char item, int16 x, int16 y, FontDesc * fontDesc, int16 color1, - int16 color2, int16 transp, SurfaceDesc * dest); -void vid_clearSurf(SurfaceDesc * dest); -void vid_drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, - int16 transp, SurfaceDesc * dest); -void vid_setPalElem(int16 index, char red, char green, char blue, int16 unused, - int16 vidMode); -void vid_setPalette(PalDesc * palDesc); -void vid_setFullPalette(PalDesc * palDesc); -void vid_initPrimary(int16 mode); -char vid_spriteUncompressor(byte *sprBuf, int16 srcWidth, int16 srcHeight, int16 x, - int16 y, int16 transp, SurfaceDesc * destDesc); -void vid_setHandlers(void); +class VideoDriver { +public: + VideoDriver() {} + virtual ~VideoDriver() {} + virtual void drawSprite(Video::SurfaceDesc *source, Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp) = 0; + virtual void fillRect(Video::SurfaceDesc *dest, int16 left, int16 top, int16 right, int16 bottom, byte color) = 0; + virtual void putPixel(int16 x, int16 y, byte color, Video::SurfaceDesc *dest) = 0; + virtual void drawLetter(unsigned char item, int16 x, int16 y, Video::FontDesc *fontDesc, byte color1, byte color2, byte transp, Video::SurfaceDesc *dest) = 0; + virtual void drawLine(Video::SurfaceDesc *dest, int16 x0, int16 y0, int16 x1, int16 y1, byte color) = 0; + virtual void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, byte transp, Video::SurfaceDesc *dest) = 0; +}; } // End of namespace Gob |