From 33737ea2dcd97026706dd75f8c2c27fa148c165a Mon Sep 17 00:00:00 2001 From: Paul Gilbert Date: Thu, 1 Sep 2016 19:10:36 -0400 Subject: TITANIC: Convert many static_casts to dynamic_cast --- engines/titanic/core/game_object.cpp | 28 ++++++++++++++-------------- engines/titanic/core/mail_man.cpp | 4 ++-- engines/titanic/core/project_item.cpp | 2 +- engines/titanic/core/view_item.cpp | 2 +- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'engines/titanic/core') diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp index 07358b8115..aa6ffda0e3 100644 --- a/engines/titanic/core/game_object.cpp +++ b/engines/titanic/core/game_object.cpp @@ -871,15 +871,15 @@ CViewItem *CGameObject::parseView(const CString &viewString) { return nullptr; // Find the designated node within the room - CNodeItem *node = static_cast(room->findChildInstanceOf(CNodeItem::_type)); + CNodeItem *node = dynamic_cast(room->findChildInstanceOf(CNodeItem::_type)); while (node && node->getName() != nodeName) - node = static_cast(room->findNextInstanceOf(CNodeItem::_type, node)); + node = dynamic_cast(room->findNextInstanceOf(CNodeItem::_type, node)); if (!node) return nullptr; - CViewItem *view = static_cast(node->findChildInstanceOf(CViewItem::_type)); + CViewItem *view = dynamic_cast(node->findChildInstanceOf(CViewItem::_type)); while (view && view->getName() != viewName) - view = static_cast(node->findNextInstanceOf(CViewItem::_type, view)); + view = dynamic_cast(node->findNextInstanceOf(CViewItem::_type, view)); if (!view) return nullptr; @@ -964,12 +964,12 @@ CGameObject *CGameObject::getNextMail(CGameObject *prior) { } CGameObject *CGameObject::findRoomObject(const CString &name) const { - return static_cast(findRoom()->findByName(name)); + return dynamic_cast(findRoom()->findByName(name)); } CGameObject *CGameObject::findInRoom(const CString &name) { CRoomItem *room = getRoom(); - return room ? static_cast(room->findByName(name)) : nullptr; + return room ? dynamic_cast(room->findByName(name)) : nullptr; } Found CGameObject::find(const CString &name, CGameObject **item, int findAreas) { @@ -996,7 +996,7 @@ Found CGameObject::find(const CString &name, CGameObject **item, int findAreas) } if (findAreas & FIND_GLOBAL) { - go = static_cast(getRoot()->findByName(name)); + go = dynamic_cast(getRoot()->findByName(name)); if (go) { *item = go; return FOUND_GLOBAL; @@ -1227,7 +1227,7 @@ void CGameObject::dragMove(const Point &pt) { CGameObject *CGameObject::getDraggingObject() const { CTreeItem *item = getGameManager()->_dragItem; - return static_cast(item); + return dynamic_cast(item); } Point CGameObject::getControid() const { @@ -1255,7 +1255,7 @@ CDontSaveFileItem *CGameObject::getDontSave() const { } CPetControl *CGameObject::getPetControl() const { - return static_cast(getDontSaveChild(CPetControl::_type)); + return dynamic_cast(getDontSaveChild(CPetControl::_type)); } CMailMan *CGameObject::getMailMan() const { @@ -1294,7 +1294,7 @@ CRoomItem *CGameObject::locateRoom(const CString &name) const { CGameObject *CGameObject::getHiddenObject(const CString &name) const { CRoomItem *room = getHiddenRoom(); - return room ? static_cast(findUnder(room, name)) : nullptr; + return room ? dynamic_cast(findUnder(room, name)) : nullptr; } CTreeItem *CGameObject::findUnder(CTreeItem *parent, const CString &name) const { @@ -1506,7 +1506,7 @@ CTreeItem *CGameObject::petContainerRemove(CGameObject *obj) { if (!obj->compareRoomNameTo("CarryParcel")) return obj; - CGameObject *item = static_cast(pet->getLastChild()); + CGameObject *item = dynamic_cast(pet->getLastChild()); if (item) item->detach(); @@ -1601,11 +1601,11 @@ void CGameObject::petUnlockInput() { /*------------------------------------------------------------------------*/ CStarControl *CGameObject::getStarControl() const { - CStarControl *starControl = static_cast(getDontSaveChild(CStarControl::_type)); + CStarControl *starControl = dynamic_cast(getDontSaveChild(CStarControl::_type)); if (!starControl) { CViewItem *view = getGameManager()->getView(); if (view) - starControl = static_cast(view->findChildInstanceOf(CStarControl::_type)); + starControl = dynamic_cast(view->findChildInstanceOf(CStarControl::_type)); } return starControl; @@ -1625,7 +1625,7 @@ bool CGameObject::starFn2() { /*------------------------------------------------------------------------*/ void CGameObject::startTalking(const CString &npcName, uint id, CViewItem *view) { - CTrueTalkNPC *npc = static_cast(getRoot()->findByName(npcName)); + CTrueTalkNPC *npc = dynamic_cast(getRoot()->findByName(npcName)); startTalking(npc, id, view); } diff --git a/engines/titanic/core/mail_man.cpp b/engines/titanic/core/mail_man.cpp index afe13bebad..11e17fc4e5 100644 --- a/engines/titanic/core/mail_man.cpp +++ b/engines/titanic/core/mail_man.cpp @@ -37,14 +37,14 @@ void CMailMan::load(SimpleFile *file) { } CGameObject *CMailMan::getFirstObject() const { - return static_cast(getFirstChild()); + return dynamic_cast(getFirstChild()); } CGameObject *CMailMan::getNextObject(CGameObject *prior) const { if (!prior || prior->getParent() != this) return nullptr; - return static_cast(prior->getNextSibling()); + return dynamic_cast(prior->getNextSibling()); } void CMailMan::addMail(CGameObject *obj, int id) { diff --git a/engines/titanic/core/project_item.cpp b/engines/titanic/core/project_item.cpp index 76293233b0..df48bad501 100644 --- a/engines/titanic/core/project_item.cpp +++ b/engines/titanic/core/project_item.cpp @@ -85,7 +85,7 @@ void CProjectItem::buildFilesList() { CTreeItem *treeItem = getFirstChild(); while (treeItem) { if (treeItem->isFileItem()) { - CString name = static_cast(treeItem)->getFilename(); + CString name = dynamic_cast(treeItem)->getFilename(); _files.add()->_name = name; } diff --git a/engines/titanic/core/view_item.cpp b/engines/titanic/core/view_item.cpp index 03e2753839..333b092ea4 100644 --- a/engines/titanic/core/view_item.cpp +++ b/engines/titanic/core/view_item.cpp @@ -169,7 +169,7 @@ void CViewItem::enterView(CViewItem *newView) { CLinkItem *CViewItem::findLink(CViewItem *newView) { for (CTreeItem *treeItem = getFirstChild(); treeItem; treeItem = scan(treeItem)) { - CLinkItem *link = static_cast(treeItem); + CLinkItem *link = dynamic_cast(treeItem); if (link && link->connectsTo(newView)) return link; } -- cgit v1.2.3