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
|
|
|
*
|
2009-06-12 12:40:18 +00:00
|
|
|
*/
|
|
|
|
|
2010-11-03 04:27:47 +00:00
|
|
|
#include "asylum/asylum.h"
|
|
|
|
|
2010-12-03 00:08:51 +00:00
|
|
|
#include "asylum/resources/actor.h"
|
|
|
|
#include "asylum/resources/encounters.h"
|
2011-07-13 20:21:51 -04:00
|
|
|
#include "asylum/resources/reaction.h"
|
2010-12-02 09:29:26 +00:00
|
|
|
#include "asylum/resources/script.h"
|
2010-12-02 09:29:36 +00:00
|
|
|
#include "asylum/resources/special.h"
|
2010-12-01 19:22:09 +00:00
|
|
|
#include "asylum/resources/worldstats.h"
|
2010-11-03 04:29:08 +00:00
|
|
|
|
2010-12-07 17:06:59 +00:00
|
|
|
#include "asylum/puzzles/boardkeyhidesto.h"
|
|
|
|
#include "asylum/puzzles/boardsalvation.h"
|
|
|
|
#include "asylum/puzzles/boardyouth.h"
|
|
|
|
#include "asylum/puzzles/clock.h"
|
|
|
|
#include "asylum/puzzles/fisherman.h"
|
|
|
|
#include "asylum/puzzles/hivecontrol.h"
|
|
|
|
#include "asylum/puzzles/hivemachine.h"
|
|
|
|
#include "asylum/puzzles/lock.h"
|
|
|
|
#include "asylum/puzzles/morguedoor.h"
|
|
|
|
#include "asylum/puzzles/pipes.h"
|
2010-12-16 01:50:53 +00:00
|
|
|
#include "asylum/puzzles/puzzle11.h"
|
2010-12-07 17:06:59 +00:00
|
|
|
#include "asylum/puzzles/tictactoe.h"
|
|
|
|
#include "asylum/puzzles/timemachine.h"
|
2010-11-27 00:04:43 +00:00
|
|
|
#include "asylum/puzzles/vcr.h"
|
2010-12-07 17:06:59 +00:00
|
|
|
#include "asylum/puzzles/wheel.h"
|
|
|
|
#include "asylum/puzzles/writings.h"
|
2010-11-27 00:04:43 +00:00
|
|
|
|
2010-11-08 21:09:13 +00:00
|
|
|
#include "asylum/system/cursor.h"
|
2010-12-01 19:21:10 +00:00
|
|
|
#include "asylum/system/savegame.h"
|
2010-11-03 04:27:47 +00:00
|
|
|
#include "asylum/system/screen.h"
|
2010-12-02 09:29:36 +00:00
|
|
|
#include "asylum/system/speech.h"
|
2010-11-03 04:27:47 +00:00
|
|
|
#include "asylum/system/text.h"
|
|
|
|
|
|
|
|
#include "asylum/views/scene.h"
|
|
|
|
#include "asylum/views/menu.h"
|
2010-12-08 06:51:10 +00:00
|
|
|
#include "asylum/views/video.h"
|
2010-11-03 04:27:47 +00:00
|
|
|
|
|
|
|
#include "asylum/respack.h"
|
|
|
|
|
2010-05-12 10:24:37 +00:00
|
|
|
#include "common/debug-channels.h"
|
2009-08-05 05:41:32 +00:00
|
|
|
#include "common/EventRecorder.h"
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2010-05-12 10:24:37 +00:00
|
|
|
#include "engines/util.h"
|
|
|
|
|
2009-06-12 12:40:18 +00:00
|
|
|
namespace Asylum {
|
|
|
|
|
2010-11-08 21:09:02 +00:00
|
|
|
AsylumEngine::AsylumEngine(OSystem *system, const ADGameDescription *gd) : Engine(system), _gameDescription(gd),
|
2011-07-13 20:21:51 -04:00
|
|
|
_console(NULL), _cursor(NULL), _encounter(NULL), _menu(NULL), _reaction(NULL), _resource(NULL), _savegame(NULL),
|
2011-08-03 18:24:50 -04:00
|
|
|
_scene(NULL), _screen(NULL), _script(NULL), _special(NULL), _speech(NULL), _sound(NULL), _text(NULL),
|
|
|
|
_video(NULL), _handler(NULL) {
|
2010-11-03 04:27:47 +00:00
|
|
|
|
2010-11-09 00:58:34 +00:00
|
|
|
// Init data
|
2010-11-16 14:24:17 +00:00
|
|
|
memset(&_gameFlags, 0, sizeof(_gameFlags));
|
2010-11-27 00:04:43 +00:00
|
|
|
memset(&_puzzles, 0, sizeof(_puzzles));
|
2010-12-03 00:08:47 +00:00
|
|
|
memset(&_sinCosTables, 0, sizeof(_sinCosTables));
|
2010-12-01 19:22:30 +00:00
|
|
|
_introPlayed = false;
|
2010-12-08 02:31:55 +00:00
|
|
|
_tickOffset = 0;
|
2010-11-08 21:09:13 +00:00
|
|
|
|
2011-07-20 12:33:34 -04:00
|
|
|
screenUpdateCount = 0;
|
|
|
|
lastScreenUpdate = 0;
|
|
|
|
|
2010-12-08 06:51:15 +00:00
|
|
|
// Debug
|
|
|
|
_delayedSceneIndex = kResourcePackInvalid;
|
|
|
|
_delayedVideoIndex = -1;
|
2010-12-10 14:27:21 +00:00
|
|
|
_previousScene = NULL;
|
2010-12-08 06:51:15 +00:00
|
|
|
|
2010-11-03 04:27:47 +00:00
|
|
|
// Add default search directories
|
|
|
|
const Common::FSNode gameDataDir(ConfMan.get("path"));
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "data");
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "vids");
|
|
|
|
SearchMan.addSubDirectoryMatching(gameDataDir, "music");
|
2009-09-21 19:11:49 +00:00
|
|
|
|
2010-11-03 04:27:47 +00:00
|
|
|
// Initialize custom debug levels
|
2010-11-08 21:09:02 +00:00
|
|
|
DebugMan.addDebugChannel(kDebugLevelMain, "Main", "Generic debug level");
|
2010-04-28 03:42:53 +00:00
|
|
|
DebugMan.addDebugChannel(kDebugLevelResources, "Resources", "Resources debugging");
|
2010-11-08 21:09:02 +00:00
|
|
|
DebugMan.addDebugChannel(kDebugLevelSprites, "Sprites", "Sprites debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelInput, "Input", "Input events debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelMenu, "Menu", "Menu debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelScripts, "Scripts", "Scripts debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelSound, "Sound", "Sound debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelSavegame, "Savegame", "Saving & restoring game debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelScene, "Scene", "Scene process and draw debugging");
|
|
|
|
DebugMan.addDebugChannel(kDebugLevelObjects, "Objects", "Debug Object Objects");
|
2009-09-21 19:11:49 +00:00
|
|
|
|
2010-11-03 04:27:47 +00:00
|
|
|
// Initialize random number source
|
2011-05-18 14:04:11 -04:00
|
|
|
_rnd = new Common::RandomSource("asylum");
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
AsylumEngine::~AsylumEngine() {
|
2011-08-03 18:24:50 -04:00
|
|
|
_handler = NULL;
|
|
|
|
|
2010-11-16 14:24:17 +00:00
|
|
|
delete _cursor;
|
2010-11-03 04:27:47 +00:00
|
|
|
delete _scene;
|
2010-11-09 03:10:09 +00:00
|
|
|
delete _encounter;
|
2011-07-13 20:21:51 -04:00
|
|
|
delete _reaction;
|
2010-12-01 19:21:10 +00:00
|
|
|
delete _savegame;
|
2009-06-13 23:03:37 +00:00
|
|
|
delete _screen;
|
2010-12-02 09:29:26 +00:00
|
|
|
delete _script;
|
2011-08-03 18:24:50 -04:00
|
|
|
delete _special;
|
|
|
|
delete _speech;
|
2010-11-03 04:27:47 +00:00
|
|
|
delete _sound;
|
2009-09-25 01:05:23 +00:00
|
|
|
delete _text;
|
2010-11-03 04:27:47 +00:00
|
|
|
delete _video;
|
2010-12-10 14:14:45 +00:00
|
|
|
delete _menu;
|
2010-11-09 03:10:09 +00:00
|
|
|
delete _resource;
|
|
|
|
delete _console;
|
2009-09-25 13:19:46 +00:00
|
|
|
|
2011-08-03 18:24:50 -04:00
|
|
|
_previousScene = NULL;
|
|
|
|
|
2010-11-27 00:04:43 +00:00
|
|
|
// Cleanup puzzles
|
|
|
|
for (uint i = 0; i < ARRAYSIZE(_puzzles); i++)
|
|
|
|
delete _puzzles[i];
|
|
|
|
|
2011-08-03 18:24:50 -04:00
|
|
|
delete _rnd;
|
|
|
|
|
2010-11-03 04:27:47 +00:00
|
|
|
// Zero passed pointers
|
|
|
|
_gameDescription = NULL;
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 04:27:47 +00:00
|
|
|
Common::Error AsylumEngine::run() {
|
|
|
|
// Initialize the graphics
|
2009-06-12 20:07:11 +00:00
|
|
|
initGraphics(640, 480, true);
|
2009-06-12 20:38:38 +00:00
|
|
|
|
2010-11-03 04:27:47 +00:00
|
|
|
// Create debugger. It requires GFX to be initialized
|
|
|
|
_console = new Console(this);
|
|
|
|
|
2010-11-08 21:09:13 +00:00
|
|
|
// Create resource manager
|
2010-11-08 21:09:02 +00:00
|
|
|
_resource = new ResourceManager();
|
2010-11-10 12:08:43 +00:00
|
|
|
_resource->setCdNumber(1);
|
2010-11-08 21:09:13 +00:00
|
|
|
|
|
|
|
// Create all game classes
|
|
|
|
_encounter = new Encounter(this);
|
|
|
|
_cursor = new Cursor(this);
|
2011-07-13 20:21:51 -04:00
|
|
|
_reaction = new Reaction(this);
|
2010-12-01 19:21:10 +00:00
|
|
|
_savegame = new Savegame(this);
|
2009-12-03 21:05:50 +00:00
|
|
|
_screen = new Screen(this);
|
2010-12-02 09:29:26 +00:00
|
|
|
_script = new ScriptManager(this);
|
2010-11-08 21:09:02 +00:00
|
|
|
_sound = new Sound(this, _mixer);
|
2010-12-02 09:29:36 +00:00
|
|
|
_special = new Special(this);
|
|
|
|
_speech = new Speech(this);
|
2010-11-08 21:09:02 +00:00
|
|
|
_text = new Text(this);
|
2011-01-23 19:25:36 +00:00
|
|
|
_video = new VideoPlayer(this, _mixer);
|
2010-11-27 00:04:43 +00:00
|
|
|
initPuzzles();
|
2009-08-09 22:56:13 +00:00
|
|
|
|
2010-12-01 19:22:30 +00:00
|
|
|
// Init tables
|
2010-12-03 00:08:47 +00:00
|
|
|
initSinCosTables(80.0, 40, 40);
|
2010-12-01 19:22:30 +00:00
|
|
|
|
2010-11-08 21:09:13 +00:00
|
|
|
// Create main menu
|
2010-12-10 14:14:45 +00:00
|
|
|
_menu = new Menu(this);
|
|
|
|
_handler = _menu;
|
2009-11-27 02:02:00 +00:00
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
// Load config
|
2009-12-01 22:42:11 +00:00
|
|
|
Config.read();
|
2009-08-01 17:51:26 +00:00
|
|
|
|
2010-12-01 19:22:09 +00:00
|
|
|
// Setup mixer
|
|
|
|
syncSoundSettings();
|
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
// Send init event to our default event handler
|
|
|
|
AsylumEvent initEvt(EVENT_ASYLUM_INIT);
|
2010-12-07 06:38:43 +00:00
|
|
|
if (_handler)
|
|
|
|
_handler->handleEvent(initEvt);
|
2009-06-12 12:40:18 +00:00
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
// Start running event loop
|
2009-06-12 12:40:18 +00:00
|
|
|
while (!shouldQuit()) {
|
2010-12-01 19:21:21 +00:00
|
|
|
handleEvents();
|
2009-06-13 13:40:48 +00:00
|
|
|
|
2010-12-02 02:34:05 +00:00
|
|
|
_system->delayMillis(10);
|
|
|
|
|
2009-06-13 13:40:48 +00:00
|
|
|
_system->updateScreen();
|
2009-06-12 12:40:18 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
return Common::kNoError;
|
2010-12-01 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2010-11-08 21:09:13 +00:00
|
|
|
void AsylumEngine::startGame(ResourcePackId sceneId, StartGameType type) {
|
2011-08-03 18:24:50 -04:00
|
|
|
if (!_cursor || !_screen || !_savegame)
|
2010-11-16 14:24:17 +00:00
|
|
|
error("[AsylumEngine::startGame] Subsystems not initialized properly!");
|
|
|
|
|
2010-11-08 21:09:13 +00:00
|
|
|
// Load the default mouse cursor
|
2010-12-02 15:18:56 +00:00
|
|
|
_cursor->set(MAKE_RESOURCE(kResourcePackSound, 14), 0, kCursorAnimationNone);
|
2010-11-08 21:09:13 +00:00
|
|
|
_cursor->hide();
|
2010-10-05 19:50:24 +00:00
|
|
|
|
2010-11-08 21:09:13 +00:00
|
|
|
// Clear the graphic list
|
|
|
|
_screen->clearGraphicsInQueue();
|
|
|
|
|
2010-12-01 19:22:30 +00:00
|
|
|
// Reset scene (this ensures the current resource pack is closed as in the original)
|
2010-11-08 21:09:13 +00:00
|
|
|
delete _scene;
|
|
|
|
_scene = new Scene(this);
|
2010-12-10 18:19:47 +00:00
|
|
|
_handler = _scene;
|
2010-11-08 21:09:13 +00:00
|
|
|
|
2010-12-01 19:22:30 +00:00
|
|
|
// Original checks for the current cd (we have all data files on disc, so this is not needed)
|
2010-11-08 21:09:13 +00:00
|
|
|
switch (type) {
|
|
|
|
default:
|
|
|
|
error("[AsylumEngine::startGame] Invalid start game type!");
|
|
|
|
|
|
|
|
case kStartGamePlayIntro:
|
2010-11-10 20:45:19 +00:00
|
|
|
_scene->enter(sceneId);
|
2010-12-01 19:22:42 +00:00
|
|
|
playIntro();
|
2010-11-08 21:09:13 +00:00
|
|
|
break;
|
2009-12-01 22:42:11 +00:00
|
|
|
|
2010-11-08 21:09:13 +00:00
|
|
|
case kStartGameLoad:
|
2010-12-01 19:22:30 +00:00
|
|
|
if (_savegame->load()) {
|
2010-12-03 00:08:51 +00:00
|
|
|
_scene->enterLoad();
|
2010-12-01 19:22:30 +00:00
|
|
|
updateReverseStereo();
|
|
|
|
switchEventHandler(_scene);
|
|
|
|
}
|
2010-11-08 21:09:13 +00:00
|
|
|
break;
|
2009-12-01 22:42:11 +00:00
|
|
|
|
2010-11-08 21:09:13 +00:00
|
|
|
case kStartGameScene:
|
|
|
|
_scene->enter(sceneId);
|
|
|
|
break;
|
2010-10-05 19:50:24 +00:00
|
|
|
}
|
2010-12-01 19:22:30 +00:00
|
|
|
|
|
|
|
_cursor->show();
|
2009-12-01 22:42:11 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:20:53 +00:00
|
|
|
void AsylumEngine::restart() {
|
2011-08-03 18:24:50 -04:00
|
|
|
if (!_cursor || !_script)
|
|
|
|
error("[AsylumEngine::restart] Subsystems not initialized properly!");
|
|
|
|
|
2010-12-01 19:22:30 +00:00
|
|
|
_cursor->hide();
|
|
|
|
|
|
|
|
// Cleanup
|
|
|
|
memset(&_gameFlags, 0, sizeof(_gameFlags));
|
|
|
|
delete _scene;
|
|
|
|
_scene = NULL;
|
2011-07-25 06:07:49 -04:00
|
|
|
delete _encounter;
|
|
|
|
_encounter = new Encounter(this);
|
2010-12-10 18:19:47 +00:00
|
|
|
_script->resetQueue();
|
2010-12-01 19:22:30 +00:00
|
|
|
|
2011-07-29 10:56:28 -04:00
|
|
|
_data.setGlobalPoint(Common::Point(-1, -1));
|
2010-12-01 19:22:30 +00:00
|
|
|
|
2010-12-03 23:18:36 +00:00
|
|
|
reset();
|
2010-12-01 19:22:30 +00:00
|
|
|
|
|
|
|
_introPlayed = false;
|
|
|
|
|
|
|
|
_screen->clear();
|
|
|
|
_sound->playMusic(kResourceNone, 0);
|
|
|
|
|
|
|
|
startGame(kResourcePackTowerCells, kStartGamePlayIntro);
|
2010-12-01 19:20:53 +00:00
|
|
|
}
|
|
|
|
|
2010-12-03 23:18:36 +00:00
|
|
|
void AsylumEngine::reset() {
|
2011-08-03 18:24:50 -04:00
|
|
|
if (!_menu)
|
|
|
|
error("[AsylumEngine::reset] Subsystems not initialized properly!");
|
|
|
|
|
2010-12-03 23:18:36 +00:00
|
|
|
// Set game as started
|
2010-12-10 14:14:45 +00:00
|
|
|
_menu->setGameStarted();
|
2010-12-03 23:18:36 +00:00
|
|
|
|
|
|
|
// Reset puzzles
|
2011-07-25 06:05:35 -04:00
|
|
|
for (uint i = 0; i < ARRAYSIZE(_puzzles); i++)
|
|
|
|
delete _puzzles[i];
|
|
|
|
|
|
|
|
initPuzzles();
|
|
|
|
|
|
|
|
// Reset shared data
|
2011-07-29 10:56:28 -04:00
|
|
|
_data.reset();
|
2010-12-03 23:18:36 +00:00
|
|
|
|
2011-07-25 06:05:35 -04:00
|
|
|
// Reset special palette info
|
|
|
|
_special->reset(true);
|
2010-12-03 23:18:36 +00:00
|
|
|
}
|
|
|
|
|
2009-08-09 13:24:36 +00:00
|
|
|
void AsylumEngine::playIntro() {
|
2010-11-16 14:24:17 +00:00
|
|
|
if (!_video || !_screen)
|
|
|
|
error("[AsylumEngine::playIntro] Subsystems not initialized properly!");
|
|
|
|
|
2010-12-01 19:22:30 +00:00
|
|
|
updateReverseStereo();
|
2009-12-01 00:37:12 +00:00
|
|
|
|
2010-12-01 19:22:30 +00:00
|
|
|
if (!_introPlayed) {
|
|
|
|
_cursor->hide();
|
2011-08-03 15:37:43 -04:00
|
|
|
_cursor->setForceHide(true);
|
2010-12-01 19:22:42 +00:00
|
|
|
if (!Config.showIntro) {
|
|
|
|
if (_scene->worldstats()->chapter == kChapter1)
|
|
|
|
_sound->playMusic(MAKE_RESOURCE(kResourcePackMusic, _scene->worldstats()->musicCurrentResourceIndex));
|
|
|
|
} else {
|
2010-12-01 19:22:30 +00:00
|
|
|
_sound->playMusic(kResourceNone, 0);
|
|
|
|
|
2010-12-10 14:14:45 +00:00
|
|
|
_video->play(1, _menu);
|
2010-12-01 19:22:30 +00:00
|
|
|
|
2010-12-01 19:22:42 +00:00
|
|
|
if (_scene->worldstats()->musicCurrentResourceIndex != kMusicStopped)
|
2010-12-01 19:22:30 +00:00
|
|
|
_sound->playMusic(MAKE_RESOURCE(kResourcePackMusic, _scene->worldstats()->musicCurrentResourceIndex));
|
|
|
|
|
|
|
|
_screen->clear();
|
|
|
|
|
|
|
|
setGameFlag(kGameFlag4);
|
|
|
|
setGameFlag(kGameFlag12);
|
|
|
|
|
2011-07-20 02:41:34 -04:00
|
|
|
// Play the intro speech: it is played after the intro video over a black background,
|
|
|
|
// and the game is "locked" until the speech is completed.
|
2011-07-20 10:41:04 +08:00
|
|
|
ResourceId introSpeech = MAKE_RESOURCE(kResourcePackSound, 7);
|
|
|
|
_sound->playSound(introSpeech);
|
|
|
|
|
2011-07-20 02:41:34 -04:00
|
|
|
do {
|
2011-07-29 20:57:59 -04:00
|
|
|
// Poll events (this ensures we don't freeze the screen)
|
2011-07-20 02:41:34 -04:00
|
|
|
Common::Event ev;
|
|
|
|
_eventMan->pollEvent(ev);
|
|
|
|
|
2011-07-28 15:19:11 -04:00
|
|
|
_system->delayMillis(100);
|
|
|
|
|
2011-07-20 02:41:34 -04:00
|
|
|
} while (_sound->isPlaying(introSpeech));
|
|
|
|
|
2010-12-01 19:22:30 +00:00
|
|
|
}
|
2011-08-03 15:37:43 -04:00
|
|
|
_cursor->setForceHide(false);
|
2010-12-01 19:22:30 +00:00
|
|
|
_introPlayed = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_cursor->show();
|
2009-08-09 13:24:36 +00:00
|
|
|
|
2010-12-08 02:31:43 +00:00
|
|
|
_savegame->loadMoviesViewed();
|
2009-08-09 13:24:36 +00:00
|
|
|
|
2010-12-01 19:22:30 +00:00
|
|
|
// Switch to scene event handling
|
|
|
|
switchEventHandler(_scene);
|
2009-08-09 13:24:36 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
void AsylumEngine::handleEvents() {
|
2011-08-03 18:24:50 -04:00
|
|
|
if (!_console || !_video || !_screen || !_sound || !_menu || !_cursor)
|
2010-11-16 14:24:17 +00:00
|
|
|
error("[AsylumEngine::handleEvents] Subsystems not initialized properly!");
|
2010-11-03 04:27:47 +00:00
|
|
|
|
|
|
|
// Show the debugger if required
|
|
|
|
_console->onFrame();
|
2009-08-09 22:56:13 +00:00
|
|
|
|
2010-12-01 19:20:53 +00:00
|
|
|
AsylumEvent ev;
|
2011-07-06 17:02:53 -04:00
|
|
|
while (_eventMan->pollEvent(ev)) {
|
2010-11-03 04:27:47 +00:00
|
|
|
switch (ev.type) {
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_KEYDOWN:
|
2010-12-01 19:21:21 +00:00
|
|
|
if ((ev.kbd.flags & Common::KBD_CTRL) && ev.kbd.keycode == Common::KEYCODE_d) {
|
2010-11-03 04:27:47 +00:00
|
|
|
_console->attach();
|
2010-12-01 19:21:21 +00:00
|
|
|
break;
|
2009-06-13 13:40:48 +00:00
|
|
|
}
|
2009-06-21 12:09:44 +00:00
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
// Handle key events
|
2010-12-07 06:38:43 +00:00
|
|
|
if (_handler)
|
|
|
|
_handler->handleEvent(ev);
|
2010-11-03 04:27:47 +00:00
|
|
|
break;
|
2009-06-13 19:38:25 +00:00
|
|
|
|
2010-12-02 09:29:42 +00:00
|
|
|
case Common::EVENT_KEYUP:
|
|
|
|
// Handle key events
|
2010-12-07 06:38:43 +00:00
|
|
|
if (_handler)
|
|
|
|
_handler->handleEvent(ev);
|
2010-12-02 09:29:42 +00:00
|
|
|
break;
|
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
2010-12-02 04:34:43 +00:00
|
|
|
case Common::EVENT_MBUTTONUP:
|
|
|
|
case Common::EVENT_MBUTTONDOWN:
|
2010-12-01 19:21:21 +00:00
|
|
|
// Handle mouse events
|
2010-12-02 04:34:43 +00:00
|
|
|
_cursor->setState(ev);
|
2010-12-07 06:38:43 +00:00
|
|
|
|
|
|
|
if (_handler)
|
|
|
|
_handler->handleEvent(ev);
|
2010-12-01 19:21:21 +00:00
|
|
|
break;
|
2010-12-01 19:20:53 +00:00
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
case Common::EVENT_QUIT:
|
|
|
|
quitGame();
|
|
|
|
break;
|
2009-06-15 12:28:19 +00:00
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
// TODO handle cases where we receive a midi or music event
|
|
|
|
}
|
|
|
|
}
|
2010-10-05 19:50:24 +00:00
|
|
|
|
2010-12-02 15:18:56 +00:00
|
|
|
// Animate cursor
|
|
|
|
_cursor->animate();
|
|
|
|
|
2010-12-01 19:21:21 +00:00
|
|
|
// Send update event to our event handler
|
|
|
|
AsylumEvent updateEvt = AsylumEvent(EVENT_ASYLUM_UPDATE);
|
2010-12-07 06:38:43 +00:00
|
|
|
if (_handler)
|
|
|
|
_handler->handleEvent(updateEvt);
|
2010-12-07 02:52:35 +00:00
|
|
|
|
2010-12-08 06:51:15 +00:00
|
|
|
// Handle debug events
|
2010-12-07 02:52:35 +00:00
|
|
|
processDelayedEvents();
|
2009-06-13 13:29:56 +00:00
|
|
|
}
|
|
|
|
|
2009-07-09 11:23:42 +00:00
|
|
|
void AsylumEngine::processDelayedEvents() {
|
2011-08-03 18:24:50 -04:00
|
|
|
if (!_video || !_sound || !_menu || !_script)
|
2010-11-16 14:24:17 +00:00
|
|
|
error("[AsylumEngine::processDelayedEvents] Subsystems not initialized properly!");
|
|
|
|
|
2010-12-10 14:26:31 +00:00
|
|
|
// check for a delayed scene change
|
2010-12-08 06:51:15 +00:00
|
|
|
if (_delayedSceneIndex != kResourcePackInvalid && isGameFlagNotSet(kGameFlagScriptProcessing)) {
|
2011-08-03 18:24:50 -04:00
|
|
|
if (!_scene)
|
|
|
|
error("[AsylumEngine::processDelayedEvents] Subsystems not initialized properly!");
|
|
|
|
|
2010-12-08 06:51:15 +00:00
|
|
|
ResourcePackId sceneIndex = _delayedSceneIndex;
|
2009-07-07 13:59:11 +00:00
|
|
|
|
2010-11-05 00:35:45 +00:00
|
|
|
// Reset delayed scene
|
2010-12-08 06:51:15 +00:00
|
|
|
_delayedSceneIndex = kResourcePackInvalid;
|
2010-11-05 00:35:45 +00:00
|
|
|
|
2010-12-10 18:19:47 +00:00
|
|
|
_scene->getActor(0)->updateStatus(kActorStatusDisabled);
|
|
|
|
_script->reset();
|
|
|
|
|
2009-07-07 13:59:11 +00:00
|
|
|
_sound->stopMusic();
|
2010-11-10 12:08:50 +00:00
|
|
|
_sound->stopAll();
|
2009-09-21 19:11:49 +00:00
|
|
|
|
2010-12-10 18:19:47 +00:00
|
|
|
switchScene(sceneIndex);
|
2009-07-07 13:59:11 +00:00
|
|
|
}
|
2010-12-08 06:51:15 +00:00
|
|
|
|
|
|
|
// Check for delayed video
|
|
|
|
if (_delayedVideoIndex != -1 && isGameFlagNotSet(kGameFlagScriptProcessing)) {
|
2011-08-03 18:24:50 -04:00
|
|
|
uint32 index = (uint32)_delayedVideoIndex;
|
2010-12-08 06:51:15 +00:00
|
|
|
_delayedVideoIndex = -1;
|
|
|
|
|
|
|
|
_video->play(index, _handler);
|
|
|
|
}
|
2009-07-07 13:59:11 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 04:29:08 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Message handlers
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-11-27 00:04:43 +00:00
|
|
|
void AsylumEngine::switchEventHandler(EventHandler *handler) {
|
2010-11-27 00:03:41 +00:00
|
|
|
if (handler == NULL)
|
2010-12-07 06:38:43 +00:00
|
|
|
warning("[AsylumEngine::switchMessageHandler] NULL handler parameter (shouldn't happen outside of debug commands)!");
|
2010-11-27 00:03:41 +00:00
|
|
|
|
|
|
|
// De-init previous handler
|
|
|
|
if (_handler != NULL) {
|
2010-11-27 00:03:53 +00:00
|
|
|
AsylumEvent deinit(EVENT_ASYLUM_DEINIT);
|
2010-11-27 00:04:43 +00:00
|
|
|
_handler->handleEvent(deinit);
|
2010-11-27 00:03:41 +00:00
|
|
|
}
|
|
|
|
|
2010-12-10 14:27:21 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// DEBUG - If a previous scene is found, replace the current scene by this one
|
|
|
|
if (handler == _scene) {
|
|
|
|
if (_previousScene) {
|
|
|
|
delete _scene;
|
|
|
|
_scene = _previousScene;
|
|
|
|
handler = _scene;
|
|
|
|
_previousScene = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-11-27 00:03:41 +00:00
|
|
|
// replace message handler
|
|
|
|
_handler = handler;
|
|
|
|
|
|
|
|
// Init new handler
|
2010-11-27 00:03:53 +00:00
|
|
|
AsylumEvent init(EVENT_ASYLUM_INIT);
|
2010-12-07 06:38:43 +00:00
|
|
|
if (_handler)
|
|
|
|
_handler->handleEvent(init);
|
2010-11-27 00:04:43 +00:00
|
|
|
}
|
|
|
|
|
2010-12-08 06:51:15 +00:00
|
|
|
void AsylumEngine::notify(AsylumEventType type, int32 param1, int32 param2) {
|
2010-12-02 15:18:56 +00:00
|
|
|
if (_handler == NULL)
|
|
|
|
error("[AsylumEngine::notify] Invalid handler parameter (cannot be NULL)!");
|
|
|
|
|
2010-12-08 06:51:15 +00:00
|
|
|
AsylumEvent evt(type, param1, param2);
|
2010-12-02 15:18:56 +00:00
|
|
|
_handler->handleEvent(evt);
|
|
|
|
}
|
|
|
|
|
2011-08-03 18:24:50 -04:00
|
|
|
EventHandler *AsylumEngine::getPuzzle(uint32 index) const {
|
|
|
|
if (index >= ARRAYSIZE(_puzzles))
|
2010-11-27 00:04:43 +00:00
|
|
|
error("[AsylumEngine::getPuzzleEventHandler] Invalid index (was: %d - max: %d)", index, ARRAYSIZE(_puzzles));
|
|
|
|
|
|
|
|
if (_puzzles[index] == NULL)
|
|
|
|
error("[AsylumEngine::getPuzzleEventHandler] This puzzle doesn't have an event handler! (index: %d)", index);
|
|
|
|
|
2010-11-27 00:04:47 +00:00
|
|
|
return (EventHandler *)_puzzles[index];
|
2010-11-03 04:29:08 +00:00
|
|
|
}
|
|
|
|
|
2010-11-27 00:04:43 +00:00
|
|
|
void AsylumEngine::initPuzzles() {
|
2010-12-07 02:52:44 +00:00
|
|
|
_puzzles[0] = new PuzzleVCR(this);
|
2010-12-07 17:06:59 +00:00
|
|
|
_puzzles[1] = new PuzzlePipes(this);
|
|
|
|
_puzzles[2] = new PuzzleTicTacToe(this);
|
|
|
|
_puzzles[3] = new PuzzleLock(this);
|
|
|
|
_puzzles[4] = NULL;// No event handler for Puzzle 5
|
|
|
|
_puzzles[5] = new PuzzleWheel(this);
|
|
|
|
_puzzles[6] = new PuzzleBoardSalvation(this);
|
|
|
|
_puzzles[7] = new PuzzleBoardYouth(this);
|
|
|
|
_puzzles[8] = new PuzzleBoardKeyHidesTo(this);
|
|
|
|
_puzzles[9] = new PuzzleWritings(this);
|
2010-12-16 01:50:53 +00:00
|
|
|
_puzzles[10] = new Puzzle11(this);
|
2010-12-07 17:06:59 +00:00
|
|
|
_puzzles[11] = new PuzzleMorgueDoor(this);
|
2010-12-16 01:50:53 +00:00
|
|
|
_puzzles[12] = new PuzzleClock(this);
|
2010-12-07 17:06:59 +00:00
|
|
|
_puzzles[13] = new PuzzleTimeMachine(this);
|
|
|
|
_puzzles[14] = new PuzzleFisherman(this);
|
|
|
|
_puzzles[15] = new PuzzleHiveMachine(this);
|
|
|
|
_puzzles[16] = new PuzzleHiveControl(this);
|
2010-12-01 19:22:30 +00:00
|
|
|
}
|
|
|
|
|
2010-12-03 00:08:47 +00:00
|
|
|
void AsylumEngine::initSinCosTables(double a2, int32 a3, int32 a4) {
|
|
|
|
uint32 offset = 0;
|
|
|
|
uint32 baseStep = 1;
|
|
|
|
|
|
|
|
do {
|
|
|
|
if (baseStep >= 1) {
|
2011-08-03 18:24:50 -04:00
|
|
|
uint32 baseAngle = 90;
|
2010-12-03 00:08:47 +00:00
|
|
|
int32 step = baseStep;
|
|
|
|
|
2011-08-03 18:24:50 -04:00
|
|
|
int16 *val = &_sinCosTables[2 * offset];
|
2010-12-03 00:08:47 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
double angle = (double)(baseAngle % 360) * 3.141592653589 * 0.005555555555555556;
|
|
|
|
|
2011-08-03 18:24:50 -04:00
|
|
|
*val = (int16)(cos(angle) * a2 - (a3 / 2.0));
|
|
|
|
*(val + 1) = (int16)(sin(angle) * a2 - (a4 / 2.0));
|
2010-12-03 00:08:47 +00:00
|
|
|
|
|
|
|
baseAngle += 360 / baseStep;
|
|
|
|
val += 2;
|
|
|
|
--step;
|
|
|
|
} while (step);
|
|
|
|
|
|
|
|
offset += baseStep;
|
|
|
|
}
|
|
|
|
|
|
|
|
++baseStep;
|
|
|
|
|
|
|
|
} while (baseStep <= 8);
|
|
|
|
}
|
|
|
|
|
2011-08-03 18:24:50 -04:00
|
|
|
int32 AsylumEngine::computeSinCosOffset(int32 val) const {
|
2010-12-03 00:08:47 +00:00
|
|
|
int32 offset = 0;
|
|
|
|
for (int32 i = val; i > 0; --i)
|
|
|
|
offset += i;
|
|
|
|
|
|
|
|
return offset - val;
|
2010-12-01 19:22:30 +00:00
|
|
|
}
|
|
|
|
|
2010-12-02 19:30:25 +00:00
|
|
|
Common::Point AsylumEngine::getSinCosValues(int32 index1, int32 index2) {
|
2011-08-03 18:24:50 -04:00
|
|
|
if (!_scene)
|
|
|
|
error("[AsylumEngine::getSinCosValues] Subsystems not initialized properly!");
|
|
|
|
|
2010-12-03 00:08:47 +00:00
|
|
|
Common::Point values;
|
|
|
|
|
|
|
|
if (_scene->worldstats()->chapter == kChapter11) {
|
|
|
|
int32 offset = computeSinCosOffset(8) + index2 + 3;
|
|
|
|
values.x = _sinCosTables[2 * offset];
|
|
|
|
values.y = _sinCosTables[1];
|
|
|
|
} else {
|
|
|
|
int32 offset = computeSinCosOffset(index1) + index2;
|
|
|
|
values.x = _sinCosTables[2 * offset];
|
|
|
|
values.y = _sinCosTables[2 * offset + 1];
|
|
|
|
}
|
|
|
|
|
|
|
|
return values;
|
2010-12-02 19:30:25 +00:00
|
|
|
}
|
|
|
|
|
2010-12-01 19:22:09 +00:00
|
|
|
void AsylumEngine::updateReverseStereo() {
|
|
|
|
if (_scene && _scene->worldstats())
|
|
|
|
_scene->worldstats()->reverseStereo = Config.reverseStereo;
|
|
|
|
}
|
|
|
|
|
2010-12-08 02:31:49 +00:00
|
|
|
void AsylumEngine::saveLoadWithSerializer(Common::Serializer &s) {
|
2011-08-03 18:24:50 -04:00
|
|
|
if (!_script)
|
|
|
|
error("[AsylumEngine::saveLoadWithSerializer] Subsystems not initialized properly!");
|
|
|
|
|
2011-07-29 05:40:52 -04:00
|
|
|
// Game flags
|
|
|
|
for (uint32 i = 0; i < ARRAYSIZE(_gameFlags); i++)
|
|
|
|
s.syncAsSint32LE(_gameFlags[i]);
|
|
|
|
|
|
|
|
// The original has the script data in the middle of other shared data,
|
|
|
|
// so to be compatible with original savegames, we want to save it in
|
|
|
|
// the proper order
|
|
|
|
_data.saveLoadAmbientSoundData(s);
|
|
|
|
|
2011-08-04 21:54:31 -04:00
|
|
|
// Original skips two elements
|
|
|
|
// (original has one unused, one used for debugging screen update counts)
|
|
|
|
s.skip(8);
|
|
|
|
|
2011-07-29 05:40:52 -04:00
|
|
|
// Script queue
|
|
|
|
_script->saveLoadWithSerializer(s);
|
|
|
|
|
|
|
|
// Shared data (the rest of it)
|
|
|
|
_data.saveLoadWithSerializer(s);
|
2010-12-08 02:31:49 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 04:27:47 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// Game flags
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
2010-11-16 14:24:17 +00:00
|
|
|
#define FLAG_MASK 0xFFFFFFE0
|
|
|
|
|
2010-11-03 04:28:19 +00:00
|
|
|
void AsylumEngine::setGameFlag(GameFlag flag) {
|
2010-11-16 14:24:17 +00:00
|
|
|
_gameFlags[flag / 32] |= 1 << (flag % FLAG_MASK);
|
2009-09-19 14:25:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 04:28:19 +00:00
|
|
|
void AsylumEngine::clearGameFlag(GameFlag flag) {
|
2010-11-16 14:24:17 +00:00
|
|
|
_gameFlags[flag / 32] &= ~(1 << (uint32)(flag % FLAG_MASK));
|
2009-09-19 14:25:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-03 04:28:19 +00:00
|
|
|
void AsylumEngine::toggleGameFlag(GameFlag flag) {
|
2010-11-16 14:24:17 +00:00
|
|
|
_gameFlags[flag / 32] ^= 1 << (uint32)(flag % FLAG_MASK);
|
2009-09-19 14:25:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 14:24:17 +00:00
|
|
|
bool AsylumEngine::isGameFlagSet(GameFlag flag) const {
|
|
|
|
return ((1 << (flag % FLAG_MASK)) & (unsigned int)_gameFlags[flag / 32]) >> (flag % FLAG_MASK) != 0;
|
2009-09-19 14:25:43 +00:00
|
|
|
}
|
|
|
|
|
2010-11-16 14:24:17 +00:00
|
|
|
bool AsylumEngine::isGameFlagNotSet(GameFlag flag) const {
|
|
|
|
return ((1 << (flag % FLAG_MASK)) & (unsigned int)_gameFlags[flag / 32]) >> (flag % FLAG_MASK) == 0;
|
2009-09-19 14:25:43 +00:00
|
|
|
}
|
|
|
|
|
2009-06-12 12:40:18 +00:00
|
|
|
} // namespace Asylum
|