diff options
54 files changed, 1373 insertions, 570 deletions
diff --git a/engines/titanic/core/background.cpp b/engines/titanic/core/background.cpp index 63aaf30ae0..ea3bdb01a8 100644 --- a/engines/titanic/core/background.cpp +++ b/engines/titanic/core/background.cpp @@ -49,4 +49,16 @@ void CBackground::load(SimpleFile *file) { CGameObject::load(file); } +bool CBackground::handleMessage(CStatusChangeMsg &msg) { + error("TODO: CBackground::handleMessage"); +} + +bool CBackground::handleMessage(CSetFrameMsg &msg) { + error("TODO: CBackground::handleMessage"); +} + +bool CBackground::handleMessage(CVisibleMsg &msg) { + error("TODO: CBackground::handleMessage"); +} + } // End of namespace Titanic diff --git a/engines/titanic/core/background.h b/engines/titanic/core/background.h index 4ce5651fc4..bd8f94987e 100644 --- a/engines/titanic/core/background.h +++ b/engines/titanic/core/background.h @@ -24,16 +24,24 @@ #define TITANIC_BACKGROUND_H #include "titanic/core/game_object.h" +#include "titanic/messages/messages.h" namespace Titanic { -class CBackground : public CGameObject { +class CBackground : public CGameObject, + public CStatusChangeMsgTarget, + public CSetFrameMsgTarget, + public CVisibleMsgTarget { protected: int _fieldBC; int _fieldC0; CString _string1; CString _string2; int _fieldDC; +protected: + virtual bool handleMessage(CStatusChangeMsg &msg); + virtual bool handleMessage(CSetFrameMsg &msg); + virtual bool handleMessage(CVisibleMsg &msg); public: CLASSDEF CBackground(); diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index a215633932..ee7e071423 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -45,7 +45,7 @@ CGameObject::CGameObject(): CNamedItem() { _field50 = 0; _field54 = 0; _field58 = 0; - _field5C = true; + _visible = true; _field60 = 0; _cursorId = CURSOR_1; _field78 = 0; @@ -54,8 +54,6 @@ CGameObject::CGameObject(): CNamedItem() { _field94 = 0; _field98 = 0; _field9C = 0; - _fieldA0 = 0; - _fieldA4 = 0; _surface = nullptr; _fieldB8 = 0; } @@ -106,7 +104,7 @@ void CGameObject::load(SimpleFile *file) { _field48 = file->readNumber(); _field4C = file->readNumber(); _fieldB8 = file->readNumber(); - _field5C = file->readNumber() != 0; + _visible = file->readNumber() != 0; _field50 = file->readNumber(); _field54 = file->readNumber(); _field58 = file->readNumber(); @@ -131,13 +129,33 @@ void CGameObject::stopMovie() { _surface->stopMovie(); } -bool CGameObject::checkPoint(const Point &pt, int v0, int v1) { - warning("TODO: CGameObject::checkPoint"); - return false; +bool CGameObject::checkPoint(const Point &pt, bool ignore40, bool visibleOnly) { + if ((!_visible && visibleOnly) || !_bounds.contains(pt)) + return false; + + if (ignore40 || _field40) + return true; + + if (!_surface) { + if (_frameNumber == -1) + return true; + loadFrame(_frameNumber); + if (!_surface) + return true; + } + + Common::Point pixelPos = pt - _bounds; + if (_surface->_blitStyleFlag) { + pixelPos.y = ((_bounds.height() - _bounds.top) / 2) * 2 - pixelPos.y; + } + + uint transColor = _surface->getTransparencyColor(); + uint pixel = _surface->getPixel(pixelPos); + return pixel != transColor; } void CGameObject::draw(CScreenManager *screenManager) { - if (!_field5C) + if (!_visible) return; if (_v1) { error("TODO: Block in CGameObject::draw"); @@ -184,6 +202,22 @@ void CGameObject::draw(CScreenManager *screenManager) { } } +void CGameObject::draw(CScreenManager *screenManager, const Common::Point &destPos) { + if (!_surface && !_resource.empty()) { + loadResource(_resource); + _resource.clear(); + } + + if (_surface) { + int xSize = _surface->getWidth(); + int ySize = _surface->getHeight(); + + if (xSize > 0 && ySize > 0) { + screenManager->blitFrom(SURFACE_BACKBUFFER, _surface, &destPos); + } + } +} + void CGameObject::loadResource(const CString &name) { switch (name.imageTypeSuffix()) { case FILETYPE_IMAGE: @@ -276,28 +310,23 @@ void CGameObject::soundFn2(int val, int val2) { } } -void CGameObject::set5C(bool val) { - if (val != _field5C) { - _field5C = val; +void CGameObject::setVisible(bool val) { + if (val != _visible) { + _visible = val; makeDirty(); } } -bool CGameObject::petFn1(int val) { - CPetControl *pet = getPetControl(); - return pet ? pet->fn1(val) : true; -} - void CGameObject::petFn2(int val) { CPetControl *pet = getPetControl(); if (pet) pet->fn2(val); } -void CGameObject::petFn3(int val) { +void CGameObject::petFn3(CTreeItem *item) { CPetControl *pet = getPetControl(); if (pet) - pet->fn3(val); + pet->fn3(item); } void CGameObject::fn1(int val1, int val2, int val3) { @@ -320,4 +349,50 @@ void CGameObject::changeStatus(int newStatus) { } } +void CGameObject::savePosition() { + _savedPos = _bounds; +} + +void CGameObject::resetPosition() { + setPosition(_savedPos); +} + +void CGameObject::setPosition(const Common::Point &newPos) { + makeDirty(); + _bounds.moveTo(newPos); + makeDirty(); +} + +bool CGameObject::checkStartDragging(CMouseDragStartMsg *msg) { + if (_visible && checkPoint(msg->_mousePos, msg->_field14, 1)) { + savePosition(); + msg->_dragItem = this; + return true; + } else { + return false; + } +} + +void CGameObject::setPetArea(PetArea newArea) const { + CPetControl *pet = getPetControl(); + if (pet) + pet->setArea(newArea); +} + +bool CGameObject::hasActiveMovie() const { + if (_surface && _surface->_movie) + return _surface->_movie->isActive(); + return false; +} + +int CGameObject::getMovie19() const { + if (_surface && _surface->_movie) + return _surface->_movie->proc19(); + return _field78; +} + +int CGameObject::getSurface45() const { + return _surface ? _surface->proc45() : 0; +} + } // End of namespace Titanic diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index 2f56f599a0..b221a7ed23 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -27,10 +27,12 @@ #include "titanic/rect.h" #include "titanic/core/movie_clip.h" #include "titanic/core/named_item.h" +#include "titanic/pet_control/pet_section.h" namespace Titanic { class CVideoSurface; +class CMouseDragStartMsg; class CGameObject : public CNamedItem { public: @@ -52,16 +54,6 @@ private: void loadImage(const CString &name, bool pendingFlag = true); void processClipList2(); - - /** - * Marks the area in the passed rect as dirty, and requiring re-rendering - */ - void makeDirty(const Rect &r); - - /** - * Marks the area occupied by the object as dirty, requiring re-rendering - */ - void makeDirty(); protected: Rect _bounds; double _field34; @@ -74,7 +66,7 @@ protected: int _field50; int _field54; int _field58; - bool _field5C; + bool _visible; CMovieClipList _clipList1; int _field78; CMovieClipList _clipList2; @@ -83,23 +75,46 @@ protected: int _field94; int _field98; int _field9C; - int _fieldA0; - int _fieldA4; + Common::Point _savedPos; CVideoSurface *_surface; CString _resource; int _fieldB8; protected: /** - * Loads a frame + * Saves the current position the object is located at */ - void loadFrame(int frameNumber); + void savePosition(); + + /** + * Resets the object back to the previously saved starting position + */ + void resetPosition(); + + /** + * Check for starting to drag the object + */ + bool checkStartDragging(CMouseDragStartMsg *msg); + + /** + * Marks the area in the passed rect as dirty, and requiring re-rendering + */ + void makeDirty(const Rect &r); + + /** + * Marks the area occupied by the object as dirty, requiring re-rendering + */ + void makeDirty(); + + /** + * Sets a new area in the PET + */ + void setPetArea(PetArea newArea) const; bool soundFn1(int val); void soundFn2(int val, int val2); - void set5C(bool val); - bool petFn1(int val); + void setVisible(bool val); void petFn2(int val); - void petFn3(int val); + void petFn3(CTreeItem *item); public: int _field60; CursorId _cursorId; @@ -123,11 +138,20 @@ public: virtual void draw(CScreenManager *screenManager); /** + * Allows the item to draw itself + */ + virtual void draw(CScreenManager *screenManager, const Common::Point &destPos); + + /** * Stops any movie currently playing for the object */ void stopMovie(); - bool checkPoint(const Point &pt, int v0, int v1); + /** + * Checks the passed point is validly in the object, + * with extra checking of object flags status + */ + bool checkPoint(const Point &pt, bool ignore40 = false, bool visibleOnly = false); void fn1(int val1, int val2, int val3); @@ -135,6 +159,24 @@ public: * Change the object's status */ void changeStatus(int newStatus); + + /** + * Set the position of the object + */ + void setPosition(const Common::Point &newPos); + + /** + * Returns true if the object has a currently active movie + */ + bool hasActiveMovie() const; + + int getMovie19() const; + int getSurface45() const; + + /** + * Loads a frame + */ + void loadFrame(int frameNumber); }; } // End of namespace Titanic diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp index f7c715fd66..022a72b33a 100644 --- a/engines/titanic/core/saveable_object.cpp +++ b/engines/titanic/core/saveable_object.cpp @@ -897,6 +897,7 @@ DEFFN(CSetChevLiftBits) DEFFN(CSetChevPanelBitMsg) DEFFN(CSetChevPanelButtonsMsg) DEFFN(CSetChevRoomBits) +DEFFN(CSetFrameMsg); DEFFN(CSetMusicControlsMsg) DEFFN(CSetVarMsg) DEFFN(CSetVolumeMsg) @@ -1479,6 +1480,7 @@ void CSaveableObject::initClassList() { ADDFN(CSetChevPanelBitMsg, CMessage); ADDFN(CSetChevPanelButtonsMsg, CMessage); ADDFN(CSetChevRoomBits, CMessage); + ADDFN(CSetFrameMsg, CMessage); ADDFN(CSetMusicControlsMsg, CMessage); ADDFN(CSetVarMsg, CMessage); ADDFN(CSetVolumeMsg, CMessage); diff --git a/engines/titanic/core/tree_item.cpp b/engines/titanic/core/tree_item.cpp index 2c985bf34e..61fcf97183 100644 --- a/engines/titanic/core/tree_item.cpp +++ b/engines/titanic/core/tree_item.cpp @@ -188,7 +188,7 @@ void CTreeItem::setParent(CTreeItem *newParent) { } void CTreeItem::addSibling(CTreeItem *item) { - _priorSibling = item->_nextSibling; + _priorSibling = item; _nextSibling = item->_nextSibling; _parent = item->_parent; @@ -284,4 +284,9 @@ CTreeItem *CTreeItem::getDontSaveChild(ClassDef *classDef) const { return dontSave->findChildInstanceOf(classDef); } +CRoomItem *CTreeItem::getRoom() const { + CGameManager *gameManager = getGameManager(); + return gameManager ? gameManager->getRoom() : nullptr; +} + } // End of namespace Titanic diff --git a/engines/titanic/core/tree_item.h b/engines/titanic/core/tree_item.h index a6c09b8126..f5e28f1056 100644 --- a/engines/titanic/core/tree_item.h +++ b/engines/titanic/core/tree_item.h @@ -33,6 +33,7 @@ class CNamedItem; class CPetControl; class CProjectItem; class CScreenManager; +class CRoomItem; class CTreeItem: public CMessageTarget { private: @@ -242,6 +243,10 @@ public: */ CTreeItem *getDontSaveChild(ClassDef *classDef) const; + /** + * Return the current room + */ + CRoomItem *getRoom() const; }; } // End of namespace Titanic diff --git a/engines/titanic/debugger.cpp b/engines/titanic/debugger.cpp index 3bd2d0f134..84f961e607 100644 --- a/engines/titanic/debugger.cpp +++ b/engines/titanic/debugger.cpp @@ -27,9 +27,10 @@ namespace Titanic { Debugger::Debugger(TitanicEngine *vm) : GUI::Debugger(), _vm(vm) { - registerCmd("continue", WRAP_METHOD(Debugger, cmdExit)); - registerCmd("dump", WRAP_METHOD(Debugger, cmdDump)); - registerCmd("room", WRAP_METHOD(Debugger, cmdRoom)); + registerCmd("continue", WRAP_METHOD(Debugger, cmdExit)); + registerCmd("dump", WRAP_METHOD(Debugger, cmdDump)); + registerCmd("room", WRAP_METHOD(Debugger, cmdRoom)); + registerCmd("pet", WRAP_METHOD(Debugger, cmdPET)); } int Debugger::strToInt(const char *s) { @@ -181,4 +182,29 @@ bool Debugger::cmdRoom(int argc, const char **argv) { return true; } +bool Debugger::cmdPET(int argc, const char **argv) { + CGameManager &gameManager = *g_vm->_window->_gameManager; + CGameState &gameState = gameManager._gameState; + + if (argc == 2) { + CString s(argv[1]); + s.toLowercase(); + + if (s == "on") { + gameState._petActive = true; + gameManager.update(); + debugPrintf("PET is now on\n"); + return true; + } else if (s == "off") { + gameState._petActive = false; + gameManager.update(); + debugPrintf("PET is now off\n"); + return true; + } + } + + debugPrintf("%s [on | off]\n", argv[0]); + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/debugger.h b/engines/titanic/debugger.h index 2f3bb91a46..29e82d699f 100644 --- a/engines/titanic/debugger.h +++ b/engines/titanic/debugger.h @@ -79,6 +79,11 @@ private: * List room details, or jump to a specific view */ bool cmdRoom(int argc, const char **argv); + + /** + * Turn the PET on or off + */ + bool cmdPET(int argc, const char **argv); protected: TitanicEngine *_vm; public: diff --git a/engines/titanic/game/cdrom.cpp b/engines/titanic/game/cdrom.cpp index 40e8ed05d8..d4e4eac4d1 100644 --- a/engines/titanic/game/cdrom.cpp +++ b/engines/titanic/game/cdrom.cpp @@ -21,6 +21,8 @@ */ #include "titanic/game/cdrom.h" +#include "titanic/core/room_item.h" +#include "titanic/game/cdrom_tray.h" namespace Titanic { @@ -29,14 +31,50 @@ CCDROM::CCDROM() : CGameObject() { void CCDROM::save(SimpleFile *file, int indent) const { file->writeNumberLine(1, indent); - file->writePoint(_pos1, indent); + file->writePoint(_tempPos, indent); CGameObject::save(file, indent); } void CCDROM::load(SimpleFile *file) { file->readNumber(); - _pos1 = file->readPoint(); + _tempPos = file->readPoint(); CGameObject::load(file); } +bool CCDROM::handleMessage(CMouseDragStartMsg &msg) { + if (checkStartDragging(&msg)) { + _tempPos = msg._mousePos - _bounds; + setPosition(msg._mousePos - _tempPos); + return true; + } else { + return false; + } +} + +bool CCDROM::handleMessage(CMouseDragEndMsg &msg) { + if (msg._dropTarget && msg._dropTarget->getName() == "newComputer") { + CCDROMTray *newTray = dynamic_cast<CCDROMTray *>(getRoom()->findByName("newTray")); + + if (newTray->_state && newTray->_string1 == "None") { + CActMsg actMsg(getName()); + actMsg.execute(newTray); + } + } + + resetPosition(); + return true; +} + +bool CCDROM::handleMessage(CMouseDragMoveMsg &msg) { + setPosition(msg._mousePos - _tempPos); + return true; +} + +bool CCDROM::handleMessage(CActMsg &msg) { + if (msg._action == "Ejected") + setVisible(true); + + return true; +} + } // End of namespace Titanic diff --git a/engines/titanic/game/cdrom.h b/engines/titanic/game/cdrom.h index c1280f6712..61bada0b74 100644 --- a/engines/titanic/game/cdrom.h +++ b/engines/titanic/game/cdrom.h @@ -24,12 +24,23 @@ #define TITANIC_CDROM_H #include "titanic/core/game_object.h" +#include "titanic/messages/messages.h" +#include "titanic/messages/mouse_messages.h" namespace Titanic { -class CCDROM : public CGameObject { +class CCDROM : public CGameObject, + public CMouseDragStartMsgTarget, + public CMouseDragEndMsgTarget, + public CMouseDragMoveMsgTarget, + public CActMsgTarget { private: - Point _pos1; + Point _tempPos; +protected: + virtual bool handleMessage(CMouseDragStartMsg &msg); + virtual bool handleMessage(CMouseDragEndMsg &msg); + virtual bool handleMessage(CMouseDragMoveMsg &msg); + virtual bool handleMessage(CActMsg &msg); public: CLASSDEF CCDROM(); diff --git a/engines/titanic/game/cdrom_tray.cpp b/engines/titanic/game/cdrom_tray.cpp index 32eea0648b..fcb65fd42d 100644 --- a/engines/titanic/game/cdrom_tray.cpp +++ b/engines/titanic/game/cdrom_tray.cpp @@ -24,12 +24,12 @@ namespace Titanic { -CCDROMTray::CCDROMTray() : CGameObject(), _fieldBC(0) { +CCDROMTray::CCDROMTray() : CGameObject(), _state(0) { } void CCDROMTray::save(SimpleFile *file, int indent) const { file->writeNumberLine(1, indent); - file->writeNumberLine(_fieldBC, indent); + file->writeNumberLine(_state, indent); file->writeQuotedLine(_string1, indent); CGameObject::save(file, indent); @@ -37,7 +37,7 @@ void CCDROMTray::save(SimpleFile *file, int indent) const { void CCDROMTray::load(SimpleFile *file) { file->readNumber(); - _fieldBC = file->readNumber(); + _state = file->readNumber(); _string1 = file->readString(); CGameObject::load(file); diff --git a/engines/titanic/game/cdrom_tray.h b/engines/titanic/game/cdrom_tray.h index 85d26c5a1d..b5c4b375fe 100644 --- a/engines/titanic/game/cdrom_tray.h +++ b/engines/titanic/game/cdrom_tray.h @@ -28,8 +28,8 @@ namespace Titanic { class CCDROMTray : public CGameObject { -private: - int _fieldBC; +public: + int _state; CString _string1; public: CLASSDEF diff --git a/engines/titanic/game/pet/pet_val_base.h b/engines/titanic/game/pet/pet_val_base.h index 310b0675b1..cdb2808108 100644 --- a/engines/titanic/game/pet/pet_val_base.h +++ b/engines/titanic/game/pet/pet_val_base.h @@ -20,12 +20,12 @@ * */ -#ifndef TITANIC_PET_VAL_BASE_H -#define TITANIC_PET_VAL_BASE_H +#ifndef TITANIC_pet_element_H +#define TITANIC_pet_element_H namespace Titanic { -class CPetValBase { +class CPetElement { protected: int _field4; int _field8; @@ -33,7 +33,7 @@ protected: int _field10; int _field14; public: - CPetValBase(); + CPetElement(); virtual void proc1() {} virtual void proc2() {} @@ -58,4 +58,4 @@ public: } // End of namespace Titanic -#endif /* TITANIC_PET_VAL_BASE_H */ +#endif /* TITANIC_pet_element_H */ diff --git a/engines/titanic/game/television.cpp b/engines/titanic/game/television.cpp index 8149b8d017..c11d446fe4 100644 --- a/engines/titanic/game/television.cpp +++ b/engines/titanic/game/television.cpp @@ -90,7 +90,7 @@ bool CTelevision::handleMessage(CLeaveViewMsg &msg) { loadFrame(622); stopMovie(); - set5C(0); + setVisible(0); _isOn = false; if (compareRoomNameTo("CSGState")) { @@ -121,10 +121,10 @@ bool CTelevision::handleMessage(CChangeSeasonMsg &msg) { } bool CTelevision::handleMessage(CEnterViewMsg &msg) { - petFn1(2); + setPetArea(PET_REMOTE); petFn2(2); petFn3(0); - set5C(0); + setVisible(0); _fieldE0 = 1; return true; @@ -175,12 +175,12 @@ bool CTelevision::handleMessage(CActMsg &msg) { if (msg._action == "TurnTVOnOff") { _isOn = !_isOn; if (_isOn) { - set5C(true); + setVisible(true); CStatusChangeMsg changeMsg; changeMsg.execute(this); } else { // TODO: Should 5C be a boolean? - set5C(_isOn); + setVisible(_isOn); stopMovie(); } } @@ -194,7 +194,7 @@ bool CTelevision::handleMessage(CPETActivateMsg &msg) { _isOn = !_isOn; if (_isOn) { - set5C(true); + setVisible(true); fn1(0, 55, 0); _fieldE0 = 1; } else { @@ -202,7 +202,7 @@ bool CTelevision::handleMessage(CPETActivateMsg &msg) { if (soundFn1(_fieldF0)) soundFn2(_fieldF0, 0); - set5C(false); + setVisible(false); } if (compareRoomNameTo("SGTState")) diff --git a/engines/titanic/game/television.h b/engines/titanic/game/television.h index 3b44f80c1a..c6c920b74c 100644 --- a/engines/titanic/game/television.h +++ b/engines/titanic/game/television.h @@ -35,7 +35,6 @@ class CTelevision : public CBackground, public CEnterViewMsgTarget, public CPETUpMsgTarget, public CPETDownMsgTarget, - public CStatusChangeMsgTarget, public CActMsgTarget, public CPETActivateMsgTarget, public CMovieEndMsgTarget, diff --git a/engines/titanic/main_game_window.cpp b/engines/titanic/main_game_window.cpp index 0b0bb92921..6abe83bd3f 100644 --- a/engines/titanic/main_game_window.cpp +++ b/engines/titanic/main_game_window.cpp @@ -147,7 +147,7 @@ void CMainGameWindow::drawPet(CScreenManager *screenManager) { if (_gameView && _gameView->_surface) { CPetControl *petControl = _gameManager->_project->getPetControl(); if (petControl) - petControl->proc26(); + petControl->draw(screenManager); } } diff --git a/engines/titanic/messages/messages.h b/engines/titanic/messages/messages.h index 77d53f21a6..99df239eda 100644 --- a/engines/titanic/messages/messages.h +++ b/engines/titanic/messages/messages.h @@ -366,6 +366,7 @@ MESSAGE1(CSetChevLiftBits, int, value, 0); MESSAGE2(CSetChevPanelBitMsg, int, value1, 0, int, value2, 0); MESSAGE1(CSetChevPanelButtonsMsg, int, value, 0); MESSAGE1(CSetChevRoomBits, int, value, 0); +MESSAGE1(CSetFrameMsg, int, frameNumber, 0); MESSAGE0(CSetMusicControlsMsg); MESSAGE2(CSetVarMsg, CString, varName, "", int, value, 0); MESSAGE2(CSetVolumeMsg, int, value1, 70, int, value2, 0); diff --git a/engines/titanic/messages/mouse_messages.h b/engines/titanic/messages/mouse_messages.h index 7fe7ef960f..41943818e2 100644 --- a/engines/titanic/messages/mouse_messages.h +++ b/engines/titanic/messages/mouse_messages.h @@ -179,12 +179,12 @@ public: MSGTARGET(CMouseDragEndMsg); class CMouseDragEndMsg : public CMouseDragMsg { public: - CTreeItem *_dragItem; + CTreeItem *_dropTarget; public: CLASSDEF - CMouseDragEndMsg() : CMouseDragMsg(), _dragItem(nullptr) {} + CMouseDragEndMsg() : CMouseDragMsg(), _dropTarget(nullptr) {} CMouseDragEndMsg(const Point &pt, CTreeItem *dragItem = nullptr) : - CMouseDragMsg(pt), _dragItem(dragItem) {} + CMouseDragMsg(pt), _dropTarget(dragItem) {} static bool isSupportedBy(const CTreeItem *item) { return dynamic_cast<const CMouseDragEndMsgTarget *>(item) != nullptr; diff --git a/engines/titanic/module.mk b/engines/titanic/module.mk index afd8453d88..4eebf04aaf 100644 --- a/engines/titanic/module.mk +++ b/engines/titanic/module.mk @@ -382,20 +382,20 @@ MODULE_OBJS := \ pet_control/pet_control.o \ pet_control/pet_control_list_item.o \ pet_control/pet_control_list_item2.o \ - pet_control/pet_control_sub_base.o \ - pet_control/pet_control_sub1.o \ - pet_control/pet_control_sub2.o \ - pet_control/pet_control_sub3.o \ - pet_control/pet_control_sub4.o \ + pet_control/pet_conversation_section.o \ + pet_control/pet_element.o \ + pet_control/pet_frame.o \ + pet_control/pet_graphic.o \ + pet_control/pet_inventory_section.o \ + pet_control/pet_rooms_section.o \ + pet_control/pet_remote_section.o \ + pet_control/pet_save_section.o \ + pet_control/pet_section.o \ pet_control/pet_control_sub5.o \ - pet_control/pet_control_sub6.o \ pet_control/pet_control_sub7.o \ - pet_control/pet_control_sub8.o \ pet_control/pet_control_sub10.o \ pet_control/pet_control_sub11.o \ pet_control/pet_control_sub12.o \ - pet_control/pet_val_base.o \ - pet_control/pet_val.o \ sound/auto_music_player.o \ sound/auto_music_player_base.o \ sound/auto_sound_player.o \ diff --git a/engines/titanic/movie.cpp b/engines/titanic/movie.cpp index 09c02a7964..193b2cad33 100644 --- a/engines/titanic/movie.cpp +++ b/engines/titanic/movie.cpp @@ -25,6 +25,24 @@ namespace Titanic { +CMovie::CMovie() : ListItem(), _state(0), _field10(0) { +} + +bool CMovie::isActive() const { + return g_vm->_movieList.contains(this); +} + +bool CMovie::get10() { + if (_field10) { + _field10 = 0; + return true; + } else { + return false; + } +} + +/*------------------------------------------------------------------------*/ + OSMovie::OSMovie(const CResourceKey &name, CVideoSurface *surface) : _videoSurface(surface) { // _aviDecoder.loadFile(name.getString()); } @@ -79,8 +97,9 @@ void OSMovie::proc18() { warning("TODO: OSMovie::proc18"); } -void OSMovie::proc19() { +int OSMovie::proc19() { warning("TODO: OSMovie::proc19"); + return 0; } void OSMovie::proc20() { @@ -92,10 +111,4 @@ void *OSMovie::proc21() { return nullptr; } -bool OSMovie::isInGlobalList() const { - return g_vm->_movieList.contains(this); -} - -/*------------------------------------------------------------------------*/ - } // End of namespace Titanic diff --git a/engines/titanic/movie.h b/engines/titanic/movie.h index 4a5777aa03..3529409fa5 100644 --- a/engines/titanic/movie.h +++ b/engines/titanic/movie.h @@ -32,7 +32,12 @@ namespace Titanic { class CVideoSurface; class CMovie : public ListItem { +protected: + int _state; + int _field10; public: + CMovie(); + virtual void proc8(int v1, CVideoSurface *surface) = 0; virtual void proc9() = 0; virtual void proc10() = 0; @@ -44,9 +49,13 @@ public: virtual void proc16() = 0; virtual void proc17() = 0; virtual void proc18() = 0; - virtual void proc19() = 0; + virtual int proc19() = 0; virtual void proc20() = 0; virtual void *proc21() = 0; + + bool isActive() const; + + bool get10(); }; class OSMovie : public CMovie { @@ -72,11 +81,9 @@ public: virtual void proc16(); virtual void proc17(); virtual void proc18(); - virtual void proc19(); + virtual int proc19(); virtual void proc20(); virtual void *proc21(); - - bool isInGlobalList() const; }; class CGlobalMovies : public List<CMovie> { diff --git a/engines/titanic/pet_control/pet_control.cpp b/engines/titanic/pet_control/pet_control.cpp index f3e78a2212..4fe0c1d255 100644 --- a/engines/titanic/pet_control/pet_control.cpp +++ b/engines/titanic/pet_control/pet_control.cpp @@ -21,18 +21,24 @@ */ #include "titanic/pet_control/pet_control.h" +#include "titanic/core/project_item.h" #include "titanic/game_manager.h" #include "titanic/game_state.h" namespace Titanic { +CPetControl::CPetControl() : CGameObject(), + _currentArea(PET_CONVERSATION), _fieldC0(0), _locked(0), _fieldC8(0), + _treeItem1(nullptr), _treeItem2(nullptr), _hiddenRoom(nullptr) { +} + void CPetControl::save(SimpleFile *file, int indent) const { file->writeNumberLine(0, indent); - file->writeNumberLine(_fieldBC, indent); + file->writeNumberLine(_currentArea, indent); file->writeQuotedLine(_string1, indent); file->writeQuotedLine(_string2, indent); - saveSubObjects(file, indent); + saveAreas(file, indent); CGameObject::save(file, indent); } @@ -41,51 +47,112 @@ void CPetControl::load(SimpleFile *file) { isValid(); if (!val) { - _fieldBC = file->readNumber(); + _currentArea = (PetArea)file->readNumber(); _string1 = file->readString(); _string2 = file->readString(); - loadSubObjects(file, 0); + loadAreas(file, 0); } CGameObject::load(file); } -bool CPetControl::isValid() const { - return _sub1.isValid() && _sub2.isValid() - && _sub3.isValid() && _sub4.isValid() - && _sub5.isValid() && _sub6.isValid() - && _sub7.isValid() && _sub8.isValid(); +bool CPetControl::isValid() { + return _convSection.isValid(this) && + _roomsSection.isValid(this) && + _remoteSection.isValid(this) && + _invSection.isValid(this) && + _sub5.isValid(this) && + _saveSection.isValid(this) && + _sub7.isValid(this) && + _frame.isValid(this); } -void CPetControl::loadSubObjects(SimpleFile *file, int param) { - _sub1.load(file, param); - _sub2.load(file, param); - _sub3.load(file, param); - _sub4.load(file, param); +void CPetControl::loadAreas(SimpleFile *file, int param) { + _convSection.load(file, param); + _roomsSection.load(file, param); + _remoteSection.load(file, param); + _invSection.load(file, param); _sub5.load(file, param); - _sub6.load(file, param); + _saveSection.load(file, param); _sub7.load(file, param); - _sub8.load(file, param); + _frame.load(file, param); } -void CPetControl::saveSubObjects(SimpleFile *file, int indent) const { - _sub1.save(file, indent); - _sub2.save(file, indent); - _sub3.save(file, indent); - _sub4.save(file, indent); +void CPetControl::saveAreas(SimpleFile *file, int indent) const { + _convSection.save(file, indent); + _roomsSection.save(file, indent); + _remoteSection.save(file, indent); + _invSection.save(file, indent); _sub5.save(file, indent); - _sub6.save(file, indent); + _saveSection.save(file, indent); _sub7.save(file, indent); - _sub8.save(file, indent); + _frame.save(file, indent); } -void CPetControl::proc26() { - warning("TODO: CPetControl::proc26"); +void CPetControl::draw(CScreenManager *screenManager) { + CGameManager *gameManager = getGameManager(); + Rect bounds = _oldBounds; + bounds.constrain(gameManager->_bounds); + + if (!bounds.isEmpty()) { + if (_fieldC8 >= 0) { + _invSection.proc5(_fieldC8); + _fieldC8 = -1; + } + + _frame.drawFrame(screenManager); + + // Draw the specific area that's currently active + switch (_currentArea) { + case PET_INVENTORY: + _invSection.draw(screenManager); + break; + case PET_CONVERSATION: + _convSection.draw(screenManager); + break; + case PET_REMOTE: + _remoteSection.draw(screenManager); + break; + case PET_ROOMS: + _roomsSection.draw(screenManager); + break; + case PET_SAVE: + _saveSection.draw(screenManager); + break; + case PET_5: + _sub5.draw(screenManager); + break; + case PET_6: + _sub7.draw(screenManager); + break; + default: + break; + } + } } void CPetControl::postLoad() { - warning("TODO: CPetControl::postLoad"); + CProjectItem *root = getRoot(); + + if (!_string1.empty() && root) + _treeItem1 = root->findByName(_string1); + if (!_string2.empty() && root) + _treeItem2 = root->findByName(_string2); + + setArea(_currentArea); + loaded(); +} + +void CPetControl::loaded() { + _convSection.postLoad(); + _roomsSection.postLoad(); + _remoteSection.postLoad(); + _invSection.postLoad(); + _sub5.postLoad(); + _saveSection.postLoad(); + _sub7.postLoad(); + _frame.postLoad(); } void CPetControl::enterNode(CNodeItem *node) { @@ -93,12 +160,12 @@ void CPetControl::enterNode(CNodeItem *node) { } void CPetControl::enterRoom(CRoomItem *room) { - _sub2.enterRoom(room); - _sub3.enterRoom(room); + _roomsSection.enterRoom(room); + _remoteSection.enterRoom(room); } void CPetControl::clear() { - _field1394 = 0; + _treeItem2 = nullptr; _string2.clear(); } @@ -107,16 +174,139 @@ bool CPetControl::fn1(int val) { return false; } +void CPetControl::fn4() { + warning("TODO: CPetControl::fn4"); +} + +PetArea CPetControl::setArea(PetArea newArea) { + if (newArea == _currentArea || !canChangeArea()) + return _currentArea; + + // Signal the currently active area that it's being left + switch (_currentArea) { + case PET_INVENTORY: + _invSection.leave(); + break; + case PET_CONVERSATION: + _convSection.leave(); + break; + case PET_REMOTE: + _remoteSection.leave(); + break; + case PET_ROOMS: + _roomsSection.leave(); + break; + case PET_SAVE: + _saveSection.leave(); + break; + case PET_5: + _sub5.leave(); + break; + case PET_6: + _sub7.leave(); + break; + default: + break; + } + + // Change the current area + PetArea oldArea = _currentArea; + _frame.setArea(newArea); + _currentArea = newArea; + + // Signal to the new view that it's been activated + switch (newArea) { + case PET_INVENTORY: + _invSection.enter(oldArea); + + break; + case PET_CONVERSATION: + _convSection.enter(oldArea); + break; + case PET_REMOTE: + _remoteSection.enter(oldArea); + break; + case PET_ROOMS: + _roomsSection.enter(oldArea); + break; + case PET_SAVE: + _saveSection.enter(oldArea); + break; + case PET_5: + _sub5.enter(oldArea); + break; + case PET_6: + _sub7.enter(oldArea); + break; + default: + break; + } + + makeDirty(); + return newArea; +} + void CPetControl::fn2(int val) { - warning("TODO: CPetControl::fn2"); + switch (_currentArea) { + case PET_INVENTORY: + _invSection.proc38(val); + break; + case PET_CONVERSATION: + _convSection.proc38(val); + break; + case PET_REMOTE: + _remoteSection.proc38(val); + break; + case PET_ROOMS: + _roomsSection.proc38(val); + break; + case PET_SAVE: + _saveSection.proc38(val); + break; + case PET_5: + _sub5.proc38(val); + break; + case PET_6: + _sub7.proc38(val); + break; + default: + break; + } } -void CPetControl::fn3(int val) { - warning("TODO: CPetControl::fn3"); +void CPetControl::fn3(CTreeItem *item) { + _treeItem2 = item; + if (item) + _string2 = item->getName(); + else + _string2.clear(); } -void CPetControl::fn4() { - warning("TODO: CPetControl::fn4"); +CRoomItem *CPetControl::getHiddenRoom() { + if (!_hiddenRoom) + _hiddenRoom = getHiddenRoom(); + + return _hiddenRoom; +} + +CGameObject *CPetControl::findItemInRoom(CRoomItem *room, + const CString &name) const { + if (!room) + return nullptr; + + for (CTreeItem *treeItem = room->getFirstChild(); treeItem; + treeItem = treeItem->scan(room)) { + if (!treeItem->getName().compareTo(name)) { + return dynamic_cast<CGameObject *>(treeItem); + } + } + + return nullptr; +} + +CGameObject *CPetControl::getHiddenObject(const CString &name) { + CRoomItem *room = getHiddenRoom(); + return room ? findItemInRoom(room, name) : nullptr; } } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control.h b/engines/titanic/pet_control/pet_control.h index b0762736fb..4f101caaf5 100644 --- a/engines/titanic/pet_control/pet_control.h +++ b/engines/titanic/pet_control/pet_control.h @@ -26,47 +26,70 @@ #include "titanic/core/game_object.h" #include "titanic/core/node_item.h" #include "titanic/core/room_item.h" -#include "titanic/pet_control/pet_control_sub1.h" -#include "titanic/pet_control/pet_control_sub2.h" -#include "titanic/pet_control/pet_control_sub3.h" -#include "titanic/pet_control/pet_control_sub4.h" +#include "titanic/pet_control/pet_conversation_section.h" +#include "titanic/pet_control/pet_frame.h" +#include "titanic/pet_control/pet_inventory_section.h" +#include "titanic/pet_control/pet_remote_section.h" +#include "titanic/pet_control/pet_rooms_section.h" +#include "titanic/pet_control/pet_save_section.h" #include "titanic/pet_control/pet_control_sub5.h" -#include "titanic/pet_control/pet_control_sub6.h" #include "titanic/pet_control/pet_control_sub7.h" -#include "titanic/pet_control/pet_control_sub8.h" namespace Titanic { class CPetControl : public CGameObject { private: - int _fieldBC; + PetArea _currentArea; int _fieldC0; - int _fieldC4; + int _locked; int _fieldC8; - CPetControlSub1 _sub1; - CPetControlSub2 _sub2; - CPetControlSub3 _sub3; - CPetControlSub4 _sub4; + CPetConversationSection _convSection; + CPetInventorySection _invSection; + CPetRemoteSection _remoteSection; + CPetRoomsSection _roomsSection; + CPetSaveSection _saveSection; CPetControlSub5 _sub5; - CPetControlSub6 _sub6; CPetControlSub7 _sub7; - CPetControlSub8 _sub8; - int _field1384; + CPetFrame _frame; + CTreeItem *_treeItem1; CString _string1; - int _field1394; + CTreeItem *_treeItem2; CString _string2; - int _field13A4; + CRoomItem *_hiddenRoom; + Rect _oldBounds; private: /** * Returns true if the control is in a valid state */ - bool isValid() const; + bool isValid(); - void loadSubObjects(SimpleFile *file, int param); + /** + * Loads data for the individual areas + */ + void loadAreas(SimpleFile *file, int param); + + /** + * Saves data for the individual areas + */ + void saveAreas(SimpleFile *file, int indent) const; + + /** + * Called at the end of the post game-load handling + */ + void loaded(); + + /** + * Scan the specified room for an item by name + */ + CGameObject *findItemInRoom(CRoomItem *room, const CString &name) const; - void saveSubObjects(SimpleFile *file, int indent) const; + /** + * Returns a reference to the special hidden room container + */ + CRoomItem *getHiddenRoom(); public: CLASSDEF + CPetControl(); /** * Save the data for the class to file @@ -78,7 +101,10 @@ public: */ virtual void load(SimpleFile *file); - virtual void proc26(); + /** + * Allows the item to draw itself + */ + virtual void draw(CScreenManager *screenManager); /** * Called after loading a game has finished @@ -104,9 +130,25 @@ public: void fn2(int val); - void fn3(int val); + void fn3(CTreeItem *item); void fn4(); + + /** + * Sets the currently viewed area within the PET + */ + PetArea setArea(PetArea newSection); + + /** + * Returns true if the current area can be changed + */ + bool canChangeArea() const { return _locked == 0; } + + /** + * Returns a game object used by the PET by name from within the + * special hidden room container + */ + CGameObject *getHiddenObject(const CString &name); }; } // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control_list_item.h b/engines/titanic/pet_control/pet_control_list_item.h index 64808c0309..e8210714c1 100644 --- a/engines/titanic/pet_control/pet_control_list_item.h +++ b/engines/titanic/pet_control/pet_control_list_item.h @@ -24,13 +24,13 @@ #define TITANIC_PET_CONTROL_LIST_ITEM_H #include "titanic/core/list.h" -#include "titanic/pet_control/pet_val.h" +#include "titanic/pet_control/pet_graphic.h" namespace Titanic { class CPetControlListItem : public ListItem { protected: - CPetVal _val; + CPetGraphic _val; int _field30; public: CPetControlListItem() : _field30(0) {} diff --git a/engines/titanic/pet_control/pet_control_sub10.h b/engines/titanic/pet_control/pet_control_sub10.h index f8534d7089..a6f863cb15 100644 --- a/engines/titanic/pet_control/pet_control_sub10.h +++ b/engines/titanic/pet_control/pet_control_sub10.h @@ -37,9 +37,9 @@ protected: int _field1C; int _field20; int _field24; - CPetVal _val1; - CPetVal _val2; - CPetVal _val3; + CPetGraphic _val1; + CPetGraphic _val2; + CPetGraphic _val3; public: CPetControlSub10(); diff --git a/engines/titanic/pet_control/pet_control_sub5.h b/engines/titanic/pet_control/pet_control_sub5.h index 5ef1b26312..f82a1eb3f1 100644 --- a/engines/titanic/pet_control/pet_control_sub5.h +++ b/engines/titanic/pet_control/pet_control_sub5.h @@ -23,23 +23,23 @@ #ifndef TITANIC_PET_CONTROL_SUB5_H #define TITANIC_PET_CONTROL_SUB5_H -#include "titanic/pet_control/pet_control_sub_base.h" +#include "titanic/pet_control/pet_section.h" #include "titanic/pet_control/pet_control_sub12.h" -#include "titanic/pet_control/pet_val.h" +#include "titanic/pet_control/pet_graphic.h" namespace Titanic { -class CPetControlSub5 : public CPetControlSubBase { +class CPetControlSub5 : public CPetSection { private: - CPetVal _val1; - CPetVal _val2; - CPetVal _val3; - CPetVal _val4; + CPetGraphic _val1; + CPetGraphic _val2; + CPetGraphic _val3; + CPetGraphic _val4; int _field98; int _field9C; int _fieldA0; - CPetVal _valArray1[6]; - CPetControlSubData _field17C; + CPetGraphic _valArray1[6]; + int _field17C; int _field18C; CPetControlSub12 _sub12; int _field20C; diff --git a/engines/titanic/pet_control/pet_control_sub7.h b/engines/titanic/pet_control/pet_control_sub7.h index f4a1decf12..fba7d2d6bf 100644 --- a/engines/titanic/pet_control/pet_control_sub7.h +++ b/engines/titanic/pet_control/pet_control_sub7.h @@ -23,12 +23,12 @@ #ifndef TITANIC_PET_CONTROL_SUB7_H #define TITANIC_PET_CONTROL_SUB7_H -#include "titanic/pet_control/pet_control_sub_base.h" +#include "titanic/pet_control/pet_section.h" #include "titanic/pet_control/pet_control_sub12.h" namespace Titanic { -class CPetControlSub7 : public CPetControlSubBase { +class CPetControlSub7 : public CPetSection { private: CPetControlSub12 _sub1; CPetControlSub12 _sub2; diff --git a/engines/titanic/pet_control/pet_control_sub8.cpp b/engines/titanic/pet_control/pet_control_sub8.cpp deleted file mode 100644 index 18c68c7ddb..0000000000 --- a/engines/titanic/pet_control/pet_control_sub8.cpp +++ /dev/null @@ -1,36 +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. - * - */ - -#include "titanic/pet_control/pet_control_sub8.h" - -namespace Titanic { - -static const int INDEXES[6] = { 1, 0, 2, 3, 4, 5 }; - -int CPetControlSub8::_indexes[6]; - -CPetControlSub8::CPetControlSub8() { - for (int idx = 0; idx < 6; ++idx) - _indexes[INDEXES[idx]] = idx; -} - -} // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control_sub1.cpp b/engines/titanic/pet_control/pet_conversation_section.cpp index 0daae0637d..890a03dac6 100644 --- a/engines/titanic/pet_control/pet_control_sub1.cpp +++ b/engines/titanic/pet_control/pet_conversation_section.cpp @@ -20,18 +20,19 @@ * */ -#include "titanic/pet_control/pet_control_sub1.h" +#include "titanic/pet_control/pet_conversation_section.h" namespace Titanic { -CPetControlSub1::CPetControlSub1() : _field414(0), _field418(0) { +CPetConversationSection::CPetConversationSection() : CPetSection(), + _field414(0), _field418(0) { } -void CPetControlSub1::save(SimpleFile *file, int indent) const { +void CPetConversationSection::save(SimpleFile *file, int indent) const { } -void CPetControlSub1::load(SimpleFile *file, int param) { +void CPetConversationSection::load(SimpleFile *file, int param) { _sub2.load(file, param); _sub1.load(file, param); diff --git a/engines/titanic/pet_control/pet_control_sub1.h b/engines/titanic/pet_control/pet_conversation_section.h index 5d0edb6c9f..15d57e7272 100644 --- a/engines/titanic/pet_control/pet_control_sub1.h +++ b/engines/titanic/pet_control/pet_conversation_section.h @@ -20,29 +20,29 @@ * */ -#ifndef TITANIC_PET_CONTROL_SUB1_H -#define TITANIC_PET_CONTROL_SUB1_H +#ifndef TITANIC_PET_CONVERSATION_SECTION_H +#define TITANIC_PET_CONVERSATION_SECTION_H -#include "titanic/pet_control/pet_control_sub_base.h" +#include "titanic/pet_control/pet_section.h" #include "titanic/pet_control/pet_control_sub12.h" -#include "titanic/pet_control/pet_val.h" +#include "titanic/pet_control/pet_graphic.h" namespace Titanic { -class CPetControlSub1 : public CPetControlSubBase { +class CPetConversationSection : public CPetSection { private: - CPetVal _val1; - CPetVal _val2; - CPetVal _val3; - CPetVal _valArray1[3]; - CPetVal _val4; - CPetVal _val5; - CPetVal _val6; - CPetControlSubData _field14C; - CPetVal _val7; - CPetVal _val8; - CPetVal _val9; - CPetVal _valArray2[9]; + CPetGraphic _val1; + CPetGraphic _val2; + CPetGraphic _val3; + CPetGraphic _valArray1[3]; + CPetGraphic _val4; + CPetGraphic _val5; + CPetGraphic _val6; + int _field14C; + CPetGraphic _val7; + CPetGraphic _val8; + CPetGraphic _val9; + CPetGraphic _valArray2[9]; int _field30C; CPetControlSub12 _sub1; CPetControlSub12 _sub2; @@ -51,7 +51,7 @@ private: int _field418; CString _string1; public: - CPetControlSub1(); + CPetConversationSection(); /** * Save the data for the class to file @@ -66,4 +66,4 @@ public: } // End of namespace Titanic -#endif /* TITANIC_PET_CONTROL_SUB1_H */ +#endif /* TITANIC_PET_CONVERSATION_SECTION_H */ diff --git a/engines/titanic/pet_control/pet_element.cpp b/engines/titanic/pet_control/pet_element.cpp new file mode 100644 index 0000000000..39d8fea7d9 --- /dev/null +++ b/engines/titanic/pet_control/pet_element.cpp @@ -0,0 +1,100 @@ +/* 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. + * + */ + +#include "common/textconsole.h" +#include "titanic/pet_control/pet_element.h" +#include "titanic/core/game_object.h" + +namespace Titanic { + +CPetElement::CPetElement() : _mode(MODE_0) {} + +void CPetElement::getBounds(Rect *rect) { + if (rect) + *rect = Rect(); +} + +bool CPetElement::proc6(const Common::Point &pt) { + bool result = _bounds.contains(pt); + if (result) + setMode(MODE_1); + return result; +} + +bool CPetElement::proc7(const Common::Point &pt) { + bool result = _bounds.contains(pt); + if (result) + setMode(MODE_0); + return result; +} + +bool CPetElement::contains1(const Common::Point &pt) const { + return _bounds.contains(pt); +} + +int CPetElement::proc9(const Common::Point &pt) { + bool result = _bounds.contains(pt); + if (result) + setMode(MODE_2); + return result; +} + +bool CPetElement::contains2(const Common::Point &pt) const { + return _bounds.contains(pt); +} + +void CPetElement::proc11(int val1, int val2) const { + CGameObject *gameObject = getObject(); + + if (gameObject) + gameObject->fn1(val1, val2, 0); +} + +void CPetElement::changeStatus(int newStatus) const { + CGameObject *gameObject = getObject(); + + if (gameObject) + gameObject->changeStatus(newStatus); +} + +bool CPetElement::hasActiveMovie() const { + CGameObject *gameObject = getObject(); + return gameObject ? gameObject->hasActiveMovie() : false; +} + +void CPetElement::loadFrame(int frameNumber) { + CGameObject *gameObject = getObject(); + if (gameObject) + gameObject->loadFrame(frameNumber); +} + +int CPetElement::proc15() { + CGameObject *gameObject = getObject(); + return gameObject ? gameObject->getMovie19() : 0; +} + +void CPetElement::setMode(PetElementMode newMode) { + if (newMode >= MODE_0 && newMode <= MODE_2) + changeMode(newMode); +} + +} // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_element.h b/engines/titanic/pet_control/pet_element.h new file mode 100644 index 0000000000..e5ab8d3fdd --- /dev/null +++ b/engines/titanic/pet_control/pet_element.h @@ -0,0 +1,127 @@ +/* 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. + * + */ + +#ifndef TITANIC_PET_ELEMENT_H +#define TITANIC_PET_ELEMENT_H + +#include "titanic/simple_file.h" +#include "titanic/string.h" +#include "titanic/core/link_item.h" + +namespace Titanic { + +enum PetElementMode { MODE_0 = 0, MODE_1 = 1, MODE_2 = 2 }; + +class CGameObject; +class CPetControl; + +class CPetElement { +protected: + Rect _bounds; + PetElementMode _mode; +public: + CPetElement(); + virtual ~CPetElement() {} + + /** + * Sets up the element + */ + virtual void setup(PetElementMode mode, const CString &name, + CPetControl *petControl) {} + + /** + * Sets up the element + */ + virtual void setup() {} + + /** + * Draw the item + */ + virtual void draw(CScreenManager *screenManager) {} + + /** + * Draw the item + */ + virtual void draw(CScreenManager *screenManager, const Common::Point &destPos) {} + + /** + * Get the bounds for the element + */ + virtual void getBounds(Rect *rect); + + virtual bool proc6(const Common::Point &pt); + virtual bool proc7(const Common::Point &pt); + + /** + * Returns whether the passed point falls inside the item + */ + virtual bool contains1(const Common::Point &pt) const; + + virtual int proc9(const Common::Point &pt); + + /** + * Returns whether the passed point falls inside the item + */ + virtual bool contains2(const Common::Point &pt) const; + + virtual void proc11(int val1, int val2) const; + + /** + * Change the status of the associated object + */ + virtual void changeStatus(int newStatus) const; + + /** + * Returns true if the object associated with the item has an active movie + */ + virtual bool hasActiveMovie() const; + + /** + * Loads a frame + */ + virtual void loadFrame(int frameNumber); + + virtual int proc15(); + + /** + * Get the game object associated with this item + */ + virtual CGameObject *getObject() const { return nullptr; } + + virtual void changeMode(PetElementMode newMode) { _mode = newMode; } + + void setMode(PetElementMode mode); + + /** + * Set the bounds for the element + */ + void setBounds(const Rect &r) { _bounds = r; } + + /** + * Translate the position of the element + */ + void translate(int deltaX, int deltaY) { _bounds.translate(deltaX, deltaY); } +}; + +} // End of namespace Titanic + +#endif /* TITANIC_PET_ELEMENT_H */ diff --git a/engines/titanic/pet_control/pet_frame.cpp b/engines/titanic/pet_control/pet_frame.cpp new file mode 100644 index 0000000000..e94bc6c848 --- /dev/null +++ b/engines/titanic/pet_control/pet_frame.cpp @@ -0,0 +1,104 @@ +/* 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. + * + */ + +#include "titanic/pet_control/pet_frame.h" + +namespace Titanic { + +static const int INDEXES[6] = { 1, 0, 2, 3, 4, 5 }; + +int CPetFrame::_indexes[6]; + +CPetFrame::CPetFrame() { + for (int idx = 0; idx < 6; ++idx) + _indexes[INDEXES[idx]] = idx; +} + +bool CPetFrame::setup(CPetControl *petControl) { + if (setPetControl(petControl)) + return setup(); + return false; +} + +bool CPetFrame::setup() { + if (_petControl) { + // TODO + } + + return true; +} + +bool CPetFrame::isValid(CPetControl *petControl) { + bool result = setPetControl(petControl); + if (result) { + _modeButtons[_indexes[0]].setMode(MODE_0); + _modeButtons[_indexes[4]].setMode(MODE_1); + } + + return result; +} + +void CPetFrame::postLoad() { + setup(); +} + +bool CPetFrame::setPetControl(CPetControl *petControl) { + if (petControl) { + _petControl = petControl; + + // Set the bounds of the individual elements + _background.setBounds(Rect(20, 350, 620, 480)); + _modeBackground.setBounds(Rect(590, 365, 611, 467)); + + Rect r(35, 373, 91, 429); + for (int idx = 0, xp = 0; xp < 490; ++idx, xp += 70) { + _indent[idx].setBounds(r); + _indent[idx].translate(xp, 0); + } + + r = Rect(590, 365, 606, 381); + const int YLIST[] = { 7, 27, 45, 66, 84 }; + for (int idx = 0; idx < 5; ++idx) { + _modeButtons[idx].setBounds(r); + _modeButtons[idx].translate(0, YLIST[idx]); + } + _modeButtons[_indexes[0]].setMode(MODE_1); + + const int XLIST[] = { 73, 54, 85, 109, 38, 71 }; + for (int idx = 0; idx < 6; ++idx) { + _titles[idx].setBounds(Rect(0, 0, 110, 11)); + _titles[idx].translate(XLIST[idx], 471); + } + } + + return true; +} + +void CPetFrame::setArea(PetArea newArea) { + warning("TODO: CPetFrame::setArea"); +} + +void CPetFrame::drawFrame(CScreenManager *screenManager) { + warning("TODO: CPetFrame::drawFrame"); +} + +} // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_control_sub8.h b/engines/titanic/pet_control/pet_frame.h index 115e6d508f..e307a73901 100644 --- a/engines/titanic/pet_control/pet_control_sub8.h +++ b/engines/titanic/pet_control/pet_frame.h @@ -20,30 +20,64 @@ * */ -#ifndef TITANIC_PET_CONTROL_SUB8_H -#define TITANIC_PET_CONTROL_SUB8_H +#ifndef TITANIC_PET_FRAME_H +#define TITANIC_PET_FRAME_H -#include "titanic/pet_control/pet_control_sub_base.h" -#include "titanic/pet_control/pet_val.h" +#include "titanic/pet_control/pet_section.h" +#include "titanic/pet_control/pet_graphic.h" namespace Titanic { -class CPetControlSub8 : public CPetControlSubBase { +class CPetFrame : public CPetSection { private: static int _indexes[6]; - CPetVal _valArray1[6]; - CPetVal _valArray2[6]; - CPetVal _val1; - CPetVal _val2; - CPetVal _val3; - CPetVal _val4; - CPetVal _valArray3[7]; + CPetGraphic _modeButtons[6]; + CPetGraphic _titles[6]; + CPetGraphic _modeBackground; + CPetGraphic _val2; + CPetGraphic _val3; + CPetGraphic _background; + CPetGraphic _indent[7]; +private: + /** + * Called to set the owning PET instance and set some initial state + */ + bool setPetControl(CPetControl *petControl); public: - CPetControlSub8(); + CPetFrame(); + + /** + * Sets up the section + */ + virtual bool setup(CPetControl *petControl); + + /** + * Sets up the section + */ + virtual bool setup(); + + /** + * Returns true if the object is in a valid state + */ + virtual bool isValid(CPetControl *petControl); + + /** + * Called after a game has been loaded + */ + virtual void postLoad(); + + /** + * Called when the current PET area changes + */ + void setArea(PetArea newArea); + /** + * Draws the PET frame + */ + void drawFrame(CScreenManager *screenManager); }; } // End of namespace Titanic -#endif /* TITANIC_PET_CONTROL_SUB8_H */ +#endif /* TITANIC_PET_FRAME_H */ diff --git a/engines/titanic/pet_control/pet_graphic.cpp b/engines/titanic/pet_control/pet_graphic.cpp new file mode 100644 index 0000000000..c9fd5f5af1 --- /dev/null +++ b/engines/titanic/pet_control/pet_graphic.cpp @@ -0,0 +1,90 @@ +/* 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. + * + */ + +#include "common/textconsole.h" +#include "titanic/core/game_object.h" +#include "titanic/pet_control/pet_graphic.h" +#include "titanic/pet_control/pet_control.h" + +namespace Titanic { + +void CPetGraphic::loadObject(PetElementMode mode, const CString &name, + CPetControl *petControl) { + switch (mode) { + case MODE_0: + _object0 = petControl->getHiddenObject(name); + break; + case MODE_1: + _object1 = petControl->getHiddenObject(name); + break; + case MODE_2: + _object2 = petControl->getHiddenObject(name); + break; + default: + break; + } +} + +void CPetGraphic::proc2() { + error("TODO"); +} + +void CPetGraphic::draw(CScreenManager *screenManager) { + draw(screenManager, Common::Point(_bounds.left, _bounds.top)); +} + +void CPetGraphic::draw(CScreenManager *screenManager, const Common::Point &destPos) { + CGameObject *obj = getObject(); + if (!obj) + obj = _object0; + + if (obj) + obj->draw(screenManager, destPos); +} + +void CPetGraphic::getBounds(Rect *rect) { + if (rect) { + CGameObject *obj = getObject(); + if (!obj) + obj = _object0; + + if (obj && obj->getSurface45()) + *rect = _bounds; + else + rect->clear(); + } +} + +CGameObject *CPetGraphic::getObject() const { + switch (_mode) { + case MODE_0: + return _object0; + case MODE_1: + return _object1; + case MODE_2: + return _object2; + default: + return nullptr; + } +} + +} // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_val.h b/engines/titanic/pet_control/pet_graphic.h index 0e909d485b..8b9c495205 100644 --- a/engines/titanic/pet_control/pet_val.h +++ b/engines/titanic/pet_control/pet_graphic.h @@ -20,31 +20,51 @@ * */ -#ifndef TITANIC_PET_VAL_H -#define TITANIC_PET_VAL_H +#ifndef TITANIC_PET_GRAPHIC_H +#define TITANIC_PET_GRAPHIC_H -#include "titanic/pet_control/pet_val_base.h" +#include "titanic/pet_control/pet_element.h" namespace Titanic { -class CPetVal: public CPetValBase { +class CPetGraphic: public CPetElement { protected: - int _field18; - int _field1C; - int _field20; + CGameObject *_object0; + CGameObject *_object1; + CGameObject *_object2; public: - CPetVal() : CPetValBase(), _field18(0), _field1C(0), _field20(0) {} + CPetGraphic() : CPetElement(), _object0(nullptr), _object1(nullptr), + _object2(nullptr) {} + + /** + * Load an object into the element + */ + virtual void loadObject(PetElementMode mode, const CString &name, + CPetControl *petControl); - virtual void proc1(); virtual void proc2(); - virtual void proc3(); - virtual void proc4(); - virtual void proc5(Rect *linkItem); + /** + * Draw the item + */ + virtual void draw(CScreenManager *screenManager); + + /** + * Draw the item + */ + virtual void draw(CScreenManager *screenManager, const Common::Point &destPos); + + /** + * Get the bounds for the element + */ + virtual void getBounds(Rect *rect); - virtual int proc16(); + /** + * Get the game object associated with this item + */ + virtual CGameObject *getObject() const; }; } // End of namespace Titanic -#endif /* TITANIC_PET_VAL_H */ +#endif /* TITANIC_PET_GRAPHIC_H */ diff --git a/engines/titanic/pet_control/pet_control_sub4.cpp b/engines/titanic/pet_control/pet_inventory_section.cpp index 041bf50fa6..d859576399 100644 --- a/engines/titanic/pet_control/pet_control_sub4.cpp +++ b/engines/titanic/pet_control/pet_inventory_section.cpp @@ -20,22 +20,22 @@ * */ -#include "titanic/pet_control/pet_control_sub4.h" +#include "titanic/pet_control/pet_inventory_section.h" namespace Titanic { -CPetControlSub4::CPetControlSub4() : _field28C(0), - _field290(0), _field294(0), _field298(0) { +CPetInventorySection::CPetInventorySection() : CPetSection(), + _field28C(0), _field290(0), _field294(0), _field298(0) { for (int idx = 0; idx < 46; ++idx) { _valArray1[idx] = _valArray2[idx] = 0; } } -void CPetControlSub4::save(SimpleFile *file, int indent) const { - +void CPetInventorySection::save(SimpleFile *file, int indent) const { + file->writeNumberLine(_field298, indent); } -void CPetControlSub4::load(SimpleFile *file, int param) { +void CPetInventorySection::load(SimpleFile *file, int param) { _field298 = file->readNumber(); } diff --git a/engines/titanic/pet_control/pet_control_sub4.h b/engines/titanic/pet_control/pet_inventory_section.h index 18dbd7c1ae..4adad469a7 100644 --- a/engines/titanic/pet_control/pet_control_sub4.h +++ b/engines/titanic/pet_control/pet_inventory_section.h @@ -20,17 +20,17 @@ * */ -#ifndef TITANIC_PET_CONTROL_SUB4_H -#define TITANIC_PET_CONTROL_SUB4_H +#ifndef TITANIC_PET_INVENTORY_SECTION_H +#define TITANIC_PET_INVENTORY_SECTION_H #include "titanic/simple_file.h" -#include "titanic/pet_control/pet_control_sub_base.h" +#include "titanic/pet_control/pet_section.h" #include "titanic/pet_control/pet_control_sub10.h" #include "titanic/pet_control/pet_control_sub12.h" namespace Titanic { -class CPetControlSub4 : public CPetControlSubBase { +class CPetInventorySection : public CPetSection { private: CPetControlSub12 _sub12; CPetControlSub10 _sub10; @@ -41,7 +41,7 @@ private: int _field294; int _field298; public: - CPetControlSub4(); + CPetInventorySection(); /** * Save the data for the class to file @@ -56,4 +56,4 @@ public: } // End of namespace Titanic -#endif /* TITANIC_PET_CONTROL_SUB4_H */ +#endif /* TITANIC_PET_INVENTORY_SECTION_H */ diff --git a/engines/titanic/pet_control/pet_control_sub3.cpp b/engines/titanic/pet_control/pet_remote_section.cpp index d134b1bbc3..7cdde01252 100644 --- a/engines/titanic/pet_control/pet_control_sub3.cpp +++ b/engines/titanic/pet_control/pet_remote_section.cpp @@ -20,7 +20,7 @@ * */ -#include "titanic/pet_control/pet_control_sub3.h" +#include "titanic/pet_control/pet_remote_section.h" namespace Titanic { diff --git a/engines/titanic/pet_control/pet_control_sub3.h b/engines/titanic/pet_control/pet_remote_section.h index aa53db5e00..6a3d1cd429 100644 --- a/engines/titanic/pet_control/pet_control_sub3.h +++ b/engines/titanic/pet_control/pet_remote_section.h @@ -20,30 +20,30 @@ * */ -#ifndef TITANIC_PET_CONTROL_SUB3_H -#define TITANIC_PET_CONTROL_SUB3_H +#ifndef TITANIC_PET_REMOTE_SECTION_H +#define TITANIC_PET_REMOTE_SECTION_H -#include "titanic/pet_control/pet_control_sub_base.h" +#include "titanic/pet_control/pet_section.h" #include "titanic/pet_control/pet_control_sub10.h" #include "titanic/pet_control/pet_control_sub12.h" -#include "titanic/pet_control/pet_val.h" +#include "titanic/pet_control/pet_graphic.h" namespace Titanic { -class CPetControlSub3 : public CPetControlSubBase { +class CPetRemoteSection : public CPetSection { private: CPetControlSub10 _sub10; - CPetVal _val1; - CPetVal _val2; - CPetVal _val3; - CPetVal _val4; - CPetVal _val5; - CPetVal _val6; - CPetVal _val7; - CPetVal _val8; - CPetVal _val9; - CPetVal _val10; - CPetVal _val11; + CPetGraphic _val1; + CPetGraphic _val2; + CPetGraphic _val3; + CPetGraphic _val4; + CPetGraphic _val5; + CPetGraphic _val6; + CPetGraphic _val7; + CPetGraphic _val8; + CPetGraphic _val9; + CPetGraphic _val10; + CPetGraphic _val11; CPetControlSub12 _sub12; public: @@ -52,4 +52,4 @@ public: } // End of namespace Titanic -#endif /* TITANIC_PET_CONTROL_SUB3_H */ +#endif /* TITANIC_PET_REMOTE_SECTION_H */ diff --git a/engines/titanic/pet_control/pet_control_sub2.cpp b/engines/titanic/pet_control/pet_rooms_section.cpp index 2e8b35e2f0..b866fb349d 100644 --- a/engines/titanic/pet_control/pet_control_sub2.cpp +++ b/engines/titanic/pet_control/pet_rooms_section.cpp @@ -20,29 +20,29 @@ * */ -#include "titanic/pet_control/pet_control_sub2.h" +#include "titanic/pet_control/pet_rooms_section.h" namespace Titanic { -CPetControlSub2::CPetControlSub2() : +CPetRoomsSection::CPetRoomsSection() : _field100(0), _field104(0), _field108(0), _field10C(0), _field110(0), _field114(0), _field118(0), _field11C(0), _field1C0(0), _field1C4(0), _field1C8(0), _field1CC(0), _field1D0(0), _field1D4(0) { } -void CPetControlSub2::save(SimpleFile *file, int indent) const { +void CPetRoomsSection::save(SimpleFile *file, int indent) const { } -void CPetControlSub2::load(SimpleFile *file, int param) { +void CPetRoomsSection::load(SimpleFile *file, int param) { if (!param) { int count = file->readNumber(); for (int idx = 0; idx < count; ++idx) { int v1 = file->readNumber(); int v2 = file->readNumber(); - warning("TODO: CPetControlSub2::load - %d,%d", v1, v2); + warning("TODO: CPetRoomsSection::load - %d,%d", v1, v2); } _listItem.setField34(file->readNumber()); diff --git a/engines/titanic/pet_control/pet_control_sub2.h b/engines/titanic/pet_control/pet_rooms_section.h index d32b30aea0..fc26c340cf 100644 --- a/engines/titanic/pet_control/pet_control_sub2.h +++ b/engines/titanic/pet_control/pet_rooms_section.h @@ -20,17 +20,17 @@ * */ -#ifndef TITANIC_PET_CONTROL_SUB2_H -#define TITANIC_PET_CONTROL_SUB2_H +#ifndef TITANIC_PET_ROOMS_SECTION_H +#define TITANIC_PET_ROOMS_SECTION_H -#include "titanic/pet_control/pet_control_sub_base.h" +#include "titanic/pet_control/pet_section.h" #include "titanic/pet_control/pet_control_sub11.h" #include "titanic/pet_control/pet_control_sub12.h" #include "titanic/pet_control/pet_control_list_item2.h" namespace Titanic { -class CPetControlSub2 : public CPetControlSubBase { +class CPetRoomsSection : public CPetSection { private: CPetControlSub11 _sub11; CPetControlListItem2 _listItem; @@ -42,7 +42,7 @@ private: int _field114; int _field118; int _field11C; - CPetVal _val1; + CPetGraphic _val1; CPetControlSub12 _sub12; int _field1C0; int _field1C4; @@ -51,7 +51,7 @@ private: int _field1D0; int _field1D4; public: - CPetControlSub2(); + CPetRoomsSection(); /** * Save the data for the class to file @@ -66,4 +66,4 @@ public: } // End of namespace Titanic -#endif /* TITANIC_PET_CONTROL_SUB2_H */ +#endif /* TITANIC_PET_ROOMS_SECTION_H */ diff --git a/engines/titanic/pet_control/pet_control_sub6.cpp b/engines/titanic/pet_control/pet_save_section.cpp index d017e81d9e..e513dd3013 100644 --- a/engines/titanic/pet_control/pet_control_sub6.cpp +++ b/engines/titanic/pet_control/pet_save_section.cpp @@ -20,7 +20,7 @@ * */ -#include "titanic/pet_control/pet_control_sub6.h" +#include "titanic/pet_control/pet_save_section.h" namespace Titanic { diff --git a/engines/titanic/pet_control/pet_control_sub6.h b/engines/titanic/pet_control/pet_save_section.h index 420da0c7ae..fb9004f47d 100644 --- a/engines/titanic/pet_control/pet_control_sub6.h +++ b/engines/titanic/pet_control/pet_save_section.h @@ -20,16 +20,16 @@ * */ -#ifndef TITANIC_PET_CONTROL_SUB6_H -#define TITANIC_PET_CONTROL_SUB6_H +#ifndef TITANIC_PET_SAVE_SECTION_H +#define TITANIC_PET_SAVE_SECTION_H -#include "titanic/pet_control/pet_control_sub_base.h" +#include "titanic/pet_control/pet_section.h" #include "titanic/pet_control/pet_control_sub10.h" #include "titanic/pet_control/pet_control_sub12.h" namespace Titanic { -class CPetControlSub6 : public CPetControlSubBase { +class CPetSaveSection : public CPetSection { private: CPetControlSub10 _sub10; CPetControlSub10 _sub12; @@ -39,4 +39,4 @@ public: } // End of namespace Titanic -#endif /* TITANIC_PET_CONTROL_SUB6_H */ +#endif /* TITANIC_PET_SAVE_SECTION_H */ diff --git a/engines/titanic/pet_control/pet_control_sub_base.cpp b/engines/titanic/pet_control/pet_section.cpp index 05a3425b5f..321f1fb94f 100644 --- a/engines/titanic/pet_control/pet_control_sub_base.cpp +++ b/engines/titanic/pet_control/pet_section.cpp @@ -21,39 +21,39 @@ */ #include "common/textconsole.h" -#include "titanic/pet_control/pet_control_sub_base.h" +#include "titanic/pet_control/pet_section.h" namespace Titanic { -void CPetControlSubBase::proc4() { +void CPetSection::proc4() { error("TODO"); } -void CPetControlSubBase::proc16() { +void CPetSection::proc16() { error("TODO"); } -void CPetControlSubBase::proc25() { +void CPetSection::proc25() { error("TODO"); } -void CPetControlSubBase::proc27() { +void CPetSection::proc27() { error("TODO"); } -void CPetControlSubBase::proc28() { +void CPetSection::proc28() { error("TODO"); } -void CPetControlSubBase::proc29() { +void CPetSection::proc29() { error("TODO"); } -void CPetControlSubBase::proc30() { +void CPetSection::proc30() { error("TODO"); } -void CPetControlSubBase::proc31() { +void CPetSection::proc31() { error("TODO"); } diff --git a/engines/titanic/pet_control/pet_control_sub_base.h b/engines/titanic/pet_control/pet_section.h index f95e1a98f5..77535662a6 100644 --- a/engines/titanic/pet_control/pet_control_sub_base.h +++ b/engines/titanic/pet_control/pet_section.h @@ -20,36 +20,56 @@ * */ -#ifndef TITANIC_PET_CONTROL_SUB_BASE_H -#define TITANIC_PET_CONTROL_SUB_BASE_H +#ifndef TITANIC_PET_SECTION_H +#define TITANIC_PET_SECTION_H #include "titanic/simple_file.h" -#include "titanic/core/room_item.h" namespace Titanic { -struct CPetControlSubData { +enum PetArea { + PET_INVENTORY = 0, PET_CONVERSATION = 1, PET_REMOTE = 2, + PET_ROOMS = 3, PET_SAVE = 4, PET_5 = 5, PET_6 = 6 +}; + +class CPetControl; +class CScreenManager; +class CRoomItem; + +struct CPetSectionSubData { int _field0; int _field4; int _field8; int _fieldC; - CPetControlSubData() : _field0(0), _field4(0), - _field8(0), _fieldC(0) {} + CPetSectionSubData() : _field0(0), _field4(0), _field8(0), + _fieldC(0) {} }; -class CPetControlSubBase { +class CPetSection { protected: - int _field4; + CPetControl *_petControl; public: - CPetControlSubBase() : _field4(0) {} - virtual ~CPetControlSubBase() {} + CPetSection() : _petControl(nullptr) {} + virtual ~CPetSection() {} + + /** + * Sets up the section + */ + virtual bool setup(CPetControl *petControl) { return false; } + + /** + * Sets up the section + */ + virtual bool setup() { return false; } - virtual int proc1() { return 0; } - virtual int proc2() { return 0; } - virtual void proc3() {} + /** + * Draw the section + */ + virtual void draw(CScreenManager *screenManager) {} + virtual void proc4(); - virtual void proc5() {} + virtual void proc5(int val) {} virtual int proc6() { return 0; } virtual int proc7() { return 0; } virtual int proc8() { return 0; } @@ -65,22 +85,33 @@ public: /** * Returns true if the object is in a valid state */ - virtual bool isValid() const { return false; } + virtual bool isValid(CPetControl *petControl) { return false; } /** * Load the data for the class from file */ virtual void load(SimpleFile *file, int param) {} - virtual void proc19() {} + /** + * Called after a game has been loaded + */ + virtual void postLoad() {} /** * Save the data for the class to file */ virtual void save(SimpleFile *file, int indent) const {} - virtual void proc21() {} - virtual void proc22() {} + /** + * Called when a section is switched to + */ + virtual void enter(PetArea oldArea) {} + + /** + * Called when a section is being left, to switch to another area + */ + virtual void leave() {} + virtual void proc23() {} /** @@ -101,9 +132,9 @@ public: virtual void proc35() {} virtual void proc36() {} virtual void proc37() {} - virtual void proc38() {} + virtual void proc38(int val) {} }; } // End of namespace Titanic -#endif /* TITANIC_PET_CONTROL_SUB_BASE_H */ +#endif /* TITANIC_PET_SECTION_H */ diff --git a/engines/titanic/pet_control/pet_val.cpp b/engines/titanic/pet_control/pet_val.cpp deleted file mode 100644 index 5bc237572e..0000000000 --- a/engines/titanic/pet_control/pet_val.cpp +++ /dev/null @@ -1,61 +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. - * - */ - -#include "common/textconsole.h" -#include "titanic/pet_control/pet_val.h" - -namespace Titanic { - -void CPetVal::proc1() { - error("TODO"); -} - -void CPetVal::proc2() { - error("TODO"); -} - -void CPetVal::proc3() { - error("TODO"); -} - -void CPetVal::proc4() { - error("TODO"); -} - -void CPetVal::proc5(Rect *rect) { - error("TODO"); -} - -int CPetVal::proc16() { - switch (_field14) { - case 0: - return _field18; - case 1: - return _field1C; - case 2: - return _field20; - default: - return 0; - } -} - -} // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_val_base.cpp b/engines/titanic/pet_control/pet_val_base.cpp deleted file mode 100644 index 9a23854450..0000000000 --- a/engines/titanic/pet_control/pet_val_base.cpp +++ /dev/null @@ -1,76 +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. - * - */ - -#include "common/textconsole.h" -#include "titanic/pet_control/pet_val_base.h" - -namespace Titanic { - -CPetValBase::CPetValBase() : _field4(0), _field8(0), _fieldC(0), - _field10(0), _field14(0) {} - -void CPetValBase::proc5(Rect *rect) { - if (rect) - *rect = Rect(); -} - -int CPetValBase::proc6() { - error("TODO"); -} - -int CPetValBase::proc7() { - error("TODO"); -} - -void CPetValBase::proc8() { - error("TODO"); -} - -int CPetValBase::proc9() { - error("TODO"); -} - -void CPetValBase::proc10() { - error("TODO"); -} - -void CPetValBase::proc11() { - error("TODO"); -} - -void CPetValBase::proc12() { - error("TODO"); -} - -void CPetValBase::proc13() { - error("TODO"); -} - -void CPetValBase::proc14() { - error("TODO"); -} - -void CPetValBase::proc15() { - error("TODO"); -} - -} // End of namespace Titanic diff --git a/engines/titanic/pet_control/pet_val_base.h b/engines/titanic/pet_control/pet_val_base.h deleted file mode 100644 index 637e95f22d..0000000000 --- a/engines/titanic/pet_control/pet_val_base.h +++ /dev/null @@ -1,67 +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. - * - */ - -#ifndef TITANIC_PET_VAL_BASE_H -#define TITANIC_PET_VAL_BASE_H - -#include "titanic/simple_file.h" -#include "titanic/core/link_item.h" - -namespace Titanic { - -class CPetValBase { -protected: - int _field4; - int _field8; - int _fieldC; - int _field10; - int _field14; -public: - CPetValBase(); - virtual ~CPetValBase() {} - - virtual void proc1() {} - virtual void proc2() {} - virtual void proc3() {} - virtual void proc4() {} - - virtual void proc5(Rect *rect); - - virtual int proc6(); - virtual int proc7(); - virtual void proc8(); - virtual int proc9(); - virtual void proc10(); - virtual void proc11(); - virtual void proc12(); - virtual void proc13(); - virtual void proc14(); - virtual void proc15(); - - virtual int proc16() { return 0; } - - virtual void proc17(int v) { _field14 = v; } -}; - -} // End of namespace Titanic - -#endif /* TITANIC_PET_VAL_BASE_H */ diff --git a/engines/titanic/simple_file.cpp b/engines/titanic/simple_file.cpp index 3cd0ef7ecc..acf02e8df1 100644 --- a/engines/titanic/simple_file.cpp +++ b/engines/titanic/simple_file.cpp @@ -28,6 +28,7 @@ namespace Titanic { bool File::open(const Common::String &name) { if (!Common::File::open(name)) error("Could not open file - %s", name.c_str()); + return true; } /*------------------------------------------------------------------------*/ diff --git a/engines/titanic/true_talk/true_talk_manager.cpp b/engines/titanic/true_talk/true_talk_manager.cpp index d13356b42c..6f42346e3f 100644 --- a/engines/titanic/true_talk/true_talk_manager.cpp +++ b/engines/titanic/true_talk/true_talk_manager.cpp @@ -66,7 +66,6 @@ void CTrueTalkManager::load(SimpleFile *file) { int ident1 = file->readNumber(); int ident2 = file->readNumber(); - int v = 0; if (ident1 != MKTAG_BE('U', 'R', 'A', 'H')) { while (ident2 != MKTAG_BE('A', 'K', 'E', 'R')) { diff --git a/engines/titanic/video_surface.cpp b/engines/titanic/video_surface.cpp index e8f0e03136..520193f376 100644 --- a/engines/titanic/video_surface.cpp +++ b/engines/titanic/video_surface.cpp @@ -132,7 +132,8 @@ void CVideoSurface::blitRect1(const Rect &srcRect, const Rect &destRect, CVideoS lock(); // TODO: Do it like the original does it - _rawSurface->blitFrom(*src->_rawSurface, srcRect, Point(destRect.left, destRect.top)); + _rawSurface->transBlitFrom(*src->_rawSurface, srcRect, destRect, + getTransparencyColor()); src->unlock(); unlock(); @@ -143,6 +144,24 @@ void CVideoSurface::blitRect2(const Rect &srcRect, const Rect &destRect, CVideoS blitRect1(srcRect, destRect, src); } +uint CVideoSurface::getTransparencyColor() { + uint32 val = -(getPixelDepth() - 2); + val &= 0xFFFF8400; + val += 0xF81F; + return val; +} + +bool CVideoSurface::proc45() { + if (_field50) { + _field50 = 0; + return true; + } else if (_movie) { + return _movie->get10(); + } else { + return false; + } +} + /*------------------------------------------------------------------------*/ OSVideoSurface::OSVideoSurface(CScreenManager *screenManager, DirectDrawSurface *surface) : @@ -176,7 +195,7 @@ void OSVideoSurface::loadTarga(const CResourceKey &key) { CTargaDecode decoder; decoder.decode(*this, key.getString()); - if (proc26() == 2) + if (getPixelDepth() == 2) shiftColors(); _resourceKey = key; @@ -188,7 +207,7 @@ void OSVideoSurface::loadJPEG(const CResourceKey &key) { CJPEGDecode decoder; decoder.decode(*this, key.getString()); - if (proc26() == 2) + if (getPixelDepth() == 2) shiftColors(); _resourceKey = key; @@ -208,28 +227,35 @@ bool OSVideoSurface::lock() { } void OSVideoSurface::unlock() { - if (_rawSurface) - _ddSurface->unlock(); - _rawSurface = nullptr; - --_lockCount; + if (!--_lockCount) { + if (_rawSurface) + _ddSurface->unlock(); + _rawSurface = nullptr; + } } bool OSVideoSurface::hasSurface() { return _ddSurface != nullptr; } -int OSVideoSurface::getWidth() const { - assert(_ddSurface); +int OSVideoSurface::getWidth() { + if (!loadIfReady()) + error("Could not load resource"); + return _ddSurface->getWidth(); } -int OSVideoSurface::getHeight() const { - assert(_ddSurface); +int OSVideoSurface::getHeight() { + if (!loadIfReady()) + error("Could not load resource"); + return _ddSurface->getHeight(); } -int OSVideoSurface::getPitch() const { - assert(_ddSurface); +int OSVideoSurface::getPitch() { + if (!loadIfReady()) + error("Could not load resource"); + return _ddSurface->getPitch(); } @@ -241,12 +267,19 @@ void OSVideoSurface::resize(int width, int height) { _videoSurfaceCounter += _ddSurface->getSize(); } -int OSVideoSurface::proc26() { +int OSVideoSurface::getPixelDepth() { if (!loadIfReady()) assert(0); - warning("TODO"); - return 0; + lock(); + + int result = _rawSurface->format.bytesPerPixel; + if (result == 1) + // Paletted 8-bit images don't store the color directly in the pixels + result = 0; + + unlock(); + return result; } bool OSVideoSurface::load() { @@ -276,27 +309,26 @@ bool OSVideoSurface::load() { } } -void OSVideoSurface::shiftColors() { +uint16 OSVideoSurface::getPixel(const Common::Point &pt) { if (!loadIfReady()) - return; - - if (!lock()) - assert(0); - - int width = getWidth(); - int height = getHeight(); - int pitch = getPitch(); - uint16 *pixels = (uint16 *)_rawSurface->getPixels(); - uint16 *p; - int x, y; + return 0; - for (y = 0; y < height; ++y, pixels += pitch) { - for (x = 0, p = pixels; x < width; ++x, ++p) { - *p = ((*p & 0xFFE0) * 2) | (*p & 0x1F); - } + if (pt.x >= 0 && pt.y >= 0 && pt.x < getWidth() && pt.y < getHeight()) { + lock(); + uint16 pixel = *(uint16 *)_rawSurface->getBasePtr(pt.x, pt.y); + unlock(); + return pixel; + } else { + return getTransparencyColor(); } +} - unlock(); +void OSVideoSurface::shiftColors() { + if (!loadIfReady()) + return; + + // Currently no further processing is needed, since for ScummVM, + // we already convert 16-bit surfaces as soon as they're loaded } void OSVideoSurface::proc32(int v1, CVideoSurface *surface) { diff --git a/engines/titanic/video_surface.h b/engines/titanic/video_surface.h index b2390fb358..de181581eb 100644 --- a/engines/titanic/video_surface.h +++ b/engines/titanic/video_surface.h @@ -115,24 +115,32 @@ public: /** * Returns the width of the surface */ - virtual int getWidth() const = 0; + virtual int getWidth() = 0; /** * Returns the height of the surface */ - virtual int getHeight() const = 0; + virtual int getHeight() = 0; /** * Returns the pitch of the surface in bytes */ - virtual int getPitch() const = 0; + virtual int getPitch() = 0; /** * Reiszes the surface */ virtual void resize(int width, int height) = 0; - virtual int proc26() = 0; + /** + * Returns the number of bytes per pixel in the surface + */ + virtual int getPixelDepth() = 0; + + /** + * Gets the pixel at the specified position within the surface + */ + virtual uint16 getPixel(const Common::Point &pt) = 0; /** * Shifts the colors of the surface.. maybe greys it out? @@ -161,6 +169,8 @@ public: */ virtual bool load() = 0; + virtual bool proc45(); + /** * Frees the underlying surface */ @@ -181,6 +191,11 @@ public: void set40(void *v) { _field40 = v; } uint16 *getPixels() { return (uint16 *)_rawSurface->getPixels(); } + + /** + * Returns the transparent color + */ + uint getTransparencyColor(); }; class OSVideoSurface : public CVideoSurface { @@ -226,24 +241,32 @@ public: /** * Returns the width of the surface */ - virtual int getWidth() const; + virtual int getWidth(); /** * Returns the height of the surface */ - virtual int getHeight() const; + virtual int getHeight(); /** * Returns the pitch of the surface in bytes */ - virtual int getPitch() const; + virtual int getPitch(); /** * Reiszes the surface */ virtual void resize(int width, int height); - virtual int proc26(); + /** + * Returns the number of bytes per pixel in the surface + */ + virtual int getPixelDepth(); + + /** + * Gets the pixel at the specified position within the surface + */ + virtual uint16 getPixel(const Common::Point &pt); /** * Shifts the colors of the surface.. maybe greys it out? |