2004-10-15 06:06:47 +00:00
|
|
|
/* ScummVM - Kyrandia Interpreter
|
2005-01-01 16:09:25 +00:00
|
|
|
* Copyright (C) 2003-2005 The ScummVM project
|
2004-04-09 12:36:06 +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
|
2004-10-15 06:06:47 +00:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2004-04-09 12:36:06 +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
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
|
|
|
|
#include "base/gameDetector.h"
|
|
|
|
#include "base/plugins.h"
|
|
|
|
#include "backends/fs/fs.h"
|
|
|
|
|
|
|
|
#include "sound/mixer.h"
|
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/config-manager.h"
|
2004-11-11 13:37:35 +00:00
|
|
|
#include "sound/mididrv.h"
|
2004-04-09 12:36:06 +00:00
|
|
|
|
2004-10-15 06:06:47 +00:00
|
|
|
#include "kyra.h"
|
|
|
|
#include "resource.h"
|
|
|
|
#include "script.h"
|
2004-11-11 13:37:35 +00:00
|
|
|
#include "wsamovie.h"
|
|
|
|
#include "sound.h"
|
2004-10-15 06:06:47 +00:00
|
|
|
|
|
|
|
struct KyraGameSettings {
|
2004-10-16 22:28:29 +00:00
|
|
|
const char *name;
|
|
|
|
const char *description;
|
|
|
|
uint32 features;
|
|
|
|
const char *detectName;
|
|
|
|
GameSettings toGameSettings() const {
|
|
|
|
GameSettings dummy = { name, description, features };
|
|
|
|
return dummy;
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
};
|
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
static const KyraGameSettings kyra_settings[] = {
|
|
|
|
{"kyra1", "Legend of Kyrandia (Floppy)", GF_FLOPPY | GF_KYRA1, "INTRO.SND"},
|
|
|
|
{"kyra1cd", "Legend of Kyrandia (CD)", GF_TALKIE | GF_KYRA1, "CHAPTER1.VRM"},
|
|
|
|
{"kyra2", "Hand of Fate (Floppy)", GF_FLOPPY | GF_KYRA2, 0 },
|
|
|
|
{"kyra2cd", "Hand of Fate (CD)", GF_TALKIE | GF_KYRA2, "AUDIO.PAK"},
|
2004-11-14 20:11:22 +00:00
|
|
|
{"kyra3", "Malcolm's Revenge", GF_TALKIE | GF_KYRA3, "K3INTRO0.VQA"},
|
2004-11-11 13:37:35 +00:00
|
|
|
{0, 0, 0, 0}
|
2004-10-15 06:06:47 +00:00
|
|
|
};
|
2004-04-09 12:36:06 +00:00
|
|
|
|
|
|
|
GameList Engine_KYRA_gameList() {
|
2004-10-16 22:28:29 +00:00
|
|
|
GameList games;
|
|
|
|
const KyraGameSettings *g = kyra_settings;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2004-10-16 22:28:29 +00:00
|
|
|
while (g->name) {
|
|
|
|
games.push_back(g->toGameSettings());
|
|
|
|
g++;
|
|
|
|
}
|
2004-04-09 12:36:06 +00:00
|
|
|
|
2004-10-16 22:28:29 +00:00
|
|
|
return games;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DetectedGameList Engine_KYRA_detectGames(const FSList &fslist) {
|
2004-10-15 06:06:47 +00:00
|
|
|
const KyraGameSettings *game;
|
2004-04-09 12:36:06 +00:00
|
|
|
DetectedGameList detectedGames;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
|
|
|
for (game = kyra_settings; game->name; ++game) {
|
|
|
|
if (game->detectName == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (FSList::const_iterator file = fslist.begin(); file != fslist.end(); ++file) {
|
2004-12-09 15:06:49 +00:00
|
|
|
if (!file->isDirectory()) {
|
|
|
|
const char *name = file->displayName().c_str();
|
|
|
|
if ((!scumm_stricmp(game->detectName, name))) {
|
|
|
|
detectedGames.push_back(game->toGameSettings());
|
|
|
|
break;
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-10-16 22:28:29 +00:00
|
|
|
return detectedGames;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Engine *Engine_KYRA_create(GameDetector *detector, OSystem *syst) {
|
|
|
|
return new Kyra::KyraEngine(detector, syst);
|
|
|
|
}
|
|
|
|
|
|
|
|
REGISTER_PLUGIN("Legend of Kyrandia Engine", Engine_KYRA_gameList, Engine_KYRA_create, Engine_KYRA_detectGames)
|
|
|
|
|
|
|
|
namespace Kyra {
|
|
|
|
KyraEngine::KyraEngine(GameDetector *detector, OSystem *syst)
|
|
|
|
: Engine(syst) {
|
|
|
|
|
|
|
|
// Setup mixer
|
|
|
|
if (!_mixer->isReady()) {
|
|
|
|
warning("Sound initialization failed.");
|
|
|
|
}
|
|
|
|
|
2004-12-27 00:27:00 +00:00
|
|
|
_mixer->setVolumeForSoundType(SoundMixer::kSFXAudioDataType, ConfMan.getInt("sfx_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(SoundMixer::kMusicAudioDataType, ConfMan.getInt("music_volume"));
|
2004-04-09 12:36:06 +00:00
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
// gets the game
|
|
|
|
if (detector->_game.features & GF_KYRA1) {
|
|
|
|
if (detector->_game.features & GF_FLOPPY)
|
|
|
|
_game = KYRA1;
|
|
|
|
else
|
|
|
|
_game = KYRA1CD;
|
|
|
|
} else if (detector->_game.features & GF_KYRA2) {
|
|
|
|
if (detector->_game.features & GF_FLOPPY)
|
|
|
|
_game = KYRA2;
|
|
|
|
else
|
|
|
|
_game = KYRA2CD;
|
|
|
|
} else if (detector->_game.features & GF_KYRA3) {
|
|
|
|
_game = KYRA3;
|
|
|
|
} else {
|
|
|
|
error("unknown game");
|
|
|
|
}
|
2004-11-23 00:03:25 +00:00
|
|
|
}
|
|
|
|
|
2004-11-24 00:14:21 +00:00
|
|
|
int KyraEngine::init(GameDetector &detector) {
|
2004-11-14 14:11:54 +00:00
|
|
|
|
2004-11-14 14:46:56 +00:00
|
|
|
// Initialize backen
|
2004-11-24 00:14:21 +00:00
|
|
|
_system->beginGFXTransaction();
|
|
|
|
initCommonGFX(detector);
|
|
|
|
_system->initSize(320, 200);
|
|
|
|
_system->endGFXTransaction();
|
|
|
|
|
2004-11-14 14:46:56 +00:00
|
|
|
_screen = new uint8[320*200];
|
|
|
|
memset(_screen, 0, sizeof(uint8) * 320 * 200);
|
|
|
|
|
2004-12-02 08:21:49 +00:00
|
|
|
int midiDrv = MidiDriver::detectMusicDriver(MDT_NATIVE | MDT_ADLIB | MDT_PREFER_NATIVE);
|
2004-11-14 14:11:54 +00:00
|
|
|
bool native_mt32 = (ConfMan.getBool("native_mt32") || (midiDrv == MD_MT32));
|
|
|
|
|
2004-12-02 08:21:49 +00:00
|
|
|
MidiDriver *driver = MidiDriver::createMidi(midiDrv);
|
2004-11-14 14:11:54 +00:00
|
|
|
if (!driver) {
|
|
|
|
// In this case we should play the Adlib tracks, but for now
|
|
|
|
// the automagic MIDI-to-Adlib conversion will do.
|
|
|
|
driver = MidiDriver_ADLIB_create(_mixer);
|
|
|
|
} else if (native_mt32)
|
|
|
|
driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
|
|
|
|
|
|
|
|
_midiDriver = new MusicPlayer(driver, this);
|
|
|
|
assert(_midiDriver);
|
|
|
|
_midiDriver->hasNativeMT32(native_mt32);
|
|
|
|
_midiDriver->setVolume(255);
|
|
|
|
|
2004-11-10 18:09:14 +00:00
|
|
|
_resMgr = new Resourcemanager(this);
|
2004-10-15 06:06:47 +00:00
|
|
|
assert(_resMgr);
|
|
|
|
|
|
|
|
setCurrentPalette(_resMgr->loadPalette("PALETTE.COL"));
|
|
|
|
|
|
|
|
// loads the 2 cursors
|
2004-11-11 13:37:35 +00:00
|
|
|
_mouse = _resMgr->loadImage("MOUSE.CPS");
|
2004-10-15 06:06:47 +00:00
|
|
|
_items = _resMgr->loadImage("ITEMS.CPS");
|
|
|
|
|
|
|
|
// loads the Font
|
|
|
|
_font = _resMgr->loadFont("8FAT.FNT");
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2004-10-15 06:06:47 +00:00
|
|
|
_npcScript = _resMgr->loadScript("_NPC.EMC");
|
2004-11-11 13:37:35 +00:00
|
|
|
|
|
|
|
// loads the scripts (only Kyrandia 1)
|
|
|
|
if (_game == KYRA1 || _game == KYRA1CD) {
|
|
|
|
_currentScript = _resMgr->loadScript("_STARTUP.EMC");
|
|
|
|
} else {
|
|
|
|
error("game start files not known");
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(_npcScript);
|
|
|
|
assert(_currentScript);
|
2004-11-23 00:03:25 +00:00
|
|
|
|
|
|
|
return 0;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KyraEngine::~KyraEngine() {
|
2004-10-15 06:06:47 +00:00
|
|
|
delete _resMgr;
|
2004-11-10 18:45:32 +00:00
|
|
|
delete[] _screen;
|
2004-10-15 06:06:47 +00:00
|
|
|
delete _mouse;
|
|
|
|
delete _items;
|
|
|
|
delete _npcScript;
|
|
|
|
delete _currentScript;
|
|
|
|
delete _font;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::errorString(const char *buf1, char *buf2) {
|
|
|
|
strcpy(buf2, buf1);
|
|
|
|
}
|
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
int KyraEngine::go() {
|
2004-04-09 12:36:06 +00:00
|
|
|
warning("Kyrandia Engine ::go()");
|
2004-10-15 06:06:47 +00:00
|
|
|
// starts the init script
|
2004-11-14 20:11:22 +00:00
|
|
|
/* if (!_currentScript->startScript(kSetupScene)) {
|
2004-10-15 06:06:47 +00:00
|
|
|
error("couldn't init '_STARTUP.EMC' script");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_currentScript->contScript() != kScriptStopped) {
|
|
|
|
if (_currentScript->state() == kScriptError) {
|
|
|
|
error("couldn't run script");
|
|
|
|
} else {
|
|
|
|
warning("init script returned: %d", _currentScript->state());
|
|
|
|
}
|
2004-11-11 13:37:35 +00:00
|
|
|
}*/
|
|
|
|
|
|
|
|
Movie* movie = _resMgr->loadMovie("MAL-KAL.WSA");
|
|
|
|
assert(movie);
|
|
|
|
CPSImage* image = _resMgr->loadImage("GEMCUT.CPS");
|
|
|
|
assert(image);
|
|
|
|
|
|
|
|
int16 currentFrame = 0;
|
|
|
|
uint32 lastFrameChange = 0;
|
|
|
|
|
|
|
|
image->transparency(0);
|
|
|
|
image->drawToPlane(_screen, 320, 200, 0, 0, 0, 0, 320, 136);
|
|
|
|
movie->setImageBackground(_screen, 320, 200);
|
|
|
|
movie->position(16, 58);
|
|
|
|
|
|
|
|
setCurrentPalette(_resMgr->loadPalette("MAL-KAL.COL"));
|
|
|
|
|
|
|
|
uint8* _buffer = new uint8[320 * 200];
|
|
|
|
assert(_buffer);
|
|
|
|
memcpy(_buffer, _screen, 320 * 200);
|
|
|
|
movie->renderFrame(_buffer, 320, 200, movie->countFrames() - 1);
|
|
|
|
|
|
|
|
if (_midiDriver) {
|
|
|
|
_midiDriver->playMusic("KYRA2A.XMI");
|
|
|
|
_midiDriver->playTrack(3);
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2004-10-15 06:06:47 +00:00
|
|
|
while(true) {
|
|
|
|
OSystem::Event event;
|
|
|
|
//if (_debugger->isAttached())
|
|
|
|
// _debugger->onFrame();
|
2004-11-11 13:37:35 +00:00
|
|
|
|
|
|
|
memcpy(_screen, _buffer, 320 * 200);
|
|
|
|
if (lastFrameChange + movie->frameChange() < _system->getMillis()) {
|
|
|
|
lastFrameChange = _system->getMillis();
|
|
|
|
++currentFrame;
|
|
|
|
|
|
|
|
if (currentFrame >= (int16)movie->countFrames()) {
|
|
|
|
currentFrame = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
movie->renderFrame(_screen, 320, 200, currentFrame);
|
|
|
|
_font->drawStringToPlane("This is only a test!", _screen, 320, 200, 75, 179, 136);
|
|
|
|
_font->drawStringToPlane("Nothing scripted!", _screen, 320, 200, 85, 189, 136);
|
2004-10-15 06:06:47 +00:00
|
|
|
updateScreen();
|
|
|
|
while (g_system->pollEvent(event)) {
|
2004-12-05 17:42:20 +00:00
|
|
|
switch (event.type) {
|
2004-11-11 13:37:35 +00:00
|
|
|
case OSystem::EVENT_QUIT:
|
|
|
|
g_system->quit();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_system->delayMillis(10);
|
|
|
|
}
|
2004-11-11 13:37:35 +00:00
|
|
|
|
|
|
|
delete movie;
|
|
|
|
delete image;
|
|
|
|
delete [] _buffer;
|
2004-11-23 00:03:25 +00:00
|
|
|
|
|
|
|
return 0;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::shutdown() {
|
|
|
|
_system->quit();
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
|
|
|
|
void KyraEngine::updateScreen(void) {
|
2004-11-10 18:09:14 +00:00
|
|
|
_system->copyRectToScreen(_screen, 320, 0, 0, 320, 200);
|
2004-10-16 22:28:29 +00:00
|
|
|
_system->updateScreen();
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::setCurrentPalette(Palette* pal, bool delNextTime) {
|
2004-11-11 13:37:35 +00:00
|
|
|
if (!pal)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// if (_delPalNextTime)
|
|
|
|
// delete _currentPal;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
// _delPalNextTime = delNextTime;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2004-11-11 13:37:35 +00:00
|
|
|
// _currentPal = pal;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2004-10-16 22:28:29 +00:00
|
|
|
if (pal->getData()) {
|
|
|
|
_system->setPalette(pal->getData(), 0, 256);
|
|
|
|
} else {
|
|
|
|
warning("palette contains no data");
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
|
|
|
|
2004-04-09 12:36:06 +00:00
|
|
|
} // End of namespace KYRA
|
|
|
|
|