scummvm/engines/neverhood/module1500.cpp
2013-05-08 20:43:44 +02:00

142 lines
3.6 KiB
C++

/* 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 "neverhood/module1500.h"
namespace Neverhood {
Module1500::Module1500(NeverhoodEngine *vm, Module *parentModule, int which, bool flag)
: Module(vm, parentModule), _flag(flag) {
if (which < 0) {
createScene(_vm->gameState().sceneNum, -1);
} else {
createScene(3, -1);
}
}
void Module1500::createScene(int sceneNum, int which) {
debug("Module1500::createScene(%d, %d)", sceneNum, which);
_vm->gameState().sceneNum = sceneNum;
switch (_vm->gameState().sceneNum) {
case 0:
_childObject = new Scene1501(_vm, this, 0x8420221D, 0xA61024C4, 150, 48);
break;
case 1:
_childObject = new Scene1501(_vm, this, 0x30050A0A, 0x58B45E58, 110, 48);
break;
case 2:
sendMessage(_parentModule, 0x0800, 0);
createSmackerScene(0x001A0005, true, true, true);
break;
case 3:
_childObject = new Scene1501(_vm, this, 0x0CA04202, 0, 110, 48);
break;
}
SetUpdateHandler(&Module1500::updateScene);
_childObject->handleUpdate();
}
void Module1500::updateScene() {
if (!updateChild()) {
switch (_vm->gameState().sceneNum) {
case 0:
createScene(1, -1);
break;
case 1:
if (_flag) {
createScene(2, -1);
} else {
leaveModule(0);
}
break;
case 3:
createScene(0, -1);
break;
default:
leaveModule(0);
break;
}
}
}
// Scene1501
Scene1501::Scene1501(NeverhoodEngine *vm, Module *parentModule, uint32 backgroundFileHash, uint32 soundFileHash, int countdown2, int countdown3)
: Scene(vm, parentModule, true), _countdown3(countdown3), _countdown2(countdown2), _countdown1(0), _flag(false) {
SetUpdateHandler(&Scene1501::update);
SetMessageHandler(&Scene1501::handleMessage);
_surfaceFlag = true;
setBackground(backgroundFileHash);
setPalette();
addEntity(_palette);
_palette->addBasePalette(backgroundFileHash, 0, 256, 0);
_palette->startFadeToPalette(12);
if (soundFileHash != 0)
playSound(0, soundFileHash);
}
void Scene1501::update() {
Scene::update();
// TODO: Since these countdowns are used a lot, maybe these can be wrapped in a class/struct
// so the code gets a little cleaner.
if (_countdown1 != 0) {
_countdown1--;
if (_countdown1 == 0) {
_vm->_screen->clear();
leaveScene(0);
}
} else if ((_countdown2 != 0 && (--_countdown2 == 0)) || !isSoundPlaying(0)) {
_countdown1 = 12;
_palette->startFadeToBlack(11);
}
if (_countdown3 != 0)
_countdown3--;
if (_countdown3 == 0 && _flag && _countdown1 == 0) {
_countdown1 = 12;
_palette->startFadeToBlack(11);
}
}
uint32 Scene1501::handleMessage(int messageNum, const MessageParam &param, Entity *sender) {
uint32 messageResult = Scene::handleMessage(messageNum, param, sender);
if (messageNum == 0x0009) {
_flag = true;
}
return messageResult;
}
} // End of namespace Neverhood