Skip to content

Commit

Permalink
TITANIC: Cleanup of engine references
Browse files Browse the repository at this point in the history
  • Loading branch information
dreammaster committed Aug 23, 2016
1 parent 65bc8cb commit 8b38295
Show file tree
Hide file tree
Showing 29 changed files with 156 additions and 76 deletions.
18 changes: 11 additions & 7 deletions engines/titanic/core/game_object.cpp
Expand Up @@ -782,24 +782,24 @@ 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;
}

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;
Expand Down Expand Up @@ -1381,10 +1381,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:
Expand Down
8 changes: 7 additions & 1 deletion engines/titanic/core/game_object.h
Expand Up @@ -23,6 +23,7 @@
#ifndef TITANIC_GAME_OBJECT_H
#define TITANIC_GAME_OBJECT_H

#include "common/stream.h"
#include "titanic/support/mouse_cursor.h"
#include "titanic/support/credit_text.h"
#include "titanic/support/movie_range_info.h"
Expand Down Expand Up @@ -442,7 +443,12 @@ class CGameObject : public CNamedItem {
/**
* Returns the current system tick count
*/
uint32 getTickCount();
uint32 getTicksCount();

/**
* Gets a resource from the DAT file
*/
Common::SeekableReadStream *getResource(const CString &name);

/**
* Returns true if a mail with a specified Id exists
Expand Down
11 changes: 5 additions & 6 deletions engines/titanic/game/announce.cpp
Expand Up @@ -21,7 +21,6 @@
*/

#include "titanic/game/announce.h"
#include "titanic/titanic.h"

namespace Titanic {

Expand Down Expand Up @@ -76,7 +75,7 @@ bool CAnnounce::TimerMsg(CTimerMsg *msg) {
"", "", "", "", "", "", ""
};

int randVal = _nameIndex ? g_vm->getRandomNumber(2) : 0;
int randVal = _nameIndex ? getRandomNumber(2) : 0;
switch (randVal) {
case 0:
case 1:
Expand All @@ -85,21 +84,21 @@ bool CAnnounce::TimerMsg(CTimerMsg *msg) {
queueSound(waveNames1[_nameIndex], _soundHandle);
++_nameIndex;
} else {
queueSound(waveNames1[1 + g_vm->getRandomNumber(17)], _soundHandle);
queueSound(waveNames1[1 + getRandomNumber(17)], _soundHandle);
}
break;

case 2:
_soundHandle = playSound("z#189.wav");
queueSound(waveNames2[1 + g_vm->getRandomNumber(35)], _soundHandle);
queueSound(waveNames2[1 + getRandomNumber(35)], _soundHandle);
break;

default:
break;
}

addTimer(1, 300000 + g_vm->getRandomNumber(30000), 0);
if (g_vm->getRandomNumber(3) == 0)
addTimer(1, 300000 + getRandomNumber(30000), 0);
if (getRandomNumber(3) == 0)
addTimer(2, 4000, 0);

} else if (msg->_timerCtr == 2) {
Expand Down
2 changes: 1 addition & 1 deletion engines/titanic/game/arboretum_gate.cpp
Expand Up @@ -21,7 +21,7 @@
*/

#include "titanic/game/arboretum_gate.h"
#include "titanic/titanic.h"
#include "titanic/game/seasonal_adjustment.h"

namespace Titanic {

Expand Down
3 changes: 1 addition & 2 deletions engines/titanic/game/bomb.cpp
Expand Up @@ -21,7 +21,6 @@
*/

#include "titanic/game/bomb.h"
#include "titanic/titanic.h"

namespace Titanic {

Expand Down Expand Up @@ -211,7 +210,7 @@ bool CBomb::EnterRoomMsg(CEnterRoomMsg *msg) {
_fieldE8 = 17;
_fieldEC = 9;
_fieldF0 = 0;
_startingTicks = g_vm->_events->getTicksCount();
_startingTicks = getTicksCount();
return true;
}

Expand Down
3 changes: 1 addition & 2 deletions engines/titanic/game/desk_click_responder.cpp
Expand Up @@ -21,7 +21,6 @@
*/

#include "titanic/game/desk_click_responder.h"
#include "titanic/titanic.h"

namespace Titanic {

Expand Down Expand Up @@ -51,7 +50,7 @@ bool CDeskClickResponder::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
if (_fieldD4)
return CClickResponder::MouseButtonDownMsg(msg);

uint ticks = g_vm->_events->getTicksCount();
uint ticks = getTicksCount();
if (!_ticks || ticks > (_ticks + 4000)) {
playSound("a#22.wav");
_ticks = ticks;
Expand Down
19 changes: 19 additions & 0 deletions engines/titanic/game/head_smash_event.cpp
Expand Up @@ -24,6 +24,11 @@

namespace Titanic {

BEGIN_MESSAGE_MAP(CHeadSmashEvent, CBackground)
ON_MESSAGE(ActMsg)
ON_MESSAGE(MovieEndMsg)
END_MESSAGE_MAP()

void CHeadSmashEvent::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
CBackground::save(file, indent);
Expand All @@ -34,4 +39,18 @@ void CHeadSmashEvent::load(SimpleFile *file) {
CBackground::load(file);
}

bool CHeadSmashEvent::ActMsg(CActMsg *msg) {
if (msg->_action == "PlayToEnd") {
setVisible(true);
playMovie(MOVIE_NOTIFY_OBJECT | MOVIE_GAMESTATE);
}

return true;
}

bool CHeadSmashEvent::MovieEndMsg(CMovieEndMsg *msg) {
changeView("CreatorsChamber.Node 1.W");
return true;
}

} // End of namespace Titanic
3 changes: 3 additions & 0 deletions engines/titanic/game/head_smash_event.h
Expand Up @@ -28,6 +28,9 @@
namespace Titanic {

class CHeadSmashEvent : public CBackground {
DECLARE_MESSAGE_MAP;
bool ActMsg(CActMsg *msg);
bool MovieEndMsg(CMovieEndMsg *msg);
public:
CLASSDEF;

Expand Down
63 changes: 58 additions & 5 deletions engines/titanic/game/head_smash_lever.cpp
Expand Up @@ -24,25 +24,78 @@

namespace Titanic {

BEGIN_MESSAGE_MAP(CHeadSmashLever, CBackground)
ON_MESSAGE(MouseButtonDownMsg)
ON_MESSAGE(ActMsg)
ON_MESSAGE(FrameMsg)
ON_MESSAGE(LoadSuccessMsg)
END_MESSAGE_MAP()

CHeadSmashLever::CHeadSmashLever() : CBackground(),
_fieldE0(0), _fieldE4(0), _fieldE8(0) {}
_enabled(false), _fieldE4(false), _ticksCount(0) {}

void CHeadSmashLever::save(SimpleFile *file, int indent) {
file->writeNumberLine(1, indent);
file->writeNumberLine(_fieldE0, indent);
file->writeNumberLine(_enabled, indent);
file->writeNumberLine(_fieldE4, indent);
file->writeNumberLine(_fieldE8, indent);
file->writeNumberLine(_ticksCount, indent);

CBackground::save(file, indent);
}

void CHeadSmashLever::load(SimpleFile *file) {
file->readNumber();
_fieldE0 = file->readNumber();
_enabled = file->readNumber();
_fieldE4 = file->readNumber();
_fieldE8 = file->readNumber();
_ticksCount = file->readNumber();

CBackground::load(file);
}

bool CHeadSmashLever::MouseButtonDownMsg(CMouseButtonDownMsg *msg) {
if (_enabled) {
playMovie(0, 14, 0);
playSound("z#54.wav");
int soundHandle = playSound("z#45.wav");
queueSound("z#49.wav", soundHandle);
_ticksCount = getTicksCount();
_fieldE4 = true;
} else {
playMovie(0);
playSound("z#56.wav");
}

return true;
}

bool CHeadSmashLever::ActMsg(CActMsg *msg) {
if (msg->_action == "EnableObject")
_enabled = true;
else if (msg->_action == "DisableObject")
_enabled = false;

return true;
}

bool CHeadSmashLever::FrameMsg(CFrameMsg *msg) {
if (_fieldE4 && msg->_ticks > (_ticksCount + 750)) {
CActMsg actMsg1("CreatorsChamber.Node 1.S");
actMsg1.execute("MoveToCreators");
CActMsg actMsg2("PlayToEnd");
actMsg2.execute("SmashingStatue");

playSound("b#16.wav");
_fieldE4 = false;
}

return true;
}

bool CHeadSmashLever::LoadSuccessMsg(CLoadSuccessMsg *msg) {
if (_fieldE4)
_ticksCount = getTicksCount();

return true;
}

} // End of namespace Titanic
11 changes: 8 additions & 3 deletions engines/titanic/game/head_smash_lever.h
Expand Up @@ -28,10 +28,15 @@
namespace Titanic {

class CHeadSmashLever : public CBackground {
DECLARE_MESSAGE_MAP;
bool MouseButtonDownMsg(CMouseButtonDownMsg *msg);
bool ActMsg(CActMsg *msg);
bool FrameMsg(CFrameMsg *msg);
bool LoadSuccessMsg(CLoadSuccessMsg *msg);
public:
int _fieldE0;
int _fieldE4;
int _fieldE8;
bool _enabled;
bool _fieldE4;
int _ticksCount;
public:
CLASSDEF;
CHeadSmashLever();
Expand Down
7 changes: 7 additions & 0 deletions engines/titanic/game/seasonal_adjustment.h
Expand Up @@ -27,6 +27,13 @@

namespace Titanic {

enum Season {
SPRING = 0,
SUMMER = 1,
AUTUMN = 2,
WINTER = 3
};

class CSeasonalAdjustment : public CBackground {
public:
int _fieldE0;
Expand Down
6 changes: 3 additions & 3 deletions engines/titanic/game/television.cpp
Expand Up @@ -20,10 +20,10 @@
*
*/

#include "titanic/titanic.h"
#include "titanic/game/television.h"
#include "titanic/pet_control/pet_control.h"
#include "titanic/game/get_lift_eye2.h"
#include "titanic/core/project_item.h"
#include "titanic/pet_control/pet_control.h"

namespace Titanic {

Expand Down Expand Up @@ -229,7 +229,7 @@ bool CTelevision::PETActivateMsg(CPETActivateMsg *msg) {
}

bool CTelevision::MovieEndMsg(CMovieEndMsg *msg) {
if (g_vm->getRandomNumber(6) == 0) {
if (getRandomNumber(6) == 0) {
CParrotSpeakMsg parrotMsg("Television", "");
parrotMsg.execute("PerchedParrot");
}
Expand Down
1 change: 0 additions & 1 deletion engines/titanic/messages/mouse_messages.cpp
Expand Up @@ -23,7 +23,6 @@
#include "titanic/messages/mouse_messages.h"
#include "titanic/support/mouse_cursor.h"
#include "titanic/support/screen_manager.h"
#include "titanic/titanic.h"

namespace Titanic {

Expand Down
2 changes: 1 addition & 1 deletion engines/titanic/moves/exit_arboretum.cpp
Expand Up @@ -21,7 +21,7 @@
*/

#include "titanic/moves/exit_arboretum.h"
#include "titanic/titanic.h"
#include "titanic/game/seasonal_adjustment.h"

namespace Titanic {

Expand Down
8 changes: 4 additions & 4 deletions engines/titanic/npcs/barbot.cpp
Expand Up @@ -380,12 +380,12 @@ bool CBarbot::LeaveViewMsg(CLeaveViewMsg *msg) {
bool CBarbot::MovieEndMsg(CMovieEndMsg *msg) {
if (msg->_endFrame == _frameNum) {
_frameNum = -1;
_field14C = g_vm->_events->getTicksCount();
_field14C = getTicksCount();
}

if (msg->_endFrame == _field148) {
_field148 = -1;
_field150 = g_vm->_events->getTicksCount();
_field150 = getTicksCount();
}

if (msg->_endFrame == _field13C) {
Expand Down Expand Up @@ -678,7 +678,7 @@ bool CBarbot::FrameMsg(CFrameMsg *msg) {
}

bool CBarbot::LoadSuccessMsg(CLoadSuccessMsg *msg) {
_field14C = _field150 = g_vm->_events->getTicksCount();
_field14C = _field150 = getTicksCount();
_frameNum = -1;
_field148 = -1;

Expand Down Expand Up @@ -720,7 +720,7 @@ bool CBarbot::TimerMsg(CTimerMsg *msg) {
if (!_fieldC4 && compareRoomNameTo("Bar")) {
CParrotSpeakMsg speakMsg("Barbot", "AskForDrink");
speakMsg.execute("PerchedParrot");
addTimer(10000 + g_vm->getRandomNumber(20000));
addTimer(10000 + getRandomNumber(20000));
}

return true;
Expand Down

0 comments on commit 8b38295

Please sign in to comment.