diff options
Diffstat (limited to 'engines/gob')
46 files changed, 3227 insertions, 5062 deletions
diff --git a/engines/gob/dataio.cpp b/engines/gob/dataio.cpp index f59fa80e8d..99cf7c1193 100644 --- a/engines/gob/dataio.cpp +++ b/engines/gob/dataio.cpp @@ -488,6 +488,9 @@ int16 DataIO::openData(const char *path) { } bool DataIO::existData(const char *path) { + if (!path || (path[0] == '\0')) + return false; + int16 handle = openData(path); if (handle < 0) @@ -584,7 +587,7 @@ byte *DataIO::getData(const char *path) { } DataStream *DataIO::getDataStream(const char *path) { - if (!path || (path[0] == '\0') || !existData(path)) + if (!existData(path)) return 0; uint32 size = getDataSize(path); diff --git a/engines/gob/demos/demoplayer.cpp b/engines/gob/demos/demoplayer.cpp index 0229bb7515..7f65721ce5 100644 --- a/engines/gob/demos/demoplayer.cpp +++ b/engines/gob/demos/demoplayer.cpp @@ -222,7 +222,7 @@ void DemoPlayer::playVideoDoubled() { int16 key; bool end = false; while (_vm->_util->checkKey(key)) - if (key == 0x011B) + if (key == kKeyEscape) end = true; if (end) break; diff --git a/engines/gob/detection.cpp b/engines/gob/detection.cpp index 9426c01ef2..61c17b16f8 100644 --- a/engines/gob/detection.cpp +++ b/engines/gob/detection.cpp @@ -68,9 +68,11 @@ static const PlainGameDescriptor gobGames[] = { {"playtoons5", "Playtoons 5 - The Stone of Wakan"}, {"playtnck1", "Playtoons Construction Kit 1 - Monsters"}, {"playtnck2", "Playtoons Construction Kit 2 - Knights"}, + {"playtnck3", "Playtoons Construction Kit 3 - Far West"}, {"bambou", "Playtoons Limited Edition - Bambou le sauveur de la jungle"}, {"fascination", "Fascination"}, {"geisha", "Geisha"}, + {"magicstones", "The Land of the Magic Stones"}, {"adibou4", "Adibou v4"}, {"adibouunknown", "Adibou (not yet supported)"}, {0, 0} @@ -3438,6 +3440,24 @@ static const GOBGameDescription gameDescriptions[] = { "playtoons2", "", { + {"playtoon.stk", 0, "4772c96be88a57f0561519e4a1526c62", 24406262}, + {"spirou.stk", 0, "5d9c7644d0c47840169b4d016765cc1a", 9816201}, + {0, 0, 0, 0} + }, + EN_ANY, + kPlatformPC, + ADGF_NO_FLAGS, + GUIO_NOSUBTITLES | GUIO_NOSPEECH + }, + kGameTypePlaytoon, + kFeatures640, + "intro2.stk", 0, 0 + }, + { + { + "playtoons2", + "", + { {"playtoon.stk", 0, "55a85036dd93cce93532d8f743d90074", 17467154}, {"spirou.stk", 0, "e3e1b6148dd72fafc3637f1a8e5764f5", 9812043}, {0, 0, 0, 0} @@ -3541,7 +3561,6 @@ static const GOBGameDescription gameDescriptions[] = { kFeatures640, "intro2.stk", 0, 0 }, - { { "playtoons4", @@ -3560,6 +3579,24 @@ static const GOBGameDescription gameDescriptions[] = { kFeatures640, "intro2.stk", 0, 0 }, + { //Supplied by goodoldgeorg in bug report #2820006 + { + "playtoons4", + "", + { + {"playtoon.stk", 0, "9e513e993a5b0e2496add3f50c08764b", 30448506}, + {"manda.stk", 0, "69a79c9f61b2618e482726f2ff68078d", 6499208}, + {0, 0, 0, 0} + }, + EN_ANY, + kPlatformPC, + ADGF_NO_FLAGS, + GUIO_NOSUBTITLES | GUIO_NOSPEECH + }, + kGameTypePlaytoon, + kFeatures640, + "intro2.stk", 0, 0 + }, { { "playtoons5", @@ -3634,6 +3671,42 @@ static const GOBGameDescription gameDescriptions[] = { }, { { + "playtnck3", + "", + { + {"playtoon.stk", 0, "5f9aae29265f1f105ad8ec195dff81de", 68382024}, + {"dan.itk", 0, "9a8f62809eca5a52f429b5b6a8e70f8f", 2861056}, + {0, 0, 0, 0} + }, + FR_FRA, + kPlatformPC, + ADGF_NO_FLAGS, + GUIO_NOSUBTITLES | GUIO_NOSPEECH + }, + kGameTypePlaytnCk, + kFeatures640, + "intro2.stk", 0, 0 + }, + { + { + "magicstones", + "", + { + {"ed4.stk", 0, "98721a7cfdc5a358d7ac56b7c6d3ba3d", 541882}, + {"ed4cd.itk", 0, "0627a91d9a6f4772c33747ce752024c2", 606993908}, + {0, 0, 0, 0} + }, + FR_FRA, + kPlatformPC, + ADGF_NO_FLAGS, + GUIO_NOSUBTITLES | GUIO_NOSPEECH + }, + kGameTypeMagicStones, + kFeatures800x600, + "ed4.stk", "main.obc", 0 + }, + { + { "adibou4", "", AD_ENTRY1s("intro.stk", "a3c35d19b2d28ea261d96321d208cb5a", 6021466), @@ -4189,6 +4262,20 @@ static const GOBGameDescription fallbackDescs[] = { }, { { + "magicstones", + "unknown", + AD_ENTRY1(0, 0), + UNK_LANG, + kPlatformPC, + ADGF_NO_FLAGS, + GUIO_NOSUBTITLES | GUIO_NOSPEECH + }, + kGameTypeMagicStones, + kFeatures800x600, + "ed4.stk", "main.obc", 0 + }, + { + { "adibou4", "", AD_ENTRY1(0, 0), @@ -4241,8 +4328,9 @@ static const ADFileBasedFallback fileBased[] = { { &fallbackDescs[19], { "intro.stk", "bambou.itk", 0 } }, { &fallbackDescs[20], { "disk0.stk", "disk1.stk", "disk2.stk", "disk3.stk", 0 } }, { &fallbackDescs[21], { "disk1.stk", "disk2.stk", "disk3.stk", 0 } }, - { &fallbackDescs[22], { "adif41.stk", "adim41.stk", 0 } }, - { &fallbackDescs[23], { "coktelplayer.scn", 0 } }, + { &fallbackDescs[22], { "ed4.stk", 0 } }, + { &fallbackDescs[23], { "adif41.stk", "adim41.stk", 0 } }, + { &fallbackDescs[24], { "coktelplayer.scn", 0 } }, { 0, { 0 } } }; diff --git a/engines/gob/draw.cpp b/engines/gob/draw.cpp index b3e5e7418c..fb3cb9bbcd 100644 --- a/engines/gob/draw.cpp +++ b/engines/gob/draw.cpp @@ -29,6 +29,7 @@ #include "gob/draw.h" #include "gob/global.h" #include "gob/util.h" +#include "gob/dataio.h" #include "gob/game.h" #include "gob/script.h" #include "gob/inter.h" @@ -60,7 +61,7 @@ Draw::Draw(GobEngine *vm) : _vm(vm) { _backDeltaX = 0; _backDeltaY = 0; - for (int i = 0; i < 8; i++) + for (int i = 0; i < kFontCount; i++) _fonts[i] = 0; _spritesArray.resize(SPRITES_COUNT); @@ -128,7 +129,7 @@ Draw::Draw(GobEngine *vm) : _vm(vm) { } Draw::~Draw() { - for (int i = 0; i < 8; i++) + for (int i = 0; i < kFontCount; i++) delete _fonts[i]; } @@ -346,6 +347,8 @@ int Draw::stringLength(const char *str, int16 fontIndex) { if ((fontIndex < 0) || (fontIndex > 7) || !_fonts[fontIndex]) return 0; + Font &font = *_fonts[fontIndex]; + int len = 0; if (_vm->_global->_language == 10) { @@ -355,16 +358,16 @@ int Draw::stringLength(const char *str, int16 fontIndex) { len += japaneseExtraCharLen[4]; i++; } else - len += _fonts[fontIndex]->itemWidth; + len += font.getCharWidth(); } } else { - if (_fonts[fontIndex]->extraData) - while (*str != 0) - len += *(_fonts[fontIndex]->extraData + (*str++ - _fonts[fontIndex]->startItem)); + if (!font.isMonospaced()) + while (*str != '\0') + len += font.getCharWidth(*str++); else - len = (strlen(str) * _fonts[fontIndex]->itemWidth); + len = strlen(str) * font.getCharWidth(); } @@ -372,14 +375,11 @@ int Draw::stringLength(const char *str, int16 fontIndex) { } void Draw::drawString(const char *str, int16 x, int16 y, int16 color1, int16 color2, - int16 transp, SurfaceDesc &dest, Video::FontDesc *font) { + int16 transp, SurfaceDesc &dest, const Font &font) { while (*str != '\0') { _vm->_video->drawLetter(*str, x, y, font, transp, color1, color2, dest); - if (!font->extraData) - x += font->itemWidth; - else - x += *(font->extraData + (*str - font->startItem)); + x += font.getCharWidth(*str); str++; } } @@ -407,23 +407,23 @@ void Draw::printTextCentered(int16 id, int16 left, int16 top, int16 right, if (str[0] == '\0') return; - int16 width = 0; - _transparency = 1; _destSpriteX = left; _destSpriteY = top; _fontIndex = fontIndex; _frontColor = color; _textToPrint = str; - if (_fonts[fontIndex]->extraData != 0) { - byte *data = _fonts[fontIndex]->extraData; - int length = strlen(str); - for (int i = 0; i < length; i++) - width += *(data + (str[i] - _fonts[_fontIndex]->startItem)); + Font &font = *_fonts[fontIndex]; + + int16 width = 0; + if (!font.isMonospaced()) { + const char *s = str; + while (*s != '\0') + width += font.getCharWidth(*s++); } else - width = strlen(str) * _fonts[fontIndex]->itemWidth; + width = strlen(str) * font.getCharWidth(); adjustCoords(1, &width, 0); _destSpriteX += (right - left + 1 - width) / 2; @@ -546,4 +546,24 @@ void Draw::wobble(SurfaceDesc &surfDesc) { delete[] offsets; } +Font *Draw::loadFont(const char *path) const { + if (!_vm->_dataIO->existData(path)) + return 0; + + byte *data = _vm->_dataIO->getData(path); + + return new Font(data); +} + +bool Draw::loadFont(int fontIndex, const char *path) { + if ((fontIndex < 0) || (fontIndex >= kFontCount)) + return false; + + delete _fonts[fontIndex]; + + _fonts[fontIndex] = loadFont(path); + + return _fonts[fontIndex] != 0; +} + } // End of namespace Gob diff --git a/engines/gob/draw.h b/engines/gob/draw.h index 26f78ce3b3..ba32df0c3e 100644 --- a/engines/gob/draw.h +++ b/engines/gob/draw.h @@ -45,6 +45,8 @@ namespace Gob { class Draw { public: + static const int kFontCount = 8; + struct FontToSprite { int8 sprite; int8 base; @@ -76,7 +78,7 @@ public: int16 _backDeltaY; FontToSprite _fontToSprite[4]; - Video::FontDesc *_fonts[8]; + Font *_fonts[kFontCount]; Common::Array<SurfaceDescPtr> _spritesArray; @@ -152,7 +154,7 @@ public: } int stringLength(const char *str, int16 fontIndex); void drawString(const char *str, int16 x, int16 y, int16 color1, int16 color2, - int16 transp, SurfaceDesc &dest, Video::FontDesc *font); + int16 transp, SurfaceDesc &dest, const Font &font); void printTextCentered(int16 id, int16 left, int16 top, int16 right, int16 bottom, const char *str, int16 fontIndex, int16 color); int32 getSpriteRectSize(int16 index); @@ -161,6 +163,9 @@ public: static const int16 _wobbleTable[360]; void wobble(SurfaceDesc &surfDesc); + Font *loadFont(const char *path) const; + bool loadFont(int fontIndex, const char *path); + virtual void initScreen() = 0; virtual void closeScreen() = 0; virtual void blitCursor() = 0; diff --git a/engines/gob/draw_v1.cpp b/engines/gob/draw_v1.cpp index 94ee32a031..e2cfcb613d 100644 --- a/engines/gob/draw_v1.cpp +++ b/engines/gob/draw_v1.cpp @@ -33,6 +33,7 @@ #include "gob/util.h" #include "gob/game.h" #include "gob/resources.h" +#include "gob/hotspots.h" #include "gob/scenery.h" #include "gob/inter.h" #include "gob/sound/sound.h" @@ -44,6 +45,12 @@ Draw_v1::Draw_v1(GobEngine *vm) : Draw(vm) { void Draw_v1::initScreen() { _backSurface = _vm->_video->initSurfDesc(_vm->_global->_videoMode, 320, 200, 0); + _frontSurface = _vm->_global->_primarySurfDesc; + + _cursorSprites = + _vm->_video->initSurfDesc(_vm->_global->_videoMode, 32, 16, 2); + _scummvmCursor = + _vm->_video->initSurfDesc(_vm->_global->_videoMode, 16, 16, SCUMMVM_CURSOR); } void Draw_v1::closeScreen() { @@ -58,7 +65,6 @@ void Draw_v1::blitCursor() { } void Draw_v1::animateCursor(int16 cursor) { - Game::Collision *ptr; int16 cursorIndex = cursor; int16 newX = 0, newY = 0; uint16 hotspotX = 0, hotspotY = 0; @@ -66,29 +72,10 @@ void Draw_v1::animateCursor(int16 cursor) { _showCursor = 2; if (cursorIndex == -1) { - cursorIndex = 0; - for (ptr = _vm->_game->_collisionAreas; ptr->left != 0xFFFF; ptr++) { - if (ptr->flags & 0xFFF0) - continue; - - if (ptr->left > _vm->_global->_inter_mouseX) - continue; - - if (ptr->right < _vm->_global->_inter_mouseX) - continue; - - if (ptr->top > _vm->_global->_inter_mouseY) - continue; + cursorIndex = + _vm->_game->_hotspots->findCursor(_vm->_global->_inter_mouseX, + _vm->_global->_inter_mouseY); - if (ptr->bottom < _vm->_global->_inter_mouseY) - continue; - - if ((ptr->flags & 0xF) < 3) - cursorIndex = 1; - else - cursorIndex = 3; - break; - } if (_cursorAnimLow[cursorIndex] == -1) cursorIndex = 1; } @@ -261,7 +248,7 @@ void Draw_v1::printTotText(int16 id) { _letterToPrint = (char) *ptr; spriteOperation(DRAW_DRAWLETTER); _destSpriteX += - _fonts[_fontIndex]->itemWidth; + _fonts[_fontIndex]->getCharWidth(); ptr++; } else { cmd = ptrEnd[17] & 0x7F; @@ -294,7 +281,7 @@ void Draw_v1::printTotText(int16 id) { spriteOperation(DRAW_PRINTTEXT); if (ptrEnd[17] & 0x80) { if (ptr[1] == ' ') { - _destSpriteX += _fonts[_fontIndex]->itemWidth; + _destSpriteX += _fonts[_fontIndex]->getCharWidth(); while (ptr[1] == ' ') ptr++; if (ptr[1] == 2) { @@ -303,10 +290,10 @@ void Draw_v1::printTotText(int16 id) { } } else if (ptr[1] == 2 && READ_LE_UINT16(ptr + 4) == _destSpriteY) { ptr += 5; - _destSpriteX += _fonts[_fontIndex]->itemWidth; + _destSpriteX += _fonts[_fontIndex]->getCharWidth(); } } else { - _destSpriteX = destSpriteX + _fonts[_fontIndex]->itemWidth; + _destSpriteX = destSpriteX + _fonts[_fontIndex]->getCharWidth(); } ptrEnd += 23; ptr++; @@ -317,7 +304,7 @@ void Draw_v1::printTotText(int16 id) { _renderFlags = savedFlags; if (_renderFlags & RENDERFLAG_COLLISIONS) - _vm->_game->checkCollisions(0, 0, 0, 0); + _vm->_game->_hotspots->check(0, 0); if ((_renderFlags & RENDERFLAG_CAPTUREPOP) && *_vm->_scenery->_pCaptureCounter != 0) { (*_vm->_scenery->_pCaptureCounter)--; @@ -354,6 +341,7 @@ void Draw_v1::spriteOperation(int16 operation) { } } + Font *font = 0; switch (operation) { case DRAW_BLITSURF: _vm->_video->drawSprite(*_spritesArray[_sourceSurface], @@ -415,20 +403,25 @@ void Draw_v1::spriteOperation(int16 operation) { break; case DRAW_PRINTTEXT: + font = _fonts[_fontIndex]; + if (!font) { + warning("Trying to print \"%s\" with undefined font %d", _textToPrint, _fontIndex); + break; + } + len = strlen(_textToPrint); dirtiedRect(_destSurface, _destSpriteX, _destSpriteY, - _destSpriteX + len * _fonts[_fontIndex]->itemWidth - 1, - _destSpriteY + _fonts[_fontIndex]->itemHeight - 1); + _destSpriteX + len * font->getCharWidth() - 1, + _destSpriteY + font->getCharHeight() - 1); for (int i = 0; i < len; i++) { _vm->_video->drawLetter(_textToPrint[i], _destSpriteX, _destSpriteY, - _fonts[_fontIndex], - _transparency, + *font, _transparency, _frontColor, _backColor, *_spritesArray[_destSurface]); - _destSpriteX += _fonts[_fontIndex]->itemWidth; + _destSpriteX += font->getCharWidth(); } break; @@ -471,14 +464,19 @@ void Draw_v1::spriteOperation(int16 operation) { break; case DRAW_DRAWLETTER: + font = _fonts[_fontIndex]; + if (!font) { + warning("Trying to print \'%c\' with undefined font %d", _letterToPrint, _fontIndex); + break; + } + if (_fontToSprite[_fontIndex].sprite == -1) { dirtiedRect(_destSurface, _destSpriteX, _destSpriteY, - _destSpriteX + _fonts[_fontIndex]->itemWidth - 1, - _destSpriteY + _fonts[_fontIndex]->itemHeight - 1); + _destSpriteX + font->getCharWidth() - 1, + _destSpriteY + font->getCharHeight() - 1); _vm->_video->drawLetter(_letterToPrint, _destSpriteX, _destSpriteY, - _fonts[_fontIndex], - _transparency, + *font, _transparency, _frontColor, _backColor, *_spritesArray[_destSurface]); break; diff --git a/engines/gob/draw_v2.cpp b/engines/gob/draw_v2.cpp index 2843456f42..8fe70589a7 100644 --- a/engines/gob/draw_v2.cpp +++ b/engines/gob/draw_v2.cpp @@ -34,6 +34,7 @@ #include "gob/game.h" #include "gob/script.h" #include "gob/resources.h" +#include "gob/hotspots.h" #include "gob/scenery.h" #include "gob/inter.h" #include "gob/video.h" @@ -82,7 +83,6 @@ void Draw_v2::blitCursor() { } void Draw_v2::animateCursor(int16 cursor) { - Game::Collision *ptr; int16 cursorIndex = cursor; int16 newX = 0, newY = 0; uint16 hotspotX = 0, hotspotY = 0; @@ -91,32 +91,10 @@ void Draw_v2::animateCursor(int16 cursor) { // .-- _draw_animateCursorSUB1 --- if (cursorIndex == -1) { - cursorIndex = 0; - for (ptr = _vm->_game->_collisionAreas; ptr->left != 0xFFFF; ptr++) { - if ((ptr->flags & 0xF00) || (ptr->id & 0x4000)) - continue; - - if (ptr->left > _vm->_global->_inter_mouseX) - continue; - - if (ptr->right < _vm->_global->_inter_mouseX) - continue; - - if (ptr->top > _vm->_global->_inter_mouseY) - continue; - - if (ptr->bottom < _vm->_global->_inter_mouseY) - continue; - - if ((ptr->flags & 0xF000) == 0) { - if ((ptr->flags & 0xF) >= 3) { - cursorIndex = 3; - break; - } else if (((ptr->flags & 0xF0) != 0x10) && (cursorIndex == 0)) - cursorIndex = 1; - } else if (cursorIndex == 0) - cursorIndex = (ptr->flags >> 12) & 0xF; - } + cursorIndex = + _vm->_game->_hotspots->findCursor(_vm->_global->_inter_mouseX, + _vm->_global->_inter_mouseY); + if (_cursorAnimLow[cursorIndex] == -1) cursorIndex = 1; } @@ -393,22 +371,22 @@ void Draw_v2::printTotText(int16 id) { if ((((*ptr >= 1) && (*ptr <= 7)) || (*ptr == 10)) && (strPos != 0)) { str[MAX(strPos, strPos2)] = 0; strPosBak = strPos; - width = strlen(str) * _fonts[fontIndex]->itemWidth; + width = strlen(str) * _fonts[fontIndex]->getCharWidth(); adjustCoords(1, &width, 0); if (colCmd & 0x0F) { rectLeft = offX - 2; rectTop = offY - 2; rectRight = offX + width + 1; - rectBottom = _fonts[fontIndex]->itemHeight; + rectBottom = _fonts[fontIndex]->getCharHeight(); adjustCoords(1, &rectBottom, 0); rectBottom += offY + 1; adjustCoords(0, &rectLeft, &rectTop); adjustCoords(2, &rectRight, &rectBottom); if (colId != -1) - _vm->_game->addNewCollision(colId + 0xD000, rectLeft, rectTop, - rectRight, rectBottom, 2, 0, 0, 0); + _vm->_game->_hotspots->add(colId + 0xD000, rectLeft, rectTop, + rectRight, rectBottom, (uint16) Hotspots::kTypeClick, 0, 0, 0, 0); if (_needAdjust != 2) printTextCentered(colCmd & 0x0F, rectLeft + 4, rectTop + 4, @@ -426,9 +404,9 @@ void Draw_v2::printTotText(int16 id) { if (_needAdjust != 2) { if ((_destSpriteX >= destX) && (_destSpriteY >= destY) && - (((_fonts[_fontIndex]->itemHeight / 2) + _destSpriteY - 1) <= spriteBottom)) { + (((_fonts[_fontIndex]->getCharHeight() / 2) + _destSpriteY - 1) <= spriteBottom)) { while (((_destSpriteX + width - 1) > spriteRight) && (width > 0)) { - width -= _fonts[_fontIndex]->itemWidth / 2; + width -= _fonts[_fontIndex]->getCharWidth() / 2; str[strlen(str) - 1] = '\0'; } spriteOperation(DRAW_PRINTTEXT); @@ -441,8 +419,8 @@ void Draw_v2::printTotText(int16 id) { if (mask[strPos] == '\0') continue; - rectLeft = _fonts[fontIndex]->itemWidth; - rectTop = _fonts[fontIndex]->itemHeight; + rectLeft = _fonts[fontIndex]->getCharWidth(); + rectTop = _fonts[fontIndex]->getCharHeight(); adjustCoords(1, &rectLeft, &rectTop); _destSpriteX = strPos * rectLeft + offX; _spriteRight = _destSpriteX + rectLeft - 1; @@ -452,7 +430,7 @@ void Draw_v2::printTotText(int16 id) { } } - rectLeft = _fonts[_fontIndex]->itemWidth; + rectLeft = _fonts[_fontIndex]->getCharWidth(); adjustCoords(1, &rectLeft, 0); offX += strPosBak * rectLeft; strPos = 0; @@ -501,8 +479,8 @@ void Draw_v2::printTotText(int16 id) { rectBottom = destY + (int16)READ_LE_UINT16(ptr + 6); adjustCoords(2, &rectLeft, &rectTop); adjustCoords(2, &rectRight, &rectBottom); - _vm->_game->addNewCollision(colId + 0x0D000, rectLeft, rectTop, - rectRight, rectBottom, 2, 0, 0, 0); + _vm->_game->_hotspots->add(colId + 0x0D000, rectLeft, rectTop, + rectRight, rectBottom, (uint16) Hotspots::kTypeClick, 0, 0, 0, 0); ptr += 8; } break; @@ -604,7 +582,7 @@ void Draw_v2::printTotText(int16 id) { if (!(_renderFlags & RENDERFLAG_COLLISIONS)) return; - _vm->_game->checkCollisions(0, 0, 0, 0); + _vm->_game->_hotspots->check(0, 0); if (*_vm->_scenery->_pCaptureCounter != 0) { (*_vm->_scenery->_pCaptureCounter)--; @@ -620,8 +598,6 @@ void Draw_v2::spriteOperation(int16 operation) { int16 left; int16 ratio; Resource *resource; - // Always assigned to -1 in Game::loadTotFile() - int16 someHandle = -1; deltaVeto = (operation & 0x10) != 0; operation &= 0x0F; @@ -783,8 +759,13 @@ void Draw_v2::spriteOperation(int16 operation) { left = _destSpriteX; if ((_fontIndex >= 4) || (_fontToSprite[_fontIndex].sprite == -1)) { + Font *font = _fonts[_fontIndex]; + if (!font) { + warning("Trying to print \"%s\" with undefined font %d", _textToPrint, _fontIndex); + break; + } - if (!_fonts[_fontIndex]->extraData) { + if (font->isMonospaced()) { if (((int8) _textToPrint[0]) == -1) { _vm->validateLanguage(); @@ -792,26 +773,20 @@ void Draw_v2::spriteOperation(int16 operation) { len = *dataBuf++; for (int i = 0; i < len; i++, dataBuf += 2) { _vm->_video->drawLetter(READ_LE_UINT16(dataBuf), _destSpriteX, - _destSpriteY, _fonts[_fontIndex], _transparency, _frontColor, + _destSpriteY, *font, _transparency, _frontColor, _backColor, *_spritesArray[_destSurface]); } } else { drawString(_textToPrint, _destSpriteX, _destSpriteY, _frontColor, - _backColor, _transparency, *_spritesArray[_destSurface], - _fonts[_fontIndex]); - _destSpriteX += len * _fonts[_fontIndex]->itemWidth; + _backColor, _transparency, *_spritesArray[_destSurface], *font); + _destSpriteX += len * font->getCharWidth(); } } else { for (int i = 0; i < len; i++) { - if ((someHandle < 0) || (_textToPrint[i] != ' ')) { - _vm->_video->drawLetter(_textToPrint[i], _destSpriteX, - _destSpriteY, _fonts[_fontIndex], _transparency, - _frontColor, _backColor, *_spritesArray[_destSurface]); - _destSpriteX += *(_fonts[_fontIndex]->extraData + - (_textToPrint[i] - _fonts[_fontIndex]->startItem)); - } - else - _destSpriteX += _fonts[_fontIndex]->itemWidth; + _vm->_video->drawLetter(_textToPrint[i], _destSpriteX, + _destSpriteY, *font, _transparency, + _frontColor, _backColor, *_spritesArray[_destSurface]); + _destSpriteX += font->getCharWidth(_textToPrint[i]); } } @@ -835,7 +810,7 @@ void Draw_v2::spriteOperation(int16 operation) { } dirtiedRect(_destSurface, left, _destSpriteY, - _destSpriteX - 1, _destSpriteY + _fonts[_fontIndex]->itemHeight - 1); + _destSpriteX - 1, _destSpriteY + _fonts[_fontIndex]->getCharHeight() - 1); break; case DRAW_DRAWBAR: @@ -906,7 +881,7 @@ void Draw_v2::spriteOperation(int16 operation) { _sourceSurface = sourceSurface; if (operation == DRAW_PRINTTEXT) { - len = _fonts[_fontIndex]->itemWidth; + len = _fonts[_fontIndex]->getCharWidth(); adjustCoords(1, &len, 0); _destSpriteX += len * strlen(_textToPrint); } diff --git a/engines/gob/driver_vga.cpp b/engines/gob/driver_vga.cpp index aff971164f..c93962c206 100644 --- a/engines/gob/driver_vga.cpp +++ b/engines/gob/driver_vga.cpp @@ -70,24 +70,22 @@ void VGAVideoDriver::fillRect(SurfaceDesc &dest, int16 left, int16 top, } void VGAVideoDriver::drawLetter(unsigned char item, int16 x, int16 y, - Video::FontDesc *fontDesc, byte color1, byte color2, + const Font &font, byte color1, byte color2, byte transp, SurfaceDesc &dest) { - byte *src, *dst; uint16 data; - src = fontDesc->dataPtr + - (item - fontDesc->startItem) * (fontDesc->itemSize & 0xFF); - dst = dest.getVidMem() + x + dest.getWidth() * y; + const byte *src = font.getCharData(item); + byte *dst = dest.getVidMem() + x + dest.getWidth() * y; - int nWidth = fontDesc->itemWidth; + int nWidth = font.getCharWidth(); if (nWidth & 7) nWidth = (nWidth & 0xF8) + 8; nWidth >>= 3; - for (int i = 0; i < fontDesc->itemHeight; i++) { - int width = fontDesc->itemWidth; + for (int i = 0; i < font.getCharHeight(); i++) { + int width = font.getCharWidth(); for (int k = 0; k < nWidth; k++) { @@ -106,7 +104,7 @@ void VGAVideoDriver::drawLetter(unsigned char item, int16 x, int16 y, } - dst += dest.getWidth() - fontDesc->itemWidth; + dst += dest.getWidth() - font.getCharWidth(); } } diff --git a/engines/gob/driver_vga.h b/engines/gob/driver_vga.h index c50ea5c475..3102016cb5 100644 --- a/engines/gob/driver_vga.h +++ b/engines/gob/driver_vga.h @@ -41,7 +41,7 @@ public: void fillRect(SurfaceDesc &dest, int16 left, int16 top, int16 right, int16 bottom, byte color); void drawLetter(unsigned char item, int16 x, int16 y, - Video::FontDesc *fontDesc, byte color1, byte color2, + const Font &font, byte color1, byte color2, byte transp, SurfaceDesc &dest); void drawSprite(SurfaceDesc &source, SurfaceDesc &dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp); diff --git a/engines/gob/game.cpp b/engines/gob/game.cpp index 5771ee9f76..d201019d08 100644 --- a/engines/gob/game.cpp +++ b/engines/gob/game.cpp @@ -29,14 +29,15 @@ #include "gob/game.h" #include "gob/helper.h" #include "gob/global.h" -#include "gob/util.h" #include "gob/dataio.h" #include "gob/variables.h" #include "gob/script.h" #include "gob/resources.h" +#include "gob/hotspots.h" #include "gob/inter.h" #include "gob/draw.h" #include "gob/mult.h" +#include "gob/scenery.h" #include "gob/videoplayer.h" #include "gob/sound/sound.h" @@ -170,30 +171,14 @@ bool Environments::has(Resources *resources, uint8 startEnv, int16 except) const Game::Game(GobEngine *vm) : _vm(vm) { - _collisionAreas = 0; - _shouldPushColls = 0; - _captureCount = 0; - _collStackSize = 0; - - for (int i = 0; i < 5; i++) { - _collStack[i] = 0; - _collStackElemSizes[i] = 0; - } - _curTotFile[0] = 0; _totToLoad[0] = 0; _startTimeKey = 0; - _mouseButtons = 0; - - _lastCollKey = 0; - _lastCollAreaIndex = 0; - _lastCollId = 0; + _mouseButtons = kMouseButtonsNone; - _activeCollResId = 0; - _activeCollIndex = 0; _handleMouse = 0; _forceHandleMouse = 0; _menuLevel = 0; @@ -201,10 +186,7 @@ Game::Game(GobEngine *vm) : _vm(vm) { _preventScroll = false; _scrollHandleMouse = false; - _noCd = false; - _tempStr[0] = 0; - _collStr[0] = 0; _numEnvironments = 0; _curEnvironment = 0; @@ -212,19 +194,181 @@ Game::Game(GobEngine *vm) : _vm(vm) { _environments = new Environments(_vm); _script = new Script(_vm); _resources = new Resources(_vm); + _hotspots = new Hotspots(_vm); } Game::~Game() { delete _environments; delete _script; delete _resources; + delete _hotspots; } -void Game::freeCollision(int16 id) { - for (int i = 0; i < 250; i++) { - if (_collisionAreas[i].id == id) - _collisionAreas[i].left = 0xFFFF; +void Game::prepareStart() { + _vm->_global->_pPaletteDesc->unused2 = _vm->_draw->_unusedPalette2; + _vm->_global->_pPaletteDesc->unused1 = _vm->_draw->_unusedPalette1; + _vm->_global->_pPaletteDesc->vgaPal = _vm->_draw->_vgaPalette; + + _vm->_video->setFullPalette(_vm->_global->_pPaletteDesc); + + _vm->_draw->initScreen(); + _vm->_video->fillRect(*_vm->_draw->_frontSurface, 0, 0, + _vm->_video->_surfWidth - 1, _vm->_video->_surfHeight - 1, 1); + + _vm->_util->setMousePos(152, 92); + _vm->_draw->_cursorX = _vm->_global->_inter_mouseX = 152; + _vm->_draw->_cursorY = _vm->_global->_inter_mouseY = 92; + + _vm->_draw->_invalidatedCount = 0; + _vm->_draw->_noInvalidated = true; + _vm->_draw->_applyPal = false; + _vm->_draw->_paletteCleared = false; + _vm->_draw->_cursorWidth = 16; + _vm->_draw->_cursorHeight = 16; + _vm->_draw->_transparentCursor = 1; + + for (int i = 0; i < 40; i++) { + _vm->_draw->_cursorAnimLow[i] = -1; + _vm->_draw->_cursorAnimDelays[i] = 0; + _vm->_draw->_cursorAnimHigh[i] = 0; } + + _vm->_draw->_renderFlags = 0; + _vm->_draw->_backDeltaX = 0; + _vm->_draw->_backDeltaY = 0; + + _startTimeKey = _vm->_util->getTimeKey(); +} + +void Game::playTot(int16 skipPlay) { + char savedTotName[20]; + int16 *oldCaptureCounter; + int16 *oldBreakFrom; + int16 *oldNestLevel; + int16 _captureCounter; + int16 breakFrom; + int16 nestLevel; + + oldNestLevel = _vm->_inter->_nestLevel; + oldBreakFrom = _vm->_inter->_breakFromLevel; + oldCaptureCounter = _vm->_scenery->_pCaptureCounter; + + _script->push(); + + _vm->_inter->_nestLevel = &nestLevel; + _vm->_inter->_breakFromLevel = &breakFrom; + _vm->_scenery->_pCaptureCounter = &_captureCounter; + strcpy(savedTotName, _curTotFile); + + if (skipPlay <= 0) { + while (!_vm->shouldQuit()) { + if (_vm->_inter->_variables) + _vm->_draw->animateCursor(4); + + if (skipPlay != -1) { + _vm->_inter->initControlVars(1); + + for (int i = 0; i < 4; i++) { + _vm->_draw->_fontToSprite[i].sprite = -1; + _vm->_draw->_fontToSprite[i].base = -1; + _vm->_draw->_fontToSprite[i].width = -1; + _vm->_draw->_fontToSprite[i].height = -1; + } + + _vm->_mult->initAll(); + _vm->_mult->zeroMultData(); + + _vm->_draw->_spritesArray[20] = _vm->_draw->_frontSurface; + _vm->_draw->_spritesArray[21] = _vm->_draw->_backSurface; + _vm->_draw->_cursorSpritesBack = _vm->_draw->_cursorSprites; + } else + _vm->_inter->initControlVars(0); + + _vm->_draw->_cursorHotspotXVar = -1; + _totToLoad[0] = 0; + + if ((_curTotFile[0] == 0) && (!_script->isLoaded())) + break; + + if (skipPlay == -2) { + _vm->_vidPlayer->primaryClose(); + skipPlay = 0; + } + + if (!_script->load(_curTotFile)) { + _vm->_draw->blitCursor(); + _vm->_inter->_terminate = 2; + break; + } + + _resources->load(_curTotFile); + + _vm->_global->_inter_animDataSize = _script->getAnimDataSize(); + if (!_vm->_inter->_variables) + _vm->_inter->allocateVars(_script->getVariablesCount() & 0xFFFF); + + _script->seek(_script->getFunctionOffset(TOTFile::kFunctionStart)); + + _vm->_inter->renewTimeInVars(); + + WRITE_VAR(13, _vm->_global->_useMouse); + WRITE_VAR(14, _vm->_global->_soundFlags); + WRITE_VAR(15, _vm->_global->_fakeVideoMode); + WRITE_VAR(16, _vm->_global->_language); + + _vm->_inter->callSub(2); + + if (_totToLoad[0] != 0) + _vm->_inter->_terminate = 0; + + _vm->_draw->blitInvalidated(); + + _script->unload(); + + _resources->unload(); + + for (int i = 0; i < *_vm->_scenery->_pCaptureCounter; i++) + capturePop(0); + + if (skipPlay != -1) { + _vm->_goblin->freeObjects(); + + _vm->_sound->blasterStop(0); + + for (int i = 0; i < Sound::kSoundsCount; i++) { + SoundDesc *sound = _vm->_sound->sampleGetBySlot(i); + + if (sound && + ((sound->getType() == SOUND_SND) || (sound->getType() == SOUND_WAV))) + _vm->_sound->sampleFree(sound); + } + } + + if (_totToLoad[0] == 0) + break; + + strcpy(_curTotFile, _totToLoad); + } + } else { + _vm->_inter->initControlVars(0); + _vm->_scenery->_pCaptureCounter = oldCaptureCounter; + _script->seek(_script->getFunctionOffset(skipPlay + 1)); + + _menuLevel++; + _vm->_inter->callSub(2); + _menuLevel--; + + if (_vm->_inter->_terminate != 0) + _vm->_inter->_terminate = 2; + } + + strcpy(_curTotFile, savedTotName); + + _vm->_inter->_nestLevel = oldNestLevel; + _vm->_inter->_breakFromLevel = oldBreakFrom; + _vm->_scenery->_pCaptureCounter = oldCaptureCounter; + + _script->pop(); } void Game::capturePush(int16 left, int16 top, int16 width, int16 height) { @@ -349,7 +493,7 @@ void Game::evaluateScroll(int16 x, int16 y) { } int16 Game::checkKeys(int16 *pMouseX, int16 *pMouseY, - int16 *pButtons, char handleMouse) { + MouseButtons *pButtons, char handleMouse) { _vm->_util->processInput(true); @@ -373,28 +517,17 @@ int16 Game::checkKeys(int16 *pMouseX, int16 *pMouseY, if (pMouseX && pMouseY && pButtons) { _vm->_util->getMouseState(pMouseX, pMouseY, pButtons); - if (*pButtons == 3) - *pButtons = 0; + if (*pButtons == kMouseButtonsBoth) + *pButtons = kMouseButtonsNone; } return _vm->_util->checkKey(); } -int16 Game::adjustKey(int16 key) { - if (key <= 0x60 || key >= 0x7B) - return key; - - return key - 0x20; -} - -void Game::start(void) { - _collisionAreas = new Collision[250]; - memset(_collisionAreas, 0, 250 * sizeof(Collision)); - +void Game::start() { prepareStart(); playTot(-2); - delete[] _collisionAreas; _vm->_draw->closeScreen(); for (int i = 0; i < SPRITES_COUNT; i++) @@ -406,6 +539,9 @@ void Game::start(void) { void Game::totSub(int8 flags, const char *newTotFile) { int8 curBackupPos; + if ((flags == 16) || (flags == 17)) + warning("Urban Stub: Game::totSub(), flags == %d", flags); + if (_numEnvironments >= Environments::kEnvironmentCount) return; @@ -417,13 +553,14 @@ void Game::totSub(int8 flags, const char *newTotFile) { _script = new Script(_vm); _resources = new Resources(_vm); + + if (flags & 0x80) + warning("Urban Stub: Game::totSub(), flags & 0x80"); + if (flags & 1) _vm->_inter->_variables = 0; strncpy0(_curTotFile, newTotFile, 9); -// if (_vm->getGameType() == kGameTypeGeisha) -// strcat(_curTotFile, ".0OT"); -// else strcat(_curTotFile, ".TOT"); if (_vm->_inter->_terminate != 0) { @@ -431,7 +568,7 @@ void Game::totSub(int8 flags, const char *newTotFile) { return; } - pushCollisions(0); + _hotspots->push(0, true); if (flags & 2) playTot(-1); @@ -441,7 +578,8 @@ void Game::totSub(int8 flags, const char *newTotFile) { if (_vm->_inter->_terminate != 2) _vm->_inter->_terminate = 0; - popCollisions(); + _hotspots->clear(); + _hotspots->pop(); if ((flags & 1) && _vm->_inter->_variables) { _vm->_inter->delocateVars(); @@ -489,13 +627,13 @@ void Game::switchTotSub(int16 index, int16 skipPlay) { return; } - pushCollisions(0); + _hotspots->push(0, true); playTot(skipPlay); if (_vm->_inter->_terminate != 2) _vm->_inter->_terminate = 0; - popCollisions(); + _hotspots->pop(); clearUnusedEnvironment(); @@ -504,87 +642,6 @@ void Game::switchTotSub(int16 index, int16 skipPlay) { _environments->get(_curEnvironment); } -void Game::setCollisions(byte arg_0) { - uint16 left; - uint16 top; - uint16 width; - uint16 height; - Collision *collArea; - - for (collArea = _collisionAreas; collArea->left != 0xFFFF; collArea++) { - if (((collArea->id & 0xC000) != 0x8000) || (collArea->funcSub == 0)) - continue; - - _script->call(collArea->funcSub); - - left = _script->readValExpr(); - top = _script->readValExpr(); - width = _script->readValExpr(); - height = _script->readValExpr(); - if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) && - (left != 0xFFFF)) { - left += _vm->_draw->_backDeltaX; - top += _vm->_draw->_backDeltaY; - } - if (_vm->_draw->_needAdjust != 2) { - _vm->_draw->adjustCoords(0, &left, &top); - if ((collArea->flags & 0x0F) < 3) - _vm->_draw->adjustCoords(2, &width, &height); - else { - height &= 0xFFFE; - _vm->_draw->adjustCoords(2, 0, &height); - } - } - collArea->left = left; - collArea->top = top; - collArea->right = left + width - 1; - collArea->bottom = top + height - 1; - - _script->pop(); - } -} - -void Game::collSub(uint16 offset) { - int16 collStackSize; - - _script->call(offset); - - _shouldPushColls = 1; - collStackSize = _collStackSize; - - _vm->_inter->funcBlock(0); - - if (collStackSize != _collStackSize) - popCollisions(); - - _shouldPushColls = 0; - - _script->pop(); - - setCollisions(); -} - -void Game::collAreaSub(int16 index, int8 enter) { - uint16 collId; - - collId = _collisionAreas[index].id & 0xF000; - - if ((collId == 0xA000) || (collId == 0x9000)) { - if (enter == 0) - WRITE_VAR(17, _collisionAreas[index].id & 0x0FFF); - else - WRITE_VAR(17, -(_collisionAreas[index].id & 0x0FFF)); - } - - if (enter != 0) { - if (_collisionAreas[index].funcEnter != 0) - collSub(_collisionAreas[index].funcEnter); - } else { - if (_collisionAreas[index].funcLeave != 0) - collSub(_collisionAreas[index].funcLeave); - } -} - void Game::clearUnusedEnvironment() { if (!_environments->has(_script)) { delete _script; @@ -594,7 +651,6 @@ void Game::clearUnusedEnvironment() { delete _resources; _resources = 0; } - } } // End of namespace Gob diff --git a/engines/gob/game.h b/engines/gob/game.h index ead4a56492..d3a758f014 100644 --- a/engines/gob/game.h +++ b/engines/gob/game.h @@ -26,11 +26,14 @@ #ifndef GOB_GAME_H #define GOB_GAME_H +#include "gob/util.h" + namespace Gob { class Script; class Resources; class Variables; +class Hotspots; class Environments { public: @@ -67,53 +70,30 @@ private: class Game { public: - -#include "common/pack-start.h" // START STRUCT PACKING - - struct Collision { - int16 id; - uint16 left; - uint16 top; - uint16 right; - uint16 bottom; - int16 flags; - int16 key; - uint16 funcEnter; - uint16 funcLeave; - uint16 funcSub; - Script *script; - } PACKED_STRUCT; - - struct InputDesc { - int16 fontIndex; - int16 backColor; - int16 frontColor; - byte *ptr; - } PACKED_STRUCT; - -#include "common/pack-end.h" // END STRUCT PACKING - - Collision *_collisionAreas; - Collision *_collStack[5]; - - Script *_script; + Script *_script; Resources *_resources; + Hotspots *_hotspots; char _curTotFile[14]; char _totToLoad[20]; int32 _startTimeKey; - int16 _mouseButtons; + MouseButtons _mouseButtons; bool _noScroll; bool _preventScroll; bool _scrollHandleMouse; - bool _noCd; + byte _handleMouse; + char _forceHandleMouse; Game(GobEngine *vm); virtual ~Game(); + void prepareStart(); + + void playTot(int16 skipPlay); + void capturePush(int16 left, int16 top, int16 width, int16 height); void capturePop(char doDraw); @@ -122,60 +102,21 @@ public: void evaluateScroll(int16 x, int16 y); int16 checkKeys(int16 *pMousex = 0, int16 *pMouseY = 0, - int16 *pButtons = 0, char handleMouse = 0); - void start(void); - - virtual void totSub(int8 flags, const char *newTotFile); - virtual void switchTotSub(int16 index, int16 skipPlay); + MouseButtons *pButtons = 0, char handleMouse = 0); + void start(); - void freeCollision(int16 id); - - virtual void playTot(int16 skipPlay) = 0; - - virtual void clearCollisions(void) = 0; - virtual int16 addNewCollision(int16 id, uint16 left, uint16 top, - uint16 right, uint16 bottom, int16 flags, int16 key, - uint16 funcEnter, uint16 funcLeave, uint16 funcSub = 0) = 0; - virtual void collisionsBlock(void) = 0; - virtual int16 multiEdit(int16 time, int16 index, int16 *pCurPos, - InputDesc *inpDesc, int16 *collResId, - int16 *collIndex, bool mono = true) = 0; - virtual int16 inputArea(int16 xPos, int16 yPos, int16 width, int16 height, - int16 backColor, int16 frontColor, char *str, int16 fontIndex, - char inpType, int16 *pTotTime, int16 *collResId, - int16 *collIndex, bool mono = true) = 0; - virtual int16 checkCollisions(byte handleMouse, int16 deltaTime, - int16 *pResId, int16 *pResIndex) = 0; - - virtual void prepareStart(void) = 0; - - virtual void pushCollisions(char all) = 0; - virtual void popCollisions(void) = 0; + void totSub(int8 flags, const char *newTotFile); + void switchTotSub(int16 index, int16 skipPlay); protected: - int16 _lastCollKey; - int16 _lastCollAreaIndex; - int16 _lastCollId; - - int16 _activeCollResId; - int16 _activeCollIndex; - byte _handleMouse; - char _forceHandleMouse; uint32 _menuLevel; char _tempStr[256]; - int16 _collStackSize; - int16 _collStackElemSizes[5]; - - char _shouldPushColls; - // Capture Common::Rect _captureStack[20]; int16 _captureCount; - char _collStr[256]; - // For totSub() int8 _curEnvironment; int8 _numEnvironments; @@ -183,129 +124,9 @@ protected: GobEngine *_vm; - virtual int16 adjustKey(int16 key); - - void collAreaSub(int16 index, int8 enter); - - virtual void setCollisions(byte arg_0 = 1); - virtual void collSub(uint16 offset); - - virtual int16 checkMousePoint(int16 all, int16 *resId, int16 *resIndex) = 0; - void clearUnusedEnvironment(); }; -class Game_v1 : public Game { -public: - virtual void playTot(int16 skipPlay); - - virtual void clearCollisions(void); - virtual int16 addNewCollision(int16 id, uint16 left, uint16 top, - uint16 right, uint16 bottom, int16 flags, int16 key, - uint16 funcEnter, uint16 funcLeave, uint16 funcSub = 0); - virtual void collisionsBlock(void); - virtual int16 multiEdit(int16 time, int16 index, int16 *pCurPos, - InputDesc *inpDesc, int16 *collResId, - int16 *collIndex, bool mono = true); - virtual int16 inputArea(int16 xPos, int16 yPos, int16 width, int16 height, - int16 backColor, int16 frontColor, char *str, int16 fontIndex, - char inpType, int16 *pTotTime, int16 *collResId, - int16 *collIndex, bool mono = true); - virtual int16 checkCollisions(byte handleMouse, int16 deltaTime, - int16 *pResId, int16 *pResIndex); - - virtual void prepareStart(void); - - virtual void pushCollisions(char all); - virtual void popCollisions(void); - - Game_v1(GobEngine *vm); - virtual ~Game_v1() {} - -protected: - virtual int16 checkMousePoint(int16 all, int16 *resId, int16 *resIndex); -}; - -class Game_v2 : public Game_v1 { -public: - virtual void playTot(int16 skipPlay); - - virtual void clearCollisions(void); - virtual int16 addNewCollision(int16 id, uint16 left, uint16 top, - uint16 right, uint16 bottom, int16 flags, int16 key, - uint16 funcEnter, uint16 funcLeave, uint16 funcSub = 0); - virtual void collisionsBlock(void); - virtual int16 multiEdit(int16 time, int16 index, int16 *pCurPos, - InputDesc *inpDesc, int16 *collResId, - int16 *collIndex, bool mono = true); - virtual int16 inputArea(int16 xPos, int16 yPos, int16 width, int16 height, - int16 backColor, int16 frontColor, char *str, int16 fontIndex, - char inpType, int16 *pTotTime, int16 *collResId, - int16 *collIndex, bool mono = true); - virtual int16 checkCollisions(byte handleMouse, int16 deltaTime, - int16 *pResId, int16 *pResIndex); - - virtual void prepareStart(void); - - virtual void pushCollisions(char all); - virtual void popCollisions(void); - - Game_v2(GobEngine *vm); - virtual ~Game_v2() {} - -protected: - struct CollLast { - int16 key; - int16 id; - int16 areaIndex; - }; - - CollLast _collLasts[5]; - - virtual int16 checkMousePoint(int16 all, int16 *resId, int16 *resIndex); -}; - -class Game_v6 : public Game_v2 { -public: - virtual void totSub(int8 flags, const char *newTotFile); - - virtual int16 addNewCollision(int16 id, uint16 left, uint16 top, - uint16 right, uint16 bottom, int16 flags, int16 key, - uint16 funcEnter, uint16 funcLeave, uint16 funcSub = 0); - - virtual void prepareStart(void); - - virtual void pushCollisions(char all); - - virtual int16 checkCollisions(byte handleMouse, int16 deltaTime, - int16 *pResId, int16 *pResIndex); - virtual void collisionsBlock(void); - - Game_v6(GobEngine *vm); - virtual ~Game_v6() {} - -protected: - uint32 _someTimeDly; - - virtual void setCollisions(byte arg_0 = 1); - virtual void collSub(uint16 offset); - - virtual int16 adjustKey(int16 key); - - virtual int16 checkMousePoint(int16 all, int16 *resId, int16 *resIndex); - - void collSubReenter(); -}; - -class Game_Fascination : public Game_v2 { -public: - virtual int16 checkCollisions(byte handleMouse, int16 deltaTime, - int16 *pResId, int16 *pResIndex); - - Game_Fascination(GobEngine *vm); - virtual ~Game_Fascination() {} -}; - } // End of namespace Gob #endif // GOB_GAME_H diff --git a/engines/gob/game_fascin.cpp b/engines/gob/game_fascin.cpp deleted file mode 100644 index 38ad03f0f8..0000000000 --- a/engines/gob/game_fascin.cpp +++ /dev/null @@ -1,203 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#include "common/endian.h" -#include "common/stream.h" - -#include "gob/gob.h" -#include "gob/game.h" -#include "gob/global.h" -#include "gob/util.h" -#include "gob/dataio.h" -#include "gob/draw.h" -#include "gob/goblin.h" -#include "gob/inter.h" -#include "gob/mult.h" -#include "gob/scenery.h" -#include "gob/video.h" -#include "gob/videoplayer.h" -#include "gob/sound/sound.h" - -namespace Gob { - -Game_Fascination::Game_Fascination(GobEngine *vm) : Game_v2(vm) { -} - -int16 Game_Fascination::checkCollisions(byte handleMouse, int16 deltaTime, int16 *pResId, - int16 *pResIndex) { - int16 resIndex; - int16 key; - int16 oldIndex; - int16 oldId; - int16 newkey; - uint32 timeKey; - - _scrollHandleMouse = handleMouse != 0; - - if (deltaTime >= -1) { - _lastCollKey = 0; - _lastCollAreaIndex = 0; - _lastCollId = 0; - } - - if (pResId != 0) - *pResId = 0; - - resIndex = 0; - - if ((_vm->_draw->_cursorIndex == -1) && - (handleMouse != 0) && (_lastCollKey == 0)) { - _lastCollKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - - if ((_lastCollKey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 1); - } - - if (handleMouse != 0) { - if ((handleMouse==1) && (_vm->_draw->_renderFlags & RENDERFLAG_UNKNOWN)) - warning("checkCollisions : RENDERFLAG_UNKNOWN - Unknown behavior"); - _vm->_draw->animateCursor(-1); - } - - timeKey = _vm->_util->getTimeKey(); - while (1) { - if (_vm->_inter->_terminate || _vm->shouldQuit()) { - if (handleMouse) - _vm->_draw->blitCursor(); - return 0; - } - - if (!_vm->_draw->_noInvalidated) { - if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - else - _vm->_draw->blitInvalidated(); - _vm->_video->waitRetrace(); - } - - key = checkKeys(&_vm->_global->_inter_mouseX, - &_vm->_global->_inter_mouseY, &_mouseButtons, handleMouse); - - if ((handleMouse == 0) && (_mouseButtons != 0)) { - _vm->_util->waitMouseRelease(0); - key = 3; - } - - if (key != 0) { - - if (handleMouse & 1) - _vm->_draw->blitCursor(); - - if (pResId != 0) - *pResId = 0; - - if (pResIndex != 0) - *pResIndex = 0; - - if (_lastCollKey != 0) - collAreaSub(_lastCollAreaIndex, 0); - - _lastCollKey = 0; - if (key != 0) - return key; - } - - if (handleMouse != 0) { - if (_mouseButtons != 0) { - if (deltaTime > 0) { - _vm->_draw->animateCursor(2); - _vm->_util->delay(deltaTime); - } else if (handleMouse & 1) - _vm->_util->waitMouseRelease(1); - _vm->_draw->animateCursor(-1); - - if (pResId != 0) - *pResId = 0; - - key = checkMousePoint(0, pResId, &resIndex); - if (pResIndex != 0) - *pResIndex = resIndex; - - if ((key != 0) || ((pResId != 0) && (*pResId != 0))) { - if ((handleMouse & 1) && - ((deltaTime <= 0) || (_mouseButtons == 0))) - _vm->_draw->blitCursor(); - - if ((_lastCollKey != 0) && (key != _lastCollKey)) - collAreaSub(_lastCollAreaIndex, 0); - - _lastCollKey = 0; - return key; - } - - if (handleMouse & 4) - return 0; - - if (_lastCollKey != 0) - collAreaSub(_lastCollAreaIndex, 0); - - _lastCollKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - if ((_lastCollKey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 1); - } else if ((_vm->_global->_inter_mouseX != _vm->_draw->_cursorX) || - (_vm->_global->_inter_mouseY != _vm->_draw->_cursorY)) { - - oldIndex = _lastCollAreaIndex; - oldId = _lastCollId; - newkey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - - if (newkey != _lastCollKey) { - if ((_lastCollKey != 0) && (oldId & 0x8000)) - collAreaSub(oldIndex, 0); - - _lastCollKey = newkey; - - if ((newkey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 1); - } - } - } - - if ((deltaTime < 0) && (key == 0) && (_mouseButtons == 0)) { - uint32 curtime = _vm->_util->getTimeKey(); - if ((curtime + deltaTime) > timeKey) { - if (pResId != 0) - *pResId = 0; - - if (pResIndex != 0) - *pResIndex = 0; - - return 0; - } - } - - if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - - _vm->_util->delay(10); - } -} - -} // End of namespace Gob diff --git a/engines/gob/game_v1.cpp b/engines/gob/game_v1.cpp deleted file mode 100644 index 87dc78e3b1..0000000000 --- a/engines/gob/game_v1.cpp +++ /dev/null @@ -1,1426 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#include "common/endian.h" -#include "common/stream.h" - -#include "gob/gob.h" -#include "gob/game.h" -#include "gob/helper.h" -#include "gob/global.h" -#include "gob/util.h" -#include "gob/dataio.h" -#include "gob/script.h" -#include "gob/resources.h" -#include "gob/draw.h" -#include "gob/inter.h" -#include "gob/mult.h" -#include "gob/video.h" -#include "gob/scenery.h" -#include "gob/sound/sound.h" - -namespace Gob { - -Game_v1::Game_v1(GobEngine *vm) : Game(vm) { -} - -void Game_v1::playTot(int16 skipPlay) { - int16 _captureCounter; - int16 breakFrom; - int16 nestLevel; - - int16 *oldNestLevel = _vm->_inter->_nestLevel; - int16 *oldBreakFrom = _vm->_inter->_breakFromLevel; - int16 *oldCaptureCounter = _vm->_scenery->_pCaptureCounter; - - _script->push(); - - _vm->_inter->_nestLevel = &nestLevel; - _vm->_inter->_breakFromLevel = &breakFrom; - _vm->_scenery->_pCaptureCounter = &_captureCounter; - - char savedTotName[20]; - strcpy(savedTotName, _curTotFile); - - if (skipPlay <= 0) { - while (!_vm->shouldQuit()) { - for (int i = 0; i < 4; i++) { - _vm->_draw->_fontToSprite[i].sprite = -1; - _vm->_draw->_fontToSprite[i].base = -1; - _vm->_draw->_fontToSprite[i].width = -1; - _vm->_draw->_fontToSprite[i].height = -1; - } - - if ((_vm->getPlatform() == Common::kPlatformMacintosh)|| - (_vm->getPlatform() == Common::kPlatformWindows)) - _vm->_sound->adlibStop(); - else - _vm->_sound->cdStop(); - - _vm->_draw->animateCursor(4); - _vm->_inter->initControlVars(1); - _vm->_mult->initAll(); - _vm->_mult->zeroMultData(); - - for (int i = 0; i < SPRITES_COUNT; i++) - _vm->_draw->freeSprite(i); - - _vm->_draw->_spritesArray[20] = _vm->_draw->_frontSurface; - _vm->_draw->_spritesArray[21] = _vm->_draw->_backSurface; - _vm->_draw->_spritesArray[23] = _vm->_draw->_cursorSprites; - - for (int i = 0; i < 20; i++) - freeSoundSlot(i); - - _totToLoad[0] = 0; - - if ((_curTotFile[0] == 0) && !_script->isLoaded()) - break; - - if (!_script->load(_curTotFile)) { - _vm->_draw->blitCursor(); - break; - } - - _resources->load(_curTotFile); - - _vm->_global->_inter_animDataSize = _script->getAnimDataSize(); - if (!_vm->_inter->_variables) - _vm->_inter->allocateVars(_script->getVariablesCount() & 0xFFFF); - - _script->seek(_script->getFunctionOffset(TOTFile::kFunctionStart)); - - _vm->_inter->renewTimeInVars(); - - WRITE_VAR(13, _vm->_global->_useMouse); - WRITE_VAR(14, _vm->_global->_soundFlags); - WRITE_VAR(15, _vm->_global->_videoMode); - WRITE_VAR(16, _vm->_global->_language); - - _vm->_inter->callSub(2); - _script->setFinished(false); - - if (_totToLoad[0] != 0) - _vm->_inter->_terminate = 0; - - _vm->_draw->blitInvalidated(); - - _script->unload(); - - _resources->unload(); - - for (int i = 0; i < *_vm->_scenery->_pCaptureCounter; i++) - capturePop(0); - - _vm->_mult->checkFreeMult(); - _vm->_mult->freeAll(); - - for (int i = 0; i < SPRITES_COUNT; i++) - _vm->_draw->freeSprite(i); - _vm->_sound->blasterStop(0); - - for (int i = 0; i < 20; i++) - freeSoundSlot(i); - - if (_totToLoad[0] == 0) - break; - - strcpy(_curTotFile, _totToLoad); - } - } - - strcpy(_curTotFile, savedTotName); - - _vm->_inter->_nestLevel = oldNestLevel; - _vm->_inter->_breakFromLevel = oldBreakFrom; - _vm->_scenery->_pCaptureCounter = oldCaptureCounter; - - _script->pop(); -} - -void Game_v1::clearCollisions() { - for (int i = 0; i < 250; i++) { - _collisionAreas[i].id = 0; - _collisionAreas[i].left = 0xFFFF; - } -} - -int16 Game_v1::addNewCollision(int16 id, uint16 left, uint16 top, - uint16 right, uint16 bottom, int16 flags, int16 key, - uint16 funcEnter, uint16 funcLeave, uint16 funcSub) { - Collision *ptr; - - debugC(5, kDebugCollisions, "addNewCollision"); - debugC(5, kDebugCollisions, "id = %X", id); - debugC(5, kDebugCollisions, "left = %d, top = %d, right = %d, bottom = %d", - left, top, right, bottom); - debugC(5, kDebugCollisions, "flags = %X, key = %X", flags, key); - debugC(5, kDebugCollisions, "funcEnter = %d, funcLeave = %d", - funcEnter, funcLeave); - - for (int i = 0; i < 250; i++) { - if (_collisionAreas[i].left != 0xFFFF) - continue; - - ptr = &_collisionAreas[i]; - ptr->id = id; - ptr->left = left; - ptr->top = top; - ptr->right = right; - ptr->bottom = bottom; - ptr->flags = flags; - ptr->key = key; - ptr->funcEnter = funcEnter; - ptr->funcLeave = funcLeave; - ptr->funcSub = funcSub; - ptr->script = 0; - - return i; - } - error("Game_v1::addNewCollision(): Collision array full"); - return 0; -} - -void Game_v1::pushCollisions(char all) { - Collision *srcPtr; - Collision *destPtr; - int16 size; - - debugC(1, kDebugCollisions, "pushCollisions"); - for (size = 0, srcPtr = _collisionAreas; srcPtr->left != 0xFFFF; srcPtr++) { - if (all || (srcPtr->id & 0x8000)) - size++; - } - - destPtr = new Collision[size]; - _collStack[_collStackSize] = destPtr; - _collStackElemSizes[_collStackSize] = size; - _collStackSize++; - - for (srcPtr = _collisionAreas; srcPtr->left != 0xFFFF; srcPtr++) { - if (all || (srcPtr->id & 0x8000)) { - memcpy(destPtr, srcPtr, sizeof(Collision)); - srcPtr->left = 0xFFFF; - destPtr++; - } - } -} - -void Game_v1::popCollisions(void) { - Collision *destPtr; - Collision *srcPtr; - - debugC(1, kDebugCollisions, "popCollision"); - - _collStackSize--; - for (destPtr = _collisionAreas; destPtr->left != 0xFFFF; destPtr++) - ; - - srcPtr = _collStack[_collStackSize]; - memcpy(destPtr, srcPtr, - _collStackElemSizes[_collStackSize] * sizeof(Collision)); - - delete[] _collStack[_collStackSize]; -} - -int16 Game_v1::checkCollisions(byte handleMouse, int16 deltaTime, - int16 *pResId, int16 *pResIndex) { - int16 resIndex; - int16 key; - int16 oldIndex; - int16 oldId; - uint32 timeKey; - bool firstIteration = true; - - if (deltaTime >= -1) { - _lastCollKey = 0; - _lastCollAreaIndex = 0; - _lastCollId = 0; - } - - if (pResId != 0) - *pResId = 0; - - resIndex = 0; - - timeKey = _vm->_util->getTimeKey(); - - if ((_vm->_draw->_cursorIndex == -1) && (handleMouse != 0) && - (_lastCollKey == 0)) { - _lastCollKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - - if ((_lastCollKey != 0) && ((_lastCollId & 0x8000) != 0)) { - _script->call(_collisionAreas[_lastCollAreaIndex].funcEnter); - _vm->_inter->funcBlock(0); - _script->pop(); - } - } - - if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - - while (1) { - if (_vm->_inter->_terminate) { - if (handleMouse) - _vm->_draw->blitCursor(); - return 0; - } - - if (!_vm->_draw->_noInvalidated) { - if (handleMouse) - _vm->_draw->animateCursor(-1); - else - _vm->_draw->blitInvalidated(); - } - - // 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 inputArea, - // and the return value is then discarded. - if (deltaTime < 0) { - uint32 curtime = _vm->_util->getTimeKey(); - if ((deltaTime == -1) || (((curtime + deltaTime) > timeKey) && !firstIteration)) { - if (pResId != 0) - *pResId = 0; - - if (pResIndex != 0) - *pResIndex = 0; - - return 0; - } - } - - key = checkKeys(&_vm->_global->_inter_mouseX, - &_vm->_global->_inter_mouseY, &_mouseButtons, handleMouse); - - if ((handleMouse == 0) && (_mouseButtons != 0)) { - _vm->_util->waitMouseRelease(0); - key = 3; - } - - if (key != 0) { - - if (handleMouse == 1) - _vm->_draw->blitCursor(); - - if (pResId != 0) - *pResId = 0; - - if (pResIndex != 0) - *pResIndex = 0; - - if ((_lastCollKey != 0) && - (_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) { - - _script->call(_collisionAreas[_lastCollAreaIndex].funcLeave); - _vm->_inter->funcBlock(0); - _script->pop(); - } - - _lastCollKey = 0; - if (key != 0) - return key; - } - - if (handleMouse != 0) { - if (_mouseButtons != 0) { - oldIndex = 0; - - _vm->_draw->animateCursor(2); - if (deltaTime <= 0) { - if (handleMouse == 1) - _vm->_util->waitMouseRelease(1); - } else if (deltaTime > 0) - _vm->_util->delay(deltaTime); - - _vm->_draw->animateCursor(-1); - if (pResId != 0) - *pResId = 0; - - key = checkMousePoint(0, pResId, &resIndex); - - if (pResIndex != 0) - *pResIndex = resIndex; - - if ((key != 0) || ((pResId != 0) && (*pResId != 0))) { - if ((handleMouse == 1) && - ((deltaTime <= 0) || (_mouseButtons == 0))) - _vm->_draw->blitCursor(); - - if ((_lastCollKey != 0) && - (_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) { - - _script->call(_collisionAreas[_lastCollAreaIndex].funcLeave); - _vm->_inter->funcBlock(0); - _script->pop(); - - } - _lastCollKey = 0; - return key; - } - - if ((_lastCollKey != 0) && - (_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) { - - _script->call(_collisionAreas[_lastCollAreaIndex].funcLeave); - _vm->_inter->funcBlock(0); - _script->pop(); - - } - - _lastCollKey = - checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - - if ((_lastCollKey != 0) && ((_lastCollId & 0x8000) != 0)) { - - _script->call(_collisionAreas[_lastCollAreaIndex].funcEnter); - _vm->_inter->funcBlock(0); - _script->pop(); - - } - } else { - - if ((handleMouse != 0) && - ((_vm->_global->_inter_mouseX != _vm->_draw->_cursorX) || - (_vm->_global->_inter_mouseY != _vm->_draw->_cursorY))) { - oldIndex = _lastCollAreaIndex; - oldId = _lastCollId; - - key = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - - if (key != _lastCollKey) { - if ((_lastCollKey != 0) && ((oldId & 0x8000) != 0)) { - - _script->call(_collisionAreas[oldIndex].funcLeave); - _vm->_inter->funcBlock(0); - _script->pop(); - - } - - _lastCollKey = key; - if ((_lastCollKey != 0) && ((_lastCollId & 0x8000) != 0)) { - - _script->call(_collisionAreas[_lastCollAreaIndex].funcEnter); - _vm->_inter->funcBlock(0); - _script->pop(); - - } - - } - } - } - } - - if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - - if (deltaTime < -10) - _vm->_util->delay(10); - - firstIteration = false; - } -} - -void Game_v1::prepareStart(void) { - clearCollisions(); - - _vm->_global->_pPaletteDesc->unused2 = _vm->_draw->_unusedPalette2; - _vm->_global->_pPaletteDesc->unused1 = _vm->_draw->_unusedPalette1; - _vm->_global->_pPaletteDesc->vgaPal = _vm->_draw->_vgaPalette; - - _vm->_video->setFullPalette(_vm->_global->_pPaletteDesc); - - _vm->_draw->initScreen(); - _vm->_video->fillRect(*_vm->_draw->_backSurface, 0, 0, 319, 199, 1); - _vm->_draw->_frontSurface = _vm->_global->_primarySurfDesc; - _vm->_video->fillRect(*_vm->_draw->_frontSurface, 0, 0, 319, 199, 1); - - _vm->_util->setMousePos(152, 92); - _vm->_draw->_cursorX = _vm->_global->_inter_mouseX = 152; - _vm->_draw->_cursorY = _vm->_global->_inter_mouseY = 92; - - _vm->_draw->_invalidatedCount = 0; - _vm->_draw->_noInvalidated = true; - _vm->_draw->_applyPal = false; - _vm->_draw->_paletteCleared = false; - _vm->_draw->_cursorWidth = 16; - _vm->_draw->_cursorHeight = 16; - _vm->_draw->_transparentCursor = 1; - - for (int i = 0; i < 40; i++) { - _vm->_draw->_cursorAnimLow[i] = -1; - _vm->_draw->_cursorAnimDelays[i] = 0; - _vm->_draw->_cursorAnimHigh[i] = 0; - } - - _vm->_draw->_cursorAnimLow[1] = 0; - _vm->_draw->_cursorSprites = - _vm->_video->initSurfDesc(_vm->_global->_videoMode, 32, 16, 2); - _vm->_draw->_scummvmCursor = - _vm->_video->initSurfDesc(_vm->_global->_videoMode, 16, 16, SCUMMVM_CURSOR); - _vm->_draw->_renderFlags = 0; - _vm->_draw->_backDeltaX = 0; - _vm->_draw->_backDeltaY = 0; - - _startTimeKey = _vm->_util->getTimeKey(); -} - -void Game_v1::collisionsBlock(void) { - InputDesc descArray[20]; - int16 array[250]; - byte count; - int16 collResId; - int16 curCmd; - int16 cmd; - int16 cmdHigh; - int16 key; - int16 flags; - uint16 left; - uint16 top; - uint16 width; - uint16 height; - int16 var_22; - int16 index; - int16 curEditIndex; - int16 deltaTime; - int16 descIndex2; - int16 stackPos2; - int16 descIndex; - int16 timeVal; - char *str; - int16 savedCollStackSize; - int16 i; - int16 counter; - int16 var_24; - int16 var_26; - int16 collStackPos; - Collision *collPtr; - uint32 timeKey; - - if (_shouldPushColls) - pushCollisions(1); - - collResId = -1; - _script->skip(1); - count = _script->readByte(); - _handleMouse = _script->readByte(); - deltaTime = 1000 * _script->readByte(); - descIndex2 = _script->readByte(); - stackPos2 = _script->readByte(); - descIndex = _script->readByte(); - - if ((stackPos2 != 0) || (descIndex != 0)) - deltaTime /= 100; - - timeVal = deltaTime; - _script->skip(1); - - uint32 startPos = _script->pos(); - - WRITE_VAR(16, 0); - var_22 = 0; - index = 0; - curEditIndex = 0; - - for (curCmd = 0; curCmd < count; curCmd++) { - array[curCmd] = 0; - cmd = _script->readByte(); - - if ((cmd & 0x40) != 0) { - cmd -= 0x40; - cmdHigh = _script->readByte(); - cmdHigh <<= 8; - } else - cmdHigh = 0; - - if ((cmd & 0x80) != 0) { - left = _script->readValExpr(); - top = _script->readValExpr(); - width = _script->readValExpr(); - height = _script->readValExpr(); - } else { - left = _script->readUint16(); - top = _script->readUint16(); - width = _script->readUint16(); - height = _script->readUint16(); - } - cmd &= 0x7F; - - debugC(1, kDebugCollisions, "collisionsBlock(%d)", cmd); - - switch (cmd) { - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - - _vm->_util->clearKeyBuf(); - var_22 = 1; - key = _script->readVarIndex(); - descArray[index].fontIndex = _script->readInt16(); - descArray[index].backColor = _script->readByte(); - descArray[index].frontColor = _script->readByte(); - - if ((cmd < 5) || (cmd > 8)) { - descArray[index].ptr = 0; - } else { - descArray[index].ptr = _script->getData() + _script->pos() + 2; - _script->skip(_script->readInt16()); - } - - if (left == 0xFFFF) - break; - - if ((cmd & 1) == 0) { - addNewCollision(curCmd + 0x8000, left, top, left + width * - _vm->_draw->_fonts[descArray[index].fontIndex]->itemWidth - 1, - top + height - 1, cmd, key, 0, _script->pos()); - - _script->skip(_script->peekUint16(2) + 2); - } else { - addNewCollision(curCmd + 0x8000, left, top, left + width * - _vm->_draw->_fonts[descArray[index].fontIndex]->itemWidth - 1, - top + height - 1, cmd, key, 0, 0); - } - index++; - break; - - case 21: - key = _script->readInt16(); - array[curCmd] = _script->readInt16(); - flags = _script->readInt16() & 3; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - (flags << 4) + cmdHigh + 2, key, _script->pos(), 0); - - _script->skip(_script->peekUint16(2) + 2); - break; - - case 20: - collResId = curCmd; - // Fall through to case 2 - - case 2: - key = _script->readInt16(); - array[curCmd] = _script->readInt16(); - flags = _script->readInt16() & 3; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, - top + height - 1, - (flags << 4) + cmdHigh + 2, key, 0, _script->pos()); - - _script->skip(_script->peekUint16(2) + 2); - break; - - case 0: - _script->skip(6); - startPos = _script->pos(); - _script->skip(_script->peekUint16(2) + 2); - key = curCmd + 0xA000; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - cmd + cmdHigh, key, - startPos, _script->pos()); - - _script->skip(_script->peekUint16(2) + 2); - break; - - case 1: - key = _script->readInt16(); - array[curCmd] = _script->readInt16(); - flags = _script->readInt16() & 3; - - startPos = _script->pos(); - _script->skip(_script->peekUint16(2) + 2); - if (key == 0) - key = curCmd + 0xA000; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - (flags << 4) + cmd + cmdHigh, key, - startPos, _script->pos()); - - _script->skip(_script->peekUint16(2) + 2); - break; - } - } - - _forceHandleMouse = 0; - _vm->_util->clearKeyBuf(); - - do { - if (var_22 != 0) { - key = multiEdit(deltaTime, index, &curEditIndex, - descArray, &_activeCollResId, &_activeCollIndex); - - if (key == 0x1C0D) { - for (i = 0; i < 250; i++) { - if (_collisionAreas[i].left == 0xFFFF) - continue; - - if ((_collisionAreas[i].id & 0x8000) == 0) - continue; - - if ((_collisionAreas[i].flags & 1) != 0) - continue; - - if ((_collisionAreas[i].flags & 0x0F) <= 2) - continue; - - collResId = _collisionAreas[i].id; - _activeCollResId = collResId; - collResId &= 0x7FFF; - _activeCollIndex = i; - break; - } - break; - } - } else - key = checkCollisions(_handleMouse, -deltaTime, - &_activeCollResId, &_activeCollIndex); - - if (((key & 0xFF) >= ' ') && ((key & 0xFF) <= 0xFF) && - ((key >> 8) > 1) && ((key >> 8) < 12)) - key = '0' + (((key >> 8) - 1) % 10) + (key & 0xFF00); - - if (_activeCollResId == 0) { - if (key != 0) { - for (i = 0; i < 250; i++) { - if (_collisionAreas[i].left == 0xFFFF) - continue; - - if ((_collisionAreas[i].id & 0x8000) == 0) - continue; - - if ((_collisionAreas[i].key == key) || - (_collisionAreas[i].key == 0x7FFF)) { - - _activeCollResId = _collisionAreas[i].id; - _activeCollIndex = i; - break; - } - } - - if (_activeCollResId == 0) { - for (i = 0; i < 250; i++) { - if (_collisionAreas[i].left == 0xFFFF) - continue; - - if ((_collisionAreas[i].id & 0x8000) == 0) - continue; - - if ((_collisionAreas[i].key & 0xFF00) != 0) - continue; - - if (_collisionAreas[i].key == 0) - continue; - - if ((adjustKey(key & 0xFF) == adjustKey(_collisionAreas[i].key)) || - (_collisionAreas[i].key == 0x7FFF)) { - _activeCollResId = _collisionAreas[i].id; - _activeCollIndex = i; - break; - } - } - } - } else { - - if ((deltaTime != 0) && (VAR(16) == 0)) { - if (stackPos2 != 0) { - collStackPos = 0; - collPtr = _collisionAreas; - - for (i = 0, collPtr = _collisionAreas; - collPtr->left != 0xFFFF; i++, collPtr++) { - - if ((collPtr->id & 0x8000) == 0) - continue; - - collStackPos++; - if (collStackPos != stackPos2) - continue; - - _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 = _vm->_util->getTimeKey(); - - uint32 savedPos = _script->pos(); - - _script->seek(collPtr->funcLeave); - - _shouldPushColls = 1; - savedCollStackSize = _collStackSize; - _vm->_inter->funcBlock(0); - - if (savedCollStackSize != _collStackSize) - popCollisions(); - - _shouldPushColls = 0; - - _script->seek(savedPos); - - deltaTime = timeVal - - (_vm->_util->getTimeKey() - timeKey); - - if (deltaTime < 2) - deltaTime = 2; - } - - if (VAR(16) == 0) - _activeCollResId = 0; - break; - } - } else { - if (descIndex != 0) { - counter = 0; - for (i = 0; i < 250; i++) { - if (_collisionAreas[i].left == 0xFFFF) - continue; - - if ((_collisionAreas[i].id & 0x8000) == 0) - continue; - - counter++; - if (counter != descIndex) - continue; - - _activeCollResId = _collisionAreas[i].id; - _activeCollIndex = i; - break; - } - } else { - for (i = 0; i < 250; i++) { - if (_collisionAreas[i].left == 0xFFFF) - continue; - - if ((_collisionAreas[i].id & 0x8000) == 0) - continue; - - _activeCollResId = _collisionAreas[i].id; - _activeCollIndex = i; - break; - } - } - } - } else { - if (descIndex2 != 0) { - counter = 0; - for (i = 0; i < 250; i++) { - if (_collisionAreas[i].left == 0xFFFF) - continue; - - if ((_collisionAreas[i].id & 0x8000) == 0) - continue; - - counter++; - if (counter != descIndex2) - continue; - - _activeCollResId = _collisionAreas[i].id; - _activeCollIndex = i; - break; - } - } - } - } - } - - if (_activeCollResId == 0) - continue; - - if (_collisionAreas[_activeCollIndex].funcLeave != 0) - continue; - - 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 (_collisionAreas[_activeCollIndex].funcEnter != 0) { - uint32 savedPos = _script->pos(); - - _script->seek(_collisionAreas[_activeCollIndex].funcEnter); - - _shouldPushColls = 1; - - collStackPos = _collStackSize; - _vm->_inter->funcBlock(0); - if (collStackPos != _collStackSize) - popCollisions(); - _shouldPushColls = 0; - - _script->seek(savedPos); - } - - WRITE_VAR(16, 0); - _activeCollResId = 0; - } - while ((_activeCollResId == 0) && !_vm->_inter->_terminate && !_vm->shouldQuit()); - - if (((uint16) _activeCollResId & ~0x8000) == collResId) { - collStackPos = 0; - var_24 = 0; - var_26 = 1; - for (i = 0; i < 250; i++) { - if (_collisionAreas[i].left == 0xFFFF) - continue; - - if ((_collisionAreas[i].id & 0x8000) == 0) - continue; - - if ((_collisionAreas[i].flags & 0x0F) < 3) - continue; - - if ((_collisionAreas[i].flags & 0x0F) > 10) - continue; - - if ((_collisionAreas[i].flags & 0x0F) > 8) { - char *ptr; - strncpy0(_tempStr, GET_VARO_STR(_collisionAreas[i].key), 255); - while ((ptr = strchr(_tempStr, ' ')) != 0) { - _vm->_util->cutFromStr(_tempStr, (ptr - _tempStr), 1); - ptr = strchr(_tempStr, ' '); - } - WRITE_VARO_STR(_collisionAreas[i].key, _tempStr); - } - - if (((_collisionAreas[i].flags & 0x0F) >= 5) && - ((_collisionAreas[i].flags & 0x0F) <= 8)) { - str = (char *) descArray[var_24].ptr; - - strncpy0(_tempStr, GET_VARO_STR(_collisionAreas[i].key), 255); - - if ((_collisionAreas[i].flags & 0x0F) < 7) - _vm->_util->prepareStr(_tempStr); - - int16 pos = 0; - do { - strncpy0(_collStr, str, 255); - pos += strlen(str) + 1; - - str += strlen(str) + 1; - - if ((_collisionAreas[i].flags & 0x0F) < 7) - _vm->_util->prepareStr(_collStr); - - if (strcmp(_tempStr, _collStr) == 0) { - WRITE_VAR(17, VAR(17) + 1); - WRITE_VAR(17 + var_26, 1); - break; - } - } while (READ_LE_UINT16(descArray[var_24].ptr - 2) > pos); - collStackPos++; - } else { - WRITE_VAR(17 + var_26, 2); - } - var_24++; - var_26++; - } - - if (collStackPos != (int16) VAR(17)) - WRITE_VAR(17, 0); - else - WRITE_VAR(17, 1); - } - - if (!_vm->_inter->_terminate) { - _script->seek(_collisionAreas[_activeCollIndex].funcLeave); - - 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) _activeCollResId & ~0x8000]); - } else - _script->setFinished(true); - - for (curCmd = 0; curCmd < count; curCmd++) - freeCollision(curCmd + 0x8000); -} - -int16 Game_v1::multiEdit(int16 time, int16 index, int16 *pCurPos, - InputDesc * inpDesc, int16 *collResId, int16 *collIndex, bool mono) { - Collision *collArea; - int16 descInd; - int16 key; - int16 found = -1; - int16 i; - - descInd = 0; - for (i = 0; i < 250; i++) { - collArea = &_collisionAreas[i]; - - if (collArea->left == 0xFFFF) - continue; - - if ((collArea->id & 0x8000) == 0) - continue; - - if ((collArea->flags & 0x0F) < 3) - continue; - - if ((collArea->flags & 0x0F) > 10) - continue; - - strncpy0(_tempStr, GET_VARO_STR(collArea->key), 255); - - _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; - - _vm->_draw->_destSurface = 21; - - _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; - - _vm->_draw->spriteOperation(DRAW_PRINTTEXT); - descInd++; - } - - for (i = 0; i < 40; i++) - WRITE_VAR_OFFSET(i * 4 + 0x44, 0); - - while (1) { - descInd = 0; - - for (i = 0; i < 250; i++) { - collArea = &_collisionAreas[i]; - - if (collArea->left == 0xFFFF) - continue; - - if ((collArea->id & 0x8000) == 0) - continue; - - if ((collArea->flags & 0x0F) < 3) - continue; - - if ((collArea->flags & 0x0F) > 10) - continue; - - if (descInd == *pCurPos) { - found = i; - break; - } - - descInd++; - } - - assert(found != -1); - - collArea = &_collisionAreas[found]; - - key = inputArea(collArea->left, collArea->top, - collArea->right - collArea->left + 1, - collArea->bottom - collArea->top + 1, - inpDesc[*pCurPos].backColor, inpDesc[*pCurPos].frontColor, - GET_VARO_STR(collArea->key), inpDesc[*pCurPos].fontIndex, - collArea->flags, &time, collResId, collIndex); - - if (_vm->_inter->_terminate) - return 0; - - switch (key) { - case 0: - if (*collResId == 0) - return 0; - - if ((_collisionAreas[*collIndex].flags & 0x0F) < 3) - return 0; - - if ((_collisionAreas[*collIndex].flags & 0x0F) > 10) - return 0; - - *pCurPos = 0; - for (i = 0; i < 250; i++) { - collArea = &_collisionAreas[i]; - - if (collArea->left == 0xFFFF) - continue; - - if ((collArea->id & 0x8000) == 0) - continue; - - if ((collArea->flags & 0x0F) < 3) - continue; - - if ((collArea->flags & 0x0F) > 10) - continue; - - if (i == *collIndex) - break; - - pCurPos[0]++; - } - break; - - case 0x3B00: - case 0x3C00: - case 0x3D00: - case 0x3E00: - case 0x3F00: - case 0x4000: - case 0x4100: - case 0x4200: - case 0x4300: - case 0x4400: - return key; - - case 0x1C0D: - - if (index == 1) - return key; - - if (*pCurPos == index - 1) { - *pCurPos = 0; - break; - } - - pCurPos[0]++; - break; - - case 0x5000: - if (index - 1 > *pCurPos) - pCurPos[0]++; - break; - - case 0x4800: - if (*pCurPos > 0) - pCurPos[0]--; - break; - } - } -} - -int16 Game_v1::inputArea(int16 xPos, int16 yPos, int16 width, int16 height, - int16 backColor, int16 frontColor, char *str, int16 fontIndex, - char inpType, int16 *pTotTime, int16 *collResId, int16 *collIndex, bool mono) { - int16 handleMouse; - uint32 editSize; - Video::FontDesc *pFont; - char curSym; - int16 key; - const char *str1; - const char *str2; - int16 i; - uint32 pos; - int16 flag; - int16 savedKey; - - if ((_handleMouse != 0) && - ((_vm->_global->_useMouse != 0) || (_forceHandleMouse != 0))) - handleMouse = 1; - else - handleMouse = 0; - - pos = strlen(str); - pFont = _vm->_draw->_fonts[fontIndex]; - editSize = width / pFont->itemWidth; - - while (1) { - strncpy0(_tempStr, str, 254); - strcat(_tempStr, " "); - if (strlen(_tempStr) > editSize) - strncpy0(_tempStr, str, 255); - - _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 = _tempStr[pos]; - - flag = 1; - - while (1) { - _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 = frontColor; - _vm->_draw->spriteOperation(DRAW_FILLRECT); - - if (flag != 0) - key = checkCollisions(handleMouse, -1, collResId, collIndex); - flag = 0; - - key = checkCollisions(handleMouse, -300, collResId, collIndex); - - if (*pTotTime > 0) { - *pTotTime -= 300; - if (*pTotTime <= 1) { - key = 0; - *collResId = 0; - break; - } - } - - _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) || (*collResId != 0)) - break; - - key = checkCollisions(handleMouse, -300, collResId, collIndex); - - if (*pTotTime > 0) { - *pTotTime -= 300; - if (*pTotTime <= 1) { - key = 0; - *collResId = 0; - break; - } - } - - if ((key != 0) || (*collResId != 0)) - break; - - if (_vm->_inter->_terminate) - return 0; - } - - if ((key == 0) || (*collResId != 0) || _vm->_inter->_terminate) - return 0; - - switch (key) { - case 0x4D00: // Right Arrow - if ((pos < strlen(str)) && (pos < (editSize - 1))) { - pos++; - continue; - } - return 0x5000; - - case 0x4B00: // Left Arrow - if (pos > 0) { - pos--; - continue; - } - return 0x4800; - - case 0xE08: // Backspace - if (pos > 0) { - _vm->_util->cutFromStr(str, pos - 1, 1); - pos--; - continue; - } - - case 0x5300: // Del - - if (pos >= strlen(str)) - continue; - - _vm->_util->cutFromStr(str, pos, 1); - continue; - - case 0x1C0D: // Enter - case 0x3B00: // F1 - case 0x3C00: // F2 - case 0x3D00: // F3 - case 0x3E00: // F4 - case 0x3F00: // F5 - case 0x4000: // F6 - case 0x4100: // F7 - case 0x4200: // F8 - case 0x4300: // F9 - case 0x4400: // F10 - case 0x4800: // Up arrow - case 0x5000: // Down arrow - return key; - - case 0x11B: // Escape - if (_vm->_global->_useMouse != 0) - continue; - - _forceHandleMouse = !_forceHandleMouse; - - if ((_handleMouse != 0) && - ((_vm->_global->_useMouse != 0) || (_forceHandleMouse != 0))) - handleMouse = 1; - else - handleMouse = 0; - - if (_vm->_global->_pressedKeys[1] == 0) - continue; - - while (_vm->_global->_pressedKeys[1] != 0) - ; - continue; - - default: - - savedKey = key; - key &= 0xFF; - - if (((inpType == 9) || (inpType == 10)) && - (key >= ' ') && (key <= 0xFF)) { - str1 = "0123456789-.,+ "; - str2 = "0123456789-,,+ "; - - if (((savedKey >> 8) > 1) && ((savedKey >> 8) < 12)) - key = ((savedKey >> 8) - 1) % 10 + '0'; - - for (i = 0; str1[i] != 0; i++) { - if (key == str1[i]) { - key = str2[i]; - break; - } - } - - if (i == (int16) strlen(str1)) - key = 0; - } - - if ((key >= ' ') && (key <= 0xFF)) { - if (editSize == strlen(str)) - _vm->_util->cutFromStr(str, strlen(str) - 1, 1); - - if ((key >= 'a') && (key <= 'z')) - key += ('A' - 'a'); - - pos++; - _tempStr[0] = key; - _tempStr[1] = 0; - - _vm->_util->insertStr(_tempStr, str, pos - 1); - } - - } - } -} - -int16 Game_v1::checkMousePoint(int16 all, int16 *resId, int16 *resIndex) { - Collision *ptr; - int16 i; - - if (resId != 0) - *resId = 0; - - *resIndex = 0; - - ptr = _collisionAreas; - for (i = 0; ptr->left != 0xFFFF; ptr++, i++) { - if (all) { - if ((ptr->flags & 0xF) > 1) - continue; - - if ((ptr->flags & 0xFF00) != 0) - continue; - - 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) - *resId = ptr->id; - - *resIndex = i; - return ptr->key; - } else { - if ((ptr->flags & 0xFF00) != 0) - continue; - - if (((ptr->flags & 0xF) != 1) && ((ptr->flags & 0xF) != 2)) - continue; - - if ((((ptr->flags & 0xF0) >> 4) != (_mouseButtons - 1)) - && (((ptr->flags & 0xF0) >> 4) != 2)) - continue; - - 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) - *resId = ptr->id; - *resIndex = i; - return ptr->key; - } - } - - if ((_mouseButtons != 1) && (all == 0)) - return 0x11B; - - return 0; -} - -} // End of namespace Gob diff --git a/engines/gob/game_v2.cpp b/engines/gob/game_v2.cpp deleted file mode 100644 index 08184e73d0..0000000000 --- a/engines/gob/game_v2.cpp +++ /dev/null @@ -1,1563 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#include "common/endian.h" -#include "common/stream.h" - -#include "gob/gob.h" -#include "gob/game.h" -#include "gob/helper.h" -#include "gob/global.h" -#include "gob/util.h" -#include "gob/dataio.h" -#include "gob/script.h" -#include "gob/resources.h" -#include "gob/draw.h" -#include "gob/goblin.h" -#include "gob/inter.h" -#include "gob/mult.h" -#include "gob/scenery.h" -#include "gob/video.h" -#include "gob/videoplayer.h" -#include "gob/sound/sound.h" - -namespace Gob { - -Game_v2::Game_v2(GobEngine *vm) : Game_v1(vm) { -} - -void Game_v2::playTot(int16 skipPlay) { - char savedTotName[20]; - int16 *oldCaptureCounter; - int16 *oldBreakFrom; - int16 *oldNestLevel; - int16 _captureCounter; - int16 breakFrom; - int16 nestLevel; - - oldNestLevel = _vm->_inter->_nestLevel; - oldBreakFrom = _vm->_inter->_breakFromLevel; - oldCaptureCounter = _vm->_scenery->_pCaptureCounter; - - _script->push(); - - _vm->_inter->_nestLevel = &nestLevel; - _vm->_inter->_breakFromLevel = &breakFrom; - _vm->_scenery->_pCaptureCounter = &_captureCounter; - strcpy(savedTotName, _curTotFile); - - if (skipPlay <= 0) { - while (!_vm->shouldQuit()) { - if (_vm->_inter->_variables) - _vm->_draw->animateCursor(4); - - if (skipPlay != -1) { - _vm->_inter->initControlVars(1); - - for (int i = 0; i < 4; i++) { - _vm->_draw->_fontToSprite[i].sprite = -1; - _vm->_draw->_fontToSprite[i].base = -1; - _vm->_draw->_fontToSprite[i].width = -1; - _vm->_draw->_fontToSprite[i].height = -1; - } - - _vm->_mult->initAll(); - _vm->_mult->zeroMultData(); - - _vm->_draw->_spritesArray[20] = _vm->_draw->_frontSurface; - _vm->_draw->_spritesArray[21] = _vm->_draw->_backSurface; - _vm->_draw->_cursorSpritesBack = _vm->_draw->_cursorSprites; - } else - _vm->_inter->initControlVars(0); - - _vm->_draw->_cursorHotspotXVar = -1; - _totToLoad[0] = 0; - - if ((_curTotFile[0] == 0) && (!_script->isLoaded())) - break; - - if (skipPlay == -2) { - _vm->_vidPlayer->primaryClose(); - skipPlay = 0; - } - - if (!_script->load(_curTotFile)) { - _vm->_draw->blitCursor(); - _vm->_inter->_terminate = 2; - break; - } - - _resources->load(_curTotFile); - - _vm->_global->_inter_animDataSize = _script->getAnimDataSize(); - if (!_vm->_inter->_variables) - _vm->_inter->allocateVars(_script->getVariablesCount() & 0xFFFF); - - _script->seek(_script->getFunctionOffset(TOTFile::kFunctionStart)); - - _vm->_inter->renewTimeInVars(); - - WRITE_VAR(13, _vm->_global->_useMouse); - WRITE_VAR(14, _vm->_global->_soundFlags); - WRITE_VAR(15, _vm->_global->_fakeVideoMode); - WRITE_VAR(16, _vm->_global->_language); - - _vm->_inter->callSub(2); - - if (_totToLoad[0] != 0) - _vm->_inter->_terminate = 0; - - _vm->_draw->blitInvalidated(); - - _script->unload(); - - _resources->unload(); - - for (int i = 0; i < *_vm->_scenery->_pCaptureCounter; i++) - capturePop(0); - - if (skipPlay != -1) { - _vm->_goblin->freeObjects(); - - _vm->_sound->blasterStop(0); - - for (int i = 0; i < Sound::kSoundsCount; i++) { - SoundDesc *sound = _vm->_sound->sampleGetBySlot(i); - - if (sound && - ((sound->getType() == SOUND_SND) || (sound->getType() == SOUND_WAV))) - _vm->_sound->sampleFree(sound); - } - } - - if (_totToLoad[0] == 0) - break; - - strcpy(_curTotFile, _totToLoad); - } - } else { - _vm->_inter->initControlVars(0); - _vm->_scenery->_pCaptureCounter = oldCaptureCounter; - _script->seek(_script->getFunctionOffset(skipPlay + 1)); - - _menuLevel++; - _vm->_inter->callSub(2); - _menuLevel--; - - if (_vm->_inter->_terminate != 0) - _vm->_inter->_terminate = 2; - } - - strcpy(_curTotFile, savedTotName); - - _vm->_inter->_nestLevel = oldNestLevel; - _vm->_inter->_breakFromLevel = oldBreakFrom; - _vm->_scenery->_pCaptureCounter = oldCaptureCounter; - - _script->pop(); -} - -void Game_v2::clearCollisions() { - _lastCollKey = 0; - - for (int i = 0; i < 150; i++) - _collisionAreas[i].left = 0xFFFF; -} - -int16 Game_v2::addNewCollision(int16 id, uint16 left, uint16 top, - uint16 right, uint16 bottom, int16 flags, int16 key, - uint16 funcEnter, uint16 funcLeave, uint16 funcSub) { - Collision *ptr; - - debugC(5, kDebugCollisions, "addNewCollision"); - debugC(5, kDebugCollisions, "id = %X", id); - debugC(5, kDebugCollisions, "left = %d, top = %d, right = %d, bottom = %d", - left, top, right, bottom); - debugC(5, kDebugCollisions, "flags = %X, key = %X", flags, key); - debugC(5, kDebugCollisions, "funcEnter = %d, funcLeave = %d", - funcEnter, funcLeave); - - for (int i = 0; i < 150; i++) { - if ((_collisionAreas[i].left != 0xFFFF) && (_collisionAreas[i].id != id)) - continue; - - ptr = &_collisionAreas[i]; - ptr->id = id; - ptr->left = left; - ptr->top = top; - ptr->right = right; - ptr->bottom = bottom; - ptr->flags = flags; - ptr->key = key; - ptr->funcEnter = funcEnter; - ptr->funcLeave = funcLeave; - ptr->funcSub = funcSub; - ptr->script = 0; - - return i; - } - error("Game_v2::addNewCollision(): Collision array full"); - return 0; -} - -void Game_v2::pushCollisions(char all) { - Collision *srcPtr; - Collision *destPtr; - int16 size; - - debugC(1, kDebugCollisions, "pushCollisions"); - for (size = 0, srcPtr = _collisionAreas; srcPtr->left != 0xFFFF; srcPtr++) - if (all || (((uint16) srcPtr->id) >= 20)) - size++; - - destPtr = new Collision[size]; - _collStack[_collStackSize] = destPtr; - - if (_vm->_inter->_terminate) - return; - - _collStackElemSizes[_collStackSize] = size; - - if (_shouldPushColls != 0) - _collStackElemSizes[_collStackSize] |= 0x8000; - - _shouldPushColls = 0; - _collLasts[_collStackSize].key = _lastCollKey; - _collLasts[_collStackSize].id = _lastCollId; - _collLasts[_collStackSize].areaIndex = _lastCollAreaIndex; - _lastCollKey = 0; - _lastCollId = 0; - _lastCollAreaIndex = 0; - _collStackSize++; - - for (srcPtr = _collisionAreas; srcPtr->left != 0xFFFF; srcPtr++) { - if (all || (((uint16) srcPtr->id) >= 20)) { - memcpy(destPtr, srcPtr, sizeof(Collision)); - srcPtr->left = 0xFFFF; - destPtr++; - } - } -} - -void Game_v2::popCollisions(void) { - Collision *destPtr; - Collision *srcPtr; - - debugC(1, kDebugCollisions, "popCollision"); - - _collStackSize--; - - _shouldPushColls = _collStackElemSizes[_collStackSize] & 0x8000 ? 1 : 0; - _collStackElemSizes[_collStackSize] &= 0x7FFF; - - _lastCollKey = _collLasts[_collStackSize].key; - _lastCollId = _collLasts[_collStackSize].id; - _lastCollAreaIndex = _collLasts[_collStackSize].areaIndex; - - for (destPtr = _collisionAreas; destPtr->left != 0xFFFF; destPtr++) - ; - - srcPtr = _collStack[_collStackSize]; - memcpy(destPtr, srcPtr, - _collStackElemSizes[_collStackSize] * sizeof(Collision)); - - delete[] _collStack[_collStackSize]; -} - -int16 Game_v2::checkCollisions(byte handleMouse, int16 deltaTime, int16 *pResId, - int16 *pResIndex) { - int16 resIndex; - int16 key; - int16 oldIndex; - int16 oldId; - int16 newkey; - uint32 timeKey; - - _scrollHandleMouse = handleMouse != 0; - - if (deltaTime >= -1) { - _lastCollKey = 0; - _lastCollAreaIndex = 0; - _lastCollId = 0; - } - - if (pResId != 0) - *pResId = 0; - - resIndex = 0; - - if ((_vm->_draw->_cursorIndex == -1) && - (handleMouse != 0) && (_lastCollKey == 0)) { - _lastCollKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - - if ((_lastCollKey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 1); - } - - if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - - timeKey = _vm->_util->getTimeKey(); - while (1) { - if (_vm->_inter->_terminate || _vm->shouldQuit()) { - if (handleMouse) - _vm->_draw->blitCursor(); - return 0; - } - - if (!_vm->_draw->_noInvalidated) { - if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - else - _vm->_draw->blitInvalidated(); - _vm->_video->waitRetrace(); - } - - key = checkKeys(&_vm->_global->_inter_mouseX, - &_vm->_global->_inter_mouseY, &_mouseButtons, handleMouse); - - if ((handleMouse == 0) && (_mouseButtons != 0)) { - _vm->_util->waitMouseRelease(0); - key = 3; - } - - if (key != 0) { - - if (handleMouse & 1) - _vm->_draw->blitCursor(); - - if (pResId != 0) - *pResId = 0; - - if (pResIndex != 0) - *pResIndex = 0; - - if (_lastCollKey != 0) - collAreaSub(_lastCollAreaIndex, 0); - - _lastCollKey = 0; - if (key != 0) - return key; - } - - if (handleMouse != 0) { - if (_mouseButtons != 0) { - if (deltaTime > 0) { - _vm->_draw->animateCursor(2); - _vm->_util->delay(deltaTime); - } else if (handleMouse & 1) - _vm->_util->waitMouseRelease(1); - _vm->_draw->animateCursor(-1); - - if (pResId != 0) - *pResId = 0; - - key = checkMousePoint(0, pResId, &resIndex); - if (pResIndex != 0) - *pResIndex = resIndex; - - if ((key != 0) || ((pResId != 0) && (*pResId != 0))) { - if ((handleMouse & 1) && - ((deltaTime <= 0) || (_mouseButtons == 0))) - _vm->_draw->blitCursor(); - - if ((_lastCollKey != 0) && (key != _lastCollKey)) - collAreaSub(_lastCollAreaIndex, 0); - - _lastCollKey = 0; - return key; - } - - if (handleMouse & 4) - return 0; - - if (_lastCollKey != 0) - collAreaSub(_lastCollAreaIndex, 0); - - _lastCollKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - if ((_lastCollKey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 1); - } else if ((_vm->_global->_inter_mouseX != _vm->_draw->_cursorX) || - (_vm->_global->_inter_mouseY != _vm->_draw->_cursorY)) { - - oldIndex = _lastCollAreaIndex; - oldId = _lastCollId; - newkey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - - if (newkey != _lastCollKey) { - if ((_lastCollKey != 0) && (oldId & 0x8000)) - collAreaSub(oldIndex, 0); - - _lastCollKey = newkey; - - if ((newkey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 1); - } - } - } - - if ((deltaTime < 0) && (key == 0) && (_mouseButtons == 0)) { - uint32 curtime = _vm->_util->getTimeKey(); - if ((curtime + deltaTime) > timeKey) { - if (pResId != 0) - *pResId = 0; - - if (pResIndex != 0) - *pResIndex = 0; - - return 0; - } - } - - if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - - _vm->_util->delay(10); - } -} - -void Game_v2::prepareStart(void) { - clearCollisions(); - - _vm->_global->_pPaletteDesc->unused2 = _vm->_draw->_unusedPalette2; - _vm->_global->_pPaletteDesc->unused1 = _vm->_draw->_unusedPalette1; - _vm->_global->_pPaletteDesc->vgaPal = _vm->_draw->_vgaPalette; - - _vm->_video->setFullPalette(_vm->_global->_pPaletteDesc); - - _vm->_draw->initScreen(); - _vm->_video->fillRect(*_vm->_draw->_frontSurface, 0, 0, - _vm->_video->_surfWidth - 1, _vm->_video->_surfHeight - 1, 1); - - _vm->_util->setMousePos(152, 92); - _vm->_draw->_cursorX = _vm->_global->_inter_mouseX = 152; - _vm->_draw->_cursorY = _vm->_global->_inter_mouseY = 92; - - _vm->_draw->_invalidatedCount = 0; - _vm->_draw->_noInvalidated = true; - _vm->_draw->_applyPal = false; - _vm->_draw->_paletteCleared = false; - _vm->_draw->_cursorWidth = 16; - _vm->_draw->_cursorHeight = 16; - _vm->_draw->_transparentCursor = 1; - - for (int i = 0; i < 40; i++) { - _vm->_draw->_cursorAnimLow[i] = -1; - _vm->_draw->_cursorAnimDelays[i] = 0; - _vm->_draw->_cursorAnimHigh[i] = 0; - } - - _vm->_draw->_renderFlags = 0; - _vm->_draw->_backDeltaX = 0; - _vm->_draw->_backDeltaY = 0; - - _startTimeKey = _vm->_util->getTimeKey(); -} - -void Game_v2::collisionsBlock(void) { - InputDesc descArray[20]; - int16 array[250]; - byte count; - int16 collResId; - int16 curCmd; - int16 cmd; - int16 cmdHigh; - int16 key; - int16 flags; - uint16 left; - uint16 top; - uint16 width; - uint16 height; - int16 var_1C; - int16 index; - int16 curEditIndex; - int16 deltaTime; - int16 stackPos2; - int16 descIndex; - int16 timeVal; - char *str; - int16 i; - int16 counter; - int16 var_24; - int16 var_26; - int16 collStackPos; - Collision *collPtr; - Collision *collArea; - int16 timeKey; - byte collAreaStart; - uint32 startPos; - uint32 offsetPos; - - if (_shouldPushColls) - pushCollisions(0); - - collAreaStart = 0; - while (_collisionAreas[collAreaStart].left != 0xFFFF) - collAreaStart++; - collArea = &_collisionAreas[collAreaStart]; - - _shouldPushColls = 0; - collResId = -1; - - _script->skip(1); - count = _script->readByte(); - - _handleMouse = _script->readByte(); - deltaTime = 1000 * _script->readByte(); - _script->skip(1); - stackPos2 = _script->readByte(); - descIndex = _script->readByte(); - - if ((stackPos2 != 0) || (descIndex != 0)) - deltaTime /= 100; - - timeVal = deltaTime; - _script->skip(1); - - startPos = _script->pos(); - WRITE_VAR(16, 0); - - var_1C = 0; - index = 0; - curEditIndex = 0; - - for (curCmd = 0; curCmd < count; curCmd++) { - array[curCmd] = 0; - cmd = _script->readByte(); - - if ((cmd & 0x40) != 0) { - cmd -= 0x40; - cmdHigh = _script->readByte(); - cmdHigh <<= 8; - } else - cmdHigh = 0; - - if ((cmd & 0x80) != 0) { - offsetPos = _script->pos(); - left = _script->readValExpr(); - top = _script->readValExpr(); - width = _script->readValExpr(); - height = _script->readValExpr(); - } else { - offsetPos = 0; - left = _script->readUint16(); - top = _script->readUint16(); - width = _script->readUint16(); - height = _script->readUint16(); - } - - if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) && (left != 0xFFFF)) { - left += _vm->_draw->_backDeltaX; - top += _vm->_draw->_backDeltaY; - } - - if (left != 0xFFFF) { - _vm->_draw->adjustCoords(0, &left, &top); - if (((cmd & 0x3F) < 20) && ((cmd & 0x3F) >= 3)) { - if (_vm->_draw->_needAdjust != 2) - height &= 0xFFFE; - _vm->_draw->adjustCoords(0, 0, &width); - } else - _vm->_draw->adjustCoords(0, &height, &width); - } - - cmd &= 0x7F; - debugC(1, kDebugCollisions, "collisionsBlock(%d)", cmd); - - switch (cmd) { - case 0: - _script->skip(6); - startPos = _script->pos(); - _script->skip(_script->peekUint16(2) + 2); - key = curCmd + 0xA000; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - cmd + cmdHigh, key, startPos, - _script->pos(), offsetPos); - - _script->skip(_script->peekUint16(2) + 2); - - break; - - case 1: - key = _script->readInt16(); - array[curCmd] = _script->readInt16(); - flags = _script->readInt16(); - - startPos = _script->pos(); - _script->skip(_script->peekUint16(2) + 2); - - if (key == 0) - key = curCmd + 0xA000; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - (flags << 4) + cmd + cmdHigh, key, startPos, - _script->pos(), offsetPos); - - _script->skip(_script->peekUint16(2) + 2); - break; - - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - _vm->_util->clearKeyBuf(); - var_1C = 1; - key = _script->readVarIndex(); - descArray[index].fontIndex = _script->readInt16(); - descArray[index].backColor = _script->readByte(); - descArray[index].frontColor = _script->readByte(); - - if ((cmd >= 5) && (cmd <= 8)) { - descArray[index].ptr = _script->getData() + _script->pos() + 2; - _script->skip(_script->peekUint16() + 2); - } else - descArray[index].ptr = 0; - - if (left == 0xFFFF) { - if ((cmd & 1) == 0) { - _script->skip(_script->peekUint16(2) + 2); - } - break; - } - - if ((cmd & 1) == 0) { - addNewCollision(curCmd + 0x8000, left, top, left + width * - _vm->_draw->_fonts[descArray[index].fontIndex]-> itemWidth - 1, - top + height - 1, cmd, key, 0, - _script->pos()); - - _script->skip(_script->peekUint16(2) + 2); - } else - addNewCollision(curCmd + 0x8000, left, top, left + width * - _vm->_draw->_fonts[descArray[index].fontIndex]-> itemWidth - 1, - top + height - 1, cmd, key, 0, 0); - - index++; - break; - - case 11: - _script->skip(6); - for (i = 0; i < 150; i++) { - if ((_collisionAreas[i].id & 0xF000) == 0xE000) { - _collisionAreas[i].id &= 0xBFFF; - _collisionAreas[i].funcEnter = - _script->pos(); - _collisionAreas[i].funcLeave = - _script->pos(); - } - } - _script->skip(_script->peekUint16(2) + 2); - break; - - case 12: - _script->skip(6); - for (i = 0; i < 150; i++) { - if ((_collisionAreas[i].id & 0xF000) == 0xD000) { - _collisionAreas[i].id &= 0xBFFF; - _collisionAreas[i].funcEnter = - _script->pos(); - _collisionAreas[i].funcLeave = - _script->pos(); - } - } - _script->skip(_script->peekUint16(2) + 2); - break; - - case 20: - collResId = curCmd; - // Fall through to case 2 - - case 2: - key = _script->readInt16(); - array[curCmd] = _script->readInt16(); - flags = _script->readInt16(); - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - (flags << 4) + cmdHigh + 2, key, 0, - _script->pos(), offsetPos); - - _script->skip(_script->peekUint16(2) + 2); - - break; - - case 21: - key = _script->readInt16(); - array[curCmd] = _script->readInt16(); - flags = _script->readInt16() & 3; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - (flags << 4) + cmdHigh + 2, key, - _script->pos(), 0, offsetPos); - - _script->skip(_script->peekUint16(2) + 2); - - break; - } - } - - _forceHandleMouse = 0; - _vm->_util->clearKeyBuf(); - - do { - if (var_1C != 0) { - key = multiEdit(deltaTime, index, &curEditIndex, descArray, - &_activeCollResId, &_activeCollIndex); - - WRITE_VAR(55, curEditIndex); - if (key == 0x1C0D) { - for (i = 0; i < 150; i++) { - if (_collisionAreas[i].left == 0xFFFF) - break; - - if ((_collisionAreas[i].id & 0xC000) != 0x8000) - continue; - - if ((_collisionAreas[i].flags & 1) != 0) - continue; - - if ((_collisionAreas[i].flags & 0x0F) <= 2) - continue; - - _activeCollResId = _collisionAreas[i].id; - collResId = _collisionAreas[i].id & 0x7FFF; - _activeCollIndex = i; - break; - } - break; - } - } else - key = checkCollisions(_handleMouse, -deltaTime, - &_activeCollResId, &_activeCollIndex); - - if (((key & 0xFF) >= ' ') && ((key & 0xFF) <= 0xFF) && - ((key >> 8) > 1) && ((key >> 8) < 12)) - key = '0' + (((key >> 8) - 1) % 10) + (key & 0xFF00); - - if (_activeCollResId == 0) { - if (key != 0) { - for (i = 0; i < 150; i++) { - if (_collisionAreas[i].left == 0xFFFF) - break; - - if ((_collisionAreas[i].id & 0xC000) != 0x8000) - continue; - - if ((_collisionAreas[i].key == key) || - (_collisionAreas[i].key == 0x7FFF)) { - _activeCollResId = _collisionAreas[i].id; - _activeCollIndex = i; - break; - } - } - - if (_activeCollResId == 0) { - for (i = 0; i < 150; i++) { - if (_collisionAreas[i].left == 0xFFFF) - break; - - if ((_collisionAreas[i].id & 0xC000) != 0x8000) - continue; - - if ((_collisionAreas[i].key & 0xFF00) != 0) - continue; - - if (_collisionAreas[i].key == 0) - continue; - - if ((adjustKey(key & 0xFF) == adjustKey(_collisionAreas[i].key)) || - (_collisionAreas[i].key == 0x7FFF)) { - _activeCollResId = _collisionAreas[i].id; - _activeCollIndex = i; - break; - } - } - } - } else if (deltaTime != 0) { - if (stackPos2 != 0) { - collStackPos = 0; - - for (i = 0, collPtr = collArea; collPtr->left != 0xFFFF; i++, collPtr++) { - if ((collPtr->id & 0xF000) != 0x8000) - continue; - - collStackPos++; - if (collStackPos != stackPos2) - continue; - - _activeCollResId = collPtr->id; - _activeCollIndex = i + collAreaStart; - _vm->_inter->storeMouse(); - if (VAR(16) != 0) - break; - - if ((_activeCollResId & 0xF000) == 0x8000) - WRITE_VAR(16, array[_activeCollResId & 0xFFF]); - else - WRITE_VAR(16, _activeCollResId & 0xFFF); - - if (collPtr->funcLeave != 0) { - int16 collResIdBak = _activeCollResId; - int16 collIndexBak = _activeCollIndex; - - timeKey = _vm->_util->getTimeKey(); - collSub(collPtr->funcLeave); - - _activeCollResId = collResIdBak; - _activeCollIndex = collIndexBak; - - _vm->_inter->animPalette(); - - deltaTime = timeVal - (_vm->_util->getTimeKey() - timeKey); - - if (deltaTime < 2) - deltaTime = 2; - if (deltaTime > timeVal) - deltaTime = timeVal; - } - - if (VAR(16) == 0) - _activeCollResId = 0; - break; - } - } else { - if (descIndex != 0) { - - counter = 0; - for (i = 0, collPtr = collArea; collPtr->left != 0xFFFF; i++, collPtr++) { - if ((collPtr->id & 0xF000) == 0x8000) - if (++counter == descIndex) { - _activeCollResId = collPtr->id; - _activeCollIndex = i + collAreaStart; - break; - } - } - - } else { - - for (i = 0, collPtr = _collisionAreas; collPtr->left != 0xFFFF; i++, collPtr++) { - if ((collPtr->id & 0xF000) == 0x8000) { - _activeCollResId = collPtr->id; - _activeCollIndex = i; - break; - } - } - if ((_lastCollKey != 0) && - (_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) - collSub(_collisionAreas[_lastCollAreaIndex].funcLeave); - _lastCollKey = 0; - } - - } - } - } - - if ((_activeCollResId == 0) || - (_collisionAreas[_activeCollIndex].funcLeave != 0)) - continue; - - _vm->_inter->storeMouse(); - if ((_activeCollResId & 0xF000) == 0x8000) - WRITE_VAR(16, array[_activeCollResId & 0xFFF]); - else - WRITE_VAR(16, _activeCollResId & 0xFFF); - - if (_collisionAreas[_activeCollIndex].funcEnter != 0) - collSub(_collisionAreas[_activeCollIndex].funcEnter); - - WRITE_VAR(16, 0); - _activeCollResId = 0; - } - while ((_activeCollResId == 0) && !_vm->_inter->_terminate && !_vm->shouldQuit()); - - if ((_activeCollResId & 0xFFF) == collResId) { - collStackPos = 0; - var_24 = 0; - var_26 = 1; - for (i = 0; i < 150; i++) { - if (_collisionAreas[i].left == 0xFFFF) - continue; - - if ((_collisionAreas[i].id & 0xC000) == 0x8000) - continue; - - if ((_collisionAreas[i].flags & 0x0F) < 3) - continue; - - if ((_collisionAreas[i].flags & 0x0F) > 10) - continue; - - if ((_collisionAreas[i].flags & 0x0F) > 8) { - char *ptr; - strncpy0(_tempStr, GET_VARO_STR(_collisionAreas[i].key), 255); - while ((ptr = strchr(_tempStr, ' '))) - _vm->_util->cutFromStr(_tempStr, (ptr - _tempStr), 1); - if (_vm->_language == 2) - while ((ptr = strchr(_tempStr, '.'))) - *ptr = ','; - WRITE_VARO_STR(_collisionAreas[i].key, _tempStr); - } - - if (((_collisionAreas[i].flags & 0x0F) >= 5) && - ((_collisionAreas[i].flags & 0x0F) <= 8)) { - str = (char *) descArray[var_24].ptr; - - strncpy0(_tempStr, GET_VARO_STR(_collisionAreas[i].key), 255); - - if ((_collisionAreas[i].flags & 0x0F) < 7) - _vm->_util->prepareStr(_tempStr); - - int16 pos = 0; - do { - strncpy0(_collStr, str, 255); - pos += strlen(str) + 1; - - str += strlen(str) + 1; - - if ((_collisionAreas[i].flags & 0x0F) < 7) - _vm->_util->prepareStr(_collStr); - - if (strcmp(_tempStr, _collStr) == 0) { - WRITE_VAR(17, VAR(17) + 1); - WRITE_VAR(17 + var_26, 1); - break; - } - } while (READ_LE_UINT16(descArray[var_24].ptr - 2) > pos); - collStackPos++; - } else { - WRITE_VAR(17 + var_26, 2); - } - var_24++; - var_26++; - } - - if (collStackPos != (int16) VAR(17)) - WRITE_VAR(17, 0); - else - WRITE_VAR(17, 1); - } - - if (_handleMouse == 1) - _vm->_draw->blitCursor(); - - if (!_vm->_inter->_terminate) { - _script->seek(_collisionAreas[_activeCollIndex].funcLeave); - - _vm->_inter->storeMouse(); - if (VAR(16) == 0) { - if ((_activeCollResId & 0xF000) == 0x8000) - WRITE_VAR(16, array[_activeCollResId & 0xFFF]); - else - WRITE_VAR(16, _activeCollResId & 0xFFF); - } - } else - _script->setFinished(true); - - for (curCmd = 0; curCmd < count; curCmd++) - freeCollision(curCmd + 0x8000); - - for (i = 0; i < 150; i++) { - if (((_collisionAreas[i].id & 0xF000) == 0xA000) || - ((_collisionAreas[i].id & 0xF000) == 0x9000)) - _collisionAreas[i].id |= 0x4000; - } -} - -int16 Game_v2::multiEdit(int16 time, int16 index, int16 *pCurPos, - InputDesc * inpDesc, int16 *collResId, int16 *collIndex, bool mono) { - Collision *collArea; - int16 descInd; - int16 key; - int16 found = -1; - int16 i; - byte *fontExtraBak = 0; - int16 needAdjust = 0; - - descInd = 0; - for (i = 0; i < 150; i++) { - collArea = &_collisionAreas[i]; - - if (collArea->left == 0xFFFF) - continue; - - if ((collArea->id & 0xC000) != 0x8000) - continue; - - if ((collArea->flags & 0x0F) < 3) - continue; - - if ((collArea->flags & 0x0F) > 10) - continue; - - strncpy0(_tempStr, GET_VARO_STR(collArea->key), 255); - - _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; - - _vm->_draw->_destSurface = 21; - - _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; - - if (mono) { - fontExtraBak = _vm->_draw->_fonts[_vm->_draw->_fontIndex]->extraData; - needAdjust = _vm->_draw->_needAdjust; - _vm->_draw->_needAdjust = 2; - _vm->_draw->_fonts[_vm->_draw->_fontIndex]->extraData = 0; - } - - _vm->_draw->spriteOperation(DRAW_FILLRECT | 0x10); - - _vm->_draw->_destSpriteY += ((collArea->bottom - collArea->top + 1) - - _vm->_draw->_fonts[_vm->_draw->_fontIndex]->itemHeight) / 2; - _vm->_draw->spriteOperation(DRAW_PRINTTEXT | 0x10); - - if (mono) { - _vm->_draw->_needAdjust = needAdjust; - _vm->_draw->_fonts[_vm->_draw->_fontIndex]->extraData = fontExtraBak; - } - - descInd++; - } - - for (i = 0; i < 40; i++) - WRITE_VAR_OFFSET(i * 4 + 0x44, 0); - - while (1) { - descInd = 0; - - for (i = 0; i < 150; i++) { - collArea = &_collisionAreas[i]; - - if (collArea->left == 0xFFFF) - continue; - - if ((collArea->id & 0xC000) != 0x8000) - continue; - - if ((collArea->flags & 0x0F) < 3) - continue; - - if ((collArea->flags & 0x0F) > 10) - continue; - - if (descInd == *pCurPos) { - found = i; - break; - } - - descInd++; - } - - assert(found != -1); - - collArea = &_collisionAreas[found]; - - key = inputArea(collArea->left, collArea->top, - collArea->right - collArea->left + 1, - collArea->bottom - collArea->top + 1, - inpDesc[*pCurPos].backColor, inpDesc[*pCurPos].frontColor, - GET_VARO_STR(collArea->key), inpDesc[*pCurPos].fontIndex, - collArea->flags, &time, collResId, collIndex, mono); - - if (_vm->_inter->_terminate) - return 0; - - switch (key) { - case 0: - if (*collResId == 0) - return 0; - - if (_mouseButtons != 0) { - for (collArea = _collisionAreas, i = 0; - collArea->left != 0xFFFF; collArea++, i++) { - if ((collArea->flags & 0xF00)) - continue; - - if ((collArea->id & 0x4000)) - continue; - - if ((collArea->left > _vm->_global->_inter_mouseX) || - (collArea->right < _vm->_global->_inter_mouseX) || - (collArea->top > _vm->_global->_inter_mouseY) || - (collArea->bottom < _vm->_global->_inter_mouseY)) - continue; - - if ((collArea->id & 0xF000)) - continue; - - if ((collArea->flags & 0x0F) < 3) - continue; - - if ((collArea->flags & 0x0F) > 10) - continue; - - *collIndex = i; - } - } - - if ((_collisionAreas[*collIndex].flags & 0x0F) < 3) - return 0; - - if ((_collisionAreas[*collIndex].flags & 0x0F) > 10) - return 0; - - *pCurPos = 0; - for (i = 0; i < 150; i++) { - collArea = &_collisionAreas[i]; - - if (collArea->left == 0xFFFF) - continue; - - if ((collArea->id & 0xC000) != 0x8000) - continue; - - if ((collArea->flags & 0x0F) < 3) - continue; - - if ((collArea->flags & 0x0F) > 10) - continue; - - if (i != *collIndex) - pCurPos[0]++; - } - break; - - case 0x3B00: - case 0x3C00: - case 0x3D00: - case 0x3E00: - case 0x3F00: - case 0x4000: - case 0x4100: - case 0x4200: - case 0x4300: - case 0x4400: - return key; - - case 0x1C0D: - - if (index == 1) - return key; - - if (*pCurPos == index - 1) { - *pCurPos = 0; - break; - } - - pCurPos[0]++; - break; - - case 0x5000: - if (index - 1 > *pCurPos) - pCurPos[0]++; - break; - - case 0x4800: - if (*pCurPos > 0) - pCurPos[0]--; - break; - } - } -} - -int16 Game_v2::inputArea(int16 xPos, int16 yPos, int16 width, int16 height, - int16 backColor, int16 frontColor, char *str, int16 fontIndex, - char inpType, int16 *pTotTime, int16 *collResId, int16 *collIndex, bool mono) { - byte handleMouse; - uint32 editSize; - Video::FontDesc *pFont; - char curSym; - int16 key; - const char *str1; - const char *str2; - int16 i; - uint32 pos; - int16 flag; - int16 savedKey; - byte *fontExtraBak = 0; - int16 needAdjust = 0; - - if ((_handleMouse != 0) && - ((_vm->_global->_useMouse != 0) || (_forceHandleMouse != 0))) - handleMouse = 1; - else - handleMouse = 0; - - pos = strlen(str); - pFont = _vm->_draw->_fonts[fontIndex]; - editSize = (!mono && pFont->extraData) ? 0 : (width / pFont->itemWidth); - - while (1) { - strncpy0(_tempStr, str, 254); - strcat(_tempStr, " "); - if ((editSize != 0) && strlen(_tempStr) > editSize) - strncpy0(_tempStr, str, 255); - - if (mono) { - fontExtraBak = _vm->_draw->_fonts[fontIndex]->extraData; - needAdjust = _vm->_draw->_needAdjust; - _vm->_draw->_needAdjust = 2; - _vm->_draw->_fonts[fontIndex]->extraData = 0; - } - - _vm->_draw->_destSpriteX = xPos; - _vm->_draw->_destSpriteY = yPos; - _vm->_draw->_spriteRight = mono ? (editSize * pFont->itemWidth) : width; - _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 | 0x10 ); - - _vm->_draw->_destSpriteY = yPos + (height - pFont->itemHeight) / 2; - _vm->_draw->spriteOperation(DRAW_PRINTTEXT | 0x10); - - if (mono) { - _vm->_draw->_needAdjust = needAdjust; - _vm->_draw->_fonts[fontIndex]->extraData = fontExtraBak; - } - - if ((editSize != 0) && (pos == editSize)) - pos--; - - curSym = _tempStr[pos]; - - flag = 1; - - if (_vm->_inter->_variables) - WRITE_VAR(56, pos); - - while (1) { - if (mono) { - fontExtraBak = _vm->_draw->_fonts[fontIndex]->extraData; - needAdjust = _vm->_draw->_needAdjust; - _vm->_draw->_needAdjust = 2; - _vm->_draw->_fonts[fontIndex]->extraData = 0; - } - - _tempStr[0] = curSym; - _tempStr[1] = 0; - - if (pFont->extraData) { - _vm->_draw->_destSpriteY = yPos; - _vm->_draw->_spriteBottom = height; - _vm->_draw->_spriteRight = 1; - - _vm->_draw->_destSpriteX = xPos; - for (uint32 j = 0; j < pos; j++) - _vm->_draw->_destSpriteX += pFont->extraData[str[j] - pFont->startItem]; - - } else { - _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 | 0x10); - - if (mono) { - _vm->_draw->_needAdjust = needAdjust; - _vm->_draw->_fonts[fontIndex]->extraData = fontExtraBak; - } - - if (flag != 0) { - key = checkCollisions(handleMouse, -1, collResId, collIndex); - if (key == 0) - key = checkCollisions(handleMouse, -300, collResId, collIndex); - flag = 0; - } else - key = checkCollisions(handleMouse, -300, collResId, collIndex); - - if (mono) { - fontExtraBak = _vm->_draw->_fonts[fontIndex]->extraData; - needAdjust = _vm->_draw->_needAdjust; - _vm->_draw->_needAdjust = 2; - _vm->_draw->_fonts[fontIndex]->extraData = 0; - } - - _tempStr[0] = curSym; - _tempStr[1] = 0; - - if (pFont->extraData) { - _vm->_draw->_destSpriteY = yPos; - _vm->_draw->_spriteBottom = height; - _vm->_draw->_spriteRight = 1; - - _vm->_draw->_destSpriteX = xPos; - for (uint32 j = 0; j < pos; j++) - _vm->_draw->_destSpriteX += pFont->extraData[str[j] - pFont->startItem]; - - } else { - _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->_fontIndex = fontIndex; - _vm->_draw->spriteOperation(DRAW_FILLRECT | 0x10); - - _vm->_draw->_destSpriteY = yPos + (height - pFont->itemHeight) / 2; - _vm->_draw->spriteOperation(DRAW_PRINTTEXT | 0x10); - - if (mono) { - _vm->_draw->_needAdjust = needAdjust; - _vm->_draw->_fonts[fontIndex]->extraData = fontExtraBak; - } - - if ((key != 0) || (*collResId != 0)) - break; - - key = checkCollisions(handleMouse, -300, collResId, collIndex); - - if ((key != 0) || (*collResId != 0) || - _vm->_inter->_terminate || _vm->shouldQuit()) - break; - - if (*pTotTime > 0) { - *pTotTime -= 600; - if (*pTotTime <= 1) { - key = 0; - *collResId = 0; - break; - } - } - } - - if ((key == 0) || (*collResId != 0) || - _vm->_inter->_terminate || _vm->shouldQuit()) - return 0; - - switch (key) { - case 0x4D00: // Right Arrow - if ((pos > strlen(str)) || (pos > (editSize - 1)) || (editSize == 0)) { - pos++; - continue; - } - return 0x5000; - - case 0x4B00: // Left Arrow - if (pos > 0) { - pos--; - continue; - } - return 0x4800; - - case 0xE08: // Backspace - if (pos > 0) { - _vm->_util->cutFromStr(str, pos - 1, 1); - pos--; - continue; - } else { - if (pos < strlen(str)) - _vm->_util->cutFromStr(str, pos, 1); - } - - case 0x5300: // Del - - if (pos >= strlen(str)) - continue; - - _vm->_util->cutFromStr(str, pos, 1); - continue; - - case 0x1C0D: // Enter - case 0x3B00: // F1 - case 0x3C00: // F2 - case 0x3D00: // F3 - case 0x3E00: // F4 - case 0x3F00: // F5 - case 0x4000: // F6 - case 0x4100: // F7 - case 0x4200: // F8 - case 0x4300: // F9 - case 0x4400: // F10 - case 0x4800: // Up arrow - case 0x5000: // Down arrow - return key; - - case 0x11B: // Escape - if (_vm->_global->_useMouse != 0) - continue; - - _forceHandleMouse = !_forceHandleMouse; - - if ((_handleMouse != 0) && - ((_vm->_global->_useMouse != 0) || (_forceHandleMouse != 0))) - handleMouse = 1; - else - handleMouse = 0; - - while (_vm->_global->_pressedKeys[1] != 0) - ; - continue; - - default: - - savedKey = key; - key &= 0xFF; - - if (((inpType == 9) || (inpType == 10)) && - (key >= ' ') && (key <= 0xFF)) { - str1 = "0123456789-.,+ "; - str2 = "0123456789-,,+ "; - - if ((((savedKey >> 8) > 1) && ((savedKey >> 8) < 12)) && - ((_vm->_global->_pressedKeys[42] != 0) || - (_vm->_global->_pressedKeys[56] != 0))) - key = ((savedKey >> 8) - 1) % 10 + '0'; - - for (i = 0; str1[i] != 0; i++) { - if (key == str1[i]) { - key = str2[i]; - break; - } - } - - if (i == (int16) strlen(str1)) - key = 0; - } - - if ((key >= ' ') && (key <= 0xFF)) { - if (editSize == 0) { - int length = _vm->_draw->stringLength(str, fontIndex) + - pFont->extraData[' ' - pFont->startItem] + - pFont->extraData[key - pFont->startItem]; - - if (length > width) - continue; - - if (((int32) strlen(str)) >= (_vm->_global->_inter_animDataSize * 4 - 1)) - continue; - - } else { - if (strlen(str) > editSize) - continue; - else if (editSize == strlen(str)) - _vm->_util->cutFromStr(str, strlen(str) - 1, 1); - } - - pos++; - _tempStr[0] = key; - _tempStr[1] = 0; - - _vm->_util->insertStr(_tempStr, str, pos - 1); - } - - } - } -} - -int16 Game_v2::checkMousePoint(int16 all, int16 *resId, int16 *resIndex) { - Collision *ptr; - int16 i; - - if (resId != 0) - *resId = 0; - - *resIndex = 0; - - ptr = _collisionAreas; - for (i = 0; ptr->left != 0xFFFF; ptr++, i++) { - if (ptr->id & 0x4000) - continue; - - if (all) { - if ((ptr->flags & 0xF) > 1) - continue; - - if ((ptr->flags & 0xF00) != 0) - continue; - - 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) - *resId = ptr->id; - - *resIndex = i; - return ptr->key; - } else { - if ((ptr->flags & 0xF00) != 0) - continue; - - if ((ptr->flags & 0xF) < 1) - continue; - - if ((((ptr->flags & 0xF0) >> 4) != (_mouseButtons - 1)) && - (((ptr->flags & 0xF0) >> 4) != 2)) - continue; - - 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) - *resId = ptr->id; - *resIndex = i; - if (((ptr->flags & 0xF) == 1) || ((ptr->flags & 0xF) == 2)) - return ptr->key; - return 0; - } - } - - if ((_mouseButtons != 1) && (all == 0)) - return 0x11B; - - return 0; -} - -} // End of namespace Gob diff --git a/engines/gob/game_v6.cpp b/engines/gob/game_v6.cpp deleted file mode 100644 index 8d40d41acc..0000000000 --- a/engines/gob/game_v6.cpp +++ /dev/null @@ -1,1114 +0,0 @@ -/* ScummVM - Graphic Adventure Engine - * - * ScummVM is the legal property of its developers, whose names - * are too numerous to list here. Please refer to the COPYRIGHT - * file distributed with this source distribution. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - * - * $URL$ - * $Id$ - * - */ - -#include "common/endian.h" -#include "common/stream.h" -#include "common/file.h" - -#include "gob/gob.h" -#include "gob/game.h" -#include "gob/helper.h" -#include "gob/global.h" -#include "gob/script.h" -#include "gob/resources.h" -#include "gob/inter.h" -#include "gob/draw.h" - -namespace Gob { - -Game_v6::Game_v6(GobEngine *vm) : Game_v2(vm) { - _someTimeDly = 0; -} - -// flagbits: 5 = freeInterVariables, 6 = skipPlay -void Game_v6::totSub(int8 flags, const char *newTotFile) { - int8 curBackupPos; - - if ((flags == 16) || (flags == 17)) - warning("Urban Stub: Game_v6::totSub(), flags == %d", flags); - - if (_numEnvironments >= Environments::kEnvironmentCount) - return; - - _environments->set(_numEnvironments); - - curBackupPos = _curEnvironment; - _numEnvironments++; - _curEnvironment = _numEnvironments; - - _script = new Script(_vm); - _resources = new Resources(_vm); - - if (flags & 0x80) - warning("Urban Stub: Game_v6::totSub(), flags & 0x80"); - - if (flags & 5) - _vm->_inter->_variables = 0; - - strncpy0(_curTotFile, newTotFile, 9); - strcat(_curTotFile, ".TOT"); - - if (_vm->_inter->_terminate != 0) { - clearUnusedEnvironment(); - return; - } - - pushCollisions(0); - - if (flags & 6) - playTot(-1); - else - playTot(0); - - if (_vm->_inter->_terminate < 2) - _vm->_inter->_terminate = 0; - - clearCollisions(); - popCollisions(); - - if ((flags & 5) && _vm->_inter->_variables) { - _vm->_inter->delocateVars(); - } - - clearUnusedEnvironment(); - - _numEnvironments--; - _curEnvironment = curBackupPos; - _environments->get(_numEnvironments); -} - -int16 Game_v6::addNewCollision(int16 id, uint16 left, uint16 top, - uint16 right, uint16 bottom, int16 flags, int16 key, - uint16 funcEnter, uint16 funcLeave, uint16 funcSub) { - Collision *ptr; - - debugC(5, kDebugCollisions, "addNewCollision"); - debugC(5, kDebugCollisions, "id = %X", id); - debugC(5, kDebugCollisions, "left = %d, top = %d, right = %d, bottom = %d", - left, top, right, bottom); - debugC(5, kDebugCollisions, "flags = %X, key = %X", flags, key); - debugC(5, kDebugCollisions, "funcEnter = %d, funcLeave = %d", - funcEnter, funcLeave); - - for (int i = 0; i < 150; i++) { - if ((_collisionAreas[i].left != 0xFFFF) && (_collisionAreas[i].id != id)) - continue; - - ptr = &_collisionAreas[i]; - - if ((ptr->id & 0xBFFF) != (id & 0xBFFF)) - ptr->id = id; - - ptr->left = left; - ptr->top = top; - ptr->right = right; - ptr->bottom = bottom; - ptr->flags = flags; - ptr->key = key; - ptr->funcEnter = funcEnter; - ptr->funcLeave = funcLeave; - ptr->funcSub = funcSub; - ptr->script = _script; - - return i; - } - error("Game_v6::addNewCollision(): Collision array full"); - return 0; -} - -void Game_v6::prepareStart(void) { - _noCd = false; - - if (Common::File::exists("cd1.itk") && Common::File::exists("cd2.itk") && - Common::File::exists("cd3.itk") && Common::File::exists("cd4.itk")) { - _noCd = true; - } - - Game_v2::prepareStart(); -} - -void Game_v6::pushCollisions(char all) { - Collision *srcPtr; - Collision *destPtr; - int16 size; - - debugC(1, kDebugCollisions, "pushCollisions"); - for (size = 0, srcPtr = _collisionAreas; srcPtr->left != 0xFFFF; srcPtr++) { - if ( (all == 1) || - ((all == 0) && (((uint16) srcPtr->id) >= 20)) || - ((all == 2) && (((srcPtr->id & 0xF000) == 0xD000) || - ((srcPtr->id & 0xF000) == 0x4000) || - ((srcPtr->id & 0xF000) == 0xE000)))) - size++; - } - - if (_collStackSize >= 5) - error("Game_v6::pushCollisions: _collStackSize == %d", _collStackSize); - - destPtr = new Collision[size]; - _collStack[_collStackSize] = destPtr; - - if (_vm->_inter->_terminate) - return; - - _collStackElemSizes[_collStackSize] = size; - - if (_shouldPushColls != 0) - _collStackElemSizes[_collStackSize] |= 0x8000; - - _shouldPushColls = 0; - _collLasts[_collStackSize].key = _lastCollKey; - _collLasts[_collStackSize].id = _lastCollId; - _collLasts[_collStackSize].areaIndex = _lastCollAreaIndex; - _lastCollKey = 0; - _lastCollId = 0; - _lastCollAreaIndex = 0; - _collStackSize++; - - for (srcPtr = _collisionAreas; srcPtr->left != 0xFFFF; srcPtr++) { - if ( (all == 1) || - ((all == 0) && (((uint16) srcPtr->id) >= 20)) || - ((all == 2) && (((srcPtr->id & 0xF000) == 0xD000) || - ((srcPtr->id & 0xF000) == 0x4000) || - ((srcPtr->id & 0xF000) == 0xE000)))) { - - memcpy(destPtr, srcPtr, sizeof(Collision)); - srcPtr->left = 0xFFFF; - destPtr++; - } - } -} - -int16 Game_v6::checkCollisions(byte handleMouse, int16 deltaTime, int16 *pResId, - int16 *pResIndex) { - int16 resIndex; - int16 key; - uint32 timeKey; - - _scrollHandleMouse = handleMouse != 0; - - if (deltaTime >= -1) { - _lastCollKey = 0; - _lastCollAreaIndex = 0; - _lastCollId = 0; - } - - if (pResId != 0) - *pResId = 0; - - resIndex = 0; - - if ((_lastCollKey != 0) && - ( (_collisionAreas[_lastCollAreaIndex].id != _lastCollId) || - (_collisionAreas[_lastCollAreaIndex].key != _lastCollKey))) { - - _lastCollKey = 0; - _lastCollAreaIndex = 0; - _lastCollId = 0; - } - - if ((_vm->_draw->_cursorIndex == -1) && - (handleMouse != 0) && (_lastCollKey == 0)) { - _lastCollKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - - if ((_lastCollKey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 1); - } - - if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - - timeKey = _vm->_util->getTimeKey(); - _vm->_draw->blitInvalidated(); - while (1) { - if (_vm->_inter->_terminate || _vm->shouldQuit()) { - if (handleMouse) - _vm->_draw->blitCursor(); - return 0; - } - - collSubReenter(); - if (!_vm->_draw->_noInvalidated) { - if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - else - _vm->_draw->blitInvalidated(); - _vm->_video->waitRetrace(); - } - - key = checkKeys(&_vm->_global->_inter_mouseX, - &_vm->_global->_inter_mouseY, &_mouseButtons, handleMouse); - - if ((handleMouse == 0) && (_mouseButtons != 0)) { - _vm->_util->waitMouseRelease(0); - key = 3; - } - - if (key != 0) { - - if (handleMouse & 1) - _vm->_draw->blitCursor(); - - if (pResId != 0) - *pResId = 0; - - if (pResIndex != 0) - *pResIndex = 0; - - if ((_lastCollKey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 0); - - _lastCollKey = 0; - if (key != 0) - return key; - - if (handleMouse) - _vm->_draw->animateCursor(-1); - } - - if (handleMouse != 0) { - if (_mouseButtons != 0) { - - if (deltaTime > 0) { - _vm->_draw->animateCursor(2); - _vm->_util->delay(deltaTime); - } else if (handleMouse & 1) - _vm->_util->waitMouseRelease(1); - - _vm->_draw->animateCursor(-1); - - if (pResId != 0) - *pResId = 0; - - key = checkMousePoint(0, pResId, &resIndex); - if (pResIndex != 0) - *pResIndex = resIndex; - - if ((key != 0) || ((pResId != 0) && (*pResId != 0))) { - if ((handleMouse & 1) && - ((deltaTime <= 0) || (_mouseButtons == 0))) - _vm->_draw->blitCursor(); - - if (key != _lastCollKey) - collAreaSub(_lastCollAreaIndex, 0); - - _lastCollKey = 0; - return key; - } - - if (handleMouse & 4) - return 0; - - if (_lastCollKey != 0) - collAreaSub(_lastCollAreaIndex, 0); - - _lastCollKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - if ((_lastCollKey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 1); - } else - collSubReenter(); - } - - if ((deltaTime == -2) && (key == 0) && (_mouseButtons == 0)) { - if (pResId != 0) - *pResId = 0; - - if (pResIndex != 0) - *pResIndex = 0; - - return 0; - - } else if (handleMouse != 0) - _vm->_draw->animateCursor(-1); - - if ((deltaTime < 0) && (key == 0) && (_mouseButtons == 0)) { - uint32 curtime = _vm->_util->getTimeKey(); - if ((curtime + deltaTime) > timeKey) { - if (pResId != 0) - *pResId = 0; - - if (pResIndex != 0) - *pResIndex = 0; - - return 0; - } - } - - _vm->_util->delay(10); - } -} - -void Game_v6::collisionsBlock(void) { - InputDesc descArray[20]; - int16 array[300]; - byte count; - int16 collResId; - int16 curCmd; - int16 cmd; - int16 cmdHigh; - int16 key; - int16 flags; - uint16 left; - uint16 top; - uint16 width; - uint16 height; - int16 deltaTime; - int16 stackPos2; - int16 descIndex; - int16 timeVal; - char *str; - int16 i; - int16 counter; - int16 var_24; - int16 var_26; - int16 collStackPos; - Collision *collPtr; - Collision *collArea; - byte collAreaStart; - int16 activeCollResId = 0; - int16 activeCollIndex = 0; - uint32 startPos; - uint32 offsetPos; - - if (_shouldPushColls) - pushCollisions(0); - - collAreaStart = 0; - while (_collisionAreas[collAreaStart].left != 0xFFFF) - collAreaStart++; - collArea = &_collisionAreas[collAreaStart]; - - _shouldPushColls = 0; - collResId = -1; - - _script->skip(1); - count = _script->readByte(); - - _handleMouse = _script->peekByte(0); - deltaTime = 1000 * _script->peekByte(1); - stackPos2 = _script->peekByte(3); - descIndex = _script->peekByte(4); - byte var_42 = _script->peekByte(5); - - if ((stackPos2 != 0) || (descIndex != 0)) { - deltaTime /= 100; - if (_script->peekByte(1) == 100) - deltaTime = 2; - } - - timeVal = deltaTime; - _script->skip(6); - - startPos = _script->pos(); - WRITE_VAR(16, 0); - - byte var_41 = 0; - int16 var_46 = 0; - int16 var_1C = 0; - int16 index = 0; - int16 curEditIndex = 0; - int right = 0, funcLeave = 0; - - for (curCmd = 0; curCmd < count; curCmd++) { - array[curCmd] = 0; - cmd = _script->readByte(); - - if ((cmd & 0x40) != 0) { - cmd -= 0x40; - cmdHigh = _script->readByte(); - cmdHigh <<= 8; - } else - cmdHigh = 0; - - if ((cmd & 0x80) != 0) { - offsetPos = _script->pos(); - left = _script->readValExpr(); - top = _script->readValExpr(); - width = _script->readValExpr(); - height = _script->readValExpr(); - } else { - offsetPos = 0; - left = _script->readUint16(); - top = _script->readUint16(); - width = _script->readUint16(); - height = _script->readUint16(); - } - - if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) && (left != 0xFFFF)) { - left += _vm->_draw->_backDeltaX; - top += _vm->_draw->_backDeltaY; - } - - if (left != 0xFFFF) { - _vm->_draw->adjustCoords(0, &left, &top); - if (((cmd & 0x3F) < 20) && ((cmd & 0x3F) >= 3)) { - if (_vm->_draw->_needAdjust != 2) - height &= 0xFFFE; - _vm->_draw->adjustCoords(0, 0, &width); - } else - _vm->_draw->adjustCoords(0, &height, &width); - } - - cmd &= 0x7F; - debugC(1, kDebugCollisions, "collisionsBlock(%d)", cmd); - - switch (cmd) { - case 0: - _script->skip(6); - startPos = _script->pos(); - _script->skip(_script->peekUint16(2) + 2); - key = curCmd + 0xA000; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - cmd + cmdHigh, key, startPos, - _script->pos(), offsetPos); - - _script->skip(_script->peekUint16(2) + 2); - - break; - - case 1: - key = _script->readInt16(); - array[curCmd] = _script->readInt16(); - flags = _script->readInt16(); - - startPos = _script->pos(); - _script->skip(_script->peekUint16(2) + 2); - - if (key == 0) - key = curCmd + 0xA000; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - (flags << 4) + cmd + cmdHigh, key, startPos, - _script->pos(), offsetPos); - - _script->skip(_script->peekUint16(2) + 2); - - break; - - case 3: - case 4: - case 5: - case 6: - case 7: - case 8: - case 9: - case 10: - _vm->_util->clearKeyBuf(); - var_1C = 1; - key = _script->readVarIndex(); - descArray[index].fontIndex = _script->readInt16(); - descArray[index].backColor = _script->readByte(); - descArray[index].frontColor = _script->readByte(); - - if ((cmd >= 5) && (cmd <= 8)) { - descArray[index].ptr = _script->getData() + _script->pos() + 2; - _script->skip(_script->peekUint16() + 2); - } else - descArray[index].ptr = 0; - - if (left == 0xFFFF) { - if ((cmd & 1) == 0) { - _script->skip(_script->peekUint16(2) + 2); - } - break; - } - - right = left + width - 1; - if (!_vm->_draw->_fonts[descArray[index].fontIndex]->extraData) - right = left + width * _vm->_draw->_fonts[descArray[index].fontIndex]->itemWidth - 1; - - funcLeave = 0; - if (!(cmd & 1)) - funcLeave = _script->pos(); - - addNewCollision(curCmd + 0x8000, left, top, right, - top + height - 1, cmd, key, 0, funcLeave, 0); - - if (!(cmd & 1)) { - _script->skip(_script->peekUint16(2) + 2); - } - - index++; - break; - - case 11: - _script->skip(6); - for (i = 0; i < 150; i++) { - if ((_collisionAreas[i].id & 0xF000) == 0xE000) { - _collisionAreas[i].id &= 0xBFFF; - _collisionAreas[i].funcEnter = - _script->pos(); - _collisionAreas[i].funcLeave = - _script->pos(); - } - } - _script->skip(_script->peekUint16(2) + 2); - break; - - case 12: - _script->skip(6); - for (i = 0; i < 150; i++) { - if ((_collisionAreas[i].id & 0xF000) == 0xD000) { - _collisionAreas[i].id &= 0xBFFF; - _collisionAreas[i].funcEnter = - _script->pos(); - _collisionAreas[i].funcLeave = - _script->pos(); - } - } - _script->skip(_script->peekUint16(2) + 2); - break; - - case 20: - collResId = curCmd; - // Fall through to case 2 - - case 2: - key = _script->readInt16(); - array[curCmd] = _script->readInt16(); - flags = _script->readInt16(); - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - (flags << 4) + cmdHigh + 2, key, 0, - _script->pos(), offsetPos); - - _script->skip(_script->peekUint16(2) + 2); - - break; - - case 21: - key = _script->readInt16(); - array[curCmd] = _script->readInt16(); - flags = _script->readInt16() & 3; - - addNewCollision(curCmd + 0x8000, left, top, - left + width - 1, top + height - 1, - (flags << 4) + cmdHigh + 2, key, - _script->pos(), 0, offsetPos); - - _script->skip(_script->peekUint16(2) + 2); - - break; - } - } - - if (var_42 != 0) - setCollisions(1); - - _forceHandleMouse = 0; - _vm->_util->clearKeyBuf(); - - do { - if (var_1C != 0) { - key = multiEdit(deltaTime, index, &curEditIndex, descArray, - &activeCollResId, &activeCollIndex, false); - - WRITE_VAR(55, curEditIndex); - if (key == 0x1C0D) { - for (i = 0; i < 150; i++) { - if (_collisionAreas[i].left == 0xFFFF) - break; - - if ((_collisionAreas[i].id & 0xC000) != 0x8000) - continue; - - if ((_collisionAreas[i].flags & 1) != 0) - continue; - - if ((_collisionAreas[i].flags & 0x0F) <= 2) - continue; - - activeCollResId = _collisionAreas[i].id; - collResId = _collisionAreas[i].id & 0x7FFF; - activeCollIndex = i; - break; - } - break; - } - } else - key = checkCollisions(_handleMouse, -deltaTime, - &activeCollResId, &activeCollIndex); - - if (((key & 0xFF) >= ' ') && ((key & 0xFF) <= 0xFF) && - ((key >> 8) > 1) && ((key >> 8) < 12)) - key = '0' + (((key >> 8) - 1) % 10) + (key & 0xFF00); - - if (activeCollResId == 0) { - if (key != 0) { - for (i = 0; i < 150; i++) { - if (_collisionAreas[i].left == 0xFFFF) - break; - - if ((_collisionAreas[i].id & 0xC000) != 0x8000) - continue; - - if ((_collisionAreas[i].key == key) || - (_collisionAreas[i].key == 0x7FFF)) { - activeCollResId = _collisionAreas[i].id; - activeCollIndex = i; - break; - } - } - - if (activeCollResId == 0) { - for (i = 0; i < 150; i++) { - if (_collisionAreas[i].left == 0xFFFF) - break; - - if ((_collisionAreas[i].id & 0xC000) != 0x8000) - continue; - - if ((_collisionAreas[i].key & 0xFF00) != 0) - continue; - - if (_collisionAreas[i].key == 0) - continue; - - if (adjustKey(key & 0xFF) == adjustKey(_collisionAreas[i].key)) { - activeCollResId = _collisionAreas[i].id; - activeCollIndex = i; - break; - } - } - } - } else if (deltaTime != 0) { - if (stackPos2 != 0) { - collStackPos = 0; - - for (i = 0, collPtr = collArea; collPtr->left != 0xFFFF; i++, collPtr++) { - if ((collPtr->id & 0xF000) != 0x8000) - continue; - - collStackPos++; - if (collStackPos != stackPos2) - continue; - - activeCollResId = collPtr->id; - activeCollIndex = i + collAreaStart; - _vm->_inter->storeMouse(); - if (VAR(16) != 0) - break; - - if ((activeCollResId & 0xF000) == 0x8000) - WRITE_VAR(16, array[activeCollResId & 0xFFF]); - else - WRITE_VAR(16, activeCollResId & 0xFFF); - - if (collPtr->funcLeave != 0) { - uint32 timeKey = _vm->_util->getTimeKey(); - collSub(collPtr->funcLeave); - - if (timeVal != 2) { - deltaTime = timeVal - (_vm->_util->getTimeKey() - timeKey); - - if ((deltaTime - var_46) < 3) { - var_46 -= (deltaTime - 3); - deltaTime = 3; - } else if (var_46 != 0) { - deltaTime -= var_46; - var_46 = 0; - } - - if (deltaTime > timeVal) - deltaTime = timeVal; - - } else - deltaTime = 2; - - } - - if (VAR(16) == 0) - activeCollResId = 0; - else - var_41 = 1; - - break; - } - } else { - if (descIndex != 0) { - - counter = 0; - for (i = 0, collPtr = collArea; collPtr->left != 0xFFFF; i++, collPtr++) { - if ((collPtr->id & 0xF000) == 0x8000) - if (++counter == descIndex) { - activeCollResId = collPtr->id; - activeCollIndex = i + collAreaStart; - break; - } - } - - } else { - - for (i = 0, collPtr = _collisionAreas; collPtr->left != 0xFFFF; i++, collPtr++) { - if ((collPtr->id & 0xF000) == 0x8000) { - activeCollResId = collPtr->id; - activeCollIndex = i; - break; - } - } - if ((_lastCollKey != 0) && - (_collisionAreas[_lastCollAreaIndex].funcLeave != 0)) - collSub(_collisionAreas[_lastCollAreaIndex].funcLeave); - - _lastCollKey = 0; - } - - } - } - } - - if (var_41 != 0) - break; - - if ((activeCollResId == 0) || - (_collisionAreas[activeCollIndex].funcLeave != 0)) - continue; - - _vm->_inter->storeMouse(); - if ((activeCollResId & 0xF000) == 0x8000) - WRITE_VAR(16, array[activeCollResId & 0xFFF]); - else - WRITE_VAR(16, activeCollResId & 0xFFF); - - if (_collisionAreas[activeCollIndex].funcEnter != 0) - collSub(_collisionAreas[activeCollIndex].funcEnter); - - WRITE_VAR(16, 0); - activeCollResId = 0; - } - while ((activeCollResId == 0) && !_vm->_inter->_terminate && !_vm->shouldQuit()); - - if ((activeCollResId & 0xFFF) == collResId) { - collStackPos = 0; - var_24 = 0; - var_26 = 1; - for (i = 0; i < 150; i++) { - if (_collisionAreas[i].left == 0xFFFF) - continue; - - if ((_collisionAreas[i].id & 0xC000) != 0x8000) - continue; - - if ((_collisionAreas[i].flags & 0x0F) < 3) - continue; - - if ((_collisionAreas[i].flags & 0x0F) > 10) - continue; - - if ((_collisionAreas[i].flags & 0x0F) > 8) { - char *ptr; - strncpy0(_tempStr, GET_VARO_STR(_collisionAreas[i].key), 255); - while ((ptr = strchr(_tempStr, ' '))) - _vm->_util->cutFromStr(_tempStr, (ptr - _tempStr), 1); - if (_vm->_language == 2) - while ((ptr = strchr(_tempStr, '.'))) - *ptr = ','; - WRITE_VARO_STR(_collisionAreas[i].key, _tempStr); - } - - if (((_collisionAreas[i].flags & 0x0F) >= 5) && - ((_collisionAreas[i].flags & 0x0F) <= 8)) { - str = (char *) descArray[var_24].ptr; - - strncpy0(_tempStr, GET_VARO_STR(_collisionAreas[i].key), 255); - - if ((_collisionAreas[i].flags & 0x0F) < 7) - _vm->_util->prepareStr(_tempStr); - - int16 pos = 0; - do { - strncpy0(_collStr, str, 255); - pos += strlen(str) + 1; - - str += strlen(str) + 1; - - if ((_collisionAreas[i].flags & 0x0F) < 7) - _vm->_util->prepareStr(_collStr); - - if (strcmp(_tempStr, _collStr) == 0) { - WRITE_VAR(17, VAR(17) + 1); - WRITE_VAR(17 + var_26, 1); - break; - } - } while (READ_LE_UINT16(descArray[var_24].ptr - 2) > pos); - collStackPos++; - } else { - WRITE_VAR(17 + var_26, 2); - } - var_24++; - var_26++; - } - - if (collStackPos != (int16) VAR(17)) - WRITE_VAR(17, 0); - else - WRITE_VAR(17, 1); - } - - if (_handleMouse == 1) - _vm->_draw->blitCursor(); - - if (!_vm->_inter->_terminate && (var_41 == 0)) { - _script->seek(_collisionAreas[activeCollIndex].funcLeave); - - _vm->_inter->storeMouse(); - if (VAR(16) == 0) { - if ((activeCollResId & 0xF000) == 0x8000) - WRITE_VAR(16, array[activeCollResId & 0xFFF]); - else - WRITE_VAR(16, activeCollResId & 0xFFF); - } - } else - _script->setFinished(true); - - for (curCmd = 0; curCmd < count; curCmd++) - freeCollision(curCmd + 0x8000); - - for (i = 0; i < 150; i++) { - if (((_collisionAreas[i].id & 0xF000) == 0xA000) || - ((_collisionAreas[i].id & 0xF000) == 0x9000)) - _collisionAreas[i].id |= 0x4000; - } -} - -void Game_v6::setCollisions(byte arg_0) { - for (Collision *collArea = _collisionAreas; collArea->left != 0xFFFF; collArea++) { - if (((collArea->id & 0xC000) != 0x8000) || (collArea->funcSub == 0)) - continue; - - if (arg_0 == 0) - if (collArea->flags & 0x80) - continue; - - Script *curScript = _script; - - _script = collArea->script; - if (!_script) - _script = curScript; - - _script->call(collArea->funcSub); - - int16 left = _script->readValExpr(); - int16 top = _script->readValExpr(); - int16 width = _script->readValExpr(); - int16 height = _script->readValExpr(); - uint16 flags = 0; - - if ((collArea->id & 0xF000) == 0xA000) - flags = _script->readValExpr(); - - if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) && - (left != -1)) { - left += _vm->_draw->_backDeltaX; - top += _vm->_draw->_backDeltaY; - } - if (_vm->_draw->_needAdjust != 2) { - _vm->_draw->adjustCoords(0, &left, &top); - if ((collArea->flags & 0x0F) < 3) - _vm->_draw->adjustCoords(2, &width, &height); - else { - height &= 0xFFFE; - _vm->_draw->adjustCoords(2, 0, &height); - } - } - - if (left < 0) { - width += left; - left = 0; - } - - if (top < 0) { - height += top; - top = 0; - } - - collArea->left = left; - collArea->top = top; - collArea->right = left + width - 1; - collArea->bottom = top + height - 1; - - if ((collArea->id & 0xF000) == 0xA000) - collArea->flags = flags; - - _script->pop(); - - _script = curScript; - } -} - -void Game_v6::collSub(uint16 offset) { - int16 collStackSize; - - uint32 savedPos = _script->pos(); - - _script->seek(offset); - - _shouldPushColls = 1; - collStackSize = _collStackSize; - - _vm->_inter->funcBlock(0); - - if (collStackSize != _collStackSize) - popCollisions(); - - _shouldPushColls = 0; - - _script->seek(savedPos); - - if ((_vm->_util->getTimeKey() - _someTimeDly) > 500) - setCollisions(0); -} - -static const byte adjustTable[] = { - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x21, 0x21, 0x21, 0x21, 0x21, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, - 0x81, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, 0x12, - 0x12, 0x12, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, - 0x40, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, - 0x04, 0x04, 0x04, 0x40, 0x40, 0x40, 0x40, 0x40, - 0x40, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, - 0x08, 0x08, 0x08, 0x40, 0x40, 0x40, 0x40, 0x20, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 -}; - -int16 Game_v6::adjustKey(int16 key) { - if (key == -1) - return -1; - - if (adjustTable[key & 0xFF] & 8) - return ((key & 0xFF) - 0x20); - - return key & 0xFF; -} - -int16 Game_v6::checkMousePoint(int16 all, int16 *resId, int16 *resIndex) { - Collision *ptr; - int16 i; - - if (resId != 0) - *resId = 0; - - *resIndex = 0; - - ptr = _collisionAreas; - for (i = 0; ptr->left != 0xFFFF; ptr++, i++) { - if (ptr->id & 0x4000) - continue; - - if (all) { - if ((ptr->flags & 0xF) > 1) - continue; - - if ((ptr->flags & 0xF00) != 0) - continue; - - 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) - *resId = ptr->id; - - *resIndex = i; - return ptr->key; - } else { - if ((ptr->flags & 0xF00) != 0) - continue; - - if ((ptr->flags & 0xF) < 1) - continue; - - if ((((ptr->flags & 0x70) >> 4) != (_mouseButtons - 1)) && - (((ptr->flags & 0x70) >> 4) != 2)) - continue; - - 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) - *resId = ptr->id; - *resIndex = i; - if (((ptr->flags & 0xF) == 1) || ((ptr->flags & 0xF) == 2)) - return ptr->key; - return 0; - } - } - - if ((_mouseButtons != 1) && (all == 0)) - return 0x11B; - - return 0; -} - -void Game_v6::collSubReenter() { - int16 lastCollAreaIndex = _lastCollAreaIndex; - int16 lastCollId = _lastCollId; - int16 collKey = checkMousePoint(1, &_lastCollId, &_lastCollAreaIndex); - - if (collKey == _lastCollKey) - return; - - if ((_lastCollKey != 0) && (lastCollId & 0x8000)) - collAreaSub(lastCollAreaIndex, 0); - - _lastCollKey = collKey; - - if ((_lastCollKey != 0) && (_lastCollId & 0x8000)) - collAreaSub(_lastCollAreaIndex, 1); -} - -} // End of namespace Gob diff --git a/engines/gob/global.cpp b/engines/gob/global.cpp index 4165938966..2969ed0870 100644 --- a/engines/gob/global.cpp +++ b/engines/gob/global.cpp @@ -123,6 +123,8 @@ Global::Global(GobEngine *vm) : _vm(vm) { _inter_mouseY = 0; _speedFactor = 1; + + _noCd = false; } Global::~Global() { diff --git a/engines/gob/global.h b/engines/gob/global.h index 982ce113cb..7849490107 100644 --- a/engines/gob/global.h +++ b/engines/gob/global.h @@ -141,6 +141,8 @@ public: // Can be 1, 2 or 3 for normal, double and triple speed, respectively uint8 _speedFactor; + bool _noCd; + Global(GobEngine *vm); ~Global(); diff --git a/engines/gob/gob.cpp b/engines/gob/gob.cpp index e534464cce..fa4f04eab8 100644 --- a/engines/gob/gob.cpp +++ b/engines/gob/gob.cpp @@ -126,7 +126,7 @@ GobEngine::GobEngine(OSystem *syst) : Engine(syst) { Common::addDebugChannel(kDebugSaveLoad, "SaveLoad", "Saving/Loading debug level"); Common::addDebugChannel(kDebugGraphics, "Graphics", "Graphics debug level"); Common::addDebugChannel(kDebugVideo, "Video", "IMD/VMD video debug level"); - Common::addDebugChannel(kDebugCollisions, "Collisions", "Collisions debug level"); + Common::addDebugChannel(kDebugHotspots, "Hotspots", "Hotspots debug level"); Common::addDebugChannel(kDebugDemo, "Demo", "Demo script debug level"); syst->getEventManager()->registerRandomSource(_rnd, "gob"); @@ -205,6 +205,10 @@ bool GobEngine::isBATDemo() const { return (_features & kFeaturesBATDemo) != 0; } +bool GobEngine::is800x600() const { + return (_features & kFeatures800x600) != 0; +} + bool GobEngine::isDemo() const { return (isSCNDemo() || isBATDemo()); } @@ -331,6 +335,7 @@ bool GobEngine::initGameParts() { _palAnim = new PalAnim(this); _vidPlayer = new VideoPlayer(this); _sound = new Sound(this); + _game = new Game(this); switch (_gameType) { case kGameTypeGeisha: @@ -341,7 +346,6 @@ bool GobEngine::initGameParts() { _inter = new Inter_v1(this); _mult = new Mult_v1(this); _draw = new Draw_v1(this); - _game = new Game_v1(this); _map = new Map_v1(this); _goblin = new Goblin_v1(this); _scenery = new Scenery_v1(this); @@ -353,7 +357,6 @@ bool GobEngine::initGameParts() { _inter = new Inter_Fascination(this); _mult = new Mult_v2(this); _draw = new Draw_v2(this); - _game = new Game_Fascination(this); _map = new Map_v2(this); _goblin = new Goblin_v2(this); _scenery = new Scenery_v2(this); @@ -367,7 +370,6 @@ bool GobEngine::initGameParts() { _inter = new Inter_v2(this); _mult = new Mult_v2(this); _draw = new Draw_v2(this); - _game = new Game_v2(this); _map = new Map_v2(this); _goblin = new Goblin_v2(this); _scenery = new Scenery_v2(this); @@ -380,7 +382,6 @@ bool GobEngine::initGameParts() { _inter = new Inter_Bargon(this); _mult = new Mult_v2(this); _draw = new Draw_Bargon(this); - _game = new Game_v2(this); _map = new Map_v2(this); _goblin = new Goblin_v2(this); _scenery = new Scenery_v2(this); @@ -394,7 +395,6 @@ bool GobEngine::initGameParts() { _inter = new Inter_v3(this); _mult = new Mult_v2(this); _draw = new Draw_v2(this); - _game = new Game_v2(this); _map = new Map_v2(this); _goblin = new Goblin_v3(this); _scenery = new Scenery_v2(this); @@ -407,7 +407,6 @@ bool GobEngine::initGameParts() { _inter = new Inter_v3(this); _mult = new Mult_v2(this); _draw = new Draw_v2(this); - _game = new Game_v2(this); _map = new Map_v2(this); _goblin = new Goblin_v3(this); _scenery = new Scenery_v2(this); @@ -420,23 +419,18 @@ bool GobEngine::initGameParts() { _inter = new Inter_v4(this); _mult = new Mult_v2(this); _draw = new Draw_v2(this); - _game = new Game_v2(this); _map = new Map_v4(this); _goblin = new Goblin_v4(this); _scenery = new Scenery_v2(this); _saveLoad = new SaveLoad_v4(this, _targetName.c_str()); break; - case kGameTypePlaytoon: - case kGameTypePlaytnCk: - case kGameTypeBambou: case kGameTypeDynasty: _init = new Init_v3(this); _video = new Video_v2(this); _inter = new Inter_v5(this); _mult = new Mult_v2(this); _draw = new Draw_v2(this); - _game = new Game_v2(this); _map = new Map_v4(this); _goblin = new Goblin_v4(this); _scenery = new Scenery_v2(this); @@ -445,18 +439,32 @@ bool GobEngine::initGameParts() { case kGameTypeAdibou4: case kGameTypeUrban: - _init = new Init_v3(this); + _init = new Init_v6(this); _video = new Video_v6(this); _inter = new Inter_v6(this); _mult = new Mult_v2(this); _draw = new Draw_v2(this); - _game = new Game_v6(this); _map = new Map_v4(this); _goblin = new Goblin_v4(this); _scenery = new Scenery_v2(this); _saveLoad = new SaveLoad_v6(this, _targetName.c_str()); break; + case kGameTypePlaytoon: + case kGameTypePlaytnCk: + case kGameTypeBambou: + _init = new Init_v2(this); + _video = new Video_v2(this); +// _inter = new Inter_Playtoons(this); + _inter = new Inter_v6(this); + _mult = new Mult_v2(this); + _draw = new Draw_v2(this); + _map = new Map_v2(this); + _goblin = new Goblin_v2(this); + _scenery = new Scenery_v2(this); + _saveLoad = new SaveLoad_Playtoons(this); + break; + default: deinitGameParts(); return false; diff --git a/engines/gob/gob.h b/engines/gob/gob.h index 5d1cb3ecf2..02f6af51bf 100644 --- a/engines/gob/gob.h +++ b/engines/gob/gob.h @@ -108,6 +108,7 @@ enum GameType { kGameTypeBambou, kGameTypeFascination, kGameTypeGeisha, + kGameTypeMagicStones, kGameTypeAdibou4, kGameTypeAdibouUnknown }; @@ -119,7 +120,8 @@ enum Features { kFeaturesAdlib = 1 << 2, kFeatures640 = 1 << 3, kFeaturesSCNDemo = 1 << 4, - kFeaturesBATDemo = 1 << 5 + kFeaturesBATDemo = 1 << 5, + kFeatures800x600 = 1 << 6 }; enum { @@ -133,7 +135,7 @@ enum { kDebugSaveLoad = 1 << 7, kDebugGraphics = 1 << 8, kDebugVideo = 1 << 9, - kDebugCollisions = 1 << 10, + kDebugHotspots = 1 << 10, kDebugDemo = 1 << 11 }; @@ -216,6 +218,7 @@ public: bool hasAdlib() const; bool isSCNDemo() const; bool isBATDemo() const; + bool is800x600() const; bool isDemo() const; GobEngine(OSystem *syst); diff --git a/engines/gob/hotspots.cpp b/engines/gob/hotspots.cpp new file mode 100644 index 0000000000..b218634d4e --- /dev/null +++ b/engines/gob/hotspots.cpp @@ -0,0 +1,1976 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "gob/hotspots.h" +#include "gob/global.h" +#include "gob/helper.h" +#include "gob/draw.h" +#include "gob/game.h" +#include "gob/script.h" +#include "gob/inter.h" + +namespace Gob { + +Hotspots::Hotspot::Hotspot() { + clear(); +} + +Hotspots::Hotspot::Hotspot(uint16 i, + uint16 l, uint16 t, uint16 r, uint16 b, uint16 f, uint16 k, + uint16 enter, uint16 leave, uint16 pos) { + + id = i; + left = l; + top = t; + right = r; + bottom = b; + flags = f; + key = k; + funcEnter = enter; + funcLeave = leave; + funcPos = pos; + script = 0; +} + +void Hotspots::Hotspot::clear() { + id = 0; + left = 0xFFFF; + top = 0; + right = 0; + bottom = 0; + flags = 0; + key = 0; + funcEnter = 0; + funcLeave = 0; + funcPos = 0; + script = 0; +} + +Hotspots::Type Hotspots::Hotspot::getType() const { + return (Type) (flags & 0xF); +} + +MouseButtons Hotspots::Hotspot::getButton() const { + uint8 buttonBits = ((flags & 0x70) >> 4); + + if (buttonBits == 0) + return kMouseButtonsLeft; + if (buttonBits == 1) + return kMouseButtonsRight; + if (buttonBits == 2) + return kMouseButtonsAny; + + return kMouseButtonsNone; +} + +uint8 Hotspots::Hotspot::getWindow() const { + return (flags & 0x0F00) >> 8; +} + +uint8 Hotspots::Hotspot::getCursor() const { + return (flags & 0xF000) >> 12; +} + +uint8 Hotspots::Hotspot::getState(uint16 id) { + return (id & 0xF000) >> 12; +} + +uint8 Hotspots::Hotspot::getState() const { + return getState(id); +} + +bool Hotspots::Hotspot::isEnd() const { + return (left == 0xFFFF); +} + +bool Hotspots::Hotspot::isInput() const { + if (getType() < kTypeInput1NoLeave) + return false; + + if (getType() > kTypeInputFloatLeave) + return false; + + return true; +} + +bool Hotspots::Hotspot::isActiveInput() const { + if (isEnd()) + return false; + + if (!isFilledEnabled()) + return false; + + if (!isInput()) + return false; + + return true; +} + +bool Hotspots::Hotspot::isInputLeave() const { + if (!isInput()) + return false; + + if (!(getType() & 1)) + return true; + + return false; +} + +bool Hotspots::Hotspot::isFilled() const { + return getState() & kStateFilled; +} + +bool Hotspots::Hotspot::isFilledEnabled() const { + return (getState() & kStateFilledDisabled) == kStateFilled; +} + +bool Hotspots::Hotspot::isFilledNew() const { + return getState() == kStateFilled; +} + +bool Hotspots::Hotspot::isDisabled() const { + return getState() & kStateDisabled; +} + +bool Hotspots::Hotspot::isIn(uint16 x, uint16 y) const { + if (x < left) + return false; + if (x > right) + return false; + if (y < top) + return false; + if (y > bottom) + return false; + + return true; +} + +bool Hotspots::Hotspot::buttonMatch(MouseButtons button) const { + MouseButtons myButton = getButton(); + + if (myButton == kMouseButtonsAny) + // Any button allowed + return true; + + if (myButton == kMouseButtonsNone) + // No button allowed + return false; + + if (myButton == button) + // Exact match + return true; + + return false; +} + +void Hotspots::Hotspot::disable() { + id |= (kStateDisabled << 12); +} + +void Hotspots::Hotspot::enable() { + id &= ~(kStateDisabled << 12); +} + + +Hotspots::Hotspots(GobEngine *vm) : _vm(vm) { + _hotspots = new Hotspot[kHotspotCount]; + + _shouldPush = false; + + _currentKey = 0; + _currentIndex = 0; + _currentId = 0; +} + +Hotspots::~Hotspots() { + delete[] _hotspots; + + // Pop the whole stack and free each element's memory + while (!_stack.empty()) { + + StackEntry backup = _stack.pop(); + + delete[] backup.hotspots; + } +} + +void Hotspots::clear() { + _currentKey = 0; + + for (int i = 0; i < kHotspotCount; i++) + _hotspots[i].clear(); +} + +uint16 Hotspots::add(uint16 id, + uint16 left, uint16 top, uint16 right, uint16 bottom, + uint16 flags, uint16 key, + uint16 funcEnter, uint16 funcLeave, uint16 funcPos) { + + Hotspot hotspot(id, left, top, right, bottom, + flags, key, funcEnter, funcLeave, funcPos); + + return add(hotspot); +} + +uint16 Hotspots::add(const Hotspot &hotspot) { + for (int i = 0; i < kHotspotCount; i++) { + Hotspot &spot = _hotspots[i]; + + // free space => add same id => update + if (! (spot.isEnd() || (spot.id == hotspot.id))) + continue; + + // When updating, keep disabled state intact + uint16 id = hotspot.id; + if ((spot.id & ~(kStateDisabled << 12)) == + (hotspot.id & ~(kStateDisabled << 12))) + id = spot.id; + + // Set + spot = hotspot; + spot.id = id; + + // Remember the current script + spot.script = _vm->_game->_script; + + debugC(1, kDebugHotspots, "Adding hotspot %03d: %3d+%3d+%3d+%3d - %04X, %04X, %04X - %5d, %5d, %5d", + i, spot.left, spot.top, spot.right, spot.bottom, + spot.id, spot.key, spot.flags, spot.funcEnter, spot.funcLeave, spot.funcPos); + + return i; + } + + error("Hotspots::add(): Hotspot array full"); + return 0xFFFF; +} + +void Hotspots::remove(uint16 id) { + for (int i = 0; i < kHotspotCount; i++) { + if (_hotspots[i].id == id) { + debugC(1, kDebugHotspots, "Removing hotspot %d: %X", i, id); + _hotspots[i].clear(); + } + } +} + +void Hotspots::removeState(uint8 state) { + for (int i = 0; i < kHotspotCount; i++) { + Hotspot &spot = _hotspots[i]; + + if (spot.getState() == state) { + debugC(1, kDebugHotspots, "Removing hotspot %d: %X (by state %X)", i, spot.id, state); + spot.clear(); + } + } +} + +void Hotspots::recalculate(bool force) { + debugC(5, kDebugHotspots, "Recalculating hotspots"); + + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + Hotspot &spot = _hotspots[i]; + + if (!force && ((spot.flags & 0x80) != 0)) + // Not forcing a special hotspot + continue; + + if (spot.funcPos == 0) + // Simple coordinates don't need update + continue; + + // Setting the needed script + Script *curScript = _vm->_game->_script; + + _vm->_game->_script = spot.script; + if (!_vm->_game->_script) + _vm->_game->_script = curScript; + + // Calling the function that contains the positions + _vm->_game->_script->call(spot.funcPos); + + // Calculate positions + int16 left = _vm->_game->_script->readValExpr(); + int16 top = _vm->_game->_script->readValExpr(); + int16 width = _vm->_game->_script->readValExpr(); + int16 height = _vm->_game->_script->readValExpr(); + + // Re-read the flags too, if applicable + uint16 flags = 0; + if (spot.getState() == (kStateFilled | kStateType2)) + flags = _vm->_game->_script->readValExpr(); + + // Apply backDelta, if needed + if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) && (left != -1)) { + left += _vm->_draw->_backDeltaX; + top += _vm->_draw->_backDeltaY; + } + + // Clamping + if (left < 0) { + width += left; + left = 0; + } + if (top < 0) { + height += top; + top = 0; + } + + // Set the updated position + spot.left = left; + spot.top = top; + spot.right = left + width - 1; + spot.bottom = top + height - 1; + + if (spot.getState() == (kStateFilled | kStateType2)) + spot.flags = flags; + + // Return + _vm->_game->_script->pop(); + + _vm->_game->_script = curScript; + } +} + +void Hotspots::push(uint8 all, bool force) { + debugC(1, kDebugHotspots, "Pushing hotspots (%d, %d)", all, force); + + // Should we push at all? + if (!_shouldPush && !force) + return; + + // Count the hotspots + uint32 size = 0; + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + Hotspot &spot = _hotspots[i]; + + // Save all of them + if ( (all == 1) || + // Don't save the global ones + ((all == 0) && (spot.id >= 20)) || + // Only save disabled ones + ((all == 2) && ((spot.getState() == (kStateFilledDisabled | kStateType1)) || + (spot.getState() == (kStateDisabled)) || + (spot.getState() == (kStateFilledDisabled | kStateType2))))) { + size++; + } + + } + + StackEntry backup; + + backup.shouldPush = _shouldPush; + backup.size = size; + backup.key = _currentKey; + backup.id = _currentId; + backup.index = _currentIndex; + + backup.hotspots = new Hotspot[size]; + + // Copy the hotspots + Hotspot *destPtr = backup.hotspots; + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + Hotspot &spot = _hotspots[i]; + + // Save all of them + if ( (all == 1) || + // Don't save the global ones + ((all == 0) && (spot.id >= 20)) || + // Only save disabled ones + ((all == 2) && ((spot.getState() == (kStateFilledDisabled | kStateType1)) || + (spot.getState() == (kStateDisabled)) || + (spot.getState() == (kStateFilledDisabled | kStateType2))))) { + + memcpy(destPtr, &spot, sizeof(Hotspot)); + destPtr++; + + spot.clear(); + } + + } + + // Reset current state + _shouldPush = false; + _currentKey = 0; + _currentId = 0; + _currentIndex = 0; + + _stack.push(backup); +} + +void Hotspots::pop() { + debugC(1, kDebugHotspots, "Popping hotspots"); + + assert(!_stack.empty()); + + StackEntry backup = _stack.pop(); + + // Find the end of the filled hotspot space + int i; + Hotspot *destPtr = _hotspots; + for (i = 0; i < kHotspotCount; i++, destPtr++) + if (destPtr->isEnd()) + break; + + if (((uint32) (kHotspotCount - i)) < backup.size) + error("Hotspots::pop(): Not enough free space in the current Hotspot " + "array to pop %d elements (got %d)", backup.size, kHotspotCount - i); + + // Copy + memcpy(destPtr, backup.hotspots, backup.size * sizeof(Hotspot)); + + _shouldPush = backup.shouldPush; + _currentKey = backup.key; + _currentId = backup.id; + _currentIndex = backup.index; + + delete[] backup.hotspots; +} + +bool Hotspots::isValid(uint16 key, uint16 id, uint16 index) const { + if (index >= kHotspotCount) + return false; + + if (key == 0) + return false; + + if (!(Hotspot::getState(id) & kStateFilled)) + return false; + + return true; +} + +void Hotspots::call(uint16 offset) { + debugC(4, kDebugHotspots, "Calling hotspot function %d", offset); + + _vm->_game->_script->call(offset); + + _shouldPush = true; + + int16 stackSize = _stack.size(); + + _vm->_inter->funcBlock(0); + + while (stackSize != _stack.size()) + pop(); + + _shouldPush = false; + + _vm->_game->_script->pop(); + + recalculate(false); +} + +void Hotspots::enter(uint16 index) { + debugC(2, kDebugHotspots, "Entering hotspot %d", index); + + if (index >= kHotspotCount) { + warning("Hotspots::enter(): Index %d out of range", index); + return; + } + + Hotspot &spot = _hotspots[index]; + + // If requested, write the ID into a variable + if ((spot.getState() == (kStateFilled | kStateType1)) || + (spot.getState() == (kStateFilled | kStateType2))) + WRITE_VAR(17, -(spot.id & 0x0FFF)); + + if (spot.funcEnter != 0) + call(spot.funcEnter); +} + +void Hotspots::leave(uint16 index) { + debugC(2, kDebugHotspots, "Leaving hotspot %d", index); + + if (index >= kHotspotCount) { + warning("Hotspots::leave(): Index %d out of range", index); + return; + } + + Hotspot &spot = _hotspots[index]; + + // If requested, write the ID into a variable + if ((spot.getState() == (kStateFilled | kStateType1)) || + (spot.getState() == (kStateFilled | kStateType2))) + WRITE_VAR(17, spot.id & 0x0FFF); + + if (spot.funcLeave != 0) + call(spot.funcLeave); +} + +uint16 Hotspots::checkMouse(Type type, uint16 &id, uint16 &index) const { + id = 0; + index = 0; + + if (type == kTypeMove) { + // Check where the mouse was moved to + + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + const Hotspot &spot = _hotspots[i]; + + if (spot.isDisabled()) + // Only consider enabled hotspots + continue; + + if (spot.getType() > kTypeMove) + // Only consider click and move hotspots + continue; + + if (spot.getWindow() != 0) + // Only check the main window + continue; + + if (!spot.isIn(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY)) + // If we're not in it, ignore it + continue; + + id = spot.id; + index = i; + + return spot.key; + } + + return 0; + + } else if (type == kTypeClick) { + // Check if something was clicked + + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + const Hotspot &spot = _hotspots[i]; + + if (spot.isDisabled()) + // Only consider enabled hotspots + continue; + + if (spot.getWindow() != 0) + // Only check the main window + continue; + + if (spot.getType() < kTypeMove) + // Only consider hotspots that can be clicked + continue; + + if (!spot.isIn(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY)) + // If we're not in it, ignore it + continue; + + if (!spot.buttonMatch(_vm->_game->_mouseButtons)) + // Don't follow hotspots with button requirements we don't meet + continue; + + id = spot.id; + index = i; + + if ((spot.getType() == kTypeMove) || (spot.getType() == kTypeClick)) + // It's a move or click => return the key + return spot.key; + + // Otherwise, the key has a different meaning, so ignore it + return 0; + } + + if (_vm->_game->_mouseButtons != kMouseButtonsLeft) + // Let the right mouse button act as an escape key + return kKeyEscape; + + return 0; + + } + + return 0; +} + +bool Hotspots::checkHotspotChanged() { + uint16 key, id, index; + + // Get the current hotspot + key = checkMouse(kTypeMove, id, index); + + if (key == _currentKey) + // Nothing changed => nothing to do + return false; + + // Leave the old area + if (isValid(_currentKey, _currentId,_currentIndex)) + leave(_currentIndex); + + _currentKey = key; + _currentId = id; + _currentIndex = index; + + // Enter the new one + if (isValid(key, id, index)) + enter(index); + + return true; +} + +uint16 Hotspots::check(uint8 handleMouse, int16 delay, uint16 &id, uint16 &index) { + _vm->_game->_scrollHandleMouse = handleMouse != 0; + + if (delay >= -1) { + _currentKey = 0; + _currentId = 0; + _currentIndex = 0; + } + + id = 0; + index = 0; + + if (handleMouse) { + if ((_vm->_draw->_cursorIndex == -1) && (_currentKey == 0)) { + // Last know state: No hotspot hit. Look if that changed + + _currentKey = checkMouse(kTypeMove, _currentId, _currentIndex); + + if (isValid(_currentKey, _currentId, _currentIndex)) + enter(_currentIndex); + } + + _vm->_draw->animateCursor(-1); + } + + uint32 startTime = _vm->_util->getTimeKey(); + + // Update display + _vm->_draw->blitInvalidated(); + _vm->_video->waitRetrace(); + + uint16 key = 0; + while (key == 0) { + + if (_vm->_inter->_terminate || _vm->shouldQuit()) { + if (handleMouse) + _vm->_draw->blitCursor(); + return 0; + } + + // Anything changed? + checkHotspotChanged(); + + // Update display + if (!_vm->_draw->_noInvalidated) { + if (handleMouse) + _vm->_draw->animateCursor(-1); + else + _vm->_draw->blitInvalidated(); + _vm->_video->waitRetrace(); + } + + // Update keyboard and mouse state + key = _vm->_game->checkKeys(&_vm->_global->_inter_mouseX, + &_vm->_global->_inter_mouseY, &_vm->_game->_mouseButtons, handleMouse); + + if (!handleMouse && (_vm->_game->_mouseButtons != kMouseButtonsNone)) { + // We don't want any mouse input but got one => Wait till it went away + + _vm->_util->waitMouseRelease(0); + key = 3; + } + + if (key != 0) { + // Got a key press + + if (handleMouse & 1) + _vm->_draw->blitCursor(); + + id = 0; + index = 0; + + // Leave the current hotspot + if (isValid(_currentKey, _currentId, _currentIndex)) + leave(_currentIndex); + + _currentKey = 0; + break; + } + + if (handleMouse) { + + if (_vm->_game->_mouseButtons != kMouseButtonsNone) { + // Mouse button pressed + + if (delay > 0) { + // If a delay was requested, wait the specified time + + _vm->_draw->animateCursor(2); + _vm->_util->delay(delay); + } else if (handleMouse & 1) + _vm->_util->waitMouseRelease(1); + + _vm->_draw->animateCursor(-1); + + // Which region was clicked? + key = checkMouse(kTypeClick, id, index); + + if ((key != 0) || (id != 0)) { + // Got a valid region + + if ( (handleMouse & 1) && + ((delay <= 0) || (_vm->_game->_mouseButtons == kMouseButtonsNone))) + _vm->_draw->blitCursor(); + + // If the hotspot changed, leave the old one + if (key != _currentKey) + leave(_currentIndex); + + _currentKey = 0; + break; + } + + if (handleMouse & 4) + // Nothing further than one simple check was requested => return + return 0; + + // Leave the current area + if (_currentKey != 0) + leave(_currentIndex); + + // No click, but do we have a move event? If so, enter that hotspot + _currentKey = checkMouse(kTypeMove, _currentId, _currentIndex); + if (isValid(_currentKey, _currentId, _currentIndex)) + enter(_currentIndex); + + } else + // No mouse button pressed, check whether the position changed at least + checkHotspotChanged(); + } + + if ((delay == -2) && (key == 0) && + (_vm->_game->_mouseButtons == kMouseButtonsNone)) { + // Nothing found and no further handling requested. Return. + + id = 0; + index = 0; + break; + } + + if (handleMouse) + _vm->_draw->animateCursor(-1); + + if ((delay < 0) && (key == 0) && + (_vm->_game->_mouseButtons == kMouseButtonsNone)) { + + // Look if we've maybe reached the timeout + + uint32 curTime = _vm->_util->getTimeKey(); + if ((curTime + delay) > startTime) { + // If so, return + + id = 0; + index = 0; + break; + } + + } + + // Sleep for a short amount of time + _vm->_util->delay(10); + + } + + return key; +} + +uint16 Hotspots::check(uint8 handleMouse, int16 delay) { + uint16 id, index; + + // Check and ignore the id and index + return Hotspots::check(handleMouse, delay, id, index); +} + +uint16 Hotspots::updateInput(uint16 xPos, uint16 yPos, uint16 width, uint16 height, + uint16 backColor, uint16 frontColor, char *str, uint16 fontIndex, + Type type, int16 &duration, uint16 &id, uint16 &index) { + + if ((fontIndex >= Draw::kFontCount) || !_vm->_draw->_fonts[fontIndex]) { + warning("Hotspots::updateInput(): Invalid font specified: %d", fontIndex); + return 0; + } + + // Check if we need to consider mouse events + bool handleMouse = false; + if ( (_vm->_game->_handleMouse != 0) && + ((_vm->_global->_useMouse != 0) || (_vm->_game->_forceHandleMouse != 0))) + handleMouse = true; + + const Font &font = *_vm->_draw->_fonts[fontIndex]; + + // Current position in the string, preset to the end + uint32 pos = strlen(str); + /* Size of input field in characters. + * If the font is not monospaced, we can't know that */ + uint32 editSize = font.isMonospaced() ? (width / font.getCharWidth()) : 0; + + uint16 key = 0; + char tempStr[256]; + + while (1) { + // If we the edit field has enough space, add a space for the new character + strncpy0(tempStr, str, 254); + strcat(tempStr, " "); + if ((editSize != 0) && strlen(tempStr) > editSize) + strncpy0(tempStr, str, 255); + + // Clear input area + fillRect(xPos, yPos, + font.isMonospaced() ? (editSize * font.getCharWidth()) : width, height, + backColor); + + // Print the current string, vertically centered + printText(xPos, yPos + (height - font.getCharHeight()) / 2, + tempStr, fontIndex, frontColor); + + // If we've reached the end of the input field, set the cursor to the last character + if ((editSize != 0) && (pos == editSize)) + pos--; + + // The character under the cursor + char curSym = tempStr[pos]; + + if (_vm->_inter->_variables) + WRITE_VAR(56, pos); + + bool first = true; + while (1) { + tempStr[0] = curSym; + tempStr[1] = 0; + + // Draw cursor + uint16 cursorX, cursorY, cursorWidth, cursorHeight; + getTextCursorPos(font, str, pos, xPos, yPos, width, height, + cursorX, cursorY, cursorWidth, cursorHeight); + fillRect(cursorX, cursorY, cursorWidth, cursorHeight, frontColor); + + if (first) { + // The first time, purge old information too + key = check(handleMouse, -1, id, index); + + if (key == 0) + // We didn't catch any input, let's try again with a real timeout + key = check(handleMouse, -300, id, index); + + first = false; + } else + // Try to catch a character + key = check(handleMouse, -300, id, index); + + tempStr[0] = curSym; + tempStr[1] = 0; + + // Clear cursor + getTextCursorPos(font, str, pos, xPos, yPos, width, height, + cursorX, cursorY, cursorWidth, cursorHeight); + fillRect(cursorX, cursorY, cursorWidth, cursorHeight, backColor); + + // Print the current string, vertically centered + printText(cursorX, yPos + (height - font.getCharHeight()) / 2, + tempStr, fontIndex, frontColor); + + if ((key != 0) || (id != 0)) + // We did get a key, stop looking + break; + + // Try again + key = check(handleMouse, -300, id, index); + + if ((key != 0) || (id != 0) || + _vm->_inter->_terminate || _vm->shouldQuit()) + // We did get a key, stop looking + break; + + if (duration > 0) { + // Look if we reached the time limit + duration -= 600; + if (duration <= 1) { + // If so, abort + key = 0; + id = 0; + break; + } + } + } + + if ((key == 0) || (id != 0) || + _vm->_inter->_terminate || _vm->shouldQuit()) + // Got no key, or a region ID instead, return + return 0; + + switch (key) { + case kKeyRight: + // If possible, move the cursor right + if (((editSize != 0) && ((pos > strlen(str)) || (pos > (editSize - 1)))) || + ((editSize == 0) && (pos > strlen(str)))) { + pos++; + continue; + } + // Continue downwards instead + return kKeyDown; + + case kKeyLeft: + // If possible, move the cursor left + if (pos > 0) { + pos--; + continue; + } + // Continue upwards instead + return kKeyUp; + + case kKeyBackspace: + if (pos > 0) { + // Delete the character to the left + _vm->_util->cutFromStr(str, pos - 1, 1); + pos--; + continue; + } else { + if (pos < strlen(str)) + // Delete the character to the right + _vm->_util->cutFromStr(str, pos, 1); + } + + case kKeyDelete: + if (pos >= strlen(str)) + continue; + + // Delete the character to the right + _vm->_util->cutFromStr(str, pos, 1); + continue; + + case kKeyReturn: + case kKeyF1: + case kKeyF2: + case kKeyF3: + case kKeyF4: + case kKeyF5: + case kKeyF6: + case kKeyF7: + case kKeyF8: + case kKeyF9: + case kKeyF10: + case kKeyUp: + case kKeyDown: + return key; + + case kKeyEscape: + // If we got an escape event, wait until the mouse buttons have been released + if (_vm->_global->_useMouse != 0) + continue; + + _vm->_game->_forceHandleMouse = !_vm->_game->_forceHandleMouse; + + handleMouse = false; + if ( (_vm->_game->_handleMouse != 0) && + ((_vm->_global->_useMouse != 0) || (_vm->_game->_forceHandleMouse != 0))) + handleMouse = true; + + while (_vm->_global->_pressedKeys[1] != 0); + continue; + + default: + // Got a "normal" key + + uint16 savedKey = key; + + key &= 0xFF; + + if (((type == kTypeInputFloatNoLeave) || (type == kTypeInputFloatLeave)) && + (key >= ' ') && (key <= 0xFF)) { + + // Only allow character found in numerical floating values + + const char *str1 = "0123456789-.,+ "; + const char *str2 = "0123456789-,,+ "; + + if ((((savedKey >> 8) > 1) && ((savedKey >> 8) < 12)) && + ((_vm->_global->_pressedKeys[42] != 0) || + (_vm->_global->_pressedKeys[56] != 0))) + key = ((savedKey >> 8) - 1) % 10 + '0'; + + int i; + for (i = 0; str1[i] != 0; i++) { + if (key == str1[i]) { + key = str2[i]; + break; + } + } + + if (i == (int16) strlen(str1)) + key = 0; + } + + if ((key >= ' ') && (key <= 0xFF)) { + if (editSize == 0) { + // Length of the string + current character + next one + int length = _vm->_draw->stringLength(str, fontIndex) + + font.getCharWidth(' ') + font.getCharWidth(key); + + if (length > width) + // We're above the limit, ignore the key + continue; + + if (((int32) strlen(str)) >= (_vm->_global->_inter_animDataSize * 4 - 1)) + // Above the limit of character allowed in a string, ignore the key + continue; + + } else { + if (strlen(str) > editSize) + // We're over the upper character limit for this field + continue; + else if (editSize == strlen(str)) + // We've reached the upper limit, overwrite the last character + _vm->_util->cutFromStr(str, strlen(str) - 1, 1); + } + + // Advance cursor + pos++; + tempStr[0] = key; + tempStr[1] = 0; + + // Add character + _vm->_util->insertStr(tempStr, str, pos - 1); + } + + } + } +} + +uint16 Hotspots::handleInputs(int16 time, uint16 inputCount, uint16 &curInput, + InputDesc *inputs, uint16 &id, uint16 &index) { + + // Redraw all texts in all inputs we currently manage + updateAllTexts(inputs); + + for (int i = 0; i < 40; i++) + WRITE_VAR(17 + i, 0); + + while (1) { + // Find the hotspot index to our current input + uint16 hotspotIndex = inputToHotspot(curInput); + + assert(hotspotIndex != 0xFFFF); + + Hotspot inputSpot = _hotspots[hotspotIndex]; + + // Handle input events from that input field + uint16 key = updateInput(inputSpot.left, inputSpot.top, + inputSpot.right - inputSpot.left + 1, + inputSpot.bottom - inputSpot.top + 1, + inputs[curInput].backColor, inputs[curInput].frontColor, + GET_VARO_STR(inputSpot.key), inputs[curInput].fontIndex, + inputSpot.getType(), time, id, index); + + if (_vm->_inter->_terminate) + return 0; + + switch (key) { + case kKeyNone: + if (id == 0) + // No key and no hotspot => return + return 0; + + if (_vm->_game->_mouseButtons != kMouseButtonsNone) + // Clicked something, get the hotspot index + index = findClickedInput(index); + + if (!_hotspots[index].isInput()) + // It's no input, return + return 0; + + // Get the associated input index + curInput = hotspotToInput(index); + break; + + case kKeyF1: + case kKeyF2: + case kKeyF3: + case kKeyF4: + case kKeyF5: + case kKeyF6: + case kKeyF7: + case kKeyF8: + case kKeyF9: + case kKeyF10: + return key; + + case kKeyReturn: + // Just one input => return + if (inputCount == 1) + return kKeyReturn; + + // End of input chain reached => wrap + if (curInput == (inputCount - 1)) { + curInput = 0; + break; + } + + // Next input + curInput++; + break; + + case kKeyDown: + // Next input + if ((inputCount - 1) > curInput) + curInput++; + break; + + case kKeyUp: + // Previous input + if (curInput > 0) + curInput--; + break; + } + } +} + +void Hotspots::evaluateNew(uint16 i, uint16 *ids, InputDesc *inputs, + uint16 &inputId, bool &hasInput, uint16 &inputCount) { + + ids[i] = 0; + + // Type and window + byte type = _vm->_game->_script->readByte(); + byte window = 0; + + if ((type & 0x40) != 0) { + // Got a window ID + + type -= 0x40; + window = _vm->_game->_script->readByte(); + } + + // Coordinates + uint16 left, top, width, height, right, bottom; + uint32 funcPos = 0; + if ((type & 0x80) != 0) { + // Complex coordinate expressions + funcPos = _vm->_game->_script->pos(); + left = _vm->_game->_script->readValExpr(); + top = _vm->_game->_script->readValExpr(); + width = _vm->_game->_script->readValExpr(); + height = _vm->_game->_script->readValExpr(); + } else { + // Immediate values + funcPos = 0; + left = _vm->_game->_script->readUint16(); + top = _vm->_game->_script->readUint16(); + width = _vm->_game->_script->readUint16(); + height = _vm->_game->_script->readUint16(); + } + type &= 0x7F; + + // Apply global drawing offset + if ((_vm->_draw->_renderFlags & RENDERFLAG_CAPTUREPOP) && (left != 0xFFFF)) { + left += _vm->_draw->_backDeltaX; + top += _vm->_draw->_backDeltaY; + } + + right = left + width - 1; + bottom = top + height - 1; + + // Enabling the hotspots again + if ((type == kTypeEnable2) || (type == kTypeEnable1)) { + uint8 wantedState = 0; + if (type == kTypeEnable2) + wantedState = kStateFilledDisabled | kStateType2; + else + wantedState = kStateFilledDisabled | kStateType1; + + _vm->_game->_script->skip(6); + + for (int j = 0; j < kHotspotCount; j++) { + Hotspot &spot = _hotspots[j]; + + if (spot.getState() == wantedState) { + spot.enable(); + spot.funcEnter = _vm->_game->_script->pos(); + spot.funcLeave = _vm->_game->_script->pos(); + } + } + + _vm->_game->_script->skipBlock(); + + return; + } + + int16 key = 0; + int16 flags = 0; + Font *font = 0; + uint32 funcEnter = 0, funcLeave = 0; + + // Evaluate parameters for the new hotspot + switch (type) { + case kTypeNone: + _vm->_game->_script->skip(6); + + funcEnter = _vm->_game->_script->pos(); + _vm->_game->_script->skipBlock(); + + funcLeave = _vm->_game->_script->pos(); + _vm->_game->_script->skipBlock(); + + key = i + ((kStateFilled | kStateType2) << 12); + flags = type + (window << 8); + break; + + case kTypeMove: + key = _vm->_game->_script->readInt16(); + ids[i] = _vm->_game->_script->readInt16(); + flags = _vm->_game->_script->readInt16(); + + funcEnter = _vm->_game->_script->pos(); + _vm->_game->_script->skipBlock(); + + funcLeave = _vm->_game->_script->pos(); + _vm->_game->_script->skipBlock(); + + if (key == 0) + key = i + ((kStateFilled | kStateType2) << 12); + + flags = type + (window << 8) + (flags << 4); + break; + + case kTypeInput1NoLeave: + case kTypeInput1Leave: + case kTypeInput2NoLeave: + case kTypeInput2Leave: + case kTypeInput3NoLeave: + case kTypeInput3Leave: + case kTypeInputFloatNoLeave: + case kTypeInputFloatLeave: + hasInput = true; + + _vm->_util->clearKeyBuf(); + + // Input text parameters + key = _vm->_game->_script->readVarIndex(); + inputs[inputCount].fontIndex = _vm->_game->_script->readInt16(); + inputs[inputCount].backColor = _vm->_game->_script->readByte(); + inputs[inputCount].frontColor = _vm->_game->_script->readByte(); + inputs[inputCount].length = 0; + inputs[inputCount].str = 0; + + if ((type >= kTypeInput2NoLeave) && (type <= kTypeInput3Leave)) { + uint16 length = _vm->_game->_script->readUint16(); + + inputs[inputCount].str = + (const char *) (_vm->_game->_script->getData() + _vm->_game->_script->pos()); + + _vm->_game->_script->skip(length); + } + + if (left == 0xFFFF) { + if (!(type & 1)) + // No coordinates but a leave block => skip it + _vm->_game->_script->skipBlock(); + break; + } + + font = _vm->_draw->_fonts[inputs[inputCount].fontIndex]; + if (font->isMonospaced()) + right = left + width * font->getCharWidth() - 1; + + funcEnter = 0; + funcPos = 0; + funcLeave = 0; + if (!(type & 1)) { + // Got a leave + funcLeave = _vm->_game->_script->pos(); + _vm->_game->_script->skipBlock(); + } + + flags = type; + + inputCount++; + break; + + case 20: + inputId = i; + // Fall through to case 2 + case kTypeClick: + key = _vm->_game->_script->readInt16(); + ids[i] = _vm->_game->_script->readInt16(); + flags = _vm->_game->_script->readInt16(); + + funcEnter = 0; + + funcLeave = _vm->_game->_script->pos(); + _vm->_game->_script->skipBlock(); + + flags = ((uint16) kTypeClick) + (window << 8) + (flags << 4); + break; + + case kTypeClickEnter: + key = _vm->_game->_script->readInt16(); + ids[i] = _vm->_game->_script->readInt16(); + flags = _vm->_game->_script->readInt16() & 3; + + funcEnter = _vm->_game->_script->pos(); + _vm->_game->_script->skipBlock(); + + funcLeave = 0; + + flags = ((uint16) kTypeClick) + (window << 8) + (flags << 4); + break; + } + + // Add the new hotspot + add(i | (kStateFilled << 12), left, top, right, bottom, + flags, key, funcEnter, funcLeave, funcPos); +} + +bool Hotspots::evaluateFind(uint16 key, int16 timeVal, const uint16 *ids, + uint16 hotspotIndex1, uint16 hotspotIndex2, uint16 endIndex, + int16 &duration, uint16 &id, uint16 &index, bool &finished) { + + if (id != 0) + // We already found a hotspot, nothing to do + return true; + + if (key != 0) { + // We've got a key + + // Find the hotspot with that key associated + findKey(key, id, index); + if (id != 0) + // Found it + return true; + + // Try it case insensitively + findKeyCaseInsensitive(key, id, index); + if (id != 0) + // Found it + return true; + + return false; + } + + if (duration != 0) { + // We've got a time duration + + if (hotspotIndex1 != 0) { + finished = + leaveNthPlain(hotspotIndex1, endIndex, timeVal, ids, id, index, duration); + } else if (hotspotIndex2 != 0) { + findNthPlain(hotspotIndex2, endIndex, id, index); + } else { + findNthPlain(0, 0, id, index); + + // Leave the current hotspot + if ((_currentKey != 0) && (_hotspots[_currentIndex].funcLeave != 0)) + call(_hotspots[_currentIndex].funcLeave); + + _currentKey = 0; + } + + if (id != 0) + return true; + + return false; + } + + return false; +} + +void Hotspots::evaluate() { + InputDesc inputs[20]; + uint16 ids[kHotspotCount]; + + // Push all local hotspots + push(0); + + // Find the current end of the hotspot block + uint16 endIndex = 0; + while (!_hotspots[endIndex].isEnd()) + endIndex++; + + _shouldPush = false; + + _vm->_game->_script->skip(1); + + // Number of new hotspots + byte count = _vm->_game->_script->readByte(); + + // Parameters of this block + _vm->_game->_handleMouse = _vm->_game->_script->peekByte(0); + int16 duration = _vm->_game->_script->peekByte(1); + byte hotspotIndex1 = _vm->_game->_script->peekByte(3); + byte hotspotIndex2 = _vm->_game->_script->peekByte(4); + bool needRecalculation = _vm->_game->_script->peekByte(5) != 0; + + // Seconds -> Milliseconds + duration *= 1000; + + if ((hotspotIndex1 != 0) || (hotspotIndex2 != 0)) { + duration /= 100; + if (_vm->_game->_script->peekByte(1) == 100) + duration = 2; + } + + int16 timeVal = duration; + + _vm->_game->_script->skip(6); + + setCurrentHotspot(0, 0); + + bool finishedDuration = false; + + uint16 id = 0; + uint16 inputId = 0xFFFF; + uint16 index = 0; + + bool hasInput = false; + uint16 inputCount = 0; + + // Adding new hotspots + for (uint16 i = 0; i < count; i++) + evaluateNew(i, ids, inputs, inputId, hasInput, inputCount); + + // Recalculate all hotspots if requested + if (needRecalculation) + recalculate(true); + + _vm->_game->_forceHandleMouse = 0; + _vm->_util->clearKeyBuf(); + + while ((id == 0) && !_vm->_inter->_terminate && !_vm->shouldQuit()) { + uint16 key = 0; + if (hasInput) { + // Input + + uint16 curInput = 0; + + key = handleInputs(duration, inputCount, curInput, inputs, id, index); + + // Notify the script of the current input index + WRITE_VAR(17 + 38, curInput); + if (key == kKeyReturn) { + // Return pressed, invoke input leave + findFirstInputLeave(id, inputId, index); + break; + } + } else + // Normal move or click check + key = check(_vm->_game->_handleMouse, -duration, id, index); + + key = convertSpecialKey(key); + + // Try to find a fitting hotspot + Hotspots::evaluateFind(key, timeVal, ids, hotspotIndex1, hotspotIndex2, endIndex, + duration, id, index, finishedDuration); + + if (finishedDuration) + break; + + if ((id == 0) || (_hotspots[index].funcLeave != 0)) + // We don't have a new ID, but haven't yet handled the leave function + continue; + + _vm->_inter->storeMouse(); + + setCurrentHotspot(ids, id); + + // Enter it + if (_hotspots[index].funcEnter != 0) + call(_hotspots[index].funcEnter); + + setCurrentHotspot(0, 0); + id = 0; + } + + if ((id & 0xFFF) == inputId) + matchInputStrings(inputs); + + if (_vm->_game->_handleMouse == 1) + _vm->_draw->blitCursor(); + + if (!_vm->_inter->_terminate && (!finishedDuration)) { + _vm->_game->_script->seek(_hotspots[index].funcLeave); + + _vm->_inter->storeMouse(); + if (getCurrentHotspot() == 0) { + // No hotspot currently handled, now we'll handle the newly found one + + setCurrentHotspot(ids, id); + } + } else + _vm->_game->_script->setFinished(true); + + for (int i = 0; i < count; i++) + // Remove all local hotspots + remove(i + (kStateFilled << 12)); + + for (int i = 0; i < kHotspotCount; i++) { + Hotspot &spot = _hotspots[i]; + + // Disable the ones still there + if ((spot.getState() == (kStateFilled | kStateType1)) || + (spot.getState() == (kStateFilled | kStateType2))) + spot.disable(); + } + +} + +int16 Hotspots::findCursor(uint16 x, uint16 y) const { + int16 cursor = 0; + + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + const Hotspot &spot = _hotspots[i]; + + if ((spot.getWindow() != 0) || spot.isDisabled()) + // Ignore disabled and non-main-windowed hotspots + continue; + + if (!spot.isIn(x, y)) + // We're not in that hotspot, ignore it + continue; + + if (spot.getCursor() == 0) { + // Hotspot doesn't itself specify a cursor... + if (spot.getType() >= kTypeInput1NoLeave) { + // ...but the type has a generic one + cursor = 3; + break; + } else if ((spot.getButton() != kMouseButtonsRight) && (cursor == 0)) + // ...but there's a generic "click" cursor + cursor = 1; + } else if (cursor == 0) + // Hotspot had an attached cursor index + cursor = spot.getCursor(); + } + + return cursor; +} + +uint16 Hotspots::inputToHotspot(uint16 input) const { + uint16 inputIndex = 0; + for (int i = 0; i < kHotspotCount; i++) { + const Hotspot &spot = _hotspots[i]; + + if (!spot.isActiveInput()) + // Not an active input + continue; + + if (inputIndex == input) + // We've found our input + return i; + + // Next one + inputIndex++; + } + + // None found + return 0xFFFF; +} + +uint16 Hotspots::hotspotToInput(uint16 hotspot) const { + uint16 input = 0; + + for (int i = 0; i < kHotspotCount; i++) { + const Hotspot &spot = _hotspots[i]; + + if (!spot.isActiveInput()) + // Not an active input + continue; + + if (i == hotspot) + // We've found our hotspot + break; + + // Next one + input++; + } + + return input; +} + +uint16 Hotspots::findClickedInput(uint16 index) const { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + const Hotspot &spot = _hotspots[i]; + + if (spot.getWindow() != 0) + // Ignore other windows + continue; + + if (spot.isDisabled()) + // Ignore disabled hotspots + continue; + + if (!spot.isIn(_vm->_global->_inter_mouseX, _vm->_global->_inter_mouseY)) + // This one wasn't it + continue; + + if (spot.getCursor() != 0) + // This one specifies a cursor, so we don't want it + continue; + + if (!spot.isInput()) + // It's no input + continue; + + index = i; + break; + } + + return index; +} + +bool Hotspots::findFirstInputLeave(uint16 &id, uint16 &inputId, uint16 &index) const { + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + const Hotspot &spot = _hotspots[i]; + + if (!spot.isFilledEnabled()) + // Not filled or disabled + continue; + + if (!spot.isInputLeave()) + // Not an input with a leave function + continue; + + id = spot.id; + inputId = spot.id & 0x7FFF; + index = i; + return true; + } + + return false; +} + +bool Hotspots::findKey(uint16 key, uint16 &id, uint16 &index) const { + id = 0; + index = 0; + + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + const Hotspot &spot = _hotspots[i]; + + if (!spot.isFilledEnabled()) + // Not filled or disabled + continue; + + // Key match Catch all + if ((spot.key == key) || (spot.key == 0x7FFF)) { + id = spot.id; + index = i; + return true; + } + } + + return false; +} + +bool Hotspots::findKeyCaseInsensitive(uint16 key, uint16 &id, uint16 &index) const { + id = 0; + index = 0; + + for (int i = 0; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + const Hotspot &spot = _hotspots[i]; + + if (!spot.isFilledEnabled()) + // Not filled or disabled, ignore + continue; + + if ((spot.key & 0xFF00) != 0) + continue; + + if (spot.key == 0) + // No associated key, ignore + continue; + + // Compare + if (toupper(key & 0xFF) == toupper(spot.key)) { + id = spot.id; + index = i; + return true; + } + } + + return false; +} + +bool Hotspots::findNthPlain(uint16 n, uint16 startIndex, uint16 &id, uint16 &index) const { + id = 0; + index = 0; + + uint16 counter = 0; + for (int i = startIndex; (i < kHotspotCount) && !_hotspots[i].isEnd(); i++) { + const Hotspot &spot = _hotspots[i]; + + if (!spot.isFilledNew()) + // Not filled, ignore + continue; + + if (++counter != n) + // Not yet the one we want + continue; + + id = spot.id; + index = i; + return true; + } + + return false; +} + +bool Hotspots::leaveNthPlain(uint16 n, uint16 startIndex, int16 timeVal, const uint16 *ids, + uint16 &id, uint16 &index, int16 &duration) { + + id = 0; + index = 0; + + if (!findNthPlain(n, startIndex, id, index)) + // Doesn't exist + return false; + + _vm->_inter->storeMouse(); + + if (getCurrentHotspot() != 0) + // We already handle a hotspot + return false; + + setCurrentHotspot(ids, id); + + const Hotspot &spot = _hotspots[index]; + if (spot.funcLeave != 0) { + // It has a leave function + + uint32 startTime, callTime; + + // Call the leave and time it + startTime = _vm->_util->getTimeKey(); + call(spot.funcLeave); + callTime = _vm->_util->getTimeKey() - startTime; + + // Remove the time it took from the time we have available + duration = CLIP<int>(timeVal - callTime, 2, timeVal); + } + + if (getCurrentHotspot() == 0) { + id = 0; + index = 0; + } + + return getCurrentHotspot() != 0; +} + +void Hotspots::setCurrentHotspot(const uint16 *ids, uint16 id) const { + if (!ids) { + WRITE_VAR(16, 0); + return; + } + + if (Hotspot::getState(id) == kStateFilled) + WRITE_VAR(16, ids[id & 0xFFF]); + else + WRITE_VAR(16, id & 0xFFF); +} + +uint32 Hotspots::getCurrentHotspot() const { + return VAR(16); +} + +void Hotspots::cleanFloatString(const Hotspot &spot) const { + char *to, *from; + + to = from = GET_VARO_STR(spot.key); + for (int i = 0; (i < 257) && (*from != '\0'); i++, from++) { + char c = *from; + + // Skip spaces + if (c == ' ') + continue; + + // Convert decimal separator if necessary + if ((_vm->_global->_language == kLanguageBritish) && (c == '.')) + c = ','; + + *to++ = c; + } + + *to = '\0'; +} + +void Hotspots::checkStringMatch(const Hotspot &spot, const InputDesc &input, + uint16 inputPos) const { + + const char *str = input.str; + + char tempStr[256]; + char spotStr[256]; + + strncpy0(tempStr, GET_VARO_STR(spot.key), 255); + + if (spot.getType() < kTypeInput3NoLeave) + _vm->_util->cleanupStr(tempStr); + + uint16 pos = 0; + do { + strncpy0(spotStr, str, 255); + + pos += strlen(str) + 1; + str += strlen(str) + 1; + + if (spot.getType() < kTypeInput3NoLeave) + _vm->_util->cleanupStr(spotStr); + + // Compare the entered string with the string we wanted + if (strcmp(tempStr, spotStr) == 0) { + WRITE_VAR(17, VAR(17) + 1); + WRITE_VAR(17 + inputPos, 1); + break; + } + } while (input.length > pos); +} + +void Hotspots::matchInputStrings(const InputDesc *inputs) const { + uint16 strInputCount = 0; + uint16 inputIndex = 0; + uint16 inputPos = 1; + + for (int i = 0; i < kHotspotCount; i++) { + const Hotspot &spot = _hotspots[i]; + + // Looking for all enabled inputs + if (spot.isEnd()) + continue; + if (!spot.isFilledEnabled()) + continue; + if (!spot.isInput()) + continue; + + if (spot.getType() >= kTypeInputFloatNoLeave) + cleanFloatString(spot); + + if ((spot.getType() >= kTypeInput2NoLeave) && (spot.getType() <= kTypeInput3Leave)) { + + // Look if we find a match between the wanted and the typed string + checkStringMatch(spot, inputs[inputIndex], inputPos); + strInputCount++; + } else + WRITE_VAR(17 + inputPos, 2); + + inputIndex++; + inputPos++; + } + + // Notify the scripts if we reached the requested hotspot + WRITE_VAR(17, (uint32) (strInputCount == ((uint16) VAR(17)))); +} + +uint16 Hotspots::convertSpecialKey(uint16 key) const { + if (((key & 0xFF) >= ' ') && ((key & 0xFF) <= 0xFF) && + ((key >> 8) > 1) && ((key >> 8) < 12)) + key = '0' + (((key >> 8) - 1) % 10) + (key & 0xFF00); + + return key; +} + +void Hotspots::getTextCursorPos(const Font &font, const char *str, + uint32 pos, uint16 x, uint16 y, uint16 width, uint16 height, + uint16 &cursorX, uint16 &cursorY, uint16 &cursorWidth, uint16 &cursorHeight) const { + + if (!font.isMonospaced()) { + // Cursor to the right of the current character + + cursorX = x; + cursorY = y; + cursorWidth = 1; + cursorHeight = height; + + // Iterate through the string and add each character's width + for (uint32 i = 0; i < pos; i++) + cursorX += font.getCharWidth(str[i]); + + } else { + // Cursor underlining the current character + + cursorX = x + font.getCharWidth() * pos; + cursorY = y + height - 1; + cursorWidth = font.getCharWidth(); + cursorHeight = 1; + } +} + +void Hotspots::fillRect(uint16 x, uint16 y, uint16 width, uint16 height, uint16 color) const { + _vm->_draw->_destSurface = 21; + _vm->_draw->_destSpriteX = x; + _vm->_draw->_destSpriteY = y; + _vm->_draw->_spriteRight = width; + _vm->_draw->_spriteBottom = height; + _vm->_draw->_backColor = color; + + _vm->_draw->spriteOperation(DRAW_FILLRECT | 0x10 ); +} + +void Hotspots::printText(uint16 x, uint16 y, const char *str, uint16 fontIndex, uint16 color) const { + _vm->_draw->_destSpriteX = x; + _vm->_draw->_destSpriteY = y; + _vm->_draw->_frontColor = color; + _vm->_draw->_fontIndex = fontIndex; + _vm->_draw->_textToPrint = str; + _vm->_draw->_transparency = 1; + + _vm->_draw->spriteOperation(DRAW_PRINTTEXT | 0x10); +} + +void Hotspots::updateAllTexts(const InputDesc *inputs) const { + uint16 input = 0; + + for (int i = 0; i < kHotspotCount; i++) { + const Hotspot &spot = _hotspots[i]; + + if (spot.isEnd()) + // It's an end, we don't want it + continue; + + if (!spot.isFilledEnabled()) + // This one's either not used or disabled + continue; + + if (!spot.isInput()) + // Not an input + continue; + + // Get its text + char tempStr[256]; + strncpy0(tempStr, GET_VARO_STR(spot.key), 255); + + // Coordinates + uint16 x = spot.left; + uint16 y = spot.top; + uint16 width = spot.right - spot.left + 1; + uint16 height = spot.bottom - spot.top + 1; + // Clear the background + fillRect(x, y, width, height, inputs[input].backColor); + + // Center the text vertically + y += (height - _vm->_draw->_fonts[_vm->_draw->_fontIndex]->getCharHeight()) / 2; + + // Draw it + printText(x, y, tempStr, inputs[input].fontIndex, inputs[input].frontColor); + + input++; + } +} + +} // End of namespace Gob diff --git a/engines/gob/hotspots.h b/engines/gob/hotspots.h new file mode 100644 index 0000000000..a389987c27 --- /dev/null +++ b/engines/gob/hotspots.h @@ -0,0 +1,272 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#ifndef GOB_HOTSPOTS_H +#define GOB_HOTSPOTS_H + +#include "common/stack.h" + +#include "gob/util.h" + +namespace Gob { + +class Font; +class Script; + +class Hotspots { +public: + static const int kHotspotCount = 250; + + enum Type { + kTypeNone = 0, + kTypeMove = 1, + kTypeClick = 2, + kTypeInput1NoLeave = 3, + kTypeInput1Leave = 4, + kTypeInput2NoLeave = 5, + kTypeInput2Leave = 6, + kTypeInput3NoLeave = 7, + kTypeInput3Leave = 8, + kTypeInputFloatNoLeave = 9, + kTypeInputFloatLeave = 10, + kTypeEnable2 = 11, + kTypeEnable1 = 12, + kTypeClickEnter = 21 + }; + + enum State { + kStateFilledDisabled = 0xC, + kStateFilled = 0x8, + kStateDisabled = 0x4, + kStateType2 = 0x2, + kStateType1 = 0x1 + }; + + Hotspots(GobEngine *vm); + ~Hotspots(); + + /** Remove all hotspots. */ + void clear(); + + /** Add a hotspot, returning the new index. */ + uint16 add(uint16 id, + uint16 left, uint16 top, uint16 right, uint16 bottom, + uint16 flags, uint16 key, + uint16 funcEnter, uint16 funcLeave, uint16 funcPos); + + /** Remove a specific hotspot. */ + void remove(uint16 id); + /** Remove all hotspots in this state. */ + void removeState(uint8 state); + + /** Push the current hotspots onto the stack. + * + * @param all 0: Don't push global ones; 1: Push all; 2: Push only the disabled ones + * @param force Force a push although _shouldPush is false + */ + void push(uint8 all, bool force = false); + /** Pop hotspots from the stack. */ + void pop(); + + /** Check the current hotspot. */ + uint16 check(uint8 handleMouse, int16 delay, uint16 &id, uint16 &index); + /** Check the current hotspot. */ + uint16 check(uint8 handleMouse, int16 delay); + + /** Evaluate hotspot changes. */ + void evaluate(); + + /** Return the cursor found in the hotspot to the coordinates. */ + int16 findCursor(uint16 x, uint16 y) const; + +private: + struct Hotspot { + uint16 id; + uint16 left; + uint16 top; + uint16 right; + uint16 bottom; + uint16 flags; + uint16 key; + uint16 funcEnter; + uint16 funcLeave; + uint16 funcPos; + Script *script; + + Hotspot(); + Hotspot(uint16 i, + uint16 l, uint16 t, uint16 r, uint16 b, uint16 f, uint16 k, + uint16 enter, uint16 leave, uint16 pos); + + void clear(); + + Type getType () const; + MouseButtons getButton() const; + uint8 getWindow() const; + uint8 getCursor() const; + uint8 getState () const; + + /** Is this hotspot the block end marker? */ + bool isEnd() const; + + bool isInput () const; + bool isActiveInput() const; + bool isInputLeave () const; + + bool isFilled () const; + bool isFilledEnabled() const; + bool isFilledNew () const; + bool isDisabled () const; + + /** Are the specified coordinates in the hotspot? */ + bool isIn(uint16 x, uint16 y) const; + /** Does the specified button trigger the hotspot? */ + bool buttonMatch(MouseButtons button) const; + + static uint8 getState(uint16 id); + + void disable(); + void enable (); + }; + + struct StackEntry { + bool shouldPush; + Hotspot *hotspots; + uint32 size; + uint32 key; + uint32 id; + uint32 index; + }; + + struct InputDesc { + uint16 fontIndex; + uint16 backColor; + uint16 frontColor; + uint16 length; + const char *str; + }; + + GobEngine *_vm; + + Hotspot *_hotspots; + Common::Stack<StackEntry> _stack; + + bool _shouldPush; + + uint16 _currentKey; + uint16 _currentIndex; + uint16 _currentId; + + /** Add a hotspot, returning the new index. */ + uint16 add(const Hotspot &hotspot); + + /** Recalculate all hotspot parameters + * + * @param force Force recalculation of all hotspots, including global ones. + */ + void recalculate(bool force); + + /** Is this a valid hotspot? */ + bool isValid(uint16 key, uint16 id, uint16 index) const; + + /** Call a hotspot subroutine. */ + void call(uint16 offset); + /** Handling hotspot enter events. */ + void enter(uint16 index); + /** Handling hotspot leave events. */ + void leave(uint16 index); + + /** Which hotspot is the mouse cursor currently at? */ + uint16 checkMouse(Type type, uint16 &id, uint16 &index) const; + + /** Did the current hotspot change in the meantime? */ + bool checkHotspotChanged(); + + /** Update events from a specific input. */ + uint16 updateInput(uint16 xPos, uint16 yPos, uint16 width, uint16 height, + uint16 backColor, uint16 frontColor, char *str, uint16 fontIndex, + Type type, int16 &duration, uint16 &id, uint16 &index); + + /** Handle all inputs we currently manage. */ + uint16 handleInputs(int16 time, uint16 inputCount, uint16 &curInput, + InputDesc *inputs, uint16 &id, uint16 &index); + + /** Evaluate adding new hotspots script commands. */ + void evaluateNew(uint16 i, uint16 *ids, InputDesc *inputs, + uint16 &inputId, bool &hasInput, uint16 &inputCount); + /** Find the hotspot requested by script commands. */ + bool evaluateFind(uint16 key, int16 timeVal, const uint16 *ids, + uint16 hotspotIndex1, uint16 hotspotIndex2, uint16 endIndex, + int16 &duration, uint16 &id, uint16 &index, bool &finished); + + // Finding specific hotspots + /** Find the hotspot index that corresponds to the input index. */ + uint16 inputToHotspot(uint16 input) const; + /** Find the input index that corresponds to the hotspot index. */ + uint16 hotspotToInput(uint16 hotspot) const; + /** Find the input that was clicked on. */ + uint16 findClickedInput(uint16 index) const; + /** Find the first input hotspot with a leave function. */ + bool findFirstInputLeave(uint16 &id, uint16 &inputId, uint16 &index) const; + /** Find the hotspot with the matching key, case sensitively. */ + bool findKey(uint16 key, uint16 &id, uint16 &index) const; + /** Find the hotspot with the matching key, case insensitively. */ + bool findKeyCaseInsensitive(uint16 key, uint16 &id, uint16 &index) const; + /** Find the nth plain (without Type1 or Type2 state) hotspot. */ + bool findNthPlain(uint16 n, uint16 startIndex, uint16 &id, uint16 &index) const; + + /** Leave the nth plain (without Type1 or Type2 state) hotspot. */ + bool leaveNthPlain(uint16 n, uint16 startIndex, int16 timeVal, const uint16 *ids, + uint16 &id, uint16 &index, int16 &duration); + + // Hotspot ID variable access + void setCurrentHotspot(const uint16 *ids, uint16 id) const; + uint32 getCurrentHotspot() const; + + // String input functions + void cleanFloatString(const Hotspot &spot) const; + void checkStringMatch(const Hotspot &spot, const InputDesc &input, + uint16 inputPos) const; + void matchInputStrings(const InputDesc *inputs) const; + + uint16 convertSpecialKey(uint16 key) const; + + /** Calculate the graphical cursor position. */ + void getTextCursorPos(const Font &font, const char *str, + uint32 pos, uint16 x, uint16 y, uint16 width, uint16 height, + uint16 &cursorX, uint16 &cursorY, uint16 &cursorWidth, uint16 &cursorHeight) const; + + /** Fill that rectangle with the color. */ + void fillRect(uint16 x, uint16 y, uint16 width, uint16 height, uint16 color) const; + /** Print the given text. */ + void printText(uint16 x, uint16 y, const char *str, uint16 fontIndex, uint16 color) const; + + /** Go through all inputs we manage and redraw their texts. */ + void updateAllTexts(const InputDesc *inputs) const; +}; + +} // End of namespace Gob + +#endif // GOB_HOTSPOTS_H diff --git a/engines/gob/init.cpp b/engines/gob/init.cpp index f9a22f52fb..faf85a5b41 100644 --- a/engines/gob/init.cpp +++ b/engines/gob/init.cpp @@ -123,8 +123,7 @@ void Init::initGame() { if (!_vm->_dataIO->existData("intro.inf")) { for (int i = 0; i < 4; i++) - if (_vm->_dataIO->existData(_fontNames[i])) - _vm->_draw->_fonts[i] = _vm->_util->loadFont(_fontNames[i]); + _vm->_draw->loadFont(i, _fontNames[i]); } else { infBuf = _vm->_dataIO->getData("intro.inf"); @@ -140,8 +139,8 @@ void Init::initGame() { buffer[j] = 0; strcat(buffer, ".let"); - if (_vm->_dataIO->existData(buffer)) - _vm->_draw->_fonts[i] = _vm->_util->loadFont(buffer); + + _vm->_draw->loadFont(i, buffer); if ((infPtr + 1) >= infEnd) break; diff --git a/engines/gob/init.h b/engines/gob/init.h index a8d4b9833e..60642d0189 100644 --- a/engines/gob/init.h +++ b/engines/gob/init.h @@ -32,7 +32,7 @@ namespace Gob { class Init { public: - void initGame(); + virtual void initGame(); virtual void initVideo() = 0; @@ -72,6 +72,14 @@ public: virtual ~Init_v3() {} }; +class Init_v6 : public Init_v3 { +public: + virtual void initGame(); + + Init_v6(GobEngine *vm); + virtual ~Init_v6() {} +}; + } // End of namespace Gob #endif // GOB_INIT_H diff --git a/engines/gob/init_v6.cpp b/engines/gob/init_v6.cpp new file mode 100644 index 0000000000..4b14c8a29c --- /dev/null +++ b/engines/gob/init_v6.cpp @@ -0,0 +1,48 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "common/endian.h" + +#include "gob/gob.h" +#include "gob/init.h" +#include "gob/global.h" + +namespace Gob { + +Init_v6::Init_v6(GobEngine *vm) : Init_v3(vm) { +} + +void Init_v6::initGame() { + _vm->_global->_noCd = false; + + if (Common::File::exists("cd1.itk") && Common::File::exists("cd2.itk") && + Common::File::exists("cd3.itk") && Common::File::exists("cd4.itk")) { + _vm->_global->_noCd = true; + } + + Init::initGame(); +} + +} // End of namespace Gob diff --git a/engines/gob/inter.cpp b/engines/gob/inter.cpp index 8be07034c6..afd215a00d 100644 --- a/engines/gob/inter.cpp +++ b/engines/gob/inter.cpp @@ -35,6 +35,7 @@ #include "gob/game.h" #include "gob/expression.h" #include "gob/script.h" +#include "gob/hotspots.h" #include "gob/scenery.h" #include "gob/sound/sound.h" @@ -180,7 +181,7 @@ void Inter::storeMouse() { WRITE_VAR(2, x); WRITE_VAR(3, y); - WRITE_VAR(4, _vm->_game->_mouseButtons); + WRITE_VAR(4, (uint32) _vm->_game->_mouseButtons); } void Inter::storeKey(int16 key) { @@ -189,20 +190,20 @@ void Inter::storeKey(int16 key) { storeMouse(); WRITE_VAR(1, _vm->_sound->blasterPlayingSound()); - if (key == 0x4800) - key = 0x0B; - else if (key == 0x5000) - key = 0x0A; - else if (key == 0x4D00) - key = 0x09; - else if (key == 0x4B00) - key = 0x08; - else if (key == 0x011B) - key = 0x1B; - else if (key == 0x0E08) - key = 0x19; - else if (key == 0x5300) - key = 0x1A; + if (key == kKeyUp) + key = kShortKeyUp; + else if (key == kKeyDown) + key = kShortKeyDown; + else if (key == kKeyRight) + key = kShortKeyRight; + else if (key == kKeyLeft) + key = kShortKeyLeft; + else if (key == kKeyEscape) + key = kShortKeyEscape; + else if (key == kKeyBackspace) + key = kShortKeyBackspace; + else if (key == kKeyDelete) + key = kShortKeyDelete; else if ((key & 0xFF) != 0) key &= 0xFF; @@ -334,7 +335,7 @@ void Inter::callSub(int16 retFlag) { if (block == 1) funcBlock(retFlag); else if (block == 2) - _vm->_game->collisionsBlock(); + _vm->_game->_hotspots->evaluate(); else error("Unknown block type %d in Inter::callSub()", block); } diff --git a/engines/gob/inter.h b/engines/gob/inter.h index d4ed2d3240..a31860885f 100644 --- a/engines/gob/inter.h +++ b/engines/gob/inter.h @@ -238,7 +238,7 @@ protected: bool o1_playComposition(OpFuncParams ¶ms); bool o1_getFreeMem(OpFuncParams ¶ms); bool o1_checkData(OpFuncParams ¶ms); - bool o1_prepareStr(OpFuncParams ¶ms); + bool o1_cleanupStr(OpFuncParams ¶ms); bool o1_insertStr(OpFuncParams ¶ms); bool o1_cutStr(OpFuncParams ¶ms); bool o1_strstr(OpFuncParams ¶ms); @@ -380,8 +380,8 @@ protected: bool o2_assign(OpFuncParams ¶ms); bool o2_printText(OpFuncParams ¶ms); bool o2_animPalInit(OpFuncParams ¶ms); - bool o2_addCollision(OpFuncParams ¶ms); - bool o2_freeCollision(OpFuncParams ¶ms); + bool o2_addHotspot(OpFuncParams ¶ms); + bool o2_removeHotspot(OpFuncParams ¶ms); bool o2_goblinFunc(OpFuncParams ¶ms); bool o2_stopSound(OpFuncParams ¶ms); bool o2_loadSound(OpFuncParams ¶ms); @@ -541,7 +541,7 @@ protected: bool o6_loadCursor(OpFuncParams ¶ms); bool o6_assign(OpFuncParams ¶ms); bool o6_palLoad(OpFuncParams ¶ms); - bool o6_freeCollision(OpFuncParams ¶ms); + bool o6_removeHotspot(OpFuncParams ¶ms); bool o6_fillRect(OpFuncParams ¶ms); void probe16bitMusic(char *fileName); diff --git a/engines/gob/inter_bargon.cpp b/engines/gob/inter_bargon.cpp index 12079600c0..b955057bac 100644 --- a/engines/gob/inter_bargon.cpp +++ b/engines/gob/inter_bargon.cpp @@ -89,7 +89,7 @@ void Inter_Bargon::oBargon_intro2(OpGobParams ¶ms) { int i; int16 mouseX; int16 mouseY; - int16 buttons; + MouseButtons buttons; SurfaceDescPtr surface; SoundDesc samples[4]; int16 comp[5] = { 0, 1, 2, 3, -1 }; @@ -107,13 +107,13 @@ void Inter_Bargon::oBargon_intro2(OpGobParams ¶ms) { for (i = 320; i >= 0; i--) { _vm->_util->setScrollOffset(i, 0); _vm->_video->dirtyRectsAll(); - if ((_vm->_game->checkKeys(&mouseX, &mouseY, &buttons, 0) == 0x11B) || + if ((_vm->_game->checkKeys(&mouseX, &mouseY, &buttons, 0) == kKeyEscape) || _vm->shouldQuit()) { _vm->_palAnim->fade(0, -2, 0); _vm->_video->clearSurf(*_vm->_draw->_frontSurface); memset((char *) _vm->_draw->_vgaPalette, 0, 768); WRITE_VAR(4, buttons); - WRITE_VAR(0, 0x11B); + WRITE_VAR(0, kKeyEscape); WRITE_VAR(57, (uint32) -1); break; } @@ -137,7 +137,7 @@ void Inter_Bargon::oBargon_intro2(OpGobParams ¶ms) { void Inter_Bargon::oBargon_intro3(OpGobParams ¶ms) { int16 mouseX; int16 mouseY; - int16 buttons; + MouseButtons buttons; Video::Color *palBak; SoundDesc samples[2]; int16 comp[3] = { 0, 1, -1 }; @@ -158,14 +158,14 @@ void Inter_Bargon::oBargon_intro3(OpGobParams ¶ms) { _vm->_video->setFullPalette(_vm->_global->_pPaletteDesc); _vm->_util->longDelay(_vm->_util->getRandom(200)); } - if ((_vm->_game->checkKeys(&mouseX, &mouseY, &buttons, 0) == 0x11B) || + if ((_vm->_game->checkKeys(&mouseX, &mouseY, &buttons, 0) == kKeyEscape) || _vm->shouldQuit()) { _vm->_sound->blasterStop(10); _vm->_palAnim->fade(0, -2, 0); _vm->_video->clearSurf(*_vm->_draw->_frontSurface); memset(_vm->_draw->_vgaPalette, 0, 768); WRITE_VAR(4, buttons); - WRITE_VAR(0, 0x11B); + WRITE_VAR(0, kKeyEscape); WRITE_VAR(57, (uint32) -1); break; } diff --git a/engines/gob/inter_v1.cpp b/engines/gob/inter_v1.cpp index d5d5fcad9a..69c392b198 100644 --- a/engines/gob/inter_v1.cpp +++ b/engines/gob/inter_v1.cpp @@ -37,6 +37,7 @@ #include "gob/expression.h" #include "gob/script.h" #include "gob/resources.h" +#include "gob/hotspots.h" #include "gob/goblin.h" #include "gob/inter.h" #include "gob/map.h" @@ -147,7 +148,7 @@ void Inter_v1::setupOpcodesFunc() { OPCODEFUNC(0x3E, o1_getFreeMem); OPCODEFUNC(0x3F, o1_checkData); - OPCODEFUNC(0x41, o1_prepareStr); + OPCODEFUNC(0x41, o1_cleanupStr); OPCODEFUNC(0x42, o1_insertStr); OPCODEFUNC(0x43, o1_cutStr); @@ -867,7 +868,16 @@ bool Inter_v1::o1_loadSpriteToPos(OpFuncParams ¶ms) { _vm->_draw->_spriteLeft = _vm->_game->_script->readInt16(); _vm->_draw->_destSpriteX = _vm->_game->_script->readValExpr(); - _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr(); + + // WORKAROUND: The EGA version of Gobliiins 1 has an invalid expression there + if (_vm->isEGA() && (_vm->_game->_script->pos() == 1398) && + !scumm_stricmp(_vm->_game->_curTotFile, "intro.tot")) { + + _vm->_draw->_destSpriteY = 0; + _vm->_game->_script->skip(1); + + } else + _vm->_draw->_destSpriteY = _vm->_game->_script->readValExpr(); _vm->_draw->_transparency = _vm->_game->_script->peekByte() & 1; _vm->_draw->_destSurface = ((int16) (_vm->_game->_script->peekByte() >> 1)) - 1; @@ -1095,7 +1105,7 @@ bool Inter_v1::o1_palLoad(OpFuncParams ¶ms) { if (!resource) break; - memcpy((char *) _vm->_draw->_vgaPalette, resource->getData(), MIN(768, resource->getSize())); + memcpy((char *) _vm->_draw->_vgaPalette, resource->getData(), MIN<int>(768, resource->getSize())); delete resource; break; @@ -1173,7 +1183,7 @@ bool Inter_v1::o1_keyFunc(OpFuncParams ¶ms) { case 0: _vm->_draw->_showCursor &= ~2; _vm->_util->longDelay(1); - key = _vm->_game->checkCollisions(0, 0, 0, 0); + key = _vm->_game->_hotspots->check(0, 0); storeKey(key); _vm->_util->clearKeyBuf(); @@ -1601,11 +1611,11 @@ bool Inter_v1::o1_checkData(OpFuncParams ¶ms) { return false; } -bool Inter_v1::o1_prepareStr(OpFuncParams ¶ms) { +bool Inter_v1::o1_cleanupStr(OpFuncParams ¶ms) { int16 strVar; strVar = _vm->_game->_script->readVarIndex(); - _vm->_util->prepareStr(GET_VARO_FSTR(strVar)); + _vm->_util->cleanupStr(GET_VARO_FSTR(strVar)); return false; } @@ -1702,12 +1712,9 @@ bool Inter_v1::o1_loadFont(OpFuncParams ¶ms) { _vm->_game->_script->evalExpr(0); index = _vm->_game->_script->readInt16(); - delete _vm->_draw->_fonts[index]; - _vm->_draw->animateCursor(4); - _vm->_draw->_fonts[index] = - _vm->_util->loadFont(_vm->_game->_script->getResultStr()); + _vm->_draw->loadFont(index, _vm->_game->_script->getResultStr()); return false; } diff --git a/engines/gob/inter_v2.cpp b/engines/gob/inter_v2.cpp index 82822330b1..20f812bb88 100644 --- a/engines/gob/inter_v2.cpp +++ b/engines/gob/inter_v2.cpp @@ -39,6 +39,7 @@ #include "gob/expression.h" #include "gob/script.h" #include "gob/resources.h" +#include "gob/hotspots.h" #include "gob/goblin.h" #include "gob/map.h" #include "gob/mult.h" @@ -121,8 +122,8 @@ void Inter_v2::setupOpcodesFunc() { OPCODEFUNC(0x17, o2_animPalInit); - OPCODEFUNC(0x18, o2_addCollision); - OPCODEFUNC(0x19, o2_freeCollision); + OPCODEFUNC(0x18, o2_addHotspot); + OPCODEFUNC(0x19, o2_removeHotspot); OPCODEFUNC(0x25, o2_goblinFunc); @@ -1176,67 +1177,51 @@ bool Inter_v2::o2_animPalInit(OpFuncParams ¶ms) { return false; } -bool Inter_v2::o2_addCollision(OpFuncParams ¶ms) { - int16 id; - int16 left, top, width, height; - int16 flags; - int16 key; - int16 funcSub; - - id = _vm->_game->_script->readValExpr(); - funcSub = _vm->_game->_script->pos(); - left = _vm->_game->_script->readValExpr(); - top = _vm->_game->_script->readValExpr(); - width = _vm->_game->_script->readValExpr(); - height = _vm->_game->_script->readValExpr(); - flags = _vm->_game->_script->readValExpr(); - key = _vm->_game->_script->readInt16(); +bool Inter_v2::o2_addHotspot(OpFuncParams ¶ms) { + int16 id = _vm->_game->_script->readValExpr(); + uint16 funcPos = _vm->_game->_script->pos(); + int16 left = _vm->_game->_script->readValExpr(); + int16 top = _vm->_game->_script->readValExpr(); + uint16 width = _vm->_game->_script->readValExpr(); + uint16 height = _vm->_game->_script->readValExpr(); + uint16 flags = _vm->_game->_script->readValExpr(); + uint16 key = _vm->_game->_script->readInt16(); if (key == 0) key = ABS(id) + 41960; - _vm->_draw->adjustCoords(0, &left, &top); - _vm->_draw->adjustCoords(2, &width, &height); - if (left < 0) { width += left; - left = 0; + left = 0; } if (top < 0) { height += top; - top = 0; + top = 0; } int16 index; if (id < 0) - index = _vm->_game->addNewCollision(0xD000 - id, left & 0xFFFC, top & 0xFFFC, - left + width + 3, top + height + 3, flags, key, 0, 0); + index = _vm->_game->_hotspots->add(0xD000 - id, left & 0xFFFC, top & 0xFFFC, + left + width + 3, top + height + 3, flags, key, 0, 0, funcPos); else - index = _vm->_game->addNewCollision(0xE000 + id, left, top, - left + width - 1, top + height - 1, flags, key, 0, 0); - - _vm->_game->_collisionAreas[index].funcSub = funcSub; + index = _vm->_game->_hotspots->add(0xE000 + id, left, top, + left + width - 1, top + height - 1, flags, key, 0, 0, funcPos); return false; } -bool Inter_v2::o2_freeCollision(OpFuncParams ¶ms) { - int16 id; +bool Inter_v2::o2_removeHotspot(OpFuncParams ¶ms) { + int16 id = _vm->_game->_script->readValExpr(); + uint8 stateType1 = Hotspots::kStateFilledDisabled | Hotspots::kStateType1; + uint8 stateType2 = Hotspots::kStateFilledDisabled | Hotspots::kStateType2; - id = _vm->_game->_script->readValExpr(); - if (id == -2) { - for (int i = 0; i < 150; i++) { - if ((_vm->_game->_collisionAreas[i].id & 0xF000) == 0xD000) - _vm->_game->_collisionAreas[i].left = 0xFFFF; - } - } else if (id == -1) { - for (int i = 0; i < 150; i++) { - if ((_vm->_game->_collisionAreas[i].id & 0xF000) == 0xE000) - _vm->_game->_collisionAreas[i].left = 0xFFFF; - } - } else - _vm->_game->freeCollision(0xE000 + id); + if (id == -2) + _vm->_game->_hotspots->removeState(stateType1); + else if (id == -1) + _vm->_game->_hotspots->removeState(stateType2); + else + _vm->_game->_hotspots->remove((stateType2 << 12) + id); return false; } diff --git a/engines/gob/inter_v5.cpp b/engines/gob/inter_v5.cpp index 1c20851c8d..986bad7cd3 100644 --- a/engines/gob/inter_v5.cpp +++ b/engines/gob/inter_v5.cpp @@ -266,9 +266,9 @@ void Inter_v5::o5_spaceShooter(OpGobParams ¶ms) { void Inter_v5::o5_getSystemCDSpeed(OpGobParams ¶ms) { WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100% - Video::FontDesc *font; - if ((font = _vm->_util->loadFont("SPEED.LET"))) { - _vm->_draw->drawString("100 %", 402, 89, 112, 144, 0, *_vm->_draw->_backSurface, font); + Font *font; + if ((font = _vm->_draw->loadFont("SPEED.LET"))) { + _vm->_draw->drawString("100 %", 402, 89, 112, 144, 0, *_vm->_draw->_backSurface, *font); _vm->_draw->forceBlit(); delete font; @@ -278,9 +278,9 @@ void Inter_v5::o5_getSystemCDSpeed(OpGobParams ¶ms) { void Inter_v5::o5_getSystemRAM(OpGobParams ¶ms) { WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100% - Video::FontDesc *font; - if ((font = _vm->_util->loadFont("SPEED.LET"))) { - _vm->_draw->drawString("100 %", 402, 168, 112, 144, 0, *_vm->_draw->_backSurface, font); + Font *font; + if ((font = _vm->_draw->loadFont("SPEED.LET"))) { + _vm->_draw->drawString("100 %", 402, 168, 112, 144, 0, *_vm->_draw->_backSurface, *font); _vm->_draw->forceBlit(); delete font; @@ -290,9 +290,9 @@ void Inter_v5::o5_getSystemRAM(OpGobParams ¶ms) { void Inter_v5::o5_getSystemCPUSpeed(OpGobParams ¶ms) { WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100% - Video::FontDesc *font; - if ((font = _vm->_util->loadFont("SPEED.LET"))) { - _vm->_draw->drawString("100 %", 402, 248, 112, 144, 0, *_vm->_draw->_backSurface, font); + Font *font; + if ((font = _vm->_draw->loadFont("SPEED.LET"))) { + _vm->_draw->drawString("100 %", 402, 248, 112, 144, 0, *_vm->_draw->_backSurface, *font); _vm->_draw->forceBlit(); delete font; @@ -302,9 +302,9 @@ void Inter_v5::o5_getSystemCPUSpeed(OpGobParams ¶ms) { void Inter_v5::o5_getSystemDrawSpeed(OpGobParams ¶ms) { WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100% - Video::FontDesc *font; - if ((font = _vm->_util->loadFont("SPEED.LET"))) { - _vm->_draw->drawString("100 %", 402, 326, 112, 144, 0, *_vm->_draw->_backSurface, font); + Font *font; + if ((font = _vm->_draw->loadFont("SPEED.LET"))) { + _vm->_draw->drawString("100 %", 402, 326, 112, 144, 0, *_vm->_draw->_backSurface, *font); _vm->_draw->forceBlit(); delete font; @@ -314,9 +314,9 @@ void Inter_v5::o5_getSystemDrawSpeed(OpGobParams ¶ms) { void Inter_v5::o5_totalSystemSpecs(OpGobParams ¶ms) { WRITE_VAR_UINT32(_vm->_game->_script->readInt16(), 100); // Fudging 100% - Video::FontDesc *font; - if ((font = _vm->_util->loadFont("SPEED.LET"))) { - _vm->_draw->drawString("100 %", 402, 405, 112, 144, 0, *_vm->_draw->_backSurface, font); + Font *font; + if ((font = _vm->_draw->loadFont("SPEED.LET"))) { + _vm->_draw->drawString("100 %", 402, 405, 112, 144, 0, *_vm->_draw->_backSurface, *font); _vm->_draw->forceBlit(); delete font; diff --git a/engines/gob/inter_v6.cpp b/engines/gob/inter_v6.cpp index 506de821d4..aa4721ff0a 100644 --- a/engines/gob/inter_v6.cpp +++ b/engines/gob/inter_v6.cpp @@ -31,10 +31,12 @@ #include "gob/inter.h" #include "gob/helper.h" #include "gob/global.h" +#include "gob/dataio.h" #include "gob/game.h" #include "gob/expression.h" #include "gob/script.h" #include "gob/resources.h" +#include "gob/hotspots.h" #include "gob/draw.h" #include "gob/sound/sound.h" #include "gob/videoplayer.h" @@ -64,7 +66,7 @@ void Inter_v6::setupOpcodesFunc() { OPCODEFUNC(0x03, o6_loadCursor); OPCODEFUNC(0x09, o6_assign); OPCODEFUNC(0x13, o6_palLoad); - OPCODEFUNC(0x19, o6_freeCollision); + OPCODEFUNC(0x19, o6_removeHotspot); OPCODEFUNC(0x33, o6_fillRect); } @@ -187,7 +189,7 @@ void Inter_v6::o6_openItk() { // (it checks CD1.ITK - CD4.ITK and the first that's found determines // the CD number), while its NO_CD modus wants everything in CD1.ITK. // So we just open the other ITKs, too. - if (_vm->_game->_noCd && !scumm_stricmp(fileName, "CD1.ITK")) { + if (_vm->_global->_noCd && !scumm_stricmp(fileName, "CD1.ITK")) { _vm->_dataIO->openDataFile("CD2.ITK", true); _vm->_dataIO->openDataFile("CD3.ITK", true); _vm->_dataIO->openDataFile("CD4.ITK", true); @@ -351,36 +353,33 @@ bool Inter_v6::o6_palLoad(OpFuncParams ¶ms) { return false; } -bool Inter_v6::o6_freeCollision(OpFuncParams ¶ms) { +bool Inter_v6::o6_removeHotspot(OpFuncParams ¶ms) { int16 id; + uint8 stateType1 = Hotspots::kStateFilledDisabled | Hotspots::kStateType1; + uint8 stateType2 = Hotspots::kStateFilledDisabled | Hotspots::kStateType2; + uint8 stateDisabled = Hotspots::kStateDisabled; id = _vm->_game->_script->readValExpr(); switch (id + 5) { case 0: - _vm->_game->pushCollisions(1); + _vm->_game->_hotspots->push(1); break; case 1: - _vm->_game->popCollisions(); + _vm->_game->_hotspots->pop(); break; case 2: - _vm->_game->pushCollisions(2); + _vm->_game->_hotspots->push(2); break; case 3: - for (int i = 0; i < 150; i++) { - if (((_vm->_game->_collisionAreas[i].id & 0xF000) == 0xD000) || - ((_vm->_game->_collisionAreas[i].id & 0xF000) == 0x4000)) - _vm->_game->_collisionAreas[i].left = 0xFFFF; - } + _vm->_game->_hotspots->removeState(stateType1); + _vm->_game->_hotspots->removeState(stateDisabled); break; case 4: - for (int i = 0; i < 150; i++) { - if ((_vm->_game->_collisionAreas[i].id & 0xF000) == 0xE000) - _vm->_game->_collisionAreas[i].left = 0xFFFF; - } + _vm->_game->_hotspots->removeState(stateType2); break; default: - _vm->_game->freeCollision(0xE000 + id); + _vm->_game->_hotspots->remove((stateType2 << 12) + id); break; } diff --git a/engines/gob/module.mk b/engines/gob/module.mk index 695976da61..611abb6038 100644 --- a/engines/gob/module.mk +++ b/engines/gob/module.mk @@ -11,10 +11,6 @@ MODULE_OBJS := \ driver_vga.o \ expression.o \ game.o \ - game_v1.o \ - game_v2.o \ - game_v6.o \ - game_fascin.o \ global.o \ gob.o \ goblin.o \ @@ -22,11 +18,12 @@ MODULE_OBJS := \ goblin_v2.o \ goblin_v3.o \ goblin_v4.o \ - videoplayer.o \ + hotspots.o \ init.o \ init_v1.o \ init_v2.o \ init_v3.o \ + init_v6.o \ inter.o \ inter_v1.o \ inter_v2.o \ @@ -56,6 +53,7 @@ MODULE_OBJS := \ video_v1.o \ video_v2.o \ video_v6.o \ + videoplayer.o \ demos/demoplayer.o \ demos/scnplayer.o \ demos/batplayer.o \ @@ -66,6 +64,7 @@ MODULE_OBJS := \ save/saveload_v3.o \ save/saveload_v4.o \ save/saveload_v6.o \ + save/saveload_playtoons.o \ save/saveconverter.o \ save/saveconverter_v2.o \ save/saveconverter_v3.o \ diff --git a/engines/gob/mult.cpp b/engines/gob/mult.cpp index 5aec5ff76e..d383d955c7 100644 --- a/engines/gob/mult.cpp +++ b/engines/gob/mult.cpp @@ -204,7 +204,7 @@ void Mult::playMult(int16 startFrame, int16 endFrame, char checkEscape, stop = false; _vm->_util->processInput(); - if (checkEscape && (_vm->_util->checkKey() == 0x11B)) + if (checkEscape && (_vm->_util->checkKey() == kKeyEscape)) stop = true; _frame++; diff --git a/engines/gob/resources.cpp b/engines/gob/resources.cpp index 20427e547b..c52b65f0d7 100644 --- a/engines/gob/resources.cpp +++ b/engines/gob/resources.cpp @@ -158,29 +158,29 @@ bool Resources::load(const Common::String &fileName) { _extFile = fileBase + ".ext"; - if (!loadTOTResourceTable()) { - unload(); - return false; - } + bool hasTOTRes = loadTOTResourceTable(); + bool hasEXTRes = loadEXTResourceTable(); - if (!loadEXTResourceTable()) { - unload(); + if (!hasTOTRes && !hasEXTRes) return false; - } - if (!loadTOTTextTable(fileBase)) { - unload(); - return false; - } + if (hasTOTRes) { + if (!loadTOTTextTable(fileBase)) { + unload(); + return false; + } - if (!loadIMFile()) { - unload(); - return false; + if (!loadIMFile()) { + unload(); + return false; + } } - if (!loadEXFile()) { - unload(); - return false; + if (hasEXTRes) { + if (!loadEXFile()) { + unload(); + return false; + } } return true; @@ -255,7 +255,7 @@ bool Resources::loadTOTResourceTable() { TOTResourceItem &item = _totResourceTable->items[i]; item.offset = stream->readSint32LE(); - item.size = stream->readSint16LE(); + item.size = stream->readUint16LE(); item.width = stream->readSint16LE(); item.height = stream->readSint16LE(); @@ -286,7 +286,7 @@ bool Resources::loadEXTResourceTable() { DataStream *stream = _vm->_dataIO->getDataStream(_extFile.c_str()); if (!stream) - return true; + return false; _extResourceTable->itemsCount = stream->readSint16LE(); _extResourceTable->unknown = stream->readByte(); @@ -588,15 +588,22 @@ Resource *Resources::getTOTResource(uint16 id) const { if (totItem.type == kResourceTOT) data = getTOTData(totItem); - if (!data) + if (!data) { + warning("Failed to load TOT resource (%s, %d/%d, %d)", + _totFile.c_str(), id, _totResourceTable->itemsCount - 1, totItem.type); return 0; + } return new Resource(data, totItem.size, false, totItem.width, totItem.height); } Resource *Resources::getEXTResource(uint16 id) const { - if (!_extResourceTable || (id > _extResourceTable->itemsCount)) + if (!_extResourceTable || (id > _extResourceTable->itemsCount)) { + warning("Trying to load non-existent EXT resource (%s, %d/%d)", + _totFile.c_str(), id, + _extResourceTable ? (_extResourceTable->itemsCount - 1) : -1); return 0; + } EXTResourceItem &extItem = _extResourceTable->items[id]; @@ -617,8 +624,11 @@ Resource *Resources::getEXTResource(uint16 id) const { if (extItem.type == kResourceEX) data = getEXData(extItem, size); - if (!data) + if (!data) { + warning("Failed to load EXT resource (%s, %d/%d, %d)", + _totFile.c_str(), id, _extResourceTable->itemsCount - 1, extItem.type); return 0; + } if (extItem.packed) { byte *packedData = data; @@ -635,7 +645,7 @@ Resource *Resources::getEXTResource(uint16 id) const { } byte *Resources::getTOTData(TOTResourceItem &totItem) const { - if (totItem.size < 0) + if (totItem.size == 0) return 0; int32 offset = _totResourceTable->dataOffset + totItem.offset - _totResStart; @@ -647,7 +657,7 @@ byte *Resources::getTOTData(TOTResourceItem &totItem) const { } byte *Resources::getIMData(TOTResourceItem &totItem) const { - if (totItem.size < 0) + if (totItem.size == 0) return 0; int32 indexOffset = totItem.index * 4; diff --git a/engines/gob/resources.h b/engines/gob/resources.h index 80acef645c..d316be83e5 100644 --- a/engines/gob/resources.h +++ b/engines/gob/resources.h @@ -109,7 +109,7 @@ private: struct TOTResourceItem { ResourceType type; - int16 size; + uint16 size; int16 width; int16 height; union { diff --git a/engines/gob/save/saveload.h b/engines/gob/save/saveload.h index a74b64b883..8d785c7233 100644 --- a/engines/gob/save/saveload.h +++ b/engines/gob/save/saveload.h @@ -445,6 +445,32 @@ protected: SaveFile *getSaveFile(const char *fileName); }; +/** Save/Load class for Playtoons. */ +/** Only used for the moment to check file presence */ + +class SaveLoad_Playtoons : public SaveLoad { +public: + SaveLoad_Playtoons(GobEngine *vm); + virtual ~SaveLoad_Playtoons(); + +protected: + struct SaveFile { + const char *sourceName; + SaveMode mode; + SaveHandler *handler; + const char *description; + }; + + static SaveFile _saveFiles[]; + + SaveMode getSaveMode(const char *fileName) const; + + const SaveFile *getSaveFile(const char *fileName) const; + + SaveFile *getSaveFile(const char *fileName); + +}; + } // End of namespace Gob #endif // GOB_SAVE_SAVELOAD_H diff --git a/engines/gob/save/saveload_playtoons.cpp b/engines/gob/save/saveload_playtoons.cpp new file mode 100644 index 0000000000..97da909e7c --- /dev/null +++ b/engines/gob/save/saveload_playtoons.cpp @@ -0,0 +1,88 @@ +/* ScummVM - Graphic Adventure Engine + * + * ScummVM is the legal property of its developers, whose names + * are too numerous to list here. Please refer to the COPYRIGHT + * file distributed with this source distribution. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * $URL$ + * $Id$ + * + */ + +#include "gob/save/saveload.h" +#include "gob/inter.h" +#include "gob/variables.h" + +namespace Gob { + +SaveLoad_Playtoons::SaveFile SaveLoad_Playtoons::_saveFiles[] = { + { "disk.001", kSaveModeExists, 0, 0}, // Playtoons 1 identification file + { "disk.002", kSaveModeExists, 0, 0}, // Playtoons 2 identification file + { "disk.003", kSaveModeExists, 0, 0}, // Playtoons 3 identification file + { "disk.004", kSaveModeExists, 0, 0}, // Playtoons 4 identification file + { "disk.005", kSaveModeExists, 0, 0}, // Playtoons 5 identification file + { "disk.006", kSaveModeExists, 0, 0}, // Playtoons CK 1 identification file + { "disk.007", kSaveModeExists, 0, 0}, // Playtoons CK 2 identification file + { "disk.008", kSaveModeExists, 0, 0}, // Playtoons CK 3 identification file + { "titre.001", kSaveModeExists, 0, 0}, // Playtoons 1 titles + { "titre.002", kSaveModeExists, 0, 0}, // Playtoons 2 titles + { "titre.003", kSaveModeExists, 0, 0}, // Playtoons 3 titles + { "titre.004", kSaveModeExists, 0, 0}, // Playtoons 4 titles + { "titre.005", kSaveModeExists, 0, 0}, // Playtoons 5 titles + { "titre.006", kSaveModeExists, 0, 0}, // Playtoons CK 1 empty title (???) + { "titre.007", kSaveModeExists, 0, 0}, // Playtoons CK 2 empty title (???) + { "titre.008", kSaveModeExists, 0, 0}, // Playtoons CK 3 empty title (???) + { "mdo.def", kSaveModeExists, 0, 0}, +}; + +SaveLoad::SaveMode SaveLoad_Playtoons::getSaveMode(const char *fileName) const { + const SaveFile *saveFile = getSaveFile(fileName); + + if (saveFile) + return saveFile->mode; + + return kSaveModeNone; +} + +SaveLoad_Playtoons::SaveLoad_Playtoons(GobEngine *vm) : + SaveLoad(vm) { +} + +SaveLoad_Playtoons::~SaveLoad_Playtoons() { +} + +const SaveLoad_Playtoons::SaveFile *SaveLoad_Playtoons::getSaveFile(const char *fileName) const { + fileName = stripPath(fileName); + + for (int i = 0; i < ARRAYSIZE(_saveFiles); i++) + if (!scumm_stricmp(fileName, _saveFiles[i].sourceName)) + return &_saveFiles[i]; + + return 0; +} + +SaveLoad_Playtoons::SaveFile *SaveLoad_Playtoons::getSaveFile(const char *fileName) { + fileName = stripPath(fileName); + + for (int i = 0; i < ARRAYSIZE(_saveFiles); i++) + if (!scumm_stricmp(fileName, _saveFiles[i].sourceName)) + return &_saveFiles[i]; + + return 0; +} + +} // End of namespace Gob diff --git a/engines/gob/script.cpp b/engines/gob/script.cpp index 6162e943bf..38b1f8fa40 100644 --- a/engines/gob/script.cpp +++ b/engines/gob/script.cpp @@ -127,6 +127,10 @@ bool Script::skip(int32 offset) { return seek(offset, SEEK_CUR); } +bool Script::skipBlock() { + return seek(peekUint16(2) + 2, SEEK_CUR); +} + int32 Script::getOffset(byte *ptr) const { if (!_totData) return -1; diff --git a/engines/gob/script.h b/engines/gob/script.h index 64a04503b1..84daeaf1af 100644 --- a/engines/gob/script.h +++ b/engines/gob/script.h @@ -53,6 +53,7 @@ public: // Stream seeking bool seek(int32 offset, int whence = SEEK_SET); bool skip(int32 offset); + bool skipBlock(); // Reading data byte readByte (); diff --git a/engines/gob/sound/sound.cpp b/engines/gob/sound/sound.cpp index d3afc9baa3..2d7ba02385 100644 --- a/engines/gob/sound/sound.cpp +++ b/engines/gob/sound/sound.cpp @@ -506,7 +506,7 @@ void Sound::blasterWaitEndPlay(bool interruptible, bool stopComp) { _blaster->endComposition(); while (_blaster->isPlaying() && !_vm->shouldQuit()) { - if (interruptible && (_vm->_util->checkKey() == 0x11B)) { + if (interruptible && (_vm->_util->checkKey() == kKeyEscape)) { WRITE_VAR(57, (uint32) -1); return; } diff --git a/engines/gob/util.cpp b/engines/gob/util.cpp index b0e7691c07..356eb3c643 100644 --- a/engines/gob/util.cpp +++ b/engines/gob/util.cpp @@ -38,14 +38,14 @@ namespace Gob { Util::Util(GobEngine *vm) : _vm(vm) { - _mouseButtons = 0; - _keyBufferHead = 0; - _keyBufferTail = 0; - _fastMode = 0; - _frameRate = 12; - _frameWaitTime = 0; + _mouseButtons = kMouseButtonsNone, + _keyBufferHead = 0; + _keyBufferTail = 0; + _fastMode = 0; + _frameRate = 12; + _frameWaitTime = 0; _startFrameTime = 0; - _frameWaitLag = 0; + _frameWaitLag = 0; } uint32 Util::getTimeKey(void) { @@ -85,7 +85,7 @@ void Util::longDelay(uint16 msecs) { } void Util::initInput(void) { - _mouseButtons = 0; + _mouseButtons = kMouseButtonsNone; _keyBufferHead = _keyBufferTail = 0; } @@ -103,16 +103,16 @@ void Util::processInput(bool scroll) { y = event.mouse.y; break; case Common::EVENT_LBUTTONDOWN: - _mouseButtons |= 1; + _mouseButtons = (MouseButtons) (((uint32) _mouseButtons) | ((uint32) kMouseButtonsLeft)); break; case Common::EVENT_RBUTTONDOWN: - _mouseButtons |= 2; + _mouseButtons = (MouseButtons) (((uint32) _mouseButtons) | ((uint32) kMouseButtonsRight)); break; case Common::EVENT_LBUTTONUP: - _mouseButtons &= ~1; + _mouseButtons = (MouseButtons) (((uint32) _mouseButtons) & ~((uint32) kMouseButtonsLeft)); break; case Common::EVENT_RBUTTONUP: - _mouseButtons &= ~2; + _mouseButtons = (MouseButtons) (((uint32) _mouseButtons) & ~((uint32) kMouseButtonsRight)); break; case Common::EVENT_KEYDOWN: if (event.kbd.flags == Common::KBD_CTRL) { @@ -179,26 +179,26 @@ int16 Util::translateKey(const Common::KeyState &key) { int16 from; int16 to; } keys[] = { - {Common::KEYCODE_INVALID, 0x0000}, - {Common::KEYCODE_BACKSPACE, 0x0E08}, - {Common::KEYCODE_SPACE, 0x3920}, - {Common::KEYCODE_RETURN, 0x1C0D}, - {Common::KEYCODE_ESCAPE, 0x011B}, - {Common::KEYCODE_DELETE, 0x5300}, - {Common::KEYCODE_UP, 0x4800}, - {Common::KEYCODE_DOWN, 0x5000}, - {Common::KEYCODE_RIGHT, 0x4D00}, - {Common::KEYCODE_LEFT, 0x4B00}, - {Common::KEYCODE_F1, 0x3B00}, - {Common::KEYCODE_F2, 0x3C00}, - {Common::KEYCODE_F3, 0x3D00}, - {Common::KEYCODE_F4, 0x3E00}, - {Common::KEYCODE_F5, 0x011B}, - {Common::KEYCODE_F6, 0x4000}, - {Common::KEYCODE_F7, 0x4100}, - {Common::KEYCODE_F8, 0x4200}, - {Common::KEYCODE_F9, 0x4300}, - {Common::KEYCODE_F10, 0x4400} + {Common::KEYCODE_INVALID, kKeyNone }, + {Common::KEYCODE_BACKSPACE, kKeyBackspace}, + {Common::KEYCODE_SPACE, kKeySpace }, + {Common::KEYCODE_RETURN, kKeyReturn }, + {Common::KEYCODE_ESCAPE, kKeyEscape }, + {Common::KEYCODE_DELETE, kKeyDelete }, + {Common::KEYCODE_UP, kKeyUp }, + {Common::KEYCODE_DOWN, kKeyDown }, + {Common::KEYCODE_RIGHT, kKeyRight }, + {Common::KEYCODE_LEFT, kKeyLeft }, + {Common::KEYCODE_F1, kKeyF1 }, + {Common::KEYCODE_F2, kKeyF2 }, + {Common::KEYCODE_F3, kKeyF3 }, + {Common::KEYCODE_F4, kKeyF4 }, + {Common::KEYCODE_F5, kKeyEscape }, + {Common::KEYCODE_F6, kKeyF6 }, + {Common::KEYCODE_F7, kKeyF7 }, + {Common::KEYCODE_F8, kKeyF8 }, + {Common::KEYCODE_F9, kKeyF9 }, + {Common::KEYCODE_F10, kKeyF10 } }; for (int i = 0; i < ARRAYSIZE(keys); i++) @@ -246,7 +246,7 @@ bool Util::checkKey(int16 &key) { return true; } -void Util::getMouseState(int16 *pX, int16 *pY, int16 *pButtons) { +void Util::getMouseState(int16 *pX, int16 *pY, MouseButtons *pButtons) { Common::Point mouse = g_system->getEventManager()->getMousePos(); *pX = mouse.x + _vm->_video->_scrollOffsetX - _vm->_video->_screenDeltaX; *pY = mouse.y + _vm->_video->_scrollOffsetY - _vm->_video->_screenDeltaY; @@ -264,15 +264,15 @@ void Util::setMousePos(int16 x, int16 y) { void Util::waitMouseUp(void) { do { processInput(); - if (_mouseButtons != 0) + if (_mouseButtons != kMouseButtonsNone) delay(10); - } while (_mouseButtons != 0); + } while (_mouseButtons != kMouseButtonsNone); } void Util::waitMouseDown(void) { int16 x; int16 y; - int16 buttons; + MouseButtons buttons; do { processInput(); @@ -283,7 +283,7 @@ void Util::waitMouseDown(void) { } void Util::waitMouseRelease(char drawMouse) { - int16 buttons; + MouseButtons buttons; int16 mouseX; int16 mouseY; @@ -300,8 +300,8 @@ void Util::forceMouseUp(bool onlyWhenSynced) { if (onlyWhenSynced && (_vm->_game->_mouseButtons != _mouseButtons)) return; - _vm->_game->_mouseButtons = 0; - _mouseButtons = 0; + _vm->_game->_mouseButtons = kMouseButtonsNone; + _mouseButtons = kMouseButtonsNone; } void Util::clearPalette(void) { @@ -379,38 +379,6 @@ void Util::setScrollOffset(int16 x, int16 y) { _vm->_video->waitRetrace(); } -Video::FontDesc *Util::loadFont(const char *path) { - Video::FontDesc *fontDesc = new Video::FontDesc; - byte *data; - - if (!fontDesc) - return 0; - - data = _vm->_dataIO->getData(path); - if (!data) { - delete fontDesc; - return 0; - } - - fontDesc->dataPtr = data + 4; - fontDesc->itemWidth = data[0] & 0x7F; - fontDesc->itemHeight = data[1]; - fontDesc->startItem = data[2]; - fontDesc->endItem = data[3]; - - fontDesc->itemSize = - ((fontDesc->itemWidth - 1) / 8 + 1) * fontDesc->itemHeight; - fontDesc->bitWidth = fontDesc->itemWidth; - - if (data[0] & 0x80) - fontDesc->extraData = data + 4 + fontDesc->itemSize * - (fontDesc->endItem - fontDesc->startItem + 1); - else - fontDesc->extraData = 0; - - return fontDesc; -} - void Util::insertStr(const char *str1, char *str2, int16 pos) { int len1 = strlen(str1); int len2 = strlen(str2); @@ -452,7 +420,7 @@ static const char trStr2[] = " "; static const char trStr3[] = " "; -void Util::prepareStr(char *str) { +void Util::cleanupStr(char *str) { char *start, *end; char buf[300]; @@ -460,17 +428,20 @@ void Util::prepareStr(char *str) { strcat(buf, trStr2); strcat(buf, trStr3); + // Translating "wrong" characters for (size_t i = 0; i < strlen(str); i++) - str[i] = buf[str[i] - 32]; + str[i] = buf[MIN<int>(str[i] - 32, 32)]; + // Trim spaces left while (str[0] == ' ') cutFromStr(str, 0, 1); + // Trim spaces right while ((strlen(str) > 0) && (str[strlen(str) - 1] == ' ')) cutFromStr(str, strlen(str) - 1, 1); + // Merge double spaces start = strchr(str, ' '); - while (start) { if (start[1] == ' ') { cutFromStr(str, start - str, 1); diff --git a/engines/gob/util.h b/engines/gob/util.h index 0a76ee40ab..82e2df94de 100644 --- a/engines/gob/util.h +++ b/engines/gob/util.h @@ -28,12 +28,53 @@ #include "common/keyboard.h" -#include "gob/video.h" - namespace Gob { +class GobEngine; + #define KEYBUFSIZE 16 +enum MouseButtons { + kMouseButtonsNone = 0, + kMouseButtonsLeft = 1, + kMouseButtonsRight = 2, + kMouseButtonsBoth = 3, + kMouseButtonsAny = 4 +}; + +enum Keys { + kKeyNone = 0x0000, + kKeyBackspace = 0x0E08, + kKeySpace = 0x3920, + kKeyReturn = 0x1C0D, + kKeyEscape = 0x011B, + kKeyDelete = 0x5300, + kKeyUp = 0x4800, + kKeyDown = 0x5000, + kKeyRight = 0x4D00, + kKeyLeft = 0x4B00, + kKeyF1 = 0x3B00, + kKeyF2 = 0x3C00, + kKeyF3 = 0x3D00, + kKeyF4 = 0x3E00, + kKeyF5 = 0x3F00, + kKeyF6 = 0x4000, + kKeyF7 = 0x4100, + kKeyF8 = 0x4200, + kKeyF9 = 0x4300, + kKeyF10 = 0x4400 +}; + +enum ShortKey { + kShortKeyUp = 0x0B, + kShortKeyDown = 0x0A, + kShortKeyRight = 0x09, + kShortKeyLeft = 0x08, + kShortKeyEscape = 0x1B, + kShortKeyBackspace = 0x19, + kShortKeyDelete = 0x1A +}; + class Util { public: struct ListNode; @@ -66,7 +107,7 @@ public: int16 checkKey(void); bool checkKey(int16 &key); - void getMouseState(int16 *pX, int16 *pY, int16 *pButtons); + void getMouseState(int16 *pX, int16 *pY, MouseButtons *pButtons); void setMousePos(int16 x, int16 y); void waitMouseUp(void); void waitMouseDown(void); @@ -80,11 +121,9 @@ public: void waitEndFrame(); void setScrollOffset(int16 x = -1, int16 y = -1); - Video::FontDesc *loadFont(const char *path); - static void insertStr(const char *str1, char *str2, int16 pos); static void cutFromStr(char *str, int16 from, int16 cutlen); - static void prepareStr(char *str); + static void cleanupStr(char *str); static void replaceChar(char *str, char c1, char c2); static void listInsertFront(List *list, void *data); @@ -95,7 +134,8 @@ public: Util(GobEngine *vm); protected: - int16 _mouseButtons; + MouseButtons _mouseButtons; + Common::KeyState _keyBuffer[KEYBUFSIZE]; int16 _keyBufferHead; int16 _keyBufferTail; diff --git a/engines/gob/video.cpp b/engines/gob/video.cpp index 3b4822cc77..98350af738 100644 --- a/engines/gob/video.cpp +++ b/engines/gob/video.cpp @@ -40,6 +40,82 @@ namespace Gob { +Font::Font(const byte *data) : _dataPtr(data) { + assert(data); + + bool hasWidths = _dataPtr[0] & 0x80; + + _data = _dataPtr + 4; + _itemWidth = _dataPtr[0] & 0x7F; + _itemHeight = _dataPtr[1]; + _startItem = _dataPtr[2]; + _endItem = _dataPtr[3]; + _charWidths = 0; + + uint8 rowAlignedBits = (_itemWidth - 1) / 8 + 1; + + _itemSize = rowAlignedBits * _itemHeight; + _bitWidth = _itemWidth; + + if (hasWidths) + _charWidths = _dataPtr + 4 + _itemSize * getCharCount(); +} + +Font::~Font() { + delete[] _dataPtr; +} + +uint8 Font::getCharWidth(uint8 c) const { + if (!_charWidths || (_endItem == 0)) + return _itemWidth; + + if ((c < _startItem) || (c > _endItem)) + return _itemWidth; + + return _charWidths[c - _startItem]; +} + +uint8 Font::getCharWidth() const { + return _itemWidth; +} + +uint8 Font::getCharHeight() const { + return _itemHeight; +} + +uint16 Font::getCharCount() const { + return _endItem - _startItem + 1; +} + +uint8 Font::getFirstChar() const { + return _startItem; +} + +uint8 Font::getLastChar() const { + return _endItem; +} + +uint8 Font::getCharSize() const { + return _itemSize; +} + +bool Font::isMonospaced() const { + return _charWidths == 0; +} + +const byte *Font::getCharData(uint8 c) const { + if (_endItem == 0) { + warning("Font::getCharData(): _endItem == 0"); + return 0; + } + + if ((c < _startItem) || (c > _endItem)) + return 0; + + return _data + (c - _startItem) * _itemSize; +} + + SurfaceDesc::SurfaceDesc(int16 vidMode, int16 width, int16 height, byte *vidMem) : _width(width), _height(height) { @@ -381,41 +457,9 @@ void Video::drawSpriteDouble(SurfaceDesc &source, SurfaceDesc &dest, _videoDriver->drawSpriteDouble(source, dest, left, top, right, bottom, x, y, transp); } -void Video::drawLetter(int16 item, int16 x, int16 y, FontDesc *fontDesc, +void Video::drawLetter(int16 item, int16 x, int16 y, const Font &font, int16 color1, int16 color2, int16 transp, SurfaceDesc &dest) { - byte *dataPtr; - byte *itemData; - int16 itemSize; - int16 newItem; - int16 curItem; - int16 newItemPos; - int16 curItemPos; - - if (fontDesc->endItem == 0) { - itemSize = fontDesc->itemSize + 3; - dataPtr = fontDesc->dataPtr; - // startItem - curItem = READ_LE_UINT16(dataPtr - 2) - 1; - - curItemPos = 0; - do { - newItemPos = ((curItemPos + curItem) / 2) * itemSize; - itemData = fontDesc->dataPtr + newItemPos; - newItem = (READ_LE_UINT16(itemData) & 0x7FFF); - if (item > newItem) - curItem = newItemPos - 1; - else - curItemPos = newItemPos + 1; - } while ((newItem != item) && (curItemPos <= curItem)); - - if (newItem != item) - return; - - fontDesc->dataPtr = itemData + 3; - item = 0; - } - - _videoDriver->drawLetter((unsigned char)item, x, y, fontDesc, color1, color2, transp, dest); + _videoDriver->drawLetter((unsigned char)item, x, y, font, color1, color2, transp, dest); } void Video::drawPackedSprite(byte *sprBuf, int16 width, int16 height, diff --git a/engines/gob/video.h b/engines/gob/video.h index c71a18daa6..b8a46598b7 100644 --- a/engines/gob/video.h +++ b/engines/gob/video.h @@ -38,6 +38,36 @@ namespace Graphics { namespace Gob { +class Font { +public: + uint8 getCharWidth (uint8 c) const; + uint8 getCharWidth () const; + uint8 getCharHeight() const; + uint16 getCharCount () const; + uint8 getFirstChar () const; + uint8 getLastChar () const; + uint8 getCharSize () const; + + bool isMonospaced() const; + + const byte *getCharData(uint8 c) const; + + Font(const byte *data); + ~Font(); + +private: + const byte *_dataPtr; + const byte *_data; + const uint8 *_charWidths; + + int8 _itemWidth; + int8 _itemHeight; + uint8 _startItem; + uint8 _endItem; + int8 _itemSize; + int8 _bitWidth; +}; + // Some Surfaces are simultaneous in Draw::spritesArray and discrete // variables, so if in doubt you should use a SurfaceDescPtr shared // pointer object to refer to any SurfaceDesc. @@ -70,23 +100,6 @@ typedef Common::SharedPtr<SurfaceDesc> SurfaceDescPtr; class Video { public: - struct FontDesc { - byte *dataPtr; - int8 itemWidth; - int8 itemHeight; - uint8 startItem; - uint8 endItem; - int8 itemSize; - int8 bitWidth; - byte *extraData; - FontDesc() : dataPtr(0), itemWidth(0), itemHeight(0), startItem(0), - endItem(0), itemSize(0), bitWidth(0) {} - ~FontDesc() { - if (dataPtr) - delete[] (dataPtr - 4); - } - }; - #define GDR_VERSION 4 #define PRIMARY_SURFACE 0x80 @@ -154,7 +167,7 @@ public: int16 x, int16 y, int16 transp); void drawSpriteDouble(SurfaceDesc &source, SurfaceDesc &dest, int16 left, int16 top, int16 right, int16 bottom, int16 x, int16 y, int16 transp); - void drawLetter(int16 item, int16 x, int16 y, FontDesc *fontDesc, + void drawLetter(int16 item, int16 x, int16 y, const Font &font, int16 color1, int16 color2, int16 transp, SurfaceDesc &dest); void drawPackedSprite(byte *sprBuf, int16 width, int16 height, int16 x, int16 y, int16 transp, SurfaceDesc &dest); @@ -266,7 +279,7 @@ public: virtual void drawSpriteDouble(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, Video::FontDesc *fontDesc, byte color1, byte color2, byte transp, SurfaceDesc &dest) = 0; + virtual void drawLetter(unsigned char item, int16 x, int16 y, const Font &font, 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; }; diff --git a/engines/gob/videoplayer.cpp b/engines/gob/videoplayer.cpp index 6c07d22333..da552d7202 100644 --- a/engines/gob/videoplayer.cpp +++ b/engines/gob/videoplayer.cpp @@ -27,7 +27,6 @@ #include "gob/videoplayer.h" #include "gob/helper.h" #include "gob/global.h" -#include "gob/util.h" #include "gob/dataio.h" #include "gob/video.h" #include "gob/draw.h" diff --git a/engines/gob/videoplayer.h b/engines/gob/videoplayer.h index 842426f90a..ead752d446 100644 --- a/engines/gob/videoplayer.h +++ b/engines/gob/videoplayer.h @@ -31,11 +31,12 @@ #include "graphics/video/coktelvideo/coktelvideo.h" -#include "gob/dataio.h" +#include "gob/util.h" namespace Gob { class GobEngine; +class DataStream; class VideoPlayer { public: @@ -60,13 +61,14 @@ public: bool primaryOpen(const char *videoFile, int16 x = -1, int16 y = -1, int32 flags = kFlagFrontSurface, Type which = kVideoTypeTry); - bool primaryPlay(int16 startFrame = -1, int16 lastFrame = -1, int16 breakKey = 27, + bool primaryPlay(int16 startFrame = -1, int16 lastFrame = -1, + int16 breakKey = kShortKeyEscape, uint16 palCmd = 8, int16 palStart = 0, int16 palEnd = 255, int16 palFrame = -1, int16 endFrame = -1, bool fade = false, int16 reverseTo = -1, bool forceSeek = false); void primaryClose(); - void playFrame(int16 frame, int16 breakKey = 27, + void playFrame(int16 frame, int16 breakKey = kShortKeyEscape, uint16 palCmd = 8, int16 palStart = 0, int16 palEnd = 255, int16 palFrame = -1 , int16 endFrame = -1); |
