diff options
Diffstat (limited to 'engines/access/martian/martian_game.cpp')
-rw-r--r-- | engines/access/martian/martian_game.cpp | 336 |
1 files changed, 266 insertions, 70 deletions
diff --git a/engines/access/martian/martian_game.cpp b/engines/access/martian/martian_game.cpp index 4e4a5135a6..69ca4d3a5a 100644 --- a/engines/access/martian/martian_game.cpp +++ b/engines/access/martian/martian_game.cpp @@ -35,108 +35,256 @@ MartianEngine::MartianEngine(OSystem *syst, const AccessGameDescription *gameDes } MartianEngine::~MartianEngine() { + _introObjects = _spec7Objects = nullptr; } -void MartianEngine::playGame() { - // Do introduction - doIntroduction(); - if (shouldQuit()) - return; +void MartianEngine::initObjects() { + _room = new MartianRoom(this); + _scripts = new MartianScripts(this); +} - // Setup the game - setupGame(); +void MartianEngine::configSelect() { + // No implementation required in MM +} - _screen->clearScreen(); - _screen->setPanel(0); - _screen->forceFadeOut(); +void MartianEngine::initVariables() { + warning("TODO: initVariables"); + + // Set player room and position + _player->_roomNumber = 7; + + _inventory->_startInvItem = 0; + _inventory->_startInvBox = 0; + Common::fill(&_objectsTable[0], &_objectsTable[100], (SpriteResource *)nullptr); + _player->_playerOff = false; + + // Setup timers + const int TIMER_DEFAULTS[] = { 4, 10, 8, 1, 1, 1, 1, 2 }; + for (int i = 0; i < 32; ++i) { + TimerEntry te; + te._initTm = te._timer = (i < 8) ? TIMER_DEFAULTS[i] : 1; + te._flag = 1; + + _timers.push_back(te); + } + + _player->_playerX = _player->_rawPlayer.x = TRAVEL_POS[_player->_roomNumber][0]; + _player->_playerY = _player->_rawPlayer.y = TRAVEL_POS[_player->_roomNumber][1]; + _room->_selectCommand = -1; + _events->setNormalCursor(CURSOR_CROSSHAIRS); + _mouseMode = 0; + _numAnimTimers = 0; + + for (int i = 0; i < 60; i++) + TRAVEL[i] = 0; + TRAVEL[7] = 1; + + for (int i = 0; i < 40; i++) + ASK[i] = 0; + ASK[33] = 1; +} + +void MartianEngine::setNoteParams() { + _events->hideCursor(); + + _screen->_orgX1 = 58; + _screen->_orgY1 = 124; + _screen->_orgX2 = 297; + _screen->_orgY2 = 199; + _screen->_lColor = 51; + _screen->drawRect(); _events->showCursor(); +} - // Setup and execute the room - _room = new MartianRoom(this); - _scripts = new MartianScripts(this); - _room->doRoom(); +void MartianEngine::displayNote(const Common::String &msg) { + _fonts._charSet._lo = 1; + _fonts._charSet._hi = 8; + _fonts._charFor._lo = 0; + _fonts._charFor._hi = 255; + + _screen->_maxChars = 40; + _screen->_printOrg = _screen->_printStart = Common::Point(59, 124); + + setNoteParams(); + + Common::String lines = msg; + Common::String line; + int width = 0; + bool lastLine = false; + do { + lastLine = _fonts._font1.getLine(lines, _screen->_maxChars * 6, line, width); + _bubbleBox->PRINTSTR(line); + _screen->_printOrg = Common::Point(_screen->_printStart.x, _screen->_printOrg.y + 6); + + if (_screen->_printOrg.y == 196) { + _events->waitKeyMouse(); + setNoteParams(); + _screen->_printOrg = _screen->_printStart; + } + } while (!lastLine); + _events->waitKeyMouse(); } -void MartianEngine::doIntroduction() { - _screen->setInitialPalettte(); - _events->setCursor(CURSOR_ARROW); +void MartianEngine::doSpecial5(int param1) { + warning("TODO: Push midi song"); + _midi->stopSong(); + _midi->_byte1F781 = false; + _midi->loadMusic(47, 4); + _midi->midiPlay(); + _screen->setDisplayScan(); + _events->clearEvents(); + _screen->forceFadeOut(); + _events->hideCursor(); + _files->loadScreen("DATA.SC"); _events->showCursor(); - _screen->setPanel(0); + _screen->setIconPalette(); + _screen->forceFadeIn(); + + Resource *cellsRes = _files->loadFile("CELLS00.LZ"); + _objectsTable[0] = new SpriteResource(this, cellsRes); + delete cellsRes; + + _timers[20]._timer = _timers[20]._initTm = 30; + Resource *notesRes = _files->loadFile("NOTES.DAT"); + notesRes->_stream->skip(param1 * 2); + int pos = notesRes->_stream->readUint16LE(); + notesRes->_stream->seek(pos); + Common::String msg = ""; + byte c; + while ((c = (char)notesRes->_stream->readByte()) != '\0') + msg += c; + + displayNote(msg); + + _midi->stopSong(); + _midi->freeMusic(); + + warning("TODO: Pop Midi"); + // _midi->_byte1F781 = true; +} + +void MartianEngine::playGame() { + // Initialize Amazon game-specific objects + initObjects(); - // TODO: Worry about implementing full intro sequence later - return; + // Setup the game + setupGame(); + configSelect(); - doTitle(); - if (shouldQuit()) - return; + if (_loadSaveSlot == -1) { + // Do introduction + doCredits(); + if (shouldQuit()) + return; - if (!_skipStart) { - _screen->setPanel(3); - doOpening(); + // Display Notes screen + doSpecial5(4); if (shouldQuit()) return; + _screen->forceFadeOut(); + } - if (!_skipStart) { - //doTent(); - if (shouldQuit()) - return; + do { + _restartFl = false; + _screen->clearScreen(); + _screen->setPanel(0); + _screen->forceFadeOut(); + _events->showCursor(); + + initVariables(); + + // If there's a pending savegame to load, load it + if (_loadSaveSlot != -1) { + loadGameState(_loadSaveSlot); + _loadSaveSlot = -1; } - } - doTitle(); + // Execute the room + _room->doRoom(); + } while (_restartFl); } -void MartianEngine::doTitle() { - /* - _screen->setDisplayScan(); - _destIn = &_buffer2; - - _screen->forceFadeOut(); +bool MartianEngine::showCredits() { _events->hideCursor(); + _screen->clearScreen(); + _destIn = _screen; - _sound->queueSound(0, 98, 30); - - _files->_setPaletteFlag = false; - _files->loadScreen(0, 3); - - _buffer2.blitFrom(*_screen); - _buffer1.blitFrom(*_screen); - _screen->forceFadeIn(); - _sound->playSound(1); + int posX = _creditsStream->readSint16LE(); + int posY = 0; - Resource *spriteData = _files->loadFile(0, 2); - _objectsTable[0] = new SpriteResource(this, spriteData); - delete spriteData; + while(posX != -1) { + posY = _creditsStream->readSint16LE(); + int frameNum = _creditsStream->readSint16LE(); + _screen->plotImage(_introObjects, frameNum, Common::Point(posX, posY)); - _sound->playSound(1); + posX = _creditsStream->readSint16LE(); + } - _files->_setPaletteFlag = false; - _files->loadScreen(0, 4); - _sound->playSound(1); + posY = _creditsStream->readSint16LE(); + if (posY == -1) { + _events->showCursor(); + _screen->forceFadeOut(); + return true; + } - _buffer2.blitFrom(*_screen); - _buffer1.blitFrom(*_screen); - _sound->playSound(1); + _screen->forceFadeIn(); + _timers[3]._timer = _timers[3]._initTm = posY; - const int COUNTDOWN[6] = { 2, 0x80, 1, 0x7d, 0, 0x87 }; - for (_pCount = 0; _pCount < 3; ++_pCount) { - _buffer2.blitFrom(_buffer1); - int id = READ_LE_UINT16(COUNTDOWN + _pCount * 4); - int xp = READ_LE_UINT16(COUNTDOWN + _pCount * 4 + 2); - _screen->plotImage(_objectsTable[0], id, Common::Point(xp, 71)); + while (!shouldQuit() && !_events->isKeyMousePressed() && _timers[3]._timer) { + _events->pollEventsAndWait(); } - // TODO: More to do - delete _objectsTable[0]; - */ + _events->showCursor(); + _screen->forceFadeOut(); + + if (_events->_rightButton) + return true; + else + return false; } -void MartianEngine::doOpening() { - warning("TODO doOpening"); +void MartianEngine::doCredits() { + _midi->_byte1F781 = false; + _midi->loadMusic(47, 3); + _midi->midiPlay(); + _screen->setDisplayScan(); + _events->hideCursor(); + _screen->forceFadeOut(); + Resource *data = _files->loadFile(41, 1); + _introObjects = new SpriteResource(this, data); + delete data; + + _files->loadScreen(41, 0); + _buffer2.copyFrom(*_screen); + _buffer1.copyFrom(*_screen); + _events->showCursor(); + _creditsStream = new Common::MemoryReadStream(CREDIT_DATA, 180); + + if (!showCredits()) { + _screen->copyFrom(_buffer2); + _screen->forceFadeIn(); + + _events->_vbCount = 550; + while (!shouldQuit() && !_events->isKeyMousePressed() && _events->_vbCount > 0) + _events->pollEventsAndWait(); + + _screen->forceFadeOut(); + while (!shouldQuit() && !_events->isKeyMousePressed()&& !showCredits()) + _events->pollEventsAndWait(); + + warning("TODO: Free word_21E2B"); + _midi->freeMusic(); + } } void MartianEngine::setupGame() { + // Load death list + _deaths.resize(20); + for (int i = 0; i < 20; ++i) { + _deaths[i]._screenId = Martian::DEATH_SCREENS[i]; + _deaths[i]._msg = Martian::DEATHMESSAGE[i]; + } // Setup timers const int TIMER_DEFAULTS[] = { 4, 10, 8, 1, 1, 1, 1, 2 }; @@ -159,8 +307,56 @@ void MartianEngine::setupGame() { _player->_playerY = _player->_rawPlayer.y = TRAVEL_POS[_player->_roomNumber][1]; } -void MartianEngine::drawHelp() { - error("TODO: drawHelp"); +void MartianEngine::showDeathText(Common::String msg) { + Common::String line = ""; + int width = 0; + bool lastLine; + do { + lastLine = _fonts._font2.getLine(msg, _screen->_maxChars * 6, line, width); + // Draw the text + _bubbleBox->PRINTSTR(line); + + _screen->_printOrg.y += 6; + _screen->_printOrg.x = _screen->_printStart.x; + + if (_screen->_printOrg.y == 180) { + _events->waitKeyMouse(); + _screen->copyBuffer(&_buffer2); + _screen->_printOrg.y = _screen->_printStart.y; + } + } while (!lastLine); + _events->waitKeyMouse(); +} + +void MartianEngine::dead(int deathId) { + // Load and display death screen + _events->hideCursor(); + _screen->forceFadeOut(); + _files->loadScreen(48, _deaths[deathId]._screenId); + _screen->setIconPalette(); + _buffer2.copyBuffer(_screen); + _screen->forceFadeIn(); + _events->showCursor(); + + // Setup fonts + _fonts._charSet._hi = 10; + _fonts._charSet._lo = 1; + _fonts._charFor._lo = 247; + _fonts._charFor._hi = 255; + _screen->_maxChars = 50; + _screen->_printOrg = Common::Point(24, 18); + _screen->_printStart = Common::Point(24, 18); + + // Display death message + showDeathText(_deaths[deathId]._msg); + + _screen->forceFadeOut(); + _room->clearRoom(); + freeChar(); + + // The original was jumping to the restart label in main + _restartFl = true; + _events->pollEvents(); } } // End of namespace Martian |