From ef1d10e926fcf31ffeb5c594a305ec0cd8bf7064 Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 26 Jun 2016 23:00:00 -0400 Subject: TITANIC: Implemented remaining CGameManager methods and others --- engines/titanic/core/game_object.cpp | 50 ++++++++++++++++++------- engines/titanic/core/game_object.h | 30 ++++++++++----- engines/titanic/core/mail_man.cpp | 6 +-- engines/titanic/core/room_item.cpp | 9 +++++ engines/titanic/core/room_item.h | 4 ++ engines/titanic/game_manager.cpp | 53 +++++++++++++++++++++++---- engines/titanic/game_manager.h | 13 +++++-- engines/titanic/pet_control/pet_control.cpp | 12 +++++- engines/titanic/pet_control/pet_control.h | 24 ++++++++++++ engines/titanic/pet_control/pet_starfield.cpp | 8 ++-- engines/titanic/pet_control/pet_starfield.h | 29 ++++++++------- engines/titanic/support/movie.cpp | 4 +- engines/titanic/support/movie.h | 12 +++++- 13 files changed, 193 insertions(+), 61 deletions(-) (limited to 'engines/titanic') diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 154d2aeefc..0bf54647f5 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -63,7 +63,7 @@ CGameObject::CGameObject(): CNamedItem() { _field4C = 0xFF; _isMail = false; _id = 0; - _field58 = 0; + _roomFlags = 0; _visible = true; _field60 = 0; _cursorId = CURSOR_ARROW; @@ -126,7 +126,7 @@ void CGameObject::load(SimpleFile *file) { _visible = file->readNumber() != 0; _isMail = file->readNumber(); _id = file->readNumber(); - _field58 = file->readNumber(); + _roomFlags = file->readNumber(); resourceKey.load(file); _surface = nullptr; @@ -688,24 +688,29 @@ CGameObject *CGameObject::getMailManNextObject(CGameObject *prior) const { return mailMan ? mailMan->getNextObject(prior) : nullptr; } -CGameObject *CGameObject::findRoomObject(const CString &name) const { - return static_cast(findRoom()->findByName(name)); -} - -CGameObject *CGameObject::findUnder(CTreeItem *parent, const CString &name) { - if (!parent) +CGameObject *CGameObject::findMailByFlags(int mode, uint roomFlags) { + CMailMan *mailMan = getMailMan(); + if (!mailMan) return nullptr; - - for (CTreeItem *treeItem = parent->getFirstChild(); treeItem; - treeItem = treeItem->scan(parent)) { - if (!treeItem->getName().compareTo(name)) { - return dynamic_cast(treeItem); - } + + for (CGameObject *obj = mailMan->getFirstObject(); obj; + obj = mailMan->getNextObject(obj)) { + if (compareRoomFlags(mode, roomFlags, obj->_roomFlags)) + return obj; } return nullptr; } +CGameObject *CGameObject::getNextMail(CGameObject *prior) { + CMailMan *mailMan = getMailMan(); + return mailMan ? mailMan->getNextObject(prior) : nullptr; +} + +CGameObject *CGameObject::findRoomObject(const CString &name) const { + return static_cast(findRoom()->findByName(name)); +} + Found CGameObject::find(const CString &name, CGameObject **item, int findAreas) { CGameObject *go; *item = nullptr; @@ -897,6 +902,23 @@ CRoomItem *CGameObject::getHiddenRoom() const { return root ? root->findHiddenRoom() : nullptr; } +CGameObject *CGameObject::getHiddenObject(const CString &name) const { + CRoomItem *room = getHiddenRoom(); + return room ? static_cast(findUnder(room, name)) : nullptr; +} + +CTreeItem *CGameObject::findUnder(CTreeItem *parent, const CString &name) const { + if (!parent) + return nullptr; + + for (CTreeItem *item = parent->getFirstChild(); item; item = item->scan(parent)) { + if (item->getName() == name) + return item; + } + + return nullptr; +} + CMusicRoom *CGameObject::getMusicRoom() const { CGameManager *gameManager = getGameManager(); return gameManager ? &gameManager->_musicRoom : nullptr; diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index d372b40f88..67bf13141d 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -195,11 +195,6 @@ protected: */ int compareRoomNameTo(const CString &name); - /** - * Display a message - */ - void displayMessage(const CString &msg) const; - /** * Gets the first object under the system MailMan */ @@ -211,14 +206,19 @@ protected: CGameObject *getMailManNextObject(CGameObject *prior) const; /** - * Finds an object by name within the object's room + * Find mail by room flags */ - CGameObject *findRoomObject(const CString &name) const; + CGameObject *findMailByFlags(int mode, uint roomFlags); /** - * Scan the specified room for an item by name + * Find next mail from a given prior one + */ + CGameObject *getNextMail(CGameObject *prior); + + /** + * Finds an object by name within the object's room */ - static CGameObject *findUnder(CTreeItem *parent, const CString &name); + CGameObject *findRoomObject(const CString &name) const; /** * Moves the item from it's original position to be under the current view @@ -299,6 +299,16 @@ protected: */ CRoomItem *getHiddenRoom() const; + /** + * Returns a hidden object + */ + CGameObject *getHiddenObject(const CString &name) const; + + /** + * Scan the specified room for an item by name + */ + CTreeItem *findUnder(CTreeItem *parent, const CString &name) const; + /** * Returns the music room instance from the game manager */ @@ -366,7 +376,7 @@ protected: public: bool _isMail; int _id; - int _field58; + uint _roomFlags; int _field60; CursorId _cursorId; bool _visible; diff --git a/engines/titanic/core/mail_man.cpp b/engines/titanic/core/mail_man.cpp index 8ac50e9767..8226ebfc80 100644 --- a/engines/titanic/core/mail_man.cpp +++ b/engines/titanic/core/mail_man.cpp @@ -55,7 +55,7 @@ void CMailMan::addMail(CGameObject *obj, int id) { void CMailMan::setMailId(CGameObject *obj, int id) { obj->_id = id; - obj->_field58 = 0; + obj->_roomFlags = 0; obj->_isMail = true; } @@ -68,11 +68,11 @@ CGameObject *CMailMan::findMail(int id) const { return nullptr; } -void CMailMan::removeMail(int id, int v) { +void CMailMan::removeMail(int id, int roomFlags) { for (CGameObject *obj = getFirstObject(); obj; obj = getNextObject(obj)) { if (obj->_isMail && obj->_id == id) { obj->_isMail = false; - obj->_field58 = v; + obj->_roomFlags = roomFlags; break; } } diff --git a/engines/titanic/core/room_item.cpp b/engines/titanic/core/room_item.cpp index 6143849661..e33d0c41dd 100644 --- a/engines/titanic/core/room_item.cpp +++ b/engines/titanic/core/room_item.cpp @@ -183,4 +183,13 @@ int CRoomItem::getScriptId() const { return 0; } +CResourceKey CRoomItem::getTransitionMovieKey() { + _transitionMovieKey.scanForFile(); + return _transitionMovieKey; +} + +CResourceKey CRoomItem::getExitMovieKey() { + return _exitMovieKey; +} + } // End of namespace Titanic diff --git a/engines/titanic/core/room_item.h b/engines/titanic/core/room_item.h index e3ba71c0ae..4692318419 100644 --- a/engines/titanic/core/room_item.h +++ b/engines/titanic/core/room_item.h @@ -72,6 +72,10 @@ public: * Get the TrueTalk script Id associated with the room */ int getScriptId() const; + + CResourceKey getTransitionMovieKey(); + + CResourceKey getExitMovieKey(); }; } // End of namespace Titanic diff --git a/engines/titanic/game_manager.cpp b/engines/titanic/game_manager.cpp index d0400a4b21..c5f0f111f9 100644 --- a/engines/titanic/game_manager.cpp +++ b/engines/titanic/game_manager.cpp @@ -34,16 +34,28 @@ CGameManager::CGameManager(CProjectItem *project, CGameView *gameView): _project(project), _gameView(gameView), _trueTalkManager(this), _inputHandler(this), _inputTranslator(&_inputHandler), _gameState(this), _sound(this), _musicRoom(this), - _field30(0), _soundMaker(nullptr), _field4C(0), + _treeItem(nullptr), _soundMaker(nullptr), _movieRoom(nullptr), _dragItem(nullptr), _field54(0), _lastDiskTicksCount(0), _tickCount2(0) { CTimeEventInfo::_nextId = 0; - _videoSurface1 = nullptr; - _videoSurface2 = CScreenManager::_screenManagerPtr->createSurface(600, 340); + _movie = nullptr; + _movieSurface = CScreenManager::_screenManagerPtr->createSurface(600, 340); _project->setGameManager(this); g_vm->_filesManager->setGameManager(this); } +CGameManager::~CGameManager() { + delete _movie; + delete _movieSurface; + + if (_treeItem) { + _treeItem->destroyAll(); + _treeItem = nullptr; + } + + _project->resetGameManager(); +} + void CGameManager::load(SimpleFile *file) { file->readNumber(); @@ -107,8 +119,33 @@ void CGameManager::initBounds() { _bounds = Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT); } +void CGameManager::roomTransition(CRoomItem *oldRoom, CRoomItem *newRoom) { + delete _movie; + _movie = nullptr; + + CResourceKey movieKey = (oldRoom == newRoom) ? oldRoom->getTransitionMovieKey() : + oldRoom->getExitMovieKey(); + CString filename = movieKey.exists(); + if (g_vm->_filesManager->fileExists(filename)) { + _movieSurface->freeSurface(); + _movie = new OSMovie(filename, _movieSurface); + } +} + void CGameManager::playClip(CMovieClip *clip, CRoomItem *oldRoom, CRoomItem *newRoom) { - warning("TODO: CGameManager::playClip"); + if (oldRoom != newRoom || newRoom != _movieRoom || !_movie) + roomTransition(oldRoom, newRoom); + + if (clip && clip->_startFrame != clip->_endFrame && _movie) { + // Clip details specifying a sub-section of movie to play + Rect tempRect(20, 10, SCREEN_WIDTH - 20, 350); + + lockInputHandler(); + CScreenManager::_screenManagerPtr->_mouseCursor->hide(); + _movie->playClip(tempRect, clip->_startFrame, clip->_endFrame); + CScreenManager::_screenManagerPtr->_mouseCursor->show(); + unlockInputHandler(); + } } void CGameManager::update() { @@ -191,11 +228,11 @@ void CGameManager::updateDiskTicksCount() { } void CGameManager::viewChange() { - delete _videoSurface1; - delete _videoSurface2; + delete _movie; + delete _movieSurface; - _videoSurface1 = nullptr; - _videoSurface2 = CScreenManager::_screenManagerPtr->createSurface(600, 340); + _movie = nullptr; + _movieSurface = CScreenManager::_screenManagerPtr->createSurface(600, 340); _trueTalkManager.clear(); for (CTreeItem *treeItem = _project; treeItem; treeItem = treeItem->scan(_project)) diff --git a/engines/titanic/game_manager.h b/engines/titanic/game_manager.h index c4e6bc6ec8..179e6cde14 100644 --- a/engines/titanic/game_manager.h +++ b/engines/titanic/game_manager.h @@ -44,12 +44,12 @@ class CGameManager { private: CTrueTalkManager _trueTalkManager; CTimeEventInfoList _timers; - int _field30; + CTreeItem *_treeItem; CBackgroundSoundMaker *_soundMaker; - CVideoSurface *_videoSurface1; - int _field4C; + CMovie *_movie; + CRoomItem *_movieRoom; int _field54; - CVideoSurface *_videoSurface2; + CVideoSurface *_movieSurface; uint _lastDiskTicksCount; uint _tickCount2; private: @@ -62,6 +62,11 @@ private: * Handles any ongoing movie playback */ void updateMovies(); + + /** + * Handles a room transition + */ + void roomTransition(CRoomItem *oldRoom, CRoomItem *newRoom); public: CProjectItem *_project; CGameView *_gameView; diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index 793436521c..1643459963 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -251,7 +251,7 @@ CRoomItem *CPetControl::getHiddenRoom() { CGameObject *CPetControl::getHiddenObject(const CString &name) { CRoomItem *room = getHiddenRoom(); - return room ? findUnder(room, name) : nullptr; + return room ? static_cast(findUnder(room, name)) : nullptr; } bool CPetControl::containsPt(const Common::Point &pt) const { @@ -677,4 +677,14 @@ int CPetControl::getMailDest(const CRoomFlags &roomFlags) const { return roomFlags.getSuccUBusNum(roomFlags.getSuccUBusRoomName()); } +void CPetControl::starsSetButtons(int val1, int val2) { + _starfield.setButtons(val1, val2); + if (_currentArea == PET_STARFIELD) + _starfield.makePetDirty(); +} + +void CPetControl::starsSetReference(bool hasRef) { + _starfield.setHasReference(hasRef); +} + } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index e389a0e31a..5601c403f4 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -385,6 +385,13 @@ public: */ void resetActiveNPC(); + /** + * Resets NPC in conversations + */ + void convResetNPC() { + _conversations.resetNPC(); + } + /** * Resets the conversation dials back to 0 position */ @@ -543,6 +550,23 @@ public: bool isSuccUBusRoom(const CRoomFlags &roomFlags) { return roomFlags.isSuccUBusRoomFlags(); } + + /** + * Called with a phonograph action for Send, Receive, or Record + */ + void phonographAction(const CString &action) { + // Original had some code that had no effect + } + + /** + * Sets the status buttons for the starfield control + */ + void starsSetButtons(int val1, int val2); + + /** + * Set whether the user has the galactic reference material + */ + void starsSetReference(bool hasRef); }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_starfield.cpp b/engines/titanic/pet_control/pet_starfield.cpp index 4230d9454f..cde512c681 100644 --- a/engines/titanic/pet_control/pet_starfield.cpp +++ b/engines/titanic/pet_control/pet_starfield.cpp @@ -28,7 +28,7 @@ namespace Titanic { CPetStarfield::CPetStarfield() : _field18C(0), _photoOn(true), - _field210(0), _rect1(22, 352, 598, 478) { + _hasReference(false), _rect1(22, 352, 598, 478) { _btnOffsets[0] = _btnOffsets[1] = _btnOffsets[2] = 0; } @@ -86,7 +86,7 @@ bool CPetStarfield::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { CPETHelmetOnOffMsg helmetMsg; helmetMsg.execute(_petControl->_remoteTarget); } else if (_imgPhoto.MouseButtonDownMsg(msg->_mousePos)) { - if (_field210) { + if (_hasReference) { _photoOn = !_photoOn; CPETPhotoOnOffMsg photoMsg; photoMsg.execute(_petControl->_remoteTarget); @@ -124,7 +124,7 @@ bool CPetStarfield::isValid(CPetControl *petControl) { void CPetStarfield::load(SimpleFile *file, int param) { if (!param) { _photoOn = file->readNumber(); - _field210 = file->readNumber(); + _hasReference = file->readNumber(); } } @@ -134,7 +134,7 @@ void CPetStarfield::postLoad() { void CPetStarfield::save(SimpleFile *file, int indent) const { file->writeNumberLine(_photoOn, indent); - file->writeNumberLine(_field210, indent); + file->writeNumberLine(_hasReference, indent); } bool CPetStarfield::setupControl(CPetControl *petControl) { diff --git a/engines/titanic/pet_control/pet_starfield.h b/engines/titanic/pet_control/pet_starfield.h index 6cfc308d24..ec659ccb31 100644 --- a/engines/titanic/pet_control/pet_starfield.h +++ b/engines/titanic/pet_control/pet_starfield.h @@ -41,7 +41,7 @@ private: int _field18C; CPetText _text; bool _photoOn; - int _field210; + bool _hasReference; private: /** * Setup the control @@ -53,18 +53,6 @@ private: */ void drawButton(int offset, int index, CScreenManager *screenManager); - void set210(int val) { _field210 = val; } - - /** - * Sets the offsets for each of the buttons - */ - void setButtons(int val1, int val2); - - /** - * Make the PET as dirty, requiring a redraw - */ - void makePetDirty(); - /** * Mouse down handling for Nav elements */ @@ -115,6 +103,21 @@ public: * Save the data for the class to file */ virtual void save(SimpleFile *file, int indent) const; + + /** + * Sets the offsets for each of the buttons + */ + void setButtons(int val1, int val2); + + /** + * Sets whether the player has the galactic reference material + */ + void setHasReference(bool hasRef) { _hasReference = hasRef; } + + /** + * Make the PET as dirty, requiring a redraw + */ + void makePetDirty(); }; } // End of namespace Titanic diff --git a/engines/titanic/support/movie.cpp b/engines/titanic/support/movie.cpp index 26620de3a6..cde3b22a8c 100644 --- a/engines/titanic/support/movie.cpp +++ b/engines/titanic/support/movie.cpp @@ -87,8 +87,8 @@ void OSMovie::play(uint startFrame, uint endFrame, int v3, bool v4) { _state = MOVIE_NONE; } -void OSMovie::proc10() { - warning("TODO: OSMovie::proc10"); +void OSMovie::playClip(const Rect &rect, uint startFrame, uint endFrame) { + warning("TODO: OSMovie::playClip"); } void OSMovie::proc11() { diff --git a/engines/titanic/support/movie.h b/engines/titanic/support/movie.h index 01f107ec5b..61dd4cf61d 100644 --- a/engines/titanic/support/movie.h +++ b/engines/titanic/support/movie.h @@ -61,7 +61,11 @@ public: */ virtual void play(uint startFrame, uint endFrame, int v3, bool v4) = 0; - virtual void proc10() = 0; + /** + * Plays a sub-section of a movie + */ + virtual void playClip(const Rect &rect, uint startFrame, uint endFrame) = 0; + virtual void proc11() = 0; virtual void proc12(const CString &name, int flags, CGameObject *obj) = 0; @@ -119,7 +123,11 @@ public: */ virtual void play(uint startFrame, uint endFrame, int v3, bool v4); - virtual void proc10(); + /** + * Plays a sub-section of a movie + */ + virtual void playClip(const Rect &rect, uint startFrame, uint endFrame); + virtual void proc11(); virtual void proc12(const CString &name, int flags, CGameObject *obj); -- cgit v1.2.3