TITANIC: Implemented remaining CGameManager methods and others

This commit is contained in:
Paul Gilbert 2016-06-26 23:00:00 -04:00
parent b6f476c70f
commit ef1d10e926
13 changed files with 194 additions and 62 deletions

View File

@ -63,7 +63,7 @@ CGameObject::CGameObject(): CNamedItem() {
_field4C = 0xFF;
_isMail = false;
_id = 0;
_field58 = 0;
_roomFlags = 0;
_visible = true;
_field60 = 0;
_cursorId = CURSOR_ARROW;
@ -126,7 +126,7 @@ void CGameObject::load(SimpleFile *file) {
_visible = file->readNumber() != 0;
_isMail = file->readNumber();
_id = file->readNumber();
_field58 = file->readNumber();
_roomFlags = file->readNumber();
resourceKey.load(file);
_surface = nullptr;
@ -688,24 +688,29 @@ CGameObject *CGameObject::getMailManNextObject(CGameObject *prior) const {
return mailMan ? mailMan->getNextObject(prior) : nullptr;
}
CGameObject *CGameObject::findRoomObject(const CString &name) const {
return static_cast<CGameObject *>(findRoom()->findByName(name));
}
CGameObject *CGameObject::findUnder(CTreeItem *parent, const CString &name) {
if (!parent)
CGameObject *CGameObject::findMailByFlags(int mode, uint roomFlags) {
CMailMan *mailMan = getMailMan();
if (!mailMan)
return nullptr;
for (CTreeItem *treeItem = parent->getFirstChild(); treeItem;
treeItem = treeItem->scan(parent)) {
if (!treeItem->getName().compareTo(name)) {
return dynamic_cast<CGameObject *>(treeItem);
}
for (CGameObject *obj = mailMan->getFirstObject(); obj;
obj = mailMan->getNextObject(obj)) {
if (compareRoomFlags(mode, roomFlags, obj->_roomFlags))
return obj;
}
return nullptr;
}
CGameObject *CGameObject::getNextMail(CGameObject *prior) {
CMailMan *mailMan = getMailMan();
return mailMan ? mailMan->getNextObject(prior) : nullptr;
}
CGameObject *CGameObject::findRoomObject(const CString &name) const {
return static_cast<CGameObject *>(findRoom()->findByName(name));
}
Found CGameObject::find(const CString &name, CGameObject **item, int findAreas) {
CGameObject *go;
*item = nullptr;
@ -897,6 +902,23 @@ CRoomItem *CGameObject::getHiddenRoom() const {
return root ? root->findHiddenRoom() : nullptr;
}
CGameObject *CGameObject::getHiddenObject(const CString &name) const {
CRoomItem *room = getHiddenRoom();
return room ? static_cast<CGameObject *>(findUnder(room, name)) : nullptr;
}
CTreeItem *CGameObject::findUnder(CTreeItem *parent, const CString &name) const {
if (!parent)
return nullptr;
for (CTreeItem *item = parent->getFirstChild(); item; item = item->scan(parent)) {
if (item->getName() == name)
return item;
}
return nullptr;
}
CMusicRoom *CGameObject::getMusicRoom() const {
CGameManager *gameManager = getGameManager();
return gameManager ? &gameManager->_musicRoom : nullptr;

View File

@ -195,11 +195,6 @@ protected:
*/
int compareRoomNameTo(const CString &name);
/**
* Display a message
*/
void displayMessage(const CString &msg) const;
/**
* Gets the first object under the system MailMan
*/
@ -210,16 +205,21 @@ protected:
*/
CGameObject *getMailManNextObject(CGameObject *prior) const;
/**
* Find mail by room flags
*/
CGameObject *findMailByFlags(int mode, uint roomFlags);
/**
* Find next mail from a given prior one
*/
CGameObject *getNextMail(CGameObject *prior);
/**
* Finds an object by name within the object's room
*/
CGameObject *findRoomObject(const CString &name) const;
/**
* Scan the specified room for an item by name
*/
static CGameObject *findUnder(CTreeItem *parent, const CString &name);
/**
* Moves the item from it's original position to be under the current view
*/
@ -299,6 +299,16 @@ protected:
*/
CRoomItem *getHiddenRoom() const;
/**
* Returns a hidden object
*/
CGameObject *getHiddenObject(const CString &name) const;
/**
* Scan the specified room for an item by name
*/
CTreeItem *findUnder(CTreeItem *parent, const CString &name) const;
/**
* Returns the music room instance from the game manager
*/
@ -366,7 +376,7 @@ protected:
public:
bool _isMail;
int _id;
int _field58;
uint _roomFlags;
int _field60;
CursorId _cursorId;
bool _visible;

View File

@ -55,7 +55,7 @@ void CMailMan::addMail(CGameObject *obj, int id) {
void CMailMan::setMailId(CGameObject *obj, int id) {
obj->_id = id;
obj->_field58 = 0;
obj->_roomFlags = 0;
obj->_isMail = true;
}
@ -68,11 +68,11 @@ CGameObject *CMailMan::findMail(int id) const {
return nullptr;
}
void CMailMan::removeMail(int id, int v) {
void CMailMan::removeMail(int id, int roomFlags) {
for (CGameObject *obj = getFirstObject(); obj; obj = getNextObject(obj)) {
if (obj->_isMail && obj->_id == id) {
obj->_isMail = false;
obj->_field58 = v;
obj->_roomFlags = roomFlags;
break;
}
}

View File

@ -183,4 +183,13 @@ int CRoomItem::getScriptId() const {
return 0;
}
CResourceKey CRoomItem::getTransitionMovieKey() {
_transitionMovieKey.scanForFile();
return _transitionMovieKey;
}
CResourceKey CRoomItem::getExitMovieKey() {
return _exitMovieKey;
}
} // End of namespace Titanic

View File

@ -72,6 +72,10 @@ public:
* Get the TrueTalk script Id associated with the room
*/
int getScriptId() const;
CResourceKey getTransitionMovieKey();
CResourceKey getExitMovieKey();
};
} // End of namespace Titanic

View File

@ -34,16 +34,28 @@ CGameManager::CGameManager(CProjectItem *project, CGameView *gameView):
_project(project), _gameView(gameView), _trueTalkManager(this),
_inputHandler(this), _inputTranslator(&_inputHandler),
_gameState(this), _sound(this), _musicRoom(this),
_field30(0), _soundMaker(nullptr), _field4C(0),
_treeItem(nullptr), _soundMaker(nullptr), _movieRoom(nullptr),
_dragItem(nullptr), _field54(0), _lastDiskTicksCount(0), _tickCount2(0) {
CTimeEventInfo::_nextId = 0;
_videoSurface1 = nullptr;
_videoSurface2 = CScreenManager::_screenManagerPtr->createSurface(600, 340);
_movie = nullptr;
_movieSurface = CScreenManager::_screenManagerPtr->createSurface(600, 340);
_project->setGameManager(this);
g_vm->_filesManager->setGameManager(this);
}
CGameManager::~CGameManager() {
delete _movie;
delete _movieSurface;
if (_treeItem) {
_treeItem->destroyAll();
_treeItem = nullptr;
}
_project->resetGameManager();
}
void CGameManager::load(SimpleFile *file) {
file->readNumber();
@ -107,8 +119,33 @@ void CGameManager::initBounds() {
_bounds = Rect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
void CGameManager::roomTransition(CRoomItem *oldRoom, CRoomItem *newRoom) {
delete _movie;
_movie = nullptr;
CResourceKey movieKey = (oldRoom == newRoom) ? oldRoom->getTransitionMovieKey() :
oldRoom->getExitMovieKey();
CString filename = movieKey.exists();
if (g_vm->_filesManager->fileExists(filename)) {
_movieSurface->freeSurface();
_movie = new OSMovie(filename, _movieSurface);
}
}
void CGameManager::playClip(CMovieClip *clip, CRoomItem *oldRoom, CRoomItem *newRoom) {
warning("TODO: CGameManager::playClip");
if (oldRoom != newRoom || newRoom != _movieRoom || !_movie)
roomTransition(oldRoom, newRoom);
if (clip && clip->_startFrame != clip->_endFrame && _movie) {
// Clip details specifying a sub-section of movie to play
Rect tempRect(20, 10, SCREEN_WIDTH - 20, 350);
lockInputHandler();
CScreenManager::_screenManagerPtr->_mouseCursor->hide();
_movie->playClip(tempRect, clip->_startFrame, clip->_endFrame);
CScreenManager::_screenManagerPtr->_mouseCursor->show();
unlockInputHandler();
}
}
void CGameManager::update() {
@ -191,11 +228,11 @@ void CGameManager::updateDiskTicksCount() {
}
void CGameManager::viewChange() {
delete _videoSurface1;
delete _videoSurface2;
delete _movie;
delete _movieSurface;
_videoSurface1 = nullptr;
_videoSurface2 = CScreenManager::_screenManagerPtr->createSurface(600, 340);
_movie = nullptr;
_movieSurface = CScreenManager::_screenManagerPtr->createSurface(600, 340);
_trueTalkManager.clear();
for (CTreeItem *treeItem = _project; treeItem; treeItem = treeItem->scan(_project))

View File

@ -44,12 +44,12 @@ class CGameManager {
private:
CTrueTalkManager _trueTalkManager;
CTimeEventInfoList _timers;
int _field30;
CTreeItem *_treeItem;
CBackgroundSoundMaker *_soundMaker;
CVideoSurface *_videoSurface1;
int _field4C;
CMovie *_movie;
CRoomItem *_movieRoom;
int _field54;
CVideoSurface *_videoSurface2;
CVideoSurface *_movieSurface;
uint _lastDiskTicksCount;
uint _tickCount2;
private:
@ -62,6 +62,11 @@ private:
* Handles any ongoing movie playback
*/
void updateMovies();
/**
* Handles a room transition
*/
void roomTransition(CRoomItem *oldRoom, CRoomItem *newRoom);
public:
CProjectItem *_project;
CGameView *_gameView;

View File

@ -251,7 +251,7 @@ CRoomItem *CPetControl::getHiddenRoom() {
CGameObject *CPetControl::getHiddenObject(const CString &name) {
CRoomItem *room = getHiddenRoom();
return room ? findUnder(room, name) : nullptr;
return room ? static_cast<CGameObject *>(findUnder(room, name)) : nullptr;
}
bool CPetControl::containsPt(const Common::Point &pt) const {
@ -677,4 +677,14 @@ int CPetControl::getMailDest(const CRoomFlags &roomFlags) const {
return roomFlags.getSuccUBusNum(roomFlags.getSuccUBusRoomName());
}
void CPetControl::starsSetButtons(int val1, int val2) {
_starfield.setButtons(val1, val2);
if (_currentArea == PET_STARFIELD)
_starfield.makePetDirty();
}
void CPetControl::starsSetReference(bool hasRef) {
_starfield.setHasReference(hasRef);
}
} // End of namespace Titanic

View File

@ -385,6 +385,13 @@ public:
*/
void resetActiveNPC();
/**
* Resets NPC in conversations
*/
void convResetNPC() {
_conversations.resetNPC();
}
/**
* Resets the conversation dials back to 0 position
*/
@ -543,6 +550,23 @@ public:
bool isSuccUBusRoom(const CRoomFlags &roomFlags) {
return roomFlags.isSuccUBusRoomFlags();
}
/**
* Called with a phonograph action for Send, Receive, or Record
*/
void phonographAction(const CString &action) {
// Original had some code that had no effect
}
/**
* Sets the status buttons for the starfield control
*/
void starsSetButtons(int val1, int val2);
/**
* Set whether the user has the galactic reference material
*/
void starsSetReference(bool hasRef);
};
} // End of namespace Titanic

View File

@ -28,7 +28,7 @@
namespace Titanic {
CPetStarfield::CPetStarfield() : _field18C(0), _photoOn(true),
_field210(0), _rect1(22, 352, 598, 478) {
_hasReference(false), _rect1(22, 352, 598, 478) {
_btnOffsets[0] = _btnOffsets[1] = _btnOffsets[2] = 0;
}
@ -86,7 +86,7 @@ bool CPetStarfield::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
CPETHelmetOnOffMsg helmetMsg;
helmetMsg.execute(_petControl->_remoteTarget);
} else if (_imgPhoto.MouseButtonDownMsg(msg->_mousePos)) {
if (_field210) {
if (_hasReference) {
_photoOn = !_photoOn;
CPETPhotoOnOffMsg photoMsg;
photoMsg.execute(_petControl->_remoteTarget);
@ -124,7 +124,7 @@ bool CPetStarfield::isValid(CPetControl *petControl) {
void CPetStarfield::load(SimpleFile *file, int param) {
if (!param) {
_photoOn = file->readNumber();
_field210 = file->readNumber();
_hasReference = file->readNumber();
}
}
@ -134,7 +134,7 @@ void CPetStarfield::postLoad() {
void CPetStarfield::save(SimpleFile *file, int indent) const {
file->writeNumberLine(_photoOn, indent);
file->writeNumberLine(_field210, indent);
file->writeNumberLine(_hasReference, indent);
}
bool CPetStarfield::setupControl(CPetControl *petControl) {

View File

@ -41,7 +41,7 @@ private:
int _field18C;
CPetText _text;
bool _photoOn;
int _field210;
bool _hasReference;
private:
/**
* Setup the control
@ -53,18 +53,6 @@ private:
*/
void drawButton(int offset, int index, CScreenManager *screenManager);
void set210(int val) { _field210 = val; }
/**
* Sets the offsets for each of the buttons
*/
void setButtons(int val1, int val2);
/**
* Make the PET as dirty, requiring a redraw
*/
void makePetDirty();
/**
* Mouse down handling for Nav elements
*/
@ -115,6 +103,21 @@ public:
* Save the data for the class to file
*/
virtual void save(SimpleFile *file, int indent) const;
/**
* Sets the offsets for each of the buttons
*/
void setButtons(int val1, int val2);
/**
* Sets whether the player has the galactic reference material
*/
void setHasReference(bool hasRef) { _hasReference = hasRef; }
/**
* Make the PET as dirty, requiring a redraw
*/
void makePetDirty();
};
} // End of namespace Titanic

View File

@ -87,8 +87,8 @@ void OSMovie::play(uint startFrame, uint endFrame, int v3, bool v4) {
_state = MOVIE_NONE;
}
void OSMovie::proc10() {
warning("TODO: OSMovie::proc10");
void OSMovie::playClip(const Rect &rect, uint startFrame, uint endFrame) {
warning("TODO: OSMovie::playClip");
}
void OSMovie::proc11() {

View File

@ -61,7 +61,11 @@ public:
*/
virtual void play(uint startFrame, uint endFrame, int v3, bool v4) = 0;
virtual void proc10() = 0;
/**
* Plays a sub-section of a movie
*/
virtual void playClip(const Rect &rect, uint startFrame, uint endFrame) = 0;
virtual void proc11() = 0;
virtual void proc12(const CString &name, int flags, CGameObject *obj) = 0;
@ -119,7 +123,11 @@ public:
*/
virtual void play(uint startFrame, uint endFrame, int v3, bool v4);
virtual void proc10();
/**
* Plays a sub-section of a movie
*/
virtual void playClip(const Rect &rect, uint startFrame, uint endFrame);
virtual void proc11();
virtual void proc12(const CString &name, int flags, CGameObject *obj);