2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2004-04-12 21:51:26 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2004-04-12 21:51:26 +00:00
|
|
|
*
|
|
|
|
* 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
|
2008-01-05 12:45:14 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-12 21:51:26 +00:00
|
|
|
* 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-12 21:51:26 +00:00
|
|
|
*
|
2006-02-11 12:44:16 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-12 21:51:26 +00:00
|
|
|
*
|
|
|
|
*/
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2004-03-14 23:39:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/config-manager.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
#include "common/system.h"
|
2007-09-19 13:55:05 +00:00
|
|
|
#include "common/events.h"
|
2005-01-10 22:06:49 +00:00
|
|
|
|
|
|
|
#include "sound/mixer.h"
|
2004-03-14 23:39:41 +00:00
|
|
|
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/saga.h"
|
|
|
|
|
2008-12-22 14:13:15 +00:00
|
|
|
#include "saga/resource.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/gfx.h"
|
|
|
|
#include "saga/render.h"
|
|
|
|
#include "saga/actor.h"
|
|
|
|
#include "saga/animation.h"
|
2004-08-10 18:31:33 +00:00
|
|
|
#include "saga/console.h"
|
2004-08-10 19:00:30 +00:00
|
|
|
#include "saga/events.h"
|
2004-08-03 00:06:18 +00:00
|
|
|
#include "saga/font.h"
|
2004-08-06 01:39:17 +00:00
|
|
|
#include "saga/interface.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/isomap.h"
|
2005-05-23 02:23:34 +00:00
|
|
|
#include "saga/puzzle.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/script.h"
|
2004-08-04 20:28:57 +00:00
|
|
|
#include "saga/scene.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/sndres.h"
|
2004-08-03 01:07:34 +00:00
|
|
|
#include "saga/sprite.h"
|
2004-08-02 16:20:35 +00:00
|
|
|
#include "saga/sound.h"
|
|
|
|
#include "saga/music.h"
|
2004-08-10 19:20:33 +00:00
|
|
|
#include "saga/palanim.h"
|
2005-01-18 15:01:21 +00:00
|
|
|
#include "saga/objectmap.h"
|
2004-03-14 23:39:41 +00:00
|
|
|
|
|
|
|
namespace Saga {
|
|
|
|
|
2004-10-27 21:32:28 +00:00
|
|
|
#define MAX_TIME_DELTA 100
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2007-11-03 21:06:58 +00:00
|
|
|
SagaEngine::SagaEngine(OSystem *syst, const SAGAGameDescription *gameDesc)
|
|
|
|
: Engine(syst), _gameDescription(gameDesc) {
|
2004-03-14 23:39:41 +00:00
|
|
|
|
2005-04-18 20:03:14 +00:00
|
|
|
_leftMouseButtonPressed = _rightMouseButtonPressed = false;
|
|
|
|
|
2004-12-03 19:15:44 +00:00
|
|
|
_console = NULL;
|
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
_resource = NULL;
|
2005-03-18 17:11:37 +00:00
|
|
|
_sndRes = NULL;
|
|
|
|
_events = NULL;
|
|
|
|
_font = NULL;
|
|
|
|
_sprite = NULL;
|
|
|
|
_anim = NULL;
|
|
|
|
_script = NULL;
|
|
|
|
_interface = NULL;
|
|
|
|
_actor = NULL;
|
|
|
|
_palanim = NULL;
|
|
|
|
_scene = NULL;
|
|
|
|
_isoMap = NULL;
|
|
|
|
_gfx = NULL;
|
2008-06-12 16:58:02 +00:00
|
|
|
_driver = NULL;
|
2005-03-18 17:11:37 +00:00
|
|
|
_console = NULL;
|
|
|
|
_render = NULL;
|
|
|
|
_music = NULL;
|
|
|
|
_sound = NULL;
|
2005-05-23 02:23:34 +00:00
|
|
|
_puzzle = NULL;
|
2005-03-18 17:11:37 +00:00
|
|
|
|
2005-07-30 14:41:25 +00:00
|
|
|
_frameCount = 0;
|
2005-09-26 07:22:32 +00:00
|
|
|
_globalFlags = 0;
|
2007-06-06 19:46:10 +00:00
|
|
|
_mouseClickCount = 0;
|
2005-09-26 07:22:32 +00:00
|
|
|
memset(_ethicsPoints, 0, sizeof(_ethicsPoints));
|
2005-07-30 14:41:25 +00:00
|
|
|
|
2004-10-01 06:45:13 +00:00
|
|
|
// The Linux version of Inherit the Earth puts all data files in an
|
|
|
|
// 'itedata' sub-directory, except for voices.rsc
|
2008-09-07 22:10:58 +00:00
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("itedata"));
|
2004-10-01 06:45:13 +00:00
|
|
|
|
|
|
|
// The Windows version of Inherit the Earth puts various data files in
|
|
|
|
// other subdirectories.
|
2008-09-07 22:10:58 +00:00
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("graphics"));
|
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("music"));
|
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("sound"));
|
2004-03-14 23:39:41 +00:00
|
|
|
|
2005-09-21 10:06:56 +00:00
|
|
|
// The Multi-OS version puts the voices file in the root directory of
|
|
|
|
// the CD. The rest of the data files are in game/itedata
|
2008-10-27 11:04:36 +00:00
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("game").getChild("itedata"));
|
2005-09-21 10:06:56 +00:00
|
|
|
|
2005-01-02 20:29:27 +00:00
|
|
|
// Mac CD Wyrmkeep
|
2008-09-07 22:10:58 +00:00
|
|
|
Common::File::addDefaultDirectory(_gameDataDir.getChild("patch"));
|
2005-01-02 20:29:27 +00:00
|
|
|
|
2005-07-08 16:56:03 +00:00
|
|
|
_displayClip.left = _displayClip.top = 0;
|
2007-09-19 13:55:05 +00:00
|
|
|
syst->getEventManager()->registerRandomSource(_rnd, "saga");
|
2004-03-14 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SagaEngine::~SagaEngine() {
|
2005-07-19 19:05:52 +00:00
|
|
|
if (_scene != NULL) {
|
|
|
|
if (_scene->isSceneLoaded()) {
|
|
|
|
_scene->endScene();
|
|
|
|
}
|
2005-05-18 18:28:10 +00:00
|
|
|
}
|
2005-01-11 21:10:36 +00:00
|
|
|
|
2008-12-25 12:09:24 +00:00
|
|
|
if (getGameId() == GID_ITE) {
|
|
|
|
delete _isoMap;
|
|
|
|
delete _puzzle;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete _sndRes;
|
|
|
|
delete _events;
|
|
|
|
|
2008-12-21 22:52:44 +00:00
|
|
|
if (!isSaga2()) {
|
|
|
|
delete _font;
|
|
|
|
delete _sprite;
|
|
|
|
}
|
|
|
|
|
2008-12-25 12:09:24 +00:00
|
|
|
delete _anim;
|
|
|
|
delete _script;
|
|
|
|
if (!isSaga2())
|
|
|
|
delete _interface;
|
|
|
|
delete _actor;
|
|
|
|
delete _palanim;
|
2005-04-24 18:26:12 +00:00
|
|
|
delete _scene;
|
|
|
|
delete _render;
|
|
|
|
delete _music;
|
|
|
|
delete _sound;
|
2008-06-12 16:58:02 +00:00
|
|
|
delete _driver;
|
2005-04-24 18:26:12 +00:00
|
|
|
delete _gfx;
|
|
|
|
delete _console;
|
2005-07-19 19:05:52 +00:00
|
|
|
delete _resource;
|
2004-03-14 23:39:41 +00:00
|
|
|
}
|
|
|
|
|
2008-11-06 17:05:54 +00:00
|
|
|
Common::Error SagaEngine::init() {
|
2008-12-19 12:03:22 +00:00
|
|
|
// Assign default values to the config manager, in case settings are missing
|
|
|
|
ConfMan.registerDefault("talkspeed", "255");
|
|
|
|
ConfMan.registerDefault("subtitles", "true");
|
|
|
|
|
|
|
|
_musicVolume = ConfMan.getInt("music_volume");
|
|
|
|
_subtitlesEnabled = ConfMan.getBool("subtitles");
|
2006-06-11 20:30:43 +00:00
|
|
|
_readingSpeed = getTalkspeed();
|
2008-12-19 12:03:22 +00:00
|
|
|
_copyProtection = ConfMan.getBool("copy_protection");
|
2007-07-13 16:37:37 +00:00
|
|
|
_gf_wyrmkeep = false;
|
2008-11-13 09:19:42 +00:00
|
|
|
_musicWasPlaying = false;
|
2005-09-02 20:17:52 +00:00
|
|
|
|
|
|
|
if (_readingSpeed > 3)
|
|
|
|
_readingSpeed = 0;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2008-12-22 14:13:15 +00:00
|
|
|
switch(getGameId()) {
|
|
|
|
case GID_ITE:
|
|
|
|
_resource = new Resource_RSC(this);
|
|
|
|
break;
|
2009-01-02 16:52:38 +00:00
|
|
|
#ifdef ENABLE_IHNM
|
2008-12-22 14:13:15 +00:00
|
|
|
case GID_IHNM:
|
|
|
|
_resource = new Resource_RES(this);
|
|
|
|
break;
|
2009-01-02 16:52:38 +00:00
|
|
|
#endif
|
|
|
|
#ifdef ENABLE_SAGA2
|
2008-12-22 14:13:15 +00:00
|
|
|
case GID_DINO:
|
|
|
|
case GID_FTA2:
|
|
|
|
_resource = new Resource_HRS(this);
|
|
|
|
break;
|
2009-01-02 16:52:38 +00:00
|
|
|
#endif
|
2008-12-22 14:13:15 +00:00
|
|
|
}
|
2005-07-19 19:05:52 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Detect game and open resource files
|
2005-07-19 19:05:52 +00:00
|
|
|
if (!initGame()) {
|
2007-04-21 21:23:26 +00:00
|
|
|
GUIErrorMessage("Error loading game resources.");
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kUnknownError;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Initialize engine modules
|
2008-12-21 22:52:44 +00:00
|
|
|
// TODO: implement differences for SAGA2
|
2008-12-25 12:09:24 +00:00
|
|
|
_sndRes = new SndRes(this);
|
2008-12-21 23:43:12 +00:00
|
|
|
_events = new Events(this);
|
|
|
|
|
|
|
|
if (!isSaga2()) {
|
2008-12-21 22:52:44 +00:00
|
|
|
_font = new Font(this);
|
|
|
|
_sprite = new Sprite(this);
|
2009-01-02 23:16:08 +00:00
|
|
|
_script = new SAGA1Script(this);
|
|
|
|
} else {
|
|
|
|
_script = new SAGA2Script(this);
|
2008-12-21 22:52:44 +00:00
|
|
|
}
|
2008-12-21 23:43:12 +00:00
|
|
|
|
2008-12-25 12:09:24 +00:00
|
|
|
_anim = new Anim(this);
|
2008-12-21 23:43:12 +00:00
|
|
|
_interface = new Interface(this); // requires script module
|
2005-10-08 15:35:07 +00:00
|
|
|
_scene = new Scene(this);
|
2008-12-21 23:43:12 +00:00
|
|
|
_actor = new Actor(this);
|
2008-12-25 12:09:24 +00:00
|
|
|
_palanim = new PalAnim(this);
|
2008-12-21 22:52:44 +00:00
|
|
|
|
2008-12-25 12:09:24 +00:00
|
|
|
if (getGameId() == GID_ITE) {
|
|
|
|
_isoMap = new IsoMap(this);
|
|
|
|
_puzzle = new Puzzle(this);
|
2008-12-21 22:52:44 +00:00
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// System initialization
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
_previousTicks = _system->getMillis();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-10-21 22:40:06 +00:00
|
|
|
// Initialize graphics
|
2008-12-22 14:36:58 +00:00
|
|
|
_gfx = new Gfx(this, _system, getDisplayInfo().width, getDisplayInfo().height);
|
2004-10-21 22:40:06 +00:00
|
|
|
|
2004-12-03 19:15:44 +00:00
|
|
|
// Graphics driver should be initialized before console
|
|
|
|
_console = new Console(this);
|
|
|
|
|
2004-10-21 22:40:06 +00:00
|
|
|
// Graphics should be initialized before music
|
2005-12-30 14:18:21 +00:00
|
|
|
int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
|
|
|
|
bool native_mt32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
|
|
|
|
bool adlib = (midiDriver == MD_ADLIB);
|
2004-11-20 17:19:15 +00:00
|
|
|
|
2008-06-12 16:58:02 +00:00
|
|
|
_driver = MidiDriver::createMidi(midiDriver);
|
2005-12-30 14:18:21 +00:00
|
|
|
if (native_mt32)
|
2008-06-12 16:58:02 +00:00
|
|
|
_driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
|
2004-04-29 03:52:59 +00:00
|
|
|
|
2008-07-01 03:01:11 +00:00
|
|
|
_music = new Music(this, _mixer, _driver);
|
2004-11-19 07:41:59 +00:00
|
|
|
_music->setNativeMT32(native_mt32);
|
2004-11-20 17:19:15 +00:00
|
|
|
_music->setAdlib(adlib);
|
2004-10-07 23:02:19 +00:00
|
|
|
_render = new Render(this, _system);
|
2004-07-31 23:00:48 +00:00
|
|
|
if (!_render->initialized()) {
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kUnknownError;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-05-01 13:19:15 +00:00
|
|
|
// Initialize system specific sound
|
2008-07-21 19:15:28 +00:00
|
|
|
_sound = new Sound(this, _mixer);
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-12-21 23:43:12 +00:00
|
|
|
if (!isSaga2()) {
|
|
|
|
_interface->converseInit();
|
|
|
|
_script->setVerb(_script->getVerbType(kVerbWalkTo));
|
|
|
|
}
|
2005-01-17 20:17:06 +00:00
|
|
|
|
2008-07-01 03:01:11 +00:00
|
|
|
_music->setVolume(_musicVolume, 1);
|
2005-06-19 21:18:00 +00:00
|
|
|
|
2008-12-21 23:43:12 +00:00
|
|
|
if (!isSaga2()) {
|
|
|
|
_gfx->initPalette();
|
|
|
|
}
|
2005-10-05 01:31:46 +00:00
|
|
|
|
2007-12-23 02:33:58 +00:00
|
|
|
if (_voiceFilesExist) {
|
2008-12-21 15:59:05 +00:00
|
|
|
if (getGameId() == GID_IHNM) {
|
2007-12-23 02:33:58 +00:00
|
|
|
if (!ConfMan.hasKey("voices")) {
|
|
|
|
_voicesEnabled = true;
|
|
|
|
ConfMan.setBool("voices", true);
|
|
|
|
} else {
|
2008-12-19 12:03:22 +00:00
|
|
|
_voicesEnabled = ConfMan.getBool("voices");
|
2007-12-23 02:33:58 +00:00
|
|
|
}
|
2007-06-13 20:13:06 +00:00
|
|
|
} else {
|
2007-12-23 02:33:58 +00:00
|
|
|
_voicesEnabled = true;
|
2007-06-13 20:13:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-07-21 19:15:28 +00:00
|
|
|
syncSoundSettings();
|
|
|
|
|
2009-01-18 20:42:33 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
// FIXME: Disabled this code for now. We want to get rid of OSystem::kFeatureAutoComputeDirtyRects
|
|
|
|
// and this is the last place to make use of it. We need to find out whether doing
|
|
|
|
// so causes any regressions. If it does, we can reenable it, if not, we can remove
|
|
|
|
// this code in 0.13.0.
|
|
|
|
|
2005-10-14 15:15:52 +00:00
|
|
|
// FIXME: This is the ugly way of reducing redraw overhead. It works
|
|
|
|
// well for 320x200 but it's unclear how well it will work for
|
|
|
|
// 640x480.
|
2008-12-21 15:59:05 +00:00
|
|
|
if (getGameId() == GID_ITE)
|
2005-10-14 15:15:52 +00:00
|
|
|
_system->setFeatureState(OSystem::kFeatureAutoComputeDirtyRects, true);
|
2009-01-18 20:42:33 +00:00
|
|
|
#endif
|
2005-10-14 15:15:52 +00:00
|
|
|
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kNoError;
|
2004-11-23 00:03:25 +00:00
|
|
|
}
|
|
|
|
|
2008-11-06 17:05:54 +00:00
|
|
|
Common::Error SagaEngine::go() {
|
2004-11-23 00:03:25 +00:00
|
|
|
int msec = 0;
|
|
|
|
|
2004-09-28 20:19:37 +00:00
|
|
|
_previousTicks = _system->getMillis();
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
if (ConfMan.hasKey("start_scene")) {
|
2005-07-08 16:56:03 +00:00
|
|
|
_scene->changeScene(ConfMan.getInt("start_scene"), 0, kTransitionNoFade);
|
2005-08-04 10:48:54 +00:00
|
|
|
} else if (ConfMan.hasKey("boot_param")) {
|
2008-12-21 15:59:05 +00:00
|
|
|
if (getGameId() == GID_ITE)
|
2008-05-26 11:10:46 +00:00
|
|
|
_interface->addToInventory(_actor->objIndexToId(0)); // Magic hat
|
2005-08-04 10:48:54 +00:00
|
|
|
_scene->changeScene(ConfMan.getInt("boot_param"), 0, kTransitionNoFade);
|
|
|
|
} else if (ConfMan.hasKey("save_slot")) {
|
2008-08-19 08:49:53 +00:00
|
|
|
// Init the current chapter to 8 (character selection) for IHNM
|
2008-12-21 15:59:05 +00:00
|
|
|
if (getGameId() == GID_IHNM)
|
2008-08-19 08:49:53 +00:00
|
|
|
_scene->changeScene(-2, 0, kTransitionFade, 8);
|
|
|
|
|
2005-06-02 22:14:57 +00:00
|
|
|
// First scene sets up palette
|
|
|
|
_scene->changeScene(getStartSceneNumber(), 0, kTransitionNoFade);
|
|
|
|
_events->handleEvents(0); // Process immediate events
|
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (getGameId() == GID_ITE)
|
2008-08-19 08:49:53 +00:00
|
|
|
_interface->setMode(kPanelMain);
|
|
|
|
else
|
|
|
|
_interface->setMode(kPanelChapterSelection);
|
|
|
|
|
|
|
|
char *fileName = calcSaveFileName(ConfMan.getInt("save_slot"));
|
2005-06-02 22:14:57 +00:00
|
|
|
load(fileName);
|
2008-08-16 22:30:19 +00:00
|
|
|
syncSoundSettings();
|
2005-06-02 22:14:57 +00:00
|
|
|
} else {
|
2005-09-28 15:49:20 +00:00
|
|
|
_framesEsc = 0;
|
2008-12-31 11:46:21 +00:00
|
|
|
//_sndRes->playVoice(0); // SAGA 2 sound test
|
2005-06-02 22:14:57 +00:00
|
|
|
_scene->startScene();
|
|
|
|
}
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2004-08-02 12:41:40 +00:00
|
|
|
uint32 currentTicks;
|
2004-04-12 21:40:49 +00:00
|
|
|
|
2008-09-30 12:27:38 +00:00
|
|
|
while (!shouldQuit()) {
|
2004-12-03 19:15:44 +00:00
|
|
|
if (_console->isAttached())
|
|
|
|
_console->onFrame();
|
|
|
|
|
2004-07-31 23:00:48 +00:00
|
|
|
if (_render->getFlags() & RF_RENDERPAUSE) {
|
2004-05-01 13:19:15 +00:00
|
|
|
// Freeze time while paused
|
2004-09-28 20:19:37 +00:00
|
|
|
_previousTicks = _system->getMillis();
|
2004-04-12 21:40:49 +00:00
|
|
|
} else {
|
2004-09-28 20:19:37 +00:00
|
|
|
currentTicks = _system->getMillis();
|
2004-08-02 12:41:40 +00:00
|
|
|
// Timer has rolled over after 49 days
|
|
|
|
if (currentTicks < _previousTicks)
|
|
|
|
msec = 0;
|
|
|
|
else {
|
|
|
|
msec = currentTicks - _previousTicks;
|
|
|
|
_previousTicks = currentTicks;
|
|
|
|
}
|
2004-10-27 21:32:28 +00:00
|
|
|
if (msec > MAX_TIME_DELTA) {
|
|
|
|
msec = MAX_TIME_DELTA;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2005-01-07 15:49:47 +00:00
|
|
|
|
2007-06-15 03:58:21 +00:00
|
|
|
// Since Puzzle and forced text are actorless, we do them here
|
2008-12-21 22:52:44 +00:00
|
|
|
if ((getGameId() == GID_ITE && _puzzle->isActive()) || _actor->isForcedTextShown()) {
|
2005-05-23 02:23:34 +00:00
|
|
|
_actor->handleSpeech(msec);
|
Allowed IHNM to use the opSpeak opcode. Aborting that code path early meant
that the instruction wasn't fully read, so the next opcode would be wrong.
This is what caused it to crash.
To keep the game from hanging, I also allowed the engine to call the
_actors->direct() function for IHNM. This allows AM's intro speech to be
played in its entirety.
Since this includes the "hate" speech, I've removed that part from the
hard-coded intro. To get the right music playing, I've enabled the
sfPlayMusic() function for IHNM. This is pure guesswork, though. Once the
scene changes, the wrong music plays again. However, this is scene music,
i.e. not scripted.
It doesn't play the background sound. Looks like _fxTable[] isn't generated
for IHNM. More noticeably, until the scene changes it doesn't show any
graphics apart from the subtitles, which are drawn in the wrong colour and
(I believe) the wrong font.
svn-id: r18712
2005-08-26 12:07:31 +00:00
|
|
|
} else if (!_scene->isInIntro()) {
|
2005-05-23 02:23:34 +00:00
|
|
|
if (_interface->getMode() == kPanelMain ||
|
2005-10-08 16:25:18 +00:00
|
|
|
_interface->getMode() == kPanelConverse ||
|
|
|
|
_interface->getMode() == kPanelCutaway ||
|
|
|
|
_interface->getMode() == kPanelNull ||
|
|
|
|
_interface->getMode() == kPanelChapterSelection)
|
2005-01-06 15:29:17 +00:00
|
|
|
_actor->direct(msec);
|
2005-05-31 01:03:13 +00:00
|
|
|
}
|
2005-01-06 14:02:53 +00:00
|
|
|
|
2004-08-12 23:57:45 +00:00
|
|
|
_events->handleEvents(msec);
|
2004-12-21 06:49:07 +00:00
|
|
|
_script->executeThreads(msec);
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
2004-05-01 13:19:15 +00:00
|
|
|
// Per frame processing
|
2004-07-31 23:00:48 +00:00
|
|
|
_render->drawScene();
|
2004-09-28 20:19:37 +00:00
|
|
|
_system->delayMillis(10);
|
2004-05-01 13:19:15 +00:00
|
|
|
}
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kNoError;
|
2004-04-12 21:40:49 +00:00
|
|
|
}
|
|
|
|
|
2005-01-08 21:06:06 +00:00
|
|
|
void SagaEngine::loadStrings(StringsTable &stringsTable, const byte *stringsPointer, size_t stringsLength) {
|
2005-01-08 20:30:07 +00:00
|
|
|
uint16 stringsCount;
|
|
|
|
size_t offset;
|
2008-02-27 15:11:16 +00:00
|
|
|
size_t prevOffset = 0;
|
2005-01-18 15:01:21 +00:00
|
|
|
int i;
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
if (stringsLength == 0) {
|
|
|
|
error("SagaEngine::loadStrings() Error loading strings list resource");
|
|
|
|
}
|
|
|
|
|
2005-01-08 21:06:06 +00:00
|
|
|
stringsTable.stringsPointer = (byte*)malloc(stringsLength);
|
|
|
|
memcpy(stringsTable.stringsPointer, stringsPointer, stringsLength);
|
2005-01-08 20:30:07 +00:00
|
|
|
|
2005-07-29 17:58:00 +00:00
|
|
|
|
2005-07-19 19:05:52 +00:00
|
|
|
MemoryReadStreamEndian scriptS(stringsTable.stringsPointer, stringsLength, isBigEndian()); //TODO: get endianess from context
|
2005-01-08 20:30:07 +00:00
|
|
|
|
|
|
|
offset = scriptS.readUint16();
|
2005-01-18 15:01:21 +00:00
|
|
|
stringsCount = offset / 2;
|
|
|
|
stringsTable.strings = (const char **)malloc(stringsCount * sizeof(*stringsTable.strings));
|
2005-07-29 17:58:00 +00:00
|
|
|
i = 0;
|
2005-01-08 20:30:07 +00:00
|
|
|
scriptS.seek(0);
|
2005-01-18 15:01:21 +00:00
|
|
|
while (i < stringsCount) {
|
2005-01-08 20:30:07 +00:00
|
|
|
offset = scriptS.readUint16();
|
2008-02-27 15:11:16 +00:00
|
|
|
// In some rooms in IHNM, string offsets can be greater than the maximum value than a 16-bit integer can hold
|
|
|
|
// We detect this by checking the previous offset, and if it was bigger than the current one, an overflow
|
|
|
|
// occured (since the string offsets are sequential), so we're adding the missing part of the number
|
|
|
|
// Fixes bug #1895205 - "IHNM: end game text/caption error"
|
|
|
|
if (prevOffset > offset)
|
|
|
|
offset += 65536;
|
|
|
|
prevOffset = offset;
|
2005-01-18 15:01:21 +00:00
|
|
|
if (offset == stringsLength) {
|
|
|
|
stringsCount = i;
|
|
|
|
stringsTable.strings = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
|
|
|
|
break;
|
|
|
|
}
|
2005-01-08 20:30:07 +00:00
|
|
|
if (offset > stringsLength) {
|
2007-09-30 01:29:12 +00:00
|
|
|
// This case should never occur, but apparently it does in the Italian fan
|
|
|
|
// translation of IHNM
|
|
|
|
warning("SagaEngine::loadStrings wrong strings table");
|
|
|
|
stringsCount = i;
|
|
|
|
stringsTable.strings = (const char **)realloc(stringsTable.strings, stringsCount * sizeof(*stringsTable.strings));
|
|
|
|
break;
|
2005-01-08 20:30:07 +00:00
|
|
|
}
|
2005-01-08 21:06:06 +00:00
|
|
|
stringsTable.strings[i] = (const char *)stringsTable.stringsPointer + offset;
|
2005-04-22 14:11:04 +00:00
|
|
|
debug(9, "string[%i]=%s", i, stringsTable.strings[i]);
|
2005-01-18 15:01:21 +00:00
|
|
|
i++;
|
2005-01-08 20:30:07 +00:00
|
|
|
}
|
2005-01-18 15:01:21 +00:00
|
|
|
stringsTable.stringsCount = stringsCount;
|
2005-01-08 20:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char *SagaEngine::getObjectName(uint16 objectId) {
|
2005-01-18 21:13:44 +00:00
|
|
|
ActorData *actor;
|
|
|
|
ObjectData *obj;
|
2005-01-18 15:01:21 +00:00
|
|
|
const HitZone *hitZone;
|
2007-06-15 16:26:14 +00:00
|
|
|
|
|
|
|
// Disable the object names in IHNM when the chapter is 8
|
2008-12-21 15:59:05 +00:00
|
|
|
if (getGameId() == GID_IHNM && _scene->currentChapterNumber() == 8)
|
2007-06-15 16:26:14 +00:00
|
|
|
return "";
|
|
|
|
|
2005-01-18 15:01:21 +00:00
|
|
|
switch (objectTypeId(objectId)) {
|
2005-03-07 11:49:59 +00:00
|
|
|
case kGameObjectObject:
|
|
|
|
obj = _actor->getObj(objectId);
|
2008-12-21 15:59:05 +00:00
|
|
|
if (getGameId() == GID_ITE)
|
2005-10-08 22:09:21 +00:00
|
|
|
return _script->_mainStrings.getString(obj->_nameIndex);
|
|
|
|
return _actor->_objectsStrings.getString(obj->_nameIndex);
|
2005-07-29 17:58:00 +00:00
|
|
|
case kGameObjectActor:
|
|
|
|
actor = _actor->getActor(objectId);
|
2005-08-10 14:53:17 +00:00
|
|
|
return _actor->_actorsStrings.getString(actor->_nameIndex);
|
2005-03-07 11:49:59 +00:00
|
|
|
case kGameObjectHitZone:
|
2005-05-23 02:23:34 +00:00
|
|
|
hitZone = _scene->_objectMap->getHitZone(objectIdToIndex(objectId));
|
2007-06-06 16:37:10 +00:00
|
|
|
|
|
|
|
if (hitZone == NULL)
|
|
|
|
return "";
|
|
|
|
|
2005-05-23 02:23:34 +00:00
|
|
|
return _scene->_sceneStrings.getString(hitZone->getNameIndex());
|
2005-01-08 20:30:07 +00:00
|
|
|
}
|
2005-01-18 21:13:44 +00:00
|
|
|
warning("SagaEngine::getObjectName name not found for 0x%X", objectId);
|
2005-01-08 20:30:07 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-01-13 22:42:49 +00:00
|
|
|
const char *SagaEngine::getTextString(int textStringId) {
|
2005-01-14 11:22:45 +00:00
|
|
|
const char *string;
|
2007-09-30 01:29:12 +00:00
|
|
|
int lang = 0;
|
|
|
|
|
2007-09-30 13:37:05 +00:00
|
|
|
switch (getLanguage()) {
|
|
|
|
case Common::DE_DEU:
|
|
|
|
lang = 1;
|
|
|
|
break;
|
2007-12-21 02:08:30 +00:00
|
|
|
case Common::IT_ITA:
|
2007-09-30 13:37:05 +00:00
|
|
|
lang = 2;
|
|
|
|
break;
|
2007-12-21 02:08:30 +00:00
|
|
|
case Common::ES_ESP:
|
2007-09-30 13:37:05 +00:00
|
|
|
lang = 3;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
lang = 0;
|
|
|
|
break;
|
|
|
|
}
|
2005-01-14 01:17:34 +00:00
|
|
|
|
2005-08-08 08:15:16 +00:00
|
|
|
string = ITEinterfaceTextStrings[lang][textStringId];
|
2005-01-14 11:22:45 +00:00
|
|
|
if (!string)
|
2005-08-08 08:15:16 +00:00
|
|
|
string = ITEinterfaceTextStrings[0][textStringId];
|
2005-01-14 11:22:45 +00:00
|
|
|
|
|
|
|
return string;
|
2005-01-13 22:42:49 +00:00
|
|
|
}
|
|
|
|
|
2005-01-15 20:12:49 +00:00
|
|
|
void SagaEngine::getExcuseInfo(int verb, const char *&textString, int &soundResourceId) {
|
2005-08-11 15:28:08 +00:00
|
|
|
textString = NULL;
|
2006-01-13 20:20:01 +00:00
|
|
|
|
2008-05-26 11:10:46 +00:00
|
|
|
if (verb == _script->getVerbType(kVerbOpen)) {
|
2005-08-16 19:04:51 +00:00
|
|
|
textString = getTextString(kTextNoPlaceToOpen);
|
2008-05-26 11:10:46 +00:00
|
|
|
soundResourceId = 239; // Boar voice 0
|
|
|
|
}
|
|
|
|
if (verb == _script->getVerbType(kVerbClose)) {
|
2005-08-16 19:04:51 +00:00
|
|
|
textString = getTextString(kTextNoOpening);
|
2008-05-26 11:10:46 +00:00
|
|
|
soundResourceId = 241; // Boar voice 2
|
|
|
|
}
|
|
|
|
if (verb == _script->getVerbType(kVerbUse)) {
|
2005-08-16 19:04:51 +00:00
|
|
|
textString = getTextString(kTextDontKnow);
|
2008-05-26 11:10:46 +00:00
|
|
|
soundResourceId = 244; // Boar voice 5
|
|
|
|
}
|
|
|
|
if (verb == _script->getVerbType(kVerbLookAt)) {
|
|
|
|
textString = getTextString(kTextNothingSpecial);
|
|
|
|
soundResourceId = 245; // Boar voice 6
|
|
|
|
}
|
|
|
|
if (verb == _script->getVerbType(kVerbPickUp)) {
|
|
|
|
textString = getTextString(kTextICantPickup);
|
|
|
|
soundResourceId = 246; // Boar voice 7
|
2005-01-15 20:12:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-26 12:08:05 +00:00
|
|
|
ColorId SagaEngine::KnownColor2ColorId(KnownColor knownColor) {
|
|
|
|
ColorId colorId = kITEColorTransBlack;
|
|
|
|
|
2008-12-21 15:59:05 +00:00
|
|
|
if (getGameId() == GID_ITE) {
|
2005-11-26 16:54:55 +00:00
|
|
|
switch (knownColor) {
|
2005-11-26 12:08:05 +00:00
|
|
|
case(kKnownColorTransparent):
|
|
|
|
colorId = kITEColorTransBlack;
|
|
|
|
break;
|
|
|
|
case (kKnownColorBrightWhite):
|
|
|
|
colorId = kITEColorBrightWhite;
|
|
|
|
break;
|
2007-08-18 01:59:18 +00:00
|
|
|
case (kKnownColorWhite):
|
|
|
|
colorId = kITEColorWhite;
|
|
|
|
break;
|
2005-11-26 12:08:05 +00:00
|
|
|
case (kKnownColorBlack):
|
|
|
|
colorId = kITEColorBlack;
|
|
|
|
break;
|
|
|
|
case (kKnownColorSubtitleTextColor):
|
|
|
|
colorId = (ColorId)255;
|
|
|
|
break;
|
|
|
|
case (kKnownColorVerbText):
|
|
|
|
colorId = kITEColorBlue;
|
|
|
|
break;
|
|
|
|
case (kKnownColorVerbTextShadow):
|
|
|
|
colorId = kITEColorBlack;
|
|
|
|
break;
|
|
|
|
case (kKnownColorVerbTextActive):
|
|
|
|
colorId = (ColorId)96;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error("SagaEngine::KnownColor2ColorId unknown color %i", knownColor);
|
|
|
|
}
|
2009-01-02 16:52:38 +00:00
|
|
|
#ifdef ENABLE_IHNM
|
2008-12-21 15:59:05 +00:00
|
|
|
} else if (getGameId() == GID_IHNM) {
|
2007-12-11 22:40:39 +00:00
|
|
|
// The default colors in the Spanish version of IHNM are shifted by one
|
|
|
|
// Fixes bug #1848016 - "IHNM: Wrong Subtitles Color (Spanish)"
|
2008-12-21 15:59:05 +00:00
|
|
|
int offset = (getLanguage() == Common::ES_ESP) ? 1 : 0;
|
2007-12-11 22:40:39 +00:00
|
|
|
|
2007-09-10 13:17:20 +00:00
|
|
|
switch (knownColor) {
|
2005-11-26 12:08:05 +00:00
|
|
|
case(kKnownColorTransparent):
|
2007-12-11 22:40:39 +00:00
|
|
|
colorId = (ColorId)(249 - offset);
|
2005-11-26 12:08:05 +00:00
|
|
|
break;
|
2007-07-30 11:55:11 +00:00
|
|
|
case (kKnownColorBrightWhite):
|
2007-12-11 22:40:39 +00:00
|
|
|
colorId = (ColorId)(251 - offset);
|
2007-07-30 11:55:11 +00:00
|
|
|
break;
|
2007-08-18 01:59:18 +00:00
|
|
|
case (kKnownColorWhite):
|
2007-12-11 22:40:39 +00:00
|
|
|
colorId = (ColorId)(251 - offset);
|
2007-09-19 08:40:12 +00:00
|
|
|
break;
|
2005-11-26 12:08:05 +00:00
|
|
|
case (kKnownColorBlack):
|
2007-12-11 22:40:39 +00:00
|
|
|
colorId = (ColorId)(249 - offset);
|
2005-11-26 12:08:05 +00:00
|
|
|
break;
|
|
|
|
case (kKnownColorVerbText):
|
2007-12-11 22:40:39 +00:00
|
|
|
colorId = (ColorId)(253 - offset);
|
2005-11-26 12:08:05 +00:00
|
|
|
break;
|
|
|
|
case (kKnownColorVerbTextShadow):
|
2007-12-11 22:40:39 +00:00
|
|
|
colorId = (ColorId)(15 - offset);
|
2005-11-26 12:08:05 +00:00
|
|
|
break;
|
|
|
|
case (kKnownColorVerbTextActive):
|
2007-12-11 22:40:39 +00:00
|
|
|
colorId = (ColorId)(252 - offset);
|
2005-11-26 12:08:05 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error("SagaEngine::KnownColor2ColorId unknown color %i", knownColor);
|
|
|
|
}
|
2009-01-02 16:52:38 +00:00
|
|
|
#endif
|
2005-11-26 12:08:05 +00:00
|
|
|
}
|
|
|
|
return colorId;
|
|
|
|
}
|
|
|
|
|
2006-06-11 20:30:43 +00:00
|
|
|
void SagaEngine::setTalkspeed(int talkspeed) {
|
|
|
|
ConfMan.setInt("talkspeed", (talkspeed * 255 + 3 / 2) / 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SagaEngine::getTalkspeed() {
|
2008-12-19 12:03:22 +00:00
|
|
|
return (ConfMan.getInt("talkspeed") * 3 + 255 / 2) / 255;
|
2006-06-11 20:30:43 +00:00
|
|
|
}
|
2005-11-26 12:08:05 +00:00
|
|
|
|
2009-01-20 23:40:35 +00:00
|
|
|
GUI::Debugger *SagaEngine::getDebugger() {
|
|
|
|
return _console;
|
|
|
|
}
|
|
|
|
|
2008-07-01 03:01:11 +00:00
|
|
|
void SagaEngine::syncSoundSettings() {
|
2008-12-19 12:03:22 +00:00
|
|
|
_subtitlesEnabled = ConfMan.getBool("subtitles");
|
2008-07-01 03:01:11 +00:00
|
|
|
_readingSpeed = getTalkspeed();
|
|
|
|
|
|
|
|
if (_readingSpeed > 3)
|
|
|
|
_readingSpeed = 0;
|
|
|
|
|
2008-12-19 12:03:22 +00:00
|
|
|
_musicVolume = ConfMan.getInt("music_volume");
|
2008-07-01 03:01:11 +00:00
|
|
|
_music->setVolume(_musicVolume, 1);
|
2008-07-21 19:15:28 +00:00
|
|
|
_sound->setVolume();
|
2008-07-01 03:01:11 +00:00
|
|
|
}
|
|
|
|
|
2008-11-11 17:34:52 +00:00
|
|
|
void SagaEngine::pauseEngineIntern(bool pause) {
|
2008-11-11 20:25:44 +00:00
|
|
|
bool engineIsPaused = (_render->getFlags() & RF_RENDERPAUSE);
|
|
|
|
if (engineIsPaused == pause)
|
2008-11-11 17:34:52 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if (pause) {
|
|
|
|
_render->setFlag(RF_RENDERPAUSE);
|
2008-11-13 23:19:25 +00:00
|
|
|
if (_music->isPlaying() && !_music->hasDigitalMusic()) {
|
2008-11-11 17:34:52 +00:00
|
|
|
_music->pause();
|
2008-11-13 09:19:42 +00:00
|
|
|
_musicWasPlaying = true;
|
|
|
|
} else {
|
|
|
|
_musicWasPlaying = false;
|
|
|
|
}
|
2008-11-11 17:34:52 +00:00
|
|
|
} else {
|
|
|
|
_render->clearFlag(RF_RENDERPAUSE);
|
2008-11-13 09:19:42 +00:00
|
|
|
if (_musicWasPlaying) {
|
2008-11-11 17:34:52 +00:00
|
|
|
_music->resume();
|
2008-11-13 09:19:42 +00:00
|
|
|
}
|
2008-11-11 17:34:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_mixer->pauseAll(pause);
|
|
|
|
}
|
|
|
|
|
2004-03-22 21:25:29 +00:00
|
|
|
} // End of namespace Saga
|