diff options
author | Paul Gilbert | 2016-04-14 20:02:52 -0400 |
---|---|---|
committer | Paul Gilbert | 2016-07-10 16:11:07 -0400 |
commit | f77a8a63cde7b40dd6fb4dfc23f11cc654c7e9a5 (patch) | |
tree | a6eeca5e8990c29b635e3190dbf416e8ddbaf76e /engines/titanic/core | |
parent | 1babcc10cfce1458ac07c8e1027c321962cf8f09 (diff) | |
download | scummvm-rg350-f77a8a63cde7b40dd6fb4dfc23f11cc654c7e9a5.tar.gz scummvm-rg350-f77a8a63cde7b40dd6fb4dfc23f11cc654c7e9a5.tar.bz2 scummvm-rg350-f77a8a63cde7b40dd6fb4dfc23f11cc654c7e9a5.zip |
TITANIC: Implemented CGameObject::find
Diffstat (limited to 'engines/titanic/core')
-rw-r--r-- | engines/titanic/core/game_object.cpp | 58 | ||||
-rw-r--r-- | engines/titanic/core/game_object.h | 23 | ||||
-rw-r--r-- | engines/titanic/core/mail_man.cpp | 50 | ||||
-rw-r--r-- | engines/titanic/core/mail_man.h | 61 | ||||
-rw-r--r-- | engines/titanic/core/saveable_object.cpp | 6 | ||||
-rw-r--r-- | engines/titanic/core/tree_item.cpp | 5 | ||||
-rw-r--r-- | engines/titanic/core/tree_item.h | 6 |
7 files changed, 206 insertions, 3 deletions
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 0a541bfb4d..ba8ab42c68 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -21,7 +21,9 @@ */ #include "titanic/core/game_object.h" +#include "titanic/core/mail_man.h" #include "titanic/core/resource_key.h" +#include "titanic/core/room_item.h" #include "titanic/pet_control/pet_control.h" #include "titanic/support/files_manager.h" #include "titanic/support/screen_manager.h" @@ -568,4 +570,60 @@ void CGameObject::petDisplayMsg(const CString &msg) const { pet->displayMessage(msg); } +CGameObject *CGameObject::getMailManFirstObject() const { + CMailMan *mailMan = getMailMan(); + return mailMan ? mailMan->getFirstObject() : nullptr; +} + +CGameObject *CGameObject::getMailManNextObject(CGameObject *prior) const { + 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; + + // Scan under PET if flagged + if (findAreas & FIND_PET) { + for (go = getPetControl()->getFirstObject(); go; go = getPetControl()->getNextObject(go)) { + if (go->getName() == name) { + *item = go; + return FOUND_PET; + } + } + } + + if (findAreas & FIND_MAILMAN) { + for (go = getMailManFirstObject(); go; go = getMailManNextObject(go)) { + if (go->getName() == name) { + *item = go; + return FOUND_MAILMAN; + } + } + } + + if (findAreas & FIND_GLOBAL) { + go = static_cast<CGameObject *>(getRoot()->findByName(name)); + if (go) { + *item = go; + return FOUND_GLOBAL; + } + } + + if (findAreas & FIND_ROOM) { + go = findRoomObject(name); + if (go) { + *item = go; + return FOUND_ROOM; + } + } + + return FOUND_NONE; +} + } // End of namespace Titanic diff --git a/engines/titanic/core/game_object.h b/engines/titanic/core/game_object.h index 09a00e30bb..86687309e7 100644 --- a/engines/titanic/core/game_object.h +++ b/engines/titanic/core/game_object.h @@ -32,6 +32,9 @@ namespace Titanic { +enum Find { FIND_GLOBAL = 1, FIND_ROOM = 2, FIND_PET = 4, FIND_MAILMAN = 8 }; +enum Found { FOUND_NONE = 0, FOUND_GLOBAL = 1, FOUND_ROOM = 2, FOUND_PET = 3, FOUND_MAILMAN = 4 }; + class CVideoSurface; class CMouseDragStartMsg; class OSMovie; @@ -165,6 +168,26 @@ protected: * Display a message in the PET */ void petDisplayMsg(const CString &msg) const; + + /** + * Gets the first object under the system MailMan + */ + CGameObject *getMailManFirstObject() const; + + /** + * Gets the next object under the system MailMan + */ + CGameObject *getMailManNextObject(CGameObject *prior) const; + + /** + * Finds an object by name within the object's room + */ + CGameObject *findRoomObject(const CString &name) const; + + /** + * Finds an item in various system areas + */ + Found find(const CString &name, CGameObject **item, int findAreas); public: int _field60; CursorId _cursorId; diff --git a/engines/titanic/core/mail_man.cpp b/engines/titanic/core/mail_man.cpp new file mode 100644 index 0000000000..cb959245b5 --- /dev/null +++ b/engines/titanic/core/mail_man.cpp @@ -0,0 +1,50 @@ +/* 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/core/mail_man.h" + +namespace Titanic { + +void CMailMan::save(SimpleFile *file, int indent) const { + file->writeNumberLine(1, indent); + file->writeNumberLine(_value, indent); + CGameObject::save(file, indent); +} + +void CMailMan::load(SimpleFile *file) { + file->readNumber(); + _value = file->readNumber(); + CGameObject::load(file); +} + +CGameObject *CMailMan::getFirstObject() const { + return static_cast<CGameObject *>(getFirstChild()); +} + +CGameObject *CMailMan::getNextObject(CGameObject *prior) const { + if (!prior || prior->getParent() != this) + return nullptr; + + return static_cast<CGameObject *>(prior->getNextSibling()); +} + +} // End of namespace Titanic diff --git a/engines/titanic/core/mail_man.h b/engines/titanic/core/mail_man.h new file mode 100644 index 0000000000..d1c84e2264 --- /dev/null +++ b/engines/titanic/core/mail_man.h @@ -0,0 +1,61 @@ +/* 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_MAIL_MAN_H +#define TITANIC_MAIL_MAN_H + +#include "titanic/core/game_object.h" + +namespace Titanic { + +class CMailMan : public CGameObject { +public: + int _value; +public: + CLASSDEF + CMailMan() : CGameObject(), _value(1) {} + + /** + * Save the data for the class to file + */ + virtual void save(SimpleFile *file, int indent) const; + + /** + * Load the data for the class from file + */ + virtual void load(SimpleFile *file); + + /** + * Get the first game object stored in the PET + */ + CGameObject *getFirstObject() const; + + /** + * Get the next game object stored in the PET following + * the passed game object + */ + CGameObject *getNextObject(CGameObject *prior) const; +}; + +} // End of namespace Titanic + +#endif /* TITANIC_MAIL_MAN_H */ diff --git a/engines/titanic/core/saveable_object.cpp b/engines/titanic/core/saveable_object.cpp index 2eacbba4a0..4a57959b57 100644 --- a/engines/titanic/core/saveable_object.cpp +++ b/engines/titanic/core/saveable_object.cpp @@ -68,6 +68,7 @@ #include "titanic/core/game_object_desc_item.h" #include "titanic/core/link_item.h" #include "titanic/core/list.h" +#include "titanic/core/mail_man.h" #include "titanic/core/message_target.h" #include "titanic/core/movie_clip.h" #include "titanic/core/multi_drop_target.h" @@ -156,7 +157,6 @@ #include "titanic/game/light_switch.h" #include "titanic/game/little_lift_button.h" #include "titanic/game/long_stick_dispenser.h" -#include "titanic/game/mail_man.h" #include "titanic/game/missiveomat.h" #include "titanic/game/missiveomat_button.h" #include "titanic/game/movie_tester.h" @@ -475,6 +475,7 @@ DEFFN(CGameObject) DEFFN(CGameObjectDescItem) DEFFN(CLinkItem) DEFFN(ListItem) +DEFFN(CMailMan) DEFFN(CMessageTarget) DEFFN(CMovieClip) DEFFN(CMultiDropTarget) @@ -565,7 +566,6 @@ DEFFN(CLight) DEFFN(CLightSwitch) DEFFN(CLittleLiftButton) DEFFN(CLongStickDispenser) -DEFFN(CMailMan) DEFFN(CMissiveOMat) DEFFN(CMissiveOMatButton) DEFFN(CMovieTester) @@ -1061,6 +1061,7 @@ void CSaveableObject::initClassList() { ADDFN(CLinkItem, CNamedItem); ADDFN(ListItem, CSaveableObject); ADDFN(CMessageTarget, CSaveableObject); + ADDFN(CMailMan, CGameObject); ADDFN(CMovieClip, ListItem); ADDFN(CMultiDropTarget, CDropTarget); ADDFN(CNamedItem, CTreeItem); @@ -1151,7 +1152,6 @@ void CSaveableObject::initClassList() { ADDFN(CLightSwitch, CBackground); ADDFN(CLittleLiftButton, CBackground); ADDFN(CLongStickDispenser, CGameObject); - ADDFN(CMailMan, CGameObject); ADDFN(CMissiveOMat, CGameObject); ADDFN(CMissiveOMatButton, CEditControl); ADDFN(CMovieTester, CGameObject); diff --git a/engines/titanic/core/tree_item.cpp b/engines/titanic/core/tree_item.cpp index d86e9b2f58..03bf0e764e 100644 --- a/engines/titanic/core/tree_item.cpp +++ b/engines/titanic/core/tree_item.cpp @@ -26,6 +26,7 @@ #include "titanic/core/game_object.h" #include "titanic/core/game_object_desc_item.h" #include "titanic/core/link_item.h" +#include "titanic/core/mail_man.h" #include "titanic/core/named_item.h" #include "titanic/core/node_item.h" #include "titanic/core/project_item.h" @@ -275,6 +276,10 @@ CPetControl *CTreeItem::getPetControl() const { return dynamic_cast<CPetControl *>(getDontSaveChild(CPetControl::_type)); } +CMailMan *CTreeItem::getMailMan() const { + return dynamic_cast<CMailMan *>(getDontSaveChild(CMailMan::_type)); +} + CTreeItem *CTreeItem::getDontSaveChild(ClassDef *classDef) const { CProjectItem *root = getRoot(); if (!root) diff --git a/engines/titanic/core/tree_item.h b/engines/titanic/core/tree_item.h index c44825f566..2f4ebc39f1 100644 --- a/engines/titanic/core/tree_item.h +++ b/engines/titanic/core/tree_item.h @@ -29,6 +29,7 @@ namespace Titanic { class CGameManager; class CDontSaveFileItem; +class CMailMan; class CMessage; class CMusicRoom; class CNamedItem; @@ -249,6 +250,11 @@ public: CPetControl *getPetControl() const; /** + * Returns the MailMan + */ + CMailMan *getMailMan() const; + + /** * Returns a child of the Dont Save area of the project of the given class */ CTreeItem *getDontSaveChild(ClassDef *classDef) const; |