/* 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/game/television.h" #include "titanic/game/get_lift_eye2.h" #include "titanic/core/project_item.h" #include "titanic/carry/magazine.h" #include "titanic/pet_control/pet_control.h" #include "titanic/titanic.h" namespace Titanic { BEGIN_MESSAGE_MAP(CTelevision, CGameObject) ON_MESSAGE(LeaveViewMsg) ON_MESSAGE(ChangeSeasonMsg) ON_MESSAGE(EnterViewMsg) ON_MESSAGE(PETUpMsg) ON_MESSAGE(PETDownMsg) ON_MESSAGE(StatusChangeMsg) ON_MESSAGE(ActMsg) ON_MESSAGE(PETActivateMsg) ON_MESSAGE(MovieEndMsg) ON_MESSAGE(ShipSettingMsg) ON_MESSAGE(TurnOff) ON_MESSAGE(TurnOn) ON_MESSAGE(LightsMsg) END_MESSAGE_MAP() int CTelevision::_seasonFrame; bool CTelevision::_turnOn; int CTelevision::_seasonUnused; int CTelevision::_floorNum; bool CTelevision::_channel4Glyph; bool CTelevision::_eyeFlag; CTelevision::CTelevision() : CBackground(), _channelNum(1), _channelsCount(7), _isOn(false), _unused(0), _soundHandle(0) { } void CTelevision::init() { _seasonFrame = 531; _turnOn = true; _seasonUnused = 0; _floorNum = 27; _channel4Glyph = true; _eyeFlag = true; } void CTelevision::deinit() { } void CTelevision::save(SimpleFile *file, int indent) { file->writeNumberLine(1, indent); file->writeNumberLine(_channelNum, indent); file->writeNumberLine(_seasonFrame, indent); file->writeNumberLine(_channelsCount, indent); file->writeNumberLine(_turnOn, indent); file->writeNumberLine(_isOn, indent); file->writeNumberLine(_seasonUnused, indent); file->writeNumberLine(_unused, indent); file->writeNumberLine(_floorNum, indent); file->writeNumberLine(_soundHandle, indent); file->writeNumberLine(_channel4Glyph, indent); file->writeNumberLine(_eyeFlag, indent); CBackground::save(file, indent); } void CTelevision::load(SimpleFile *file) { file->readNumber(); _channelNum = file->readNumber(); _seasonFrame = file->readNumber(); _channelsCount = file->readNumber(); _turnOn = file->readNumber() != 0; _isOn = file->readNumber() != 0; _seasonUnused = file->readNumber(); _unused = file->readNumber(); _floorNum = file->readNumber(); _soundHandle = file->readNumber(); _channel4Glyph = file->readNumber(); _eyeFlag = file->readNumber(); CBackground::load(file); } bool CTelevision::LeaveViewMsg(CLeaveViewMsg *msg) { petClear(); if (_isOn) { if (isSoundActive(_soundHandle)) stopSound(_soundHandle, 0); loadFrame(622); stopMovie(); setVisible(0); _isOn = false; if (compareRoomNameTo("CSGState")) { CVisibleMsg visibleMsg(true); visibleMsg.execute("Tellypic"); } } return true; } bool CTelevision::ChangeSeasonMsg(CChangeSeasonMsg *msg) { if (msg->_season == "Autumn") { _seasonFrame = 545; _seasonUnused = 0; } else if (msg->_season == "Winter") { _seasonFrame = 503; _seasonUnused = 0; } else if (msg->_season == "Spring") { _seasonFrame = 517; _seasonUnused = 0; } else if (msg->_season == "Summer") { _seasonFrame = 531; _seasonUnused = 0; } return true; } bool CTelevision::EnterViewMsg(CEnterViewMsg *msg) { petSetArea(PET_REMOTE); petHighlightGlyph(GLYPH_TELEVISION_CONTROL); petSetRemoteTarget(); setVisible(0); _channelNum = 1; return true; } static const int START_FRAMES[9] = { 0, 0, 56, 112, 168, 224, 280, 336, 392 }; static const int END_FRAMES[8] = { 0, 55, 111, 167, 223, 279, 335, 391 }; bool CTelevision::PETUpMsg(CPETUpMsg *msg) { if (msg->_name == "Television" && _isOn) { if (isSoundActive(_soundHandle)) stopSound(_soundHandle, 0); _channelNum = (_channelNum % _channelsCount) + 1; stopMovie(); playMovie(START_FRAMES[_channelNum], END_FRAMES[_channelNum], MOVIE_NOTIFY_OBJECT); } return true; } bool CTelevision::PETDownMsg(CPETDownMsg *msg) { if (msg->_name == "Television" && _isOn) { if (isSoundActive(_soundHandle)) stopSound(_soundHandle, 0); if (--_channelNum < 1) _channelNum += _channelsCount; stopMovie(); playMovie(START_FRAMES[_channelNum], END_FRAMES[_channelNum], MOVIE_NOTIFY_OBJECT); } return true; } bool CTelevision::StatusChangeMsg(CStatusChangeMsg *msg) { if (_isOn) { stopMovie(); playMovie(0); } return true; } bool CTelevision::ActMsg(CActMsg *msg) { if (msg->_action == "TurnTVOnOff") { _isOn = !_isOn; if (_isOn) { setVisible(true); CStatusChangeMsg changeMsg; changeMsg.execute(this); } else { setVisible(_isOn); stopMovie(); } } return true; } bool CTelevision::PETActivateMsg(CPETActivateMsg *msg) { if (msg->_name == "Television") { CVisibleMsg visibleMsg(_isOn); _isOn = !_isOn; if (_isOn) { setVisible(true); playMovie(0, 55, 0); _channelNum = 1; } else { stopMovie(); if (isSoundActive(_soundHandle)) stopSound(_soundHandle, 0); setVisible(false); } if (compareRoomNameTo("SGTState")) visibleMsg.execute("Tellypic"); } return true; } bool CTelevision::MovieEndMsg(CMovieEndMsg *msg) { if (getRandomNumber(6) == 0) { CParrotSpeakMsg parrotMsg("Television", ""); parrotMsg.execute("PerchedParrot"); } if (_channelNum == 3 && compareRoomNameTo("SGTState") && getPassengerClass() == THIRD_CLASS) { playSound("z#47.wav"); _soundHandle = playSound("b#20.wav"); CMagazine *magazine = dynamic_cast(getRoot()->findByName("Magazine")); if (magazine) { CPetControl *pet = getPetControl(); uint roomFlags = pet->getRoomFlags(); debugC(kDebugScripts, "Assigned room - %d", roomFlags); magazine->addMail(roomFlags); magazine->removeMail(roomFlags, roomFlags); } loadFrame(561); } else if (_channelNum == 2) { loadFrame(_seasonFrame); } else if (_channelNum == 4 && _channel4Glyph) { if (_turnOn) loadFrame(502); else petDisplayMessage(NOTHING_ON_CHANNEL); } else if (_channelNum == 5 && *CGetLiftEye2::_destObject != "NULL") { loadFrame(393 + _floorNum); } else { petDisplayMessage(NOTHING_ON_CHANNEL); } return true; } bool CTelevision::ShipSettingMsg(CShipSettingMsg *msg) { _floorNum = msg->_value; return true; } bool CTelevision::TurnOff(CTurnOff *msg) { _turnOn = false; return true; } bool CTelevision::TurnOn(CTurnOn *msg) { _turnOn = true; return true; } bool CTelevision::LightsMsg(CLightsMsg *msg) { CPetControl *pet = getPetControl(); bool flag = false; if (pet) flag = pet->isRoom59706(); if (msg->_flag2 || !flag) _turnOn = true; return true; } } // End of namespace Titanic