aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic/core/game_object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/titanic/core/game_object.cpp')
-rw-r--r--engines/titanic/core/game_object.cpp125
1 files changed, 78 insertions, 47 deletions
diff --git a/engines/titanic/core/game_object.cpp b/engines/titanic/core/game_object.cpp
index 67b7920f04..7848734792 100644
--- a/engines/titanic/core/game_object.cpp
+++ b/engines/titanic/core/game_object.cpp
@@ -42,7 +42,7 @@ int CGameObject::_soundHandles[4];
void CGameObject::init() {
_credits = nullptr;
- _soundHandles[0] = _soundHandles[1] = 0;
+ _soundHandles[0] = _soundHandles[1] = -1;
_soundHandles[2] = _soundHandles[3] = -1;
}
@@ -438,7 +438,8 @@ bool CGameObject::isSoundActive(int handle) const {
return false;
}
-void CGameObject::playGlobalSound(const CString &resName, int mode, bool initialMute, bool repeated, int handleIndex) {
+void CGameObject::playGlobalSound(const CString &resName, int mode, bool initialMute, bool repeated,
+ int handleIndex, Audio::Mixer::SoundType soundType) {
if (handleIndex < 0 || handleIndex > 3)
return;
CGameManager *gameManager = getGameManager();
@@ -463,19 +464,20 @@ void CGameObject::playGlobalSound(const CString &resName, int mode, bool initial
CProximity prox;
prox._channelVolume = volume;
prox._repeated = repeated;
+ prox._soundType = soundType;
switch (handleIndex) {
case 0:
- prox._channel = 6;
+ prox._channelMode = 6;
break;
case 1:
- prox._channel = 7;
+ prox._channelMode = 7;
break;
case 2:
- prox._channel = 8;
+ prox._channelMode = 8;
break;
case 3:
- prox._channel = 9;
+ prox._channelMode = 9;
break;
default:
break;
@@ -519,7 +521,6 @@ void CGameObject::stopGlobalSound(bool transition, int handleIndex) {
sound.stopSound(_soundHandles[handleIndex]);
_soundHandles[handleIndex] = -1;
}
- warning("CGameObject::soundFn4");
}
void CGameObject::setGlobalSoundVolume(int mode, uint seconds, int handleIndex) {
@@ -657,10 +658,10 @@ void CGameObject::playClip(uint startFrame, uint endFrame) {
gameManager->playClip(clip, room, room);
}
-void CGameObject::playRandomClip(const char **names, uint flags) {
+void CGameObject::playRandomClip(const char *const *names, uint flags) {
// Count size of array
int count = 0;
- for (const char **p = names; *p; ++p)
+ for (const char *const *p = names; *p; ++p)
++count;
// Play clip
@@ -668,6 +669,20 @@ void CGameObject::playRandomClip(const char **names, uint flags) {
playClip(name, flags);
}
+void CGameObject::playCutscene(uint startFrame, uint endFrame) {
+ if (!_surface) {
+ if (!_resource.empty())
+ loadResource(_resource);
+ _resource.clear();
+ }
+
+ if (_surface && _surface->loadIfReady() && _surface->_movie) {
+ disableMouse();
+ _surface->_movie->playCutscene(_bounds, startFrame, endFrame);
+ enableMouse();
+ }
+}
+
void CGameObject::savePosition() {
_savedPos = _bounds;
}
@@ -726,7 +741,7 @@ int CGameObject::playSound(const CString &name, uint volume, int val3, bool repe
}
int CGameObject::playSound(const CString &name, CProximity &prox) {
- if (prox._field28 == 2) {
+ if (prox._positioningMode == POSMODE_VECTOR) {
// If the proximity doesn't have a position defined, default it to
// the position of the view to which the game object belongs
if (prox._posX == 0.0 && prox._posY == 0.0 && prox._posZ == 0.0)
@@ -768,30 +783,34 @@ void CGameObject::stopSound(int handle, uint seconds) {
}
int CGameObject::addTimer(int endVal, uint firstDuration, uint repeatDuration) {
- CTimeEventInfo *timer = new CTimeEventInfo(g_vm->_events->getTicksCount(),
- repeatDuration != 0, firstDuration, repeatDuration, this, endVal, CString());
+ CTimeEventInfo *timer = new CTimeEventInfo(getTicksCount(), repeatDuration != 0,
+ firstDuration, repeatDuration, this, endVal, CString());
getGameManager()->addTimer(timer);
return timer->_id;
}
int CGameObject::addTimer(uint firstDuration, uint repeatDuration) {
- CTimeEventInfo *timer = new CTimeEventInfo(g_vm->_events->getTicksCount(),
- repeatDuration != 0, firstDuration, repeatDuration, this, 0, CString());
+ CTimeEventInfo *timer = new CTimeEventInfo(getTicksCount(), repeatDuration != 0,
+ firstDuration, repeatDuration, this, 0, CString());
getGameManager()->addTimer(timer);
return timer->_id;
}
+void CGameObject::stopTimer(int id) {
+ getGameManager()->stopTimer(id);
+}
+
int CGameObject::startAnimTimer(const CString &action, uint firstDuration, uint repeatDuration) {
- CTimeEventInfo *timer = new CTimeEventInfo(g_vm->_events->getTicksCount(),
- repeatDuration > 0, firstDuration, repeatDuration, this, 0, action);
+ CTimeEventInfo *timer = new CTimeEventInfo(getTicksCount(), repeatDuration > 0,
+ firstDuration, repeatDuration, this, 0, action);
getGameManager()->addTimer(timer);
return timer->_id;
}
-void CGameObject::stopTimer(int id) {
+void CGameObject::stopAnimTimer(int id) {
getGameManager()->stopTimer(id);
}
@@ -852,15 +871,15 @@ CViewItem *CGameObject::parseView(const CString &viewString) {
return nullptr;
// Find the designated node within the room
- CNodeItem *node = static_cast<CNodeItem *>(room->findChildInstanceOf(CNodeItem::_type));
+ CNodeItem *node = dynamic_cast<CNodeItem *>(room->findChildInstanceOf(CNodeItem::_type));
while (node && node->getName() != nodeName)
- node = static_cast<CNodeItem *>(room->findNextInstanceOf(CNodeItem::_type, node));
+ node = dynamic_cast<CNodeItem *>(room->findNextInstanceOf(CNodeItem::_type, node));
if (!node)
return nullptr;
- CViewItem *view = static_cast<CViewItem *>(node->findChildInstanceOf(CViewItem::_type));
+ CViewItem *view = dynamic_cast<CViewItem *>(node->findChildInstanceOf(CViewItem::_type));
while (view && view->getName() != viewName)
- view = static_cast<CViewItem *>(node->findNextInstanceOf(CViewItem::_type, view));
+ view = dynamic_cast<CViewItem *>(node->findNextInstanceOf(CViewItem::_type, view));
if (!view)
return nullptr;
@@ -879,7 +898,12 @@ CString CGameObject::getViewFullName() const {
}
void CGameObject::sleep(uint milli) {
- g_vm->_events->sleep(milli);
+ // Use an empty event target so that standard scene drawing won't happen
+ Events &events = *g_vm->_events;
+ CEventTarget nullTarget;
+ events.addTarget(&nullTarget);
+ events.sleep(milli);
+ events.removeTarget();
}
Point CGameObject::getMousePos() const {
@@ -945,12 +969,12 @@ CGameObject *CGameObject::getNextMail(CGameObject *prior) {
}
CGameObject *CGameObject::findRoomObject(const CString &name) const {
- return static_cast<CGameObject *>(findRoom()->findByName(name));
+ return dynamic_cast<CGameObject *>(findRoom()->findByName(name));
}
CGameObject *CGameObject::findInRoom(const CString &name) {
CRoomItem *room = getRoom();
- return room ? static_cast<CGameObject *>(room->findByName(name)) : nullptr;
+ return room ? dynamic_cast<CGameObject *>(room->findByName(name)) : nullptr;
}
Found CGameObject::find(const CString &name, CGameObject **item, int findAreas) {
@@ -977,7 +1001,7 @@ Found CGameObject::find(const CString &name, CGameObject **item, int findAreas)
}
if (findAreas & FIND_GLOBAL) {
- go = static_cast<CGameObject *>(getRoot()->findByName(name));
+ go = dynamic_cast<CGameObject *>(getRoot()->findByName(name));
if (go) {
*item = go;
return FOUND_GLOBAL;
@@ -998,21 +1022,21 @@ Found CGameObject::find(const CString &name, CGameObject **item, int findAreas)
void CGameObject::moveToView() {
CViewItem *view = getGameManager()->getView();
detach();
- view->addUnder(this);
+ addUnder(view);
}
void CGameObject::moveToView(const CString &name) {
CViewItem *view = parseView(name);
detach();
- view->addUnder(this);
+ addUnder(view);
}
-void CGameObject::stateInc14() {
- getGameManager()->_gameState.inc14();
+void CGameObject::stateChangeSeason() {
+ getGameManager()->_gameState.changeSeason();
}
-int CGameObject::stateGet14() const {
- return getGameManager()->_gameState._field14;
+Season CGameObject::stateGetSeason() const {
+ return getGameManager()->_gameState._seasonNum;
}
void CGameObject::stateSet24() {
@@ -1048,7 +1072,7 @@ void CGameObject::setMovieFrameRate(double rate) {
_surface->setMovieFrameRate(rate);
}
-void CGameObject::setTextBorder(const CString &str, int border, int borderRight) {
+void CGameObject::setText(const CString &str, int border, int borderRight) {
if (!_text)
_text = new CPetText();
_textBorder = border;
@@ -1142,8 +1166,8 @@ void CGameObject::mouseUnlockE4() {
CScreenManager::_screenManagerPtr->_mouseCursor->unlockE4();
}
-void CGameObject::mouseSaveState(int v1, int v2, int v3) {
- CScreenManager::_screenManagerPtr->_mouseCursor->saveState(v1, v2, v3);
+void CGameObject::mouseSetPosition(const Point &pt, double rate) {
+ CScreenManager::_screenManagerPtr->_mouseCursor->setPosition(pt, rate);
}
void CGameObject::lockInputHandler() {
@@ -1172,6 +1196,10 @@ void CGameObject::loadSurface() {
_surface->loadIfReady();
}
+bool CGameObject::changeView(const CString &viewName) {
+ return changeView(viewName, "");
+}
+
bool CGameObject::changeView(const CString &viewName, const CString &clipName) {
CViewItem *newView = parseView(viewName);
CGameManager *gameManager = getGameManager();
@@ -1202,9 +1230,9 @@ void CGameObject::dragMove(const Point &pt) {
setPosition(Point(pt.x - _bounds.width() / 2, pt.y - _bounds.height() / 2));
}
-bool CGameObject::isObjectDragging() const {
+CGameObject *CGameObject::getDraggingObject() const {
CTreeItem *item = getGameManager()->_dragItem;
- return item ? static_cast<CGameObject *>(item) != nullptr : false;
+ return dynamic_cast<CGameObject *>(item);
}
Point CGameObject::getControid() const {
@@ -1232,7 +1260,7 @@ CDontSaveFileItem *CGameObject::getDontSave() const {
}
CPetControl *CGameObject::getPetControl() const {
- return static_cast<CPetControl *>(getDontSaveChild(CPetControl::_type));
+ return dynamic_cast<CPetControl *>(getDontSaveChild(CPetControl::_type));
}
CMailMan *CGameObject::getMailMan() const {
@@ -1271,7 +1299,7 @@ CRoomItem *CGameObject::locateRoom(const CString &name) const {
CGameObject *CGameObject::getHiddenObject(const CString &name) const {
CRoomItem *room = getHiddenRoom();
- return room ? static_cast<CGameObject *>(findUnder(room, name)) : nullptr;
+ return room ? dynamic_cast<CGameObject *>(findUnder(room, name)) : nullptr;
}
CTreeItem *CGameObject::findUnder(CTreeItem *parent, const CString &name) const {
@@ -1363,10 +1391,14 @@ int CGameObject::getClipDuration(const CString &name, int frameRate) const {
return clip ? (clip->_endFrame - clip->_startFrame) * 1000 / frameRate : 0;
}
-uint32 CGameObject::getTickCount() {
+uint32 CGameObject::getTicksCount() {
return g_vm->_events->getTicksCount();
}
+Common::SeekableReadStream *CGameObject::getResource(const CString &name) {
+ return g_vm->_filesManager->getResource(name);
+}
+
bool CGameObject::compareRoomFlags(int mode, uint flags1, uint flags2) {
switch (mode) {
case 1:
@@ -1424,7 +1456,7 @@ void CGameObject::resetMail() {
mailMan->resetValue();
}
-int CGameObject::getNewRandomNumber(int max, int *oldVal) {
+int CGameObject::getRandomNumber(int max, int *oldVal) {
if (oldVal) {
int startingVal = *oldVal;
while (*oldVal == startingVal && max > 0)
@@ -1479,7 +1511,7 @@ CTreeItem *CGameObject::petContainerRemove(CGameObject *obj) {
if (!obj->compareRoomNameTo("CarryParcel"))
return obj;
- CGameObject *item = static_cast<CGameObject *>(pet->getLastChild());
+ CGameObject *item = dynamic_cast<CGameObject *>(pet->getLastChild());
if (item)
item->detach();
@@ -1574,11 +1606,11 @@ void CGameObject::petUnlockInput() {
/*------------------------------------------------------------------------*/
CStarControl *CGameObject::getStarControl() const {
- CStarControl *starControl = static_cast<CStarControl *>(getDontSaveChild(CStarControl::_type));
+ CStarControl *starControl = dynamic_cast<CStarControl *>(getDontSaveChild(CStarControl::_type));
if (!starControl) {
CViewItem *view = getGameManager()->getView();
if (view)
- starControl = static_cast<CStarControl *>(view->findChildInstanceOf(CStarControl::_type));
+ starControl = dynamic_cast<CStarControl *>(view->findChildInstanceOf(CStarControl::_type));
}
return starControl;
@@ -1590,16 +1622,15 @@ void CGameObject::starFn1(int v) {
starControl->fn1(v);
}
-void CGameObject::starFn2() {
+bool CGameObject::starFn2() {
CStarControl *starControl = getStarControl();
- if (starControl)
- starControl->fn4();
+ return starControl ? starControl->fn4() : false;
}
/*------------------------------------------------------------------------*/
void CGameObject::startTalking(const CString &npcName, uint id, CViewItem *view) {
- CTrueTalkNPC *npc = static_cast<CTrueTalkNPC *>(getRoot()->findByName(npcName));
+ CTrueTalkNPC *npc = dynamic_cast<CTrueTalkNPC *>(getRoot()->findByName(npcName));
startTalking(npc, id, view);
}