2009-06-12 12:40:18 +00:00
|
|
|
/* 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.
|
2009-06-12 14:19:33 +00:00
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
2009-06-12 12:40:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/file.h"
|
2009-08-05 05:41:32 +00:00
|
|
|
#include "common/EventRecorder.h"
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2009-06-12 17:34:06 +00:00
|
|
|
#include "asylum/asylum.h"
|
2009-06-15 14:37:23 +00:00
|
|
|
#include "asylum/respack.h"
|
2009-09-29 23:33:48 +00:00
|
|
|
#include "asylum/config.h"
|
2009-06-12 12:40:18 +00:00
|
|
|
|
|
|
|
namespace Asylum {
|
|
|
|
|
|
|
|
AsylumEngine::AsylumEngine(OSystem *system, Common::Language language)
|
2009-09-21 19:11:49 +00:00
|
|
|
: Engine(system) {
|
|
|
|
|
2009-07-08 19:17:47 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelMain, "Main", "Generic debug level");
|
2009-07-06 23:35:54 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelResources, "Resources", "Resources debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelSprites, "Sprites", "Sprites debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelInput, "Input", "Input events debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelMenu, "Menu", "Menu debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelScripts, "Scripts", "Scripts debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelSound, "Sound", "Sound debugging");
|
|
|
|
Common::addDebugChannel(kDebugLevelSavegame, "Savegame", "Saving & restoring game debugging");
|
2009-09-21 19:11:49 +00:00
|
|
|
Common::addDebugChannel(kDebugLevelScene, "Scene", "Scene process and draw debugging");
|
|
|
|
|
2009-09-24 02:24:59 +00:00
|
|
|
SearchMan.addSubDirectoryMatching(_gameDataDir, "data");
|
|
|
|
SearchMan.addSubDirectoryMatching(_gameDataDir, "vids");
|
|
|
|
SearchMan.addSubDirectoryMatching(_gameDataDir, "music");
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2009-11-11 09:51:36 +00:00
|
|
|
Common::enableDebugChannel("Scripts");
|
|
|
|
|
2009-08-05 05:41:32 +00:00
|
|
|
g_eventRec.registerRandomSource(_rnd, "asylum");
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AsylumEngine::~AsylumEngine() {
|
2009-07-09 11:18:15 +00:00
|
|
|
Common::clearAllDebugChannels();
|
|
|
|
|
2009-06-21 12:09:44 +00:00
|
|
|
delete _console;
|
2009-06-19 08:53:58 +00:00
|
|
|
delete _scene;
|
2009-06-14 14:31:23 +00:00
|
|
|
delete _mainMenu;
|
2009-06-13 23:16:07 +00:00
|
|
|
delete _video;
|
2009-06-13 23:03:37 +00:00
|
|
|
delete _sound;
|
|
|
|
delete _screen;
|
2009-08-07 12:03:23 +00:00
|
|
|
delete _encounter;
|
2009-09-25 01:05:23 +00:00
|
|
|
delete _text;
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error AsylumEngine::run() {
|
2009-07-08 19:17:47 +00:00
|
|
|
Common::Error err;
|
|
|
|
err = init();
|
|
|
|
if (err != Common::kNoError)
|
2009-09-21 19:11:49 +00:00
|
|
|
return err;
|
2009-09-25 13:19:46 +00:00
|
|
|
|
2009-07-08 19:17:47 +00:00
|
|
|
return go();
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Will do the same as subroutine at address 0041A500
|
|
|
|
Common::Error AsylumEngine::init() {
|
2009-06-12 20:07:11 +00:00
|
|
|
initGraphics(640, 480, true);
|
2009-06-12 20:38:38 +00:00
|
|
|
|
2009-09-25 13:19:46 +00:00
|
|
|
_screen = new Screen(this);
|
|
|
|
_sound = new Sound(_mixer);
|
|
|
|
_video = new Video(_mixer);
|
|
|
|
_console = new Console(this);
|
|
|
|
_text = new Text(_screen);
|
|
|
|
_mainMenu = 0;
|
|
|
|
_scene = 0;
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2009-08-09 22:56:13 +00:00
|
|
|
_introPlaying = false;
|
|
|
|
|
2009-11-27 02:02:00 +00:00
|
|
|
memset(_gameFlags, 0, 1512);
|
|
|
|
|
2009-07-08 19:17:47 +00:00
|
|
|
return Common::kNoError;
|
2009-06-14 18:46:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Common::Error AsylumEngine::go() {
|
2009-06-12 12:40:18 +00:00
|
|
|
// TODO: save dialogue key codes into sntrm_k.txt (need to figure out why they use such thing)
|
|
|
|
// TODO: load startup configurations (address 0041A970)
|
|
|
|
// TODO: init unknown game stuffs (address 0040F430)
|
|
|
|
// TODO: if savegame exists on folder, than start NewGame()
|
|
|
|
|
2009-09-25 13:19:46 +00:00
|
|
|
// FIXME The scene shouldn't be created here, as we don't technically know
|
|
|
|
// how the scene is starting. This was put in for testing, but will eventually
|
|
|
|
// have to be removed once saveload is implemented
|
2009-09-19 14:25:43 +00:00
|
|
|
_scene = new Scene(5, this);
|
2009-08-01 17:51:26 +00:00
|
|
|
|
2009-09-25 13:19:46 +00:00
|
|
|
// FIXME This is just here for testing purposes. It is also defined
|
2009-08-09 13:24:36 +00:00
|
|
|
// in the processActionList() method when the necessary action is fired.
|
|
|
|
// Once the blowup puzzle testing is removed from checkForEvent(), this
|
|
|
|
// can be removed as well.
|
2009-09-21 19:11:49 +00:00
|
|
|
_scene->setBlowUpPuzzle(new BlowUpPuzzleVCR(_scene));
|
2009-07-09 02:14:07 +00:00
|
|
|
|
2009-06-15 12:28:19 +00:00
|
|
|
// Set up main menu
|
2009-09-19 14:51:42 +00:00
|
|
|
_mainMenu = new MainMenu(this);
|
2009-06-15 12:28:19 +00:00
|
|
|
|
2009-08-07 12:03:23 +00:00
|
|
|
// XXX Testing
|
|
|
|
_encounter = new Encounter(_scene);
|
|
|
|
|
2009-08-09 13:24:36 +00:00
|
|
|
// TODO you should be able to skip this if you want. The original
|
|
|
|
// allows this through the /SKIP command line argument.
|
|
|
|
// Also, this routine is used to set game flags 4 and 12, so if we're
|
|
|
|
// skipping the intro, but not loading a save file, those flags
|
|
|
|
// need to be set somewhere else.
|
2009-08-10 11:53:45 +00:00
|
|
|
//playIntro();
|
2009-08-09 13:24:36 +00:00
|
|
|
|
2009-06-15 12:28:19 +00:00
|
|
|
// Enter first scene
|
2009-09-19 14:25:43 +00:00
|
|
|
setGameFlag(4);
|
|
|
|
setGameFlag(12);
|
2009-08-10 11:53:45 +00:00
|
|
|
_scene->enterScene();
|
2009-06-12 12:40:18 +00:00
|
|
|
|
|
|
|
while (!shouldQuit()) {
|
2009-06-13 19:38:25 +00:00
|
|
|
checkForEvent(true);
|
2009-06-28 11:59:25 +00:00
|
|
|
waitForTimer(55);
|
2009-06-13 13:40:48 +00:00
|
|
|
}
|
|
|
|
|
2009-07-08 19:17:47 +00:00
|
|
|
return Common::kNoError;
|
2009-06-13 13:40:48 +00:00
|
|
|
}
|
2009-06-12 21:09:17 +00:00
|
|
|
|
2009-06-13 13:40:48 +00:00
|
|
|
void AsylumEngine::waitForTimer(int msec_delay) {
|
|
|
|
uint32 start_time = _system->getMillis();
|
|
|
|
|
|
|
|
while (_system->getMillis() < start_time + msec_delay) {
|
2009-06-13 19:38:25 +00:00
|
|
|
checkForEvent(false);
|
2009-07-09 11:23:42 +00:00
|
|
|
processDelayedEvents();
|
2009-06-13 13:40:48 +00:00
|
|
|
_system->updateScreen();
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
2009-06-13 13:40:48 +00:00
|
|
|
}
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2009-08-09 13:24:36 +00:00
|
|
|
void AsylumEngine::playIntro() {
|
|
|
|
_video->playVideo(1, kSubtitlesOn);
|
2009-09-20 21:10:43 +00:00
|
|
|
|
2009-09-19 12:24:53 +00:00
|
|
|
if (_scene->worldstats()->musicCurrentResId != 0xFFFFFD66)
|
2009-09-20 21:10:43 +00:00
|
|
|
_sound->playMusic(_scene->worldstats()->musicCurrentResId);
|
2009-08-09 13:24:36 +00:00
|
|
|
|
|
|
|
_screen->clearScreen();
|
|
|
|
|
2009-09-19 14:25:43 +00:00
|
|
|
setGameFlag(4);
|
|
|
|
setGameFlag(12);
|
2009-08-09 13:24:36 +00:00
|
|
|
|
2009-09-20 21:10:43 +00:00
|
|
|
// Play the intro sound sample (the screen is blacked out, you hear
|
|
|
|
// an alarm sounding and men talking about.
|
2009-09-29 23:33:48 +00:00
|
|
|
_sound->playSound(0x8012007, false, Config.sfxVolume, 0);
|
2009-08-09 13:24:36 +00:00
|
|
|
}
|
|
|
|
|
2009-08-18 21:07:40 +00:00
|
|
|
void AsylumEngine::checkForEvent(bool doUpdate) { // k_sub_40AE30 (0040AE30)
|
2009-08-09 22:56:13 +00:00
|
|
|
|
|
|
|
// NOTE
|
|
|
|
// In the original version of Sanitarium, the control loop for the sound
|
|
|
|
// effect that played after the intro video involved a while loop that
|
|
|
|
// executed until the sound handle was released.
|
|
|
|
// This caused the application to be locked until the while loop's execution
|
|
|
|
// completed successfully. Our implementation circumvents this issue
|
|
|
|
// by moving the logic to the event loop and checking whether a flag is
|
|
|
|
// set to determine if control should be returned to the engine.
|
|
|
|
if (_introPlaying) {
|
2009-09-20 21:10:43 +00:00
|
|
|
if (!_sound->isPlaying(0x8012007)) {
|
2009-08-09 22:56:13 +00:00
|
|
|
_introPlaying = false;
|
|
|
|
|
|
|
|
// TODO Since we've currently only got one sfx handle to play with in
|
|
|
|
// the sound class, entering the scene overwrites the "alarm" loop.
|
|
|
|
// This sound is technically supposed to play until the actor disables
|
|
|
|
// the alarm by flipping the switch. The sound class needs to be extended
|
|
|
|
// to be able to handle multiple handles.
|
|
|
|
// The currently active sound resources can probably also be buffered into
|
|
|
|
// the scene's soundResId[] array (seems that's the way the original worked,
|
|
|
|
// especially when you examine isSoundinList() or isSoundPlaying())
|
|
|
|
|
|
|
|
_scene->enterScene();
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-06-13 13:40:48 +00:00
|
|
|
Common::Event ev;
|
|
|
|
|
|
|
|
if (_system->getEventManager()->pollEvent(ev)) {
|
|
|
|
if (ev.type == Common::EVENT_KEYDOWN) {
|
|
|
|
if (ev.kbd.keycode == Common::KEYCODE_ESCAPE) {
|
2009-06-15 12:28:19 +00:00
|
|
|
// Toggle menu
|
|
|
|
if (_mainMenu->isActive()) {
|
|
|
|
_mainMenu->closeMenu();
|
2009-06-15 14:15:12 +00:00
|
|
|
_scene->enterScene();
|
2009-06-21 12:09:44 +00:00
|
|
|
} else if (_scene->isActive()) {
|
2009-06-15 12:28:19 +00:00
|
|
|
_mainMenu->openMenu();
|
2009-09-21 19:11:49 +00:00
|
|
|
} else if (_scene->getBlowUpPuzzle()->isActive()) {
|
|
|
|
_scene->getBlowUpPuzzle()->closeBlowUp();
|
|
|
|
_scene->enterScene();
|
2009-06-15 12:28:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2009-06-13 13:40:48 +00:00
|
|
|
}
|
2009-06-21 12:09:44 +00:00
|
|
|
|
2009-09-21 19:11:49 +00:00
|
|
|
// XXX: TEST ONLY
|
|
|
|
if (ev.kbd.keycode == Common::KEYCODE_b) {
|
|
|
|
//_mainMenu->closeMenu();
|
|
|
|
_scene->getBlowUpPuzzle()->openBlowUp();
|
|
|
|
}
|
2009-08-01 17:51:26 +00:00
|
|
|
|
2009-06-21 12:09:44 +00:00
|
|
|
if (ev.kbd.flags == Common::KBD_CTRL) {
|
|
|
|
if (ev.kbd.keycode == Common::KEYCODE_d)
|
|
|
|
_console->attach();
|
|
|
|
}
|
|
|
|
|
2009-06-13 13:29:56 +00:00
|
|
|
}
|
|
|
|
}
|
2009-06-13 19:38:25 +00:00
|
|
|
|
|
|
|
if (doUpdate) {
|
2009-08-09 13:28:49 +00:00
|
|
|
if (_mainMenu->isActive() || _scene->isActive() || _scene->getBlowUpPuzzle()->isActive())
|
2009-06-21 12:09:44 +00:00
|
|
|
// Copy background image
|
|
|
|
_screen->copyBackBufferToScreen();
|
|
|
|
|
|
|
|
if (_console->isAttached())
|
|
|
|
_console->onFrame();
|
2009-06-13 19:38:25 +00:00
|
|
|
}
|
2009-06-15 12:28:19 +00:00
|
|
|
|
2009-08-09 13:28:49 +00:00
|
|
|
if (_mainMenu->isActive())
|
2009-06-15 12:28:19 +00:00
|
|
|
// Main menu active, pass events to it
|
|
|
|
_mainMenu->handleEvent(&ev, doUpdate);
|
2009-08-09 13:28:49 +00:00
|
|
|
else if (_scene->isActive())
|
2009-06-15 12:28:19 +00:00
|
|
|
// Pass events to the game
|
2009-06-15 14:15:12 +00:00
|
|
|
_scene->handleEvent(&ev, doUpdate);
|
2009-09-21 19:11:49 +00:00
|
|
|
else if (_scene->getBlowUpPuzzle()->isActive())
|
2009-08-01 17:51:26 +00:00
|
|
|
// Pass events to BlowUp Puzzles
|
2009-08-06 00:04:09 +00:00
|
|
|
_scene->getBlowUpPuzzle()->handleEvent(&ev, doUpdate);
|
2009-08-09 22:56:13 +00:00
|
|
|
|
|
|
|
if (_introPlaying) {
|
|
|
|
|
|
|
|
}
|
2009-06-13 13:29:56 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 11:23:42 +00:00
|
|
|
void AsylumEngine::processDelayedEvents() {
|
|
|
|
// check for a delayed video
|
2009-09-19 13:31:00 +00:00
|
|
|
int videoIdx = _scene->actions()->delayedVideoIndex;
|
2009-07-09 02:14:07 +00:00
|
|
|
if (videoIdx >= 0) {
|
2009-06-21 12:09:44 +00:00
|
|
|
_sound->stopMusic();
|
2009-09-20 21:10:43 +00:00
|
|
|
_sound->stopAllSounds();
|
2009-07-09 02:14:07 +00:00
|
|
|
_video->playVideo(videoIdx, kSubtitlesOn);
|
2009-09-19 13:31:00 +00:00
|
|
|
_scene->actions()->delayedVideoIndex = -1;
|
2009-06-21 12:09:44 +00:00
|
|
|
|
2009-08-09 13:28:49 +00:00
|
|
|
if (_mainMenu->isActive())
|
2009-06-21 12:09:44 +00:00
|
|
|
_mainMenu->openMenu();
|
2009-08-09 13:28:49 +00:00
|
|
|
else if (_scene->isActive())
|
2009-06-21 12:09:44 +00:00
|
|
|
_scene->enterScene();
|
|
|
|
}
|
2009-07-07 13:59:11 +00:00
|
|
|
|
2009-07-09 11:23:42 +00:00
|
|
|
// check for a delayed scene change
|
2009-09-19 13:31:00 +00:00
|
|
|
int sceneIdx = _scene->actions()->delayedSceneIndex;
|
2009-11-28 12:30:02 +00:00
|
|
|
// XXX Flag 183 indicates whether the actionlist is currently
|
|
|
|
// processing
|
|
|
|
if (sceneIdx >= 0 && isGameFlagNotSet(183)) {
|
2009-07-07 13:59:11 +00:00
|
|
|
_sound->stopMusic();
|
2009-09-20 21:10:43 +00:00
|
|
|
_sound->stopAllSounds();
|
2009-09-21 19:11:49 +00:00
|
|
|
|
2009-07-08 19:17:47 +00:00
|
|
|
if (_scene)
|
|
|
|
delete _scene;
|
2009-07-07 13:59:11 +00:00
|
|
|
|
2009-09-19 14:25:43 +00:00
|
|
|
_scene = new Scene(sceneIdx, this);
|
2009-07-08 19:17:47 +00:00
|
|
|
_scene->enterScene();
|
2009-08-08 12:38:17 +00:00
|
|
|
|
2009-09-19 13:31:00 +00:00
|
|
|
_scene->actions()->delayedSceneIndex = -1;
|
2009-07-07 13:59:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-19 14:25:43 +00:00
|
|
|
void AsylumEngine::setGameFlag(int flag) {
|
|
|
|
_gameFlags[flag / 32] |= 1 << flag % -32;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsylumEngine::clearGameFlag(int flag) {
|
|
|
|
_gameFlags[flag / 32] &= ~(1 << flag % -32);
|
|
|
|
}
|
|
|
|
|
|
|
|
void AsylumEngine::toggleGameFlag(int flag) {
|
|
|
|
_gameFlags[flag / 32] ^= 1 << flag % -32;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsylumEngine::isGameFlagSet(int flag) {
|
|
|
|
return ((1 << flag % -32) & (unsigned int)_gameFlags[flag / 32]) >> flag % -32 != 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool AsylumEngine::isGameFlagNotSet(int flag) {
|
|
|
|
return ((1 << flag % -32) & (unsigned int)_gameFlags[flag / 32]) >> flag % -32 == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-06-12 12:40:18 +00:00
|
|
|
} // namespace Asylum
|