From f0889c17a46019b8b294a74d054d0c60e445190b Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Sun, 19 Jun 2016 20:58:37 -0400 Subject: TITANIC: Implementing lots of cGameObject methods --- engines/titanic/core/game_object.cpp | 91 ++++++++++++++++++++++++++++- engines/titanic/core/game_object.h | 41 +++++++++++++ engines/titanic/core/mail_man.cpp | 17 ++++++ engines/titanic/core/mail_man.h | 9 +++ engines/titanic/game_state.cpp | 2 +- engines/titanic/game_state.h | 2 +- engines/titanic/pet_control/pet_control.cpp | 4 -- engines/titanic/pet_control/pet_control.h | 6 +- engines/titanic/support/movie.cpp | 8 ++- engines/titanic/support/movie.h | 2 + engines/titanic/support/video_surface.cpp | 4 ++ engines/titanic/support/video_surface.h | 4 ++ 12 files changed, 178 insertions(+), 12 deletions(-) diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 2da7d79949..4a5dd9b065 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -343,7 +343,10 @@ void CGameObject::loadFrame(int frameNumber) { } void CGameObject::processClipList2() { - warning("CGameObject::processClipList2"); + for (CMovieClipList::iterator i = _clipList2.begin(); i != _clipList2.end(); ++i) + (*i)->process(this); + + _clipList2.destroyContents(); } void CGameObject::makeDirty(const Rect &r) { @@ -429,6 +432,17 @@ void CGameObject::playClip(uint startFrame, uint endFrame) { gameManager->playClip(clip, room, room); } +void CGameObject::playRandomClip(const char **names, uint flags) { + // Count size of array + int count = 0; + for (const char **p = names; *p; ++p) + ++count; + + // Play clip + const char *name = names[g_vm->getRandomNumber(count - 1)]; + playClip(name, flags); +} + void CGameObject::playMovie(uint flags) { _frameNumber = -1; if (!_surface && !_resource.empty()) { @@ -844,6 +858,11 @@ void CGameObject::dragMove(const Point &pt) { setPosition(Point(pt.x - _bounds.width() / 2, pt.y - _bounds.height() / 2)); } +Point CGameObject::getControid() const { + return Point(_bounds.left + _bounds.width() / 2, + _bounds.top + _bounds.height() / 2); +} + bool CGameObject::clipExistsByStart(const CString &name, int startFrame) const { return _clipList1.existsByStart(name, startFrame); } @@ -943,7 +962,75 @@ void CGameObject::createCredits() { _credits = new CCreditText(); CScreenManager *screenManager = getGameManager()->setScreenManager(); _credits->load(this, screenManager, _bounds); - +} + +void CGameObject::fn10(int v1, int v2, int v3) { + makeDirty(); + _field44 = v1; + _field48 = v2; + _field4C = v3; +} + +void CGameObject::setMovie14(int v) { + if (!_surface && !_resource.empty()) { + loadResource(_resource); + _resource.clear(); + } + + if (_surface && _surface->_movie) + _surface->_movie->_field14 = v; +} + +void CGameObject::movie38(int v1, int v2) { + if (_surface) + _surface->proc38(v1, v2); +} + +void CGameObject::movie38(int v1) { + if (_surface) + _surface->proc38(-1, v1); +} + +int CGameObject::getClipDuration(const CString &name, int frameRate) const { + CMovieClip *clip = _clipList1.findByName(name); + return clip ? (clip->_endFrame - clip->_startFrame) * 1000 / frameRate : 0; +} + +void CGameObject::petIncC0() { + getPetControl()->incC0(); +} + +void CGameObject::petDecC0() { + getPetControl()->decC0(); +} + +void CGameObject::setState1C(bool flag) { + getGameManager()->_gameState._field1C = flag; +} + +void CGameObject::mailFn10(int v) { + CMailMan *mailMan = getMailMan(); + if (mailMan) { + makeDirty(); + mailMan->fn10(this, v); + } +} + +void CGameObject::mailFn11(int v) { + CMailMan *mailMan = getMailMan(); + if (mailMan) { + makeDirty(); + mailMan->fn11(this, v); + } +} + +bool CGameObject::mailExists(int id) const { + return findMail(id) != nullptr; +} + +CGameObject *CGameObject::findMail(int id) const { + CMailMan *mailMan = getMailMan(); + return mailMan ? mailMan->findMail(id) : nullptr; } } // End of namespace Titanic diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index 44e12319e4..01f15ceb85 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -275,6 +275,11 @@ protected: */ void dragMove(const Point &pt); + /** + * Get the centre of the game object's bounds + */ + Point getControid() const; + /** * Set the position of the object */ @@ -292,6 +297,11 @@ protected: */ void playClip(uint startFrame, uint endFrame); + /** + * Play a clip randomly from a passed list of names + */ + void playRandomClip(const char **names, uint flags); + /** * Return the current view/node/room as a single string */ @@ -353,6 +363,37 @@ protected: * Set's the player's passenger class */ void setPassengerClass(int newClass); + + void setMovie14(int v); + + void movie38(int v1, int v2); + + void movie38(int v1); + + void fn10(int v1, int v2, int v3); + + /** + * Gets the duration of a specified clip in milliseconds + */ + int getClipDuration(const CString &name, int frameRate = 14) const; + + void petIncC0(); + void petDecC0(); + + void setState1C(bool flag); + + void mailFn10(int v); + void mailFn11(int v); + + /** + * Returns true if a mail with a specified Id exists + */ + bool mailExists(int id) const; + + /** + * Returns a specified mail, if one exists + */ + CGameObject *findMail(int id) const; public: int _field60; CursorId _cursorId; diff --git a/engines/titanic/core/mail_man.cpp b/engines/titanic/core/mail_man.cpp index cb959245b5..e96b697dff 100644 --- a/engines/titanic/core/mail_man.cpp +++ b/engines/titanic/core/mail_man.cpp @@ -47,4 +47,21 @@ CGameObject *CMailMan::getNextObject(CGameObject *prior) const { return static_cast(prior->getNextSibling()); } +void CMailMan::fn10(CGameObject *obj, int v) { + warning("TODO: CMailMan::fn10"); +} + +void CMailMan::fn11(CGameObject *obj, int v) { + warning("TODO: CMailMan::fn11"); +} + +CGameObject *CMailMan::findMail(int id) const { + for (CGameObject *obj = getFirstObject(); obj; obj = getNextObject(obj)) { + if (_field50 && _field54 == id) + return obj; + } + + return nullptr; +} + } // End of namespace Titanic diff --git a/engines/titanic/core/mail_man.h b/engines/titanic/core/mail_man.h index d1c84e2264..1a95729ff1 100644 --- a/engines/titanic/core/mail_man.h +++ b/engines/titanic/core/mail_man.h @@ -54,8 +54,17 @@ public: * the passed game object */ CGameObject *getNextObject(CGameObject *prior) const; + + void fn10(CGameObject *obj, int v); + void fn11(CGameObject *obj, int v); + + /** + * Scan the mail list for a specified item + */ + CGameObject *findMail(int id) const; }; + } // End of namespace Titanic #endif /* TITANIC_MAIL_MAN_H */ diff --git a/engines/titanic/game_state.cpp b/engines/titanic/game_state.cpp index c552c69831..d129767e10 100644 --- a/engines/titanic/game_state.cpp +++ b/engines/titanic/game_state.cpp @@ -46,7 +46,7 @@ bool CGameStateMovieList::clear() { CGameState::CGameState(CGameManager *gameManager) : _gameManager(gameManager), _gameLocation(this), _passengerClass(0), _priorClass(0), _mode(GSMODE_UNSELECTED), - _field14(0), _petActive(false), _field1C(0), _quitGame(false), + _field14(0), _petActive(false), _field1C(false), _quitGame(false), _field24(0), _nodeChangeCtr(0), _nodeEnterTicks(0), _field38(0) { } diff --git a/engines/titanic/game_state.h b/engines/titanic/game_state.h index 65126120be..327459278d 100644 --- a/engines/titanic/game_state.h +++ b/engines/titanic/game_state.h @@ -59,7 +59,7 @@ public: GameStateMode _mode; int _field14; bool _petActive; - int _field1C; + bool _field1C; bool _quitGame; int _field24; uint _nodeChangeCtr; diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index 51631a3e1b..37af6f7d0a 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -239,10 +239,6 @@ bool CPetControl::containsPt(const Common::Point &pt) const { return _drawBounds.contains(pt); } -bool CPetControl::getC0() const { - return _fieldC0 > 0; -} - bool CPetControl::MouseButtonDownMsg(CMouseButtonDownMsg *msg) { if (!containsPt(msg->_mousePos) || getC0()) return false; diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index cf1589ca62..71785cedb6 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -92,8 +92,6 @@ private: */ bool containsPt(const Common::Point &pt) const; - bool getC0() const; - /** * Checks whether a designated NPC in present in the current view */ @@ -304,6 +302,10 @@ public: * Resets the dial display to reflect new values */ void resetDials(int flag = 1); + + bool getC0() const { return _fieldC0 > 0; } + void incC0() { ++_fieldC0; } + void decC0() { --_fieldC0; } }; } // End of namespace Titanic diff --git a/engines/titanic/support/movie.cpp b/engines/titanic/support/movie.cpp index 1c94cab250..26620de3a6 100644 --- a/engines/titanic/support/movie.cpp +++ b/engines/titanic/support/movie.cpp @@ -26,7 +26,8 @@ namespace Titanic { -CMovie::CMovie() : ListItem(), _state(MOVIE_STOPPED), _field10(0) { +CMovie::CMovie() : ListItem(), _state(MOVIE_STOPPED), _field10(0), + _field14(0) { } CMovie::~CMovie() { @@ -50,7 +51,10 @@ bool CMovie::get10() { OSMovie::OSMovie(const CResourceKey &name, CVideoSurface *surface) : _videoSurface(surface), _gameObject(nullptr), _endFrame(-1) { - _video = new Video::AVIDecoder(); + Video::AVIDecoder *decoder = new Video::AVIDecoder(); + _video = decoder; + _field14 = 1; + if (!_video->loadFile(name.getString())) error("Could not open video - %s", name.getString().c_str()); } diff --git a/engines/titanic/support/movie.h b/engines/titanic/support/movie.h index 20de84afa5..01f107ec5b 100644 --- a/engines/titanic/support/movie.h +++ b/engines/titanic/support/movie.h @@ -45,6 +45,8 @@ class CMovie : public ListItem { protected: MovieState _state; int _field10; +public: + int _field14; public: CMovie(); virtual ~CMovie(); diff --git a/engines/titanic/support/video_surface.cpp b/engines/titanic/support/video_surface.cpp index 813138da4a..3b026c546c 100644 --- a/engines/titanic/support/video_surface.cpp +++ b/engines/titanic/support/video_surface.cpp @@ -418,6 +418,10 @@ void OSVideoSurface::setMovieFrame(uint frameNumber) { _movie->setFrame(frameNumber); } +void OSVideoSurface::proc38(int v1, int v2) { + warning("OSVideoSurface::proc38"); +} + bool OSVideoSurface::loadIfReady() { _videoSurfaceNum = _videoSurfaceCounter; diff --git a/engines/titanic/support/video_surface.h b/engines/titanic/support/video_surface.h index aee28be730..8d0dd2ffac 100644 --- a/engines/titanic/support/video_surface.h +++ b/engines/titanic/support/video_surface.h @@ -178,6 +178,8 @@ public: */ virtual void setMovieFrame(uint frameNumber) = 0; + virtual void proc38(int v1, int v2) = 0; + /** * Loads the surface's resource if there's one pending */ @@ -343,6 +345,8 @@ public: */ virtual void setMovieFrame(uint frameNumber); + virtual void proc38(int v1, int v2); + /** * Loads the surface's resource if there's one pending */ -- cgit v1.2.3