2005-01-09 16:06:29 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
2006-01-18 17:39:49 +00:00
|
|
|
* Copyright (C) 2004-2006 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
|
2005-10-18 01:30:26 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-04-09 12:36:06 +00:00
|
|
|
*
|
2006-02-09 12:19:53 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2004-04-09 12:36:06 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2005-06-24 15:23:51 +00:00
|
|
|
#include "common/stdafx.h"
|
2004-04-09 12:36:06 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
#include "backends/fs/fs.h"
|
|
|
|
|
2004-04-09 12:36:06 +00:00
|
|
|
#include "base/gameDetector.h"
|
|
|
|
#include "base/plugins.h"
|
|
|
|
|
|
|
|
#include "common/config-manager.h"
|
2005-08-19 22:12:09 +00:00
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/system.h"
|
2005-10-13 21:12:47 +00:00
|
|
|
#include "common/md5.h"
|
2005-12-10 17:51:40 +00:00
|
|
|
#include "common/savefile.h"
|
2005-08-19 22:12:09 +00:00
|
|
|
|
|
|
|
#include "sound/mixer.h"
|
2004-11-11 13:37:35 +00:00
|
|
|
#include "sound/mididrv.h"
|
2004-04-09 12:36:06 +00:00
|
|
|
|
2006-01-04 07:39:16 +00:00
|
|
|
#include "gui/message.h"
|
|
|
|
|
2005-06-24 16:01:42 +00:00
|
|
|
#include "kyra/kyra.h"
|
|
|
|
#include "kyra/resource.h"
|
2005-08-19 22:12:09 +00:00
|
|
|
#include "kyra/screen.h"
|
2005-06-24 16:01:42 +00:00
|
|
|
#include "kyra/script.h"
|
2005-10-06 11:57:02 +00:00
|
|
|
#include "kyra/seqplayer.h"
|
2005-06-24 16:01:42 +00:00
|
|
|
#include "kyra/sound.h"
|
2005-10-03 20:21:18 +00:00
|
|
|
#include "kyra/sprites.h"
|
2005-08-19 22:12:09 +00:00
|
|
|
#include "kyra/wsamovie.h"
|
2006-01-02 22:58:59 +00:00
|
|
|
#include "kyra/animator.h"
|
|
|
|
#include "kyra/text.h"
|
2005-12-09 14:52:31 +00:00
|
|
|
#include "kyra/debugger.h"
|
2005-08-19 22:12:09 +00:00
|
|
|
|
|
|
|
using namespace Kyra;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2005-10-13 21:12:47 +00:00
|
|
|
enum {
|
|
|
|
// We only compute MD5 of the first megabyte of our data files.
|
|
|
|
kMD5FileSizeLimit = 1024 * 1024
|
|
|
|
};
|
|
|
|
|
|
|
|
// Kyra MD5 detection brutally ripped from the Gobliins engine.
|
2004-10-15 06:06:47 +00:00
|
|
|
struct KyraGameSettings {
|
2006-01-21 13:01:20 +00:00
|
|
|
const char *gameid;
|
2004-10-16 22:28:29 +00:00
|
|
|
const char *description;
|
2005-10-13 21:12:47 +00:00
|
|
|
byte id;
|
2004-10-16 22:28:29 +00:00
|
|
|
uint32 features;
|
2005-10-13 21:12:47 +00:00
|
|
|
const char *md5sum;
|
|
|
|
const char *checkFile;
|
2004-10-15 06:06:47 +00:00
|
|
|
};
|
|
|
|
|
2006-02-10 10:42:21 +00:00
|
|
|
// We could get rid of md5 detection at least for kyra 1 since we can locate all
|
|
|
|
// needed files for detecting the right language and version (Floppy, Talkie)
|
2005-10-13 21:12:47 +00:00
|
|
|
static const KyraGameSettings kyra_games[] = {
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_ENGLISH | GF_FLOPPY, // english floppy 1.0 from Malice
|
2005-11-09 22:26:12 +00:00
|
|
|
"3c244298395520bb62b5edfe41688879", "GEMCUT.EMC" },
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_ENGLISH | GF_FLOPPY,
|
2005-10-13 21:12:47 +00:00
|
|
|
"796e44863dd22fa635b042df1bf16673", "GEMCUT.EMC" },
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_FRENCH | GF_FLOPPY,
|
2005-10-13 21:12:47 +00:00
|
|
|
"abf8eb360e79a6c2a837751fbd4d3d24", "GEMCUT.EMC" },
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_GERMAN | GF_FLOPPY,
|
2005-10-13 21:12:47 +00:00
|
|
|
"6018e1dfeaca7fe83f8d0b00eb0dd049", "GEMCUT.EMC"},
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_GERMAN | GF_FLOPPY, // from Arne.F
|
2006-02-06 00:43:34 +00:00
|
|
|
"f0b276781f47c130f423ec9679fe9ed9", "GEMCUT.EMC"},
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_SPANISH | GF_FLOPPY, // from VooD
|
2005-10-18 19:59:51 +00:00
|
|
|
"8909b41596913b3f5deaf3c9f1017b01", "GEMCUT.EMC"},
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_SPANISH | GF_FLOPPY, // floppy 1.8 from clemmy
|
2005-11-19 00:16:45 +00:00
|
|
|
"747861d2a9c643c59fdab570df5b9093", "GEMCUT.EMC"},
|
2006-03-14 19:48:08 +00:00
|
|
|
//{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_AMIGA | GF_FLOPPY | GF_ENGLISH,
|
|
|
|
// "2bd1da653eaefd691e050e4a9eb68a64", "GEMCUT.PAK" },
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_ENGLISH | GF_TALKIE,
|
2005-10-13 21:12:47 +00:00
|
|
|
"fac399fe62f98671e56a005c5e94e39f", "GEMCUT.PAK" },
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_GERMAN | GF_TALKIE,
|
2005-10-13 21:12:47 +00:00
|
|
|
"230f54e6afc007ab4117159181a1c722", "GEMCUT.PAK" },
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia", GI_KYRA1, GF_FRENCH | GF_TALKIE,
|
2005-10-13 21:12:47 +00:00
|
|
|
"b037c41768b652a040360ffa3556fd2a", "GEMCUT.PAK" },
|
2006-02-10 10:42:21 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia Demo", GI_KYRA1, GF_DEMO | GF_ENGLISH,
|
2005-10-13 21:12:47 +00:00
|
|
|
"fb722947d94897512b13b50cc84fd648", "DEMO1.WSA" },
|
|
|
|
{ 0, 0, 0, 0, 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
// Keep list of different supported games
|
2006-03-09 02:52:51 +00:00
|
|
|
static const PlainGameDescriptor kyra_list[] = {
|
2006-02-18 00:12:36 +00:00
|
|
|
{ "kyra1", "The Legend of Kyrandia" },
|
|
|
|
{ 0, 0 }
|
2004-10-15 06:06:47 +00:00
|
|
|
};
|
2004-04-09 12:36:06 +00:00
|
|
|
|
2006-02-10 10:42:21 +00:00
|
|
|
struct KyraLanguageTable {
|
|
|
|
const char *file;
|
|
|
|
uint32 language;
|
|
|
|
Common::Language detLanguage;
|
|
|
|
};
|
|
|
|
|
|
|
|
static const KyraLanguageTable kyra_languages[] = {
|
|
|
|
{ "MAIN15.CPS", GF_ENGLISH, Common::EN_USA },
|
|
|
|
{ "MAIN_ENG.CPS", GF_ENGLISH, Common::EN_USA },
|
|
|
|
{ "MAIN_FRE.CPS", GF_FRENCH, Common::FR_FRA },
|
|
|
|
{ "MAIN_GER.CPS", GF_GERMAN, Common::DE_DEU },
|
|
|
|
{ "MAIN_SPA.CPS", GF_SPANISH, Common::ES_ESP },
|
|
|
|
{ 0, 0, Common::UNK_LANG }
|
|
|
|
};
|
|
|
|
|
|
|
|
static Common::Language convertKyraLang(uint32 features) {
|
|
|
|
if (features & GF_ENGLISH) {
|
|
|
|
return Common::EN_USA;
|
|
|
|
} else if (features & GF_FRENCH) {
|
|
|
|
return Common::FR_FRA;
|
|
|
|
} else if (features & GF_GERMAN) {
|
|
|
|
return Common::DE_DEU;
|
|
|
|
} else if (features & GF_SPANISH) {
|
|
|
|
return Common::ES_ESP;
|
|
|
|
}
|
|
|
|
return Common::UNK_LANG;
|
|
|
|
}
|
|
|
|
|
2006-02-18 11:15:37 +00:00
|
|
|
GameList Engine_KYRA_gameIDList() {
|
2004-10-16 22:28:29 +00:00
|
|
|
GameList games;
|
2006-03-09 02:52:51 +00:00
|
|
|
const PlainGameDescriptor *g = kyra_list;
|
2005-10-13 21:12:47 +00:00
|
|
|
|
2006-01-21 13:01:20 +00:00
|
|
|
while (g->gameid) {
|
2006-02-17 00:22:53 +00:00
|
|
|
games.push_back(*g);
|
2004-10-16 22:28:29 +00:00
|
|
|
g++;
|
|
|
|
}
|
|
|
|
return games;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
2006-03-09 02:52:51 +00:00
|
|
|
GameDescriptor Engine_KYRA_findGameID(const char *gameid) {
|
|
|
|
const PlainGameDescriptor *g = kyra_list;
|
2006-02-18 11:15:37 +00:00
|
|
|
while (g->gameid) {
|
2006-03-02 22:29:01 +00:00
|
|
|
if (0 == scumm_stricmp(gameid, g->gameid))
|
2006-02-18 11:15:37 +00:00
|
|
|
break;
|
|
|
|
g++;
|
|
|
|
}
|
|
|
|
return *g;
|
|
|
|
}
|
|
|
|
|
2004-04-09 12:36:06 +00:00
|
|
|
DetectedGameList Engine_KYRA_detectGames(const FSList &fslist) {
|
|
|
|
DetectedGameList detectedGames;
|
2005-10-13 21:12:47 +00:00
|
|
|
const KyraGameSettings *g;
|
|
|
|
FSList::const_iterator file;
|
2004-10-15 06:06:47 +00:00
|
|
|
|
2005-10-13 21:12:47 +00:00
|
|
|
// Iterate over all files in the given directory
|
|
|
|
bool isFound = false;
|
|
|
|
for (file = fslist.begin(); file != fslist.end(); file++) {
|
|
|
|
if (file->isDirectory())
|
2004-10-15 06:06:47 +00:00
|
|
|
continue;
|
|
|
|
|
2006-01-21 13:01:20 +00:00
|
|
|
for (g = kyra_games; g->gameid; g++) {
|
2005-10-13 21:12:47 +00:00
|
|
|
if (scumm_stricmp(file->displayName().c_str(), g->checkFile) == 0)
|
|
|
|
isFound = true;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
2005-10-13 21:12:47 +00:00
|
|
|
if (isFound)
|
|
|
|
break;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
2005-10-13 21:12:47 +00:00
|
|
|
if (file == fslist.end())
|
|
|
|
return detectedGames;
|
|
|
|
|
|
|
|
uint8 md5sum[16];
|
|
|
|
char md5str[32 + 1];
|
|
|
|
|
|
|
|
if (Common::md5_file(file->path().c_str(), md5sum, NULL, kMD5FileSizeLimit)) {
|
|
|
|
for (int i = 0; i < 16; i++) {
|
|
|
|
sprintf(md5str + i * 2, "%02x", (int)md5sum[i]);
|
|
|
|
}
|
2006-01-21 13:01:20 +00:00
|
|
|
for (g = kyra_games; g->gameid; g++) {
|
2005-10-13 21:12:47 +00:00
|
|
|
if (strcmp(g->md5sum, (char *)md5str) == 0) {
|
2006-03-09 12:52:54 +00:00
|
|
|
DetectedGame dg(*g, convertKyraLang(g->features));
|
|
|
|
dg.updateDesc(); // Append the language, if set, to the description.
|
|
|
|
detectedGames.push_back(dg);
|
2005-10-13 21:12:47 +00:00
|
|
|
}
|
|
|
|
}
|
2006-03-28 09:42:54 +00:00
|
|
|
if (detectedGames.empty()) {
|
2006-02-14 01:19:30 +00:00
|
|
|
printf("Unknown MD5 (%s)! Please report the details (language, platform, etc.) of this game to the ScummVM team\n", md5str);
|
2005-10-13 21:12:47 +00:00
|
|
|
|
2006-03-09 02:52:51 +00:00
|
|
|
const PlainGameDescriptor *g1 = kyra_list;
|
2006-01-21 13:01:20 +00:00
|
|
|
while (g1->gameid) {
|
2006-02-17 00:22:53 +00:00
|
|
|
detectedGames.push_back(*g1);
|
2005-10-13 21:12:47 +00:00
|
|
|
g1++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-10-16 22:28:29 +00:00
|
|
|
return detectedGames;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
Engine *Engine_KYRA_create(GameDetector *detector, OSystem *system) {
|
|
|
|
return new KyraEngine(detector, system);
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
2005-03-25 17:55:57 +00:00
|
|
|
REGISTER_PLUGIN(KYRA, "Legend of Kyrandia Engine")
|
2004-04-09 12:36:06 +00:00
|
|
|
|
|
|
|
namespace Kyra {
|
2005-08-19 22:12:09 +00:00
|
|
|
|
|
|
|
KyraEngine::KyraEngine(GameDetector *detector, OSystem *system)
|
|
|
|
: Engine(system) {
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq_Forest = _seq_KallakWriting = _seq_KyrandiaLogo = _seq_KallakMalcolm =
|
|
|
|
_seq_MalcolmTree = _seq_WestwoodLogo = _seq_Demo1 = _seq_Demo2 = _seq_Demo3 =
|
|
|
|
_seq_Demo4 = 0;
|
|
|
|
|
|
|
|
_seq_WSATable = _seq_CPSTable = _seq_COLTable = _seq_textsTable = 0;
|
|
|
|
_seq_WSATable_Size = _seq_CPSTable_Size = _seq_COLTable_Size = _seq_textsTable_Size = 0;
|
2005-12-26 14:53:51 +00:00
|
|
|
|
|
|
|
_roomFilenameTable = _characterImageTable = 0;
|
|
|
|
_roomFilenameTableSize = _characterImageTableSize = 0;
|
|
|
|
_itemList = _takenList = _placedList = _droppedList = _noDropList = 0;
|
|
|
|
_itemList_Size = _takenList_Size = _placedList_Size = _droppedList_Size = _noDropList_Size = 0;
|
|
|
|
_putDownFirst = _waitForAmulet = _blackJewel = _poisonGone = _healingTip = 0;
|
|
|
|
_putDownFirst_Size = _waitForAmulet_Size = _blackJewel_Size = _poisonGone_Size = _healingTip_Size = 0;
|
2005-12-31 17:25:47 +00:00
|
|
|
_thePoison = _fluteString = _wispJewelStrings = _magicJewelString = _flaskFull = _fullFlask = 0;
|
|
|
|
_thePoison_Size = _fluteString_Size = _wispJewelStrings_Size = 0;
|
|
|
|
_magicJewelString_Size = _flaskFull_Size = _fullFlask_Size = 0;
|
2005-12-26 14:53:51 +00:00
|
|
|
|
2006-03-18 14:43:18 +00:00
|
|
|
_defaultShapeTable = 0;
|
|
|
|
_healingShapeTable = _healingShape2Table = 0;
|
2005-12-26 14:53:51 +00:00
|
|
|
_defaultShapeTableSize = _healingShapeTableSize = _healingShape2TableSize = 0;
|
2005-12-31 17:25:47 +00:00
|
|
|
_posionDeathShapeTable = _fluteAnimShapeTable = 0;
|
|
|
|
_posionDeathShapeTableSize = _fluteAnimShapeTableSize = 0;
|
|
|
|
_winterScrollTable = _winterScroll1Table = _winterScroll2Table = 0;
|
|
|
|
_winterScrollTableSize = _winterScroll1TableSize = _winterScroll2TableSize = 0;
|
|
|
|
_drinkAnimationTable = _brandonToWispTable = _magicAnimationTable = _brandonStoneTable = 0;
|
|
|
|
_drinkAnimationTableSize = _brandonToWispTableSize = _magicAnimationTableSize = _brandonStoneTableSize = 0;
|
2006-03-18 14:43:18 +00:00
|
|
|
memset(&_specialPalettes, 0, sizeof(_specialPalettes));
|
2004-04-09 12:36:06 +00:00
|
|
|
|
|
|
|
// Setup mixer
|
|
|
|
if (!_mixer->isReady()) {
|
|
|
|
warning("Sound initialization failed.");
|
|
|
|
}
|
|
|
|
|
2005-05-11 01:02:33 +00:00
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, ConfMan.getInt("sfx_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, ConfMan.getInt("music_volume"));
|
2005-10-12 19:15:32 +00:00
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, ConfMan.getInt("speech_volume"));
|
2004-04-09 12:36:06 +00:00
|
|
|
|
2006-02-14 23:31:25 +00:00
|
|
|
// sets up all engine specific debug levels
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelScriptFuncs, "ScriptFuncs", "Script function debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelScript, "Script", "Script interpreter debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelSprites, "Sprites", "Sprite debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelScreen, "Screen", "Screen debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelSound, "Sound", "Sound debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelAnimator, "Animator", "Animator debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelMain, "Main", "Generic debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelGUI, "GUI", "GUI debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelSequence, "Sequence", "Sequence debug level");
|
|
|
|
Common::addSpecialDebugLevel(kDebugLevelMovie, "Movie", "Movie debug level");
|
|
|
|
|
2005-10-13 21:12:47 +00:00
|
|
|
// Detect game features based on MD5. Again brutally ripped from Gobliins.
|
|
|
|
uint8 md5sum[16];
|
|
|
|
char md5str[32 + 1];
|
|
|
|
|
|
|
|
const KyraGameSettings *g;
|
|
|
|
bool found = false;
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
// Fallback. Maybe we will be able to determine game type from game
|
|
|
|
// data contents
|
2005-10-14 11:25:48 +00:00
|
|
|
_features = 0;
|
2005-10-13 21:12:47 +00:00
|
|
|
|
2006-01-21 13:01:20 +00:00
|
|
|
for (g = kyra_games; g->gameid; g++) {
|
2005-10-13 21:12:47 +00:00
|
|
|
if (!Common::File::exists(g->checkFile))
|
|
|
|
continue;
|
|
|
|
|
2006-03-25 04:17:17 +00:00
|
|
|
if (Common::md5_file(g->checkFile, md5sum, NULL, kMD5FileSizeLimit)) {
|
2005-10-13 21:12:47 +00:00
|
|
|
for (int j = 0; j < 16; j++) {
|
|
|
|
sprintf(md5str + j*2, "%02x", (int)md5sum[j]);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (strcmp(g->md5sum, (char *)md5str) == 0) {
|
|
|
|
_features = g->features;
|
|
|
|
_game = g->id;
|
|
|
|
|
|
|
|
if (g->description)
|
|
|
|
g_system->setWindowCaption(g->description);
|
|
|
|
|
|
|
|
found = true;
|
|
|
|
break;
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2005-10-13 21:12:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2006-02-14 01:19:30 +00:00
|
|
|
printf("Unknown MD5 (%s)! Please report the details (language, platform, etc.) of this game to the ScummVM team", md5str);
|
2006-02-10 10:42:21 +00:00
|
|
|
_features = 0;
|
2005-10-14 11:25:48 +00:00
|
|
|
_game = GI_KYRA1;
|
2005-10-18 19:59:51 +00:00
|
|
|
Common::File test;
|
|
|
|
if (test.open("INTRO.VRM")) {
|
|
|
|
_features |= GF_TALKIE;
|
|
|
|
} else {
|
|
|
|
_features |= GF_FLOPPY;
|
|
|
|
}
|
2006-02-10 10:42:21 +00:00
|
|
|
|
|
|
|
// tries to detect the language
|
|
|
|
const KyraLanguageTable *lang = kyra_languages;
|
|
|
|
for (; lang->file; ++lang) {
|
|
|
|
if (test.open(lang->file)) {
|
|
|
|
_features |= lang->language;
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
_features |= GF_LNGUNK;
|
|
|
|
}
|
2004-11-11 13:37:35 +00:00
|
|
|
}
|
2004-11-23 00:03:25 +00:00
|
|
|
}
|
|
|
|
|
2004-11-24 00:14:21 +00:00
|
|
|
int KyraEngine::init(GameDetector &detector) {
|
|
|
|
_system->beginGFXTransaction();
|
2006-02-17 00:01:18 +00:00
|
|
|
initCommonGFX(detector, false);
|
2006-02-11 00:17:20 +00:00
|
|
|
//for debug reasons (see Screen::updateScreen)
|
|
|
|
//_system->initSize(640, 200);
|
2004-11-24 00:14:21 +00:00
|
|
|
_system->initSize(320, 200);
|
|
|
|
_system->endGFXTransaction();
|
|
|
|
|
2006-03-28 15:15:36 +00:00
|
|
|
// for now we prefer Adlib over native MIDI
|
2005-12-30 16:36:53 +00:00
|
|
|
int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB/* | MDT_PREFER_MIDI*/);
|
2004-11-14 14:11:54 +00:00
|
|
|
|
2005-12-30 14:18:21 +00:00
|
|
|
if (midiDriver == MD_ADLIB) {
|
2006-02-27 22:39:55 +00:00
|
|
|
_sound = new SoundAdlibPC(_mixer, this);
|
|
|
|
assert(_sound);
|
|
|
|
} else {
|
|
|
|
bool native_mt32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
|
|
|
|
|
|
|
|
MidiDriver *driver = MidiDriver::createMidi(midiDriver);
|
|
|
|
assert(driver);
|
|
|
|
if (native_mt32) {
|
|
|
|
driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
|
|
|
|
}
|
2004-11-14 14:11:54 +00:00
|
|
|
|
2006-02-27 22:39:55 +00:00
|
|
|
SoundMidiPC *soundMidiPc = new SoundMidiPC(driver, _mixer, this);
|
|
|
|
_sound = soundMidiPc;
|
|
|
|
assert(_sound);
|
|
|
|
soundMidiPc->hasNativeMT32(native_mt32);
|
2006-03-28 15:15:36 +00:00
|
|
|
|
|
|
|
// Unlike some SCUMM games, it's not that the MIDI sounds are
|
|
|
|
// missing. It's just that at least at the time of writing they
|
|
|
|
// decidedly inferior to the Adlib ones.
|
|
|
|
|
|
|
|
if (ConfMan.getBool("multi_midi")) {
|
|
|
|
SoundAdlibPC *adlib = new SoundAdlibPC(_mixer, this);
|
|
|
|
assert(adlib);
|
|
|
|
|
|
|
|
_sound = new MixedSoundDriver(this, _mixer, soundMidiPc, adlib);
|
|
|
|
assert(_sound);
|
|
|
|
}
|
2006-02-27 22:39:55 +00:00
|
|
|
}
|
|
|
|
if (!_sound->init()) {
|
|
|
|
error("Couldn't init sound");
|
|
|
|
}
|
2006-01-13 23:06:04 +00:00
|
|
|
_sound->setVolume(255);
|
2005-09-11 14:35:34 +00:00
|
|
|
|
2005-12-10 17:51:40 +00:00
|
|
|
_saveFileMan = _system->getSavefileManager();
|
|
|
|
assert(_saveFileMan);
|
2005-08-19 22:12:09 +00:00
|
|
|
_res = new Resource(this);
|
|
|
|
assert(_res);
|
|
|
|
_screen = new Screen(this, _system);
|
|
|
|
assert(_screen);
|
2005-10-03 20:21:18 +00:00
|
|
|
_sprites = new Sprites(this, _system);
|
|
|
|
assert(_sprites);
|
2005-10-06 11:57:02 +00:00
|
|
|
_seq = new SeqPlayer(this, _system);
|
|
|
|
assert(_seq);
|
2006-01-03 19:03:09 +00:00
|
|
|
_animator = new ScreenAnimator(this, _system);
|
2006-01-02 22:58:59 +00:00
|
|
|
assert(_animator);
|
|
|
|
_animator->init(5, 11, 12);
|
|
|
|
assert(*_animator);
|
|
|
|
_text = new TextDisplayer(_screen);
|
|
|
|
assert(_text);
|
2006-03-18 14:43:18 +00:00
|
|
|
_staticres = new StaticResource(this);
|
|
|
|
assert(_staticres);
|
|
|
|
assert(_staticres->init());
|
|
|
|
initStaticResource();
|
2005-10-29 18:37:40 +00:00
|
|
|
|
2005-12-10 15:52:38 +00:00
|
|
|
_paletteChanged = 1;
|
2005-10-29 18:37:40 +00:00
|
|
|
_currentCharacter = 0;
|
|
|
|
_characterList = new Character[11];
|
|
|
|
assert(_characterList);
|
|
|
|
for (int i = 0; i < 11; ++i) {
|
|
|
|
memset(&_characterList[i], 0, sizeof(Character));
|
2005-12-24 18:00:35 +00:00
|
|
|
memset(_characterList[i].inventoryItems, 0xFF, sizeof(_characterList[i].inventoryItems));
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
_characterList[0].sceneId = 5;
|
|
|
|
_characterList[0].height = 48;
|
|
|
|
_characterList[0].facing = 3;
|
|
|
|
_characterList[0].currentAnimFrame = 7;
|
|
|
|
|
|
|
|
_scriptInterpreter = new ScriptHelper(this);
|
|
|
|
assert(_scriptInterpreter);
|
|
|
|
|
|
|
|
_npcScriptData = new ScriptData;
|
|
|
|
memset(_npcScriptData, 0, sizeof(ScriptData));
|
|
|
|
assert(_npcScriptData);
|
2005-12-09 23:02:16 +00:00
|
|
|
_npcScript = new ScriptState;
|
|
|
|
assert(_npcScript);
|
|
|
|
memset(_npcScript, 0, sizeof(ScriptState));
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
_scriptMain = new ScriptState;
|
|
|
|
assert(_scriptMain);
|
|
|
|
memset(_scriptMain, 0, sizeof(ScriptState));
|
|
|
|
|
|
|
|
_scriptClickData = new ScriptData;
|
|
|
|
assert(_scriptClickData);
|
|
|
|
memset(_scriptClickData, 0, sizeof(ScriptData));
|
|
|
|
_scriptClick = new ScriptState;
|
|
|
|
assert(_scriptClick);
|
|
|
|
memset(_scriptClick, 0, sizeof(ScriptState));
|
|
|
|
|
2005-12-09 14:52:31 +00:00
|
|
|
_debugger = new Debugger(this);
|
|
|
|
assert(_debugger);
|
2005-10-29 18:37:40 +00:00
|
|
|
memset(_shapes, 0, sizeof(_shapes));
|
2006-01-02 13:20:02 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) {
|
|
|
|
_movieObjects[i] = createWSAMovie();
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
memset(_flagsTable, 0, sizeof(_flagsTable));
|
|
|
|
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag = false;
|
|
|
|
_abortWalkFlag2 = false;
|
2005-12-09 14:52:31 +00:00
|
|
|
_talkingCharNum = -1;
|
2005-11-10 14:08:50 +00:00
|
|
|
_charSayUnk3 = -1;
|
2005-10-30 19:58:51 +00:00
|
|
|
_mouseX = _mouseY = -1;
|
2005-12-09 14:52:31 +00:00
|
|
|
memset(_currSentenceColor, 0, 3);
|
|
|
|
_startSentencePalIndex = -1;
|
|
|
|
_fadeText = false;
|
|
|
|
|
2005-12-31 15:41:37 +00:00
|
|
|
_cauldronState = 0;
|
2005-12-31 17:25:47 +00:00
|
|
|
_crystalState[0] = _crystalState[1] = -1;
|
2005-12-31 15:41:37 +00:00
|
|
|
|
2005-12-29 22:18:40 +00:00
|
|
|
_brandonStatusBit = 0;
|
|
|
|
_brandonStatusBit0x02Flag = _brandonStatusBit0x20Flag = 10;
|
2005-10-29 18:37:40 +00:00
|
|
|
_brandonPosX = _brandonPosY = -1;
|
2005-12-26 14:53:51 +00:00
|
|
|
_deathHandler = 0xFF;
|
2005-12-28 21:34:40 +00:00
|
|
|
_poisonDeathCounter = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
|
|
|
|
memset(_itemTable, 0, sizeof(_itemTable));
|
|
|
|
memset(_exitList, 0xFFFF, sizeof(_exitList));
|
|
|
|
_exitListPtr = 0;
|
2005-11-26 16:37:20 +00:00
|
|
|
_pathfinderFlag = _pathfinderFlag2 = 0;
|
2005-11-10 14:08:50 +00:00
|
|
|
_lastFindWayRet = 0;
|
2005-11-09 22:26:12 +00:00
|
|
|
_sceneChangeState = _loopFlag2 = 0;
|
2005-11-11 22:17:06 +00:00
|
|
|
_timerNextRun = 0;
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
_movFacingTable = new int[150];
|
|
|
|
assert(_movFacingTable);
|
2005-11-01 14:19:50 +00:00
|
|
|
_movFacingTable[0] = 8;
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2006-03-08 13:15:13 +00:00
|
|
|
_configTextspeed = 1;
|
|
|
|
_configWalkspeed = 2;
|
|
|
|
_configMusic = true;
|
|
|
|
_configSounds = true;
|
|
|
|
_configVoice = 1;
|
|
|
|
|
2006-02-13 03:52:57 +00:00
|
|
|
_skipFlag = false;
|
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
_marbleVaseItem = -1;
|
2005-12-24 18:00:35 +00:00
|
|
|
memset(_foyerItemTable, -1, sizeof(_foyerItemTable));
|
2005-11-18 23:55:31 +00:00
|
|
|
_mouseState = _itemInHand = -1;
|
|
|
|
_handleInput = false;
|
2005-11-27 10:02:23 +00:00
|
|
|
|
|
|
|
_currentRoom = 0xFFFF;
|
2005-12-09 23:02:16 +00:00
|
|
|
_scenePhasingFlag = 0;
|
2005-12-08 17:19:18 +00:00
|
|
|
_lastProcessedItem = 0;
|
|
|
|
_lastProcessedItemHeight = 16;
|
2005-12-10 19:02:56 +00:00
|
|
|
|
2005-12-13 16:56:33 +00:00
|
|
|
_unkScreenVar1 = 1;
|
|
|
|
_unkScreenVar2 = 0;
|
|
|
|
_unkScreenVar3 = 0;
|
2006-01-04 07:39:16 +00:00
|
|
|
_unkAmuletVar = 0;
|
2005-12-22 18:14:52 +00:00
|
|
|
|
2006-01-06 10:45:42 +00:00
|
|
|
_endSequenceNeedLoading = 1;
|
|
|
|
_malcolmFlag = 0;
|
|
|
|
_beadStateVar = 0;
|
|
|
|
_endSequenceSkipFlag = 0;
|
|
|
|
_unkEndSeqVar2 = 0;
|
|
|
|
_endSequenceBackUpRect = 0;
|
|
|
|
_unkEndSeqVar4 = 0;
|
|
|
|
_unkEndSeqVar5 = 0;
|
|
|
|
_lastDisplayedPanPage = 0;
|
|
|
|
memset(_panPagesTable, 0, sizeof(_panPagesTable));
|
|
|
|
_finalA = _finalB = _finalC = 0;
|
2006-02-11 08:31:13 +00:00
|
|
|
memset(&_kyragemFadingState, 0, sizeof(_kyragemFadingState));
|
|
|
|
_kyragemFadingState.gOffset = 0x13;
|
|
|
|
_kyragemFadingState.bOffset = 0x13;
|
|
|
|
|
2005-12-24 18:00:35 +00:00
|
|
|
_mousePressFlag = false;
|
2006-01-03 23:41:52 +00:00
|
|
|
|
|
|
|
_targetName = detector._targetName;
|
2006-01-27 08:23:53 +00:00
|
|
|
_menuDirectlyToLoad = false;
|
2006-01-12 14:53:23 +00:00
|
|
|
|
|
|
|
_lastMusicCommand = 0;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2006-02-09 12:19:53 +00:00
|
|
|
_gameSpeed = 60;
|
|
|
|
_tickLength = (uint8)(1000.0 / _gameSpeed);
|
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
return 0;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KyraEngine::~KyraEngine() {
|
2006-01-06 10:45:42 +00:00
|
|
|
closeFinalWsa();
|
2006-01-02 13:20:02 +00:00
|
|
|
_scriptInterpreter->unloadScript(_npcScriptData);
|
|
|
|
_scriptInterpreter->unloadScript(_scriptClickData);
|
|
|
|
|
2005-12-09 14:52:31 +00:00
|
|
|
delete _debugger;
|
2005-10-03 20:21:18 +00:00
|
|
|
delete _sprites;
|
2006-01-02 22:58:59 +00:00
|
|
|
delete _animator;
|
2005-08-19 22:12:09 +00:00
|
|
|
delete _screen;
|
|
|
|
delete _res;
|
2006-01-13 23:06:04 +00:00
|
|
|
delete _sound;
|
2005-12-10 17:51:40 +00:00
|
|
|
delete _saveFileMan;
|
2005-10-06 11:57:02 +00:00
|
|
|
delete _seq;
|
2005-10-29 18:37:40 +00:00
|
|
|
delete _scriptInterpreter;
|
2006-01-02 22:58:59 +00:00
|
|
|
delete _text;
|
2005-10-29 18:37:40 +00:00
|
|
|
|
|
|
|
delete _npcScriptData;
|
|
|
|
delete _scriptMain;
|
|
|
|
|
|
|
|
delete _scriptClickData;
|
|
|
|
delete _scriptClick;
|
|
|
|
|
|
|
|
delete [] _characterList;
|
2005-10-22 00:24:07 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
delete [] _movFacingTable;
|
2006-01-22 09:34:12 +00:00
|
|
|
|
|
|
|
free(_scrollUpButton.process0PtrShape);
|
|
|
|
free(_scrollUpButton.process1PtrShape);
|
|
|
|
free(_scrollUpButton.process2PtrShape);
|
|
|
|
free(_scrollDownButton.process0PtrShape);
|
|
|
|
free(_scrollDownButton.process1PtrShape);
|
|
|
|
free(_scrollDownButton.process2PtrShape);
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
for (int i = 0; i < ARRAYSIZE(_shapes); ++i) {
|
|
|
|
if (_shapes[i] != 0) {
|
|
|
|
free(_shapes[i]);
|
2006-01-02 13:20:02 +00:00
|
|
|
_shapes[i] = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
for (int i2 = 0; i2 < ARRAYSIZE(_shapes); i2++) {
|
|
|
|
if (_shapes[i2] == _shapes[i] && i2 != i) {
|
|
|
|
_shapes[i2] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (int i = 0; i < ARRAYSIZE(_sceneAnimTable); ++i) {
|
|
|
|
free(_sceneAnimTable[i]);
|
2005-10-22 00:24:07 +00:00
|
|
|
}
|
2006-02-14 23:31:25 +00:00
|
|
|
|
|
|
|
Common::clearAllSpecialDebugLevels();
|
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() {
|
2005-08-19 22:12:09 +00:00
|
|
|
_quitFlag = false;
|
2005-09-08 19:09:52 +00:00
|
|
|
uint32 sz;
|
2005-09-10 06:48:34 +00:00
|
|
|
|
2006-03-14 19:48:08 +00:00
|
|
|
if (_features & GF_FLOPPY && !(_features & GF_AMIGA)) {
|
2005-09-10 06:48:34 +00:00
|
|
|
_screen->loadFont(Screen::FID_6_FNT, _res->fileData("6.FNT", &sz));
|
|
|
|
}
|
2005-09-08 19:09:52 +00:00
|
|
|
_screen->loadFont(Screen::FID_8_FNT, _res->fileData("8FAT.FNT", &sz));
|
2005-09-02 11:12:09 +00:00
|
|
|
_screen->setScreenDim(0);
|
2005-09-10 06:40:20 +00:00
|
|
|
|
2005-10-03 20:21:18 +00:00
|
|
|
_abortIntroFlag = false;
|
|
|
|
|
2005-10-13 21:12:47 +00:00
|
|
|
if (_features & GF_DEMO) {
|
2005-09-10 06:40:20 +00:00
|
|
|
seq_demo();
|
|
|
|
} else {
|
2005-11-10 14:08:50 +00:00
|
|
|
setGameFlag(0xF3);
|
|
|
|
setGameFlag(0xFD);
|
|
|
|
setGameFlag(0xEF);
|
2005-09-10 06:40:20 +00:00
|
|
|
seq_intro();
|
2006-01-27 08:23:53 +00:00
|
|
|
if (_skipIntroFlag &&_abortIntroFlag)
|
|
|
|
resetGameFlag(0xEF);
|
2005-09-10 06:40:20 +00:00
|
|
|
startup();
|
2005-11-10 14:08:50 +00:00
|
|
|
resetGameFlag(0xEF);
|
2005-09-10 06:40:20 +00:00
|
|
|
mainLoop();
|
|
|
|
}
|
2005-11-10 14:08:50 +00:00
|
|
|
quitGame();
|
2005-08-19 22:12:09 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-11-11 13:37:35 +00:00
|
|
|
|
2005-09-10 00:15:40 +00:00
|
|
|
void KyraEngine::startup() {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::startup()");
|
2005-09-10 00:15:40 +00:00
|
|
|
static const uint8 colorMap[] = { 0, 0, 0, 0, 12, 12, 12, 0, 0, 0, 0, 0 };
|
|
|
|
_screen->setTextColorMap(colorMap);
|
2005-09-10 20:03:53 +00:00
|
|
|
// _screen->setFont(Screen::FID_6_FNT);
|
2005-09-10 00:15:40 +00:00
|
|
|
_screen->setAnimBlockPtr(3750);
|
2005-10-29 18:37:40 +00:00
|
|
|
memset(_sceneAnimTable, 0, sizeof(_sceneAnimTable));
|
2005-10-22 00:24:07 +00:00
|
|
|
loadMouseShapes();
|
2005-10-29 18:37:40 +00:00
|
|
|
_currentCharacter = &_characterList[0];
|
|
|
|
for (int i = 1; i < 5; ++i)
|
2006-02-11 08:31:13 +00:00
|
|
|
_animator->setCharacterDefaultFrame(i);
|
2005-10-29 18:37:40 +00:00
|
|
|
for (int i = 5; i <= 10; ++i)
|
|
|
|
setCharactersPositions(i);
|
2006-02-11 08:31:13 +00:00
|
|
|
_animator->setCharactersHeight();
|
2006-02-09 07:37:19 +00:00
|
|
|
resetBrandonPoisonFlags();
|
2005-10-29 18:37:40 +00:00
|
|
|
_maskBuffer = _screen->getPagePtr(5);
|
|
|
|
_screen->_curPage = 0;
|
|
|
|
// XXX
|
|
|
|
for (int i = 0; i < 0x0C; ++i) {
|
|
|
|
int size = _screen->getRectSize(3, 24);
|
|
|
|
_shapes[365+i] = (byte*)malloc(size);
|
|
|
|
}
|
2005-12-10 15:52:38 +00:00
|
|
|
_shapes[0] = (uint8*)malloc(_screen->getRectSize(3, 24));
|
2005-10-29 18:37:40 +00:00
|
|
|
memset(_shapes[0], 0, _screen->getRectSize(3, 24));
|
2005-12-10 15:52:38 +00:00
|
|
|
_shapes[1] = (uint8*)malloc(_screen->getRectSize(4, 32));
|
2005-10-29 18:37:40 +00:00
|
|
|
memset(_shapes[1], 0, _screen->getRectSize(4, 32));
|
2005-12-10 15:52:38 +00:00
|
|
|
_shapes[2] = (uint8*)malloc(_screen->getRectSize(8, 69));
|
2005-10-29 18:37:40 +00:00
|
|
|
memset(_shapes[2], 0, _screen->getRectSize(8, 69));
|
2005-12-10 15:52:38 +00:00
|
|
|
_shapes[3] = (uint8*)malloc(_screen->getRectSize(8, 69));
|
2005-10-29 18:37:40 +00:00
|
|
|
memset(_shapes[3], 0, _screen->getRectSize(8, 69));
|
|
|
|
for (int i = 0; i < _roomTableSize; ++i) {
|
|
|
|
for (int item = 0; item < 12; ++item) {
|
|
|
|
_roomTable[i].itemsTable[item] = 0xFF;
|
2005-12-08 17:19:18 +00:00
|
|
|
_roomTable[i].itemsXPos[item] = 0xFFFF;
|
|
|
|
_roomTable[i].itemsYPos[item] = 0xFF;
|
2006-01-03 23:41:52 +00:00
|
|
|
_roomTable[i].needInit[item] = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
loadCharacterShapes();
|
|
|
|
loadSpecialEffectShapes();
|
|
|
|
loadItems();
|
2005-12-24 18:00:35 +00:00
|
|
|
loadButtonShapes();
|
|
|
|
initMainButtonList();
|
2005-10-29 18:37:40 +00:00
|
|
|
loadMainScreen();
|
2005-11-11 22:17:06 +00:00
|
|
|
setupTimers();
|
2005-10-29 18:37:40 +00:00
|
|
|
loadPalette("PALETTE.COL", _screen->_currentPalette);
|
2005-11-11 22:17:06 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
// XXX
|
2006-02-09 07:37:19 +00:00
|
|
|
_animator->initAnimStateList();
|
2005-10-29 18:37:40 +00:00
|
|
|
setCharactersInDefaultScene();
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
if (!_scriptInterpreter->loadScript("_STARTUP.EMC", _npcScriptData, _opcodeTable, _opcodeTableSize, 0)) {
|
|
|
|
error("Could not load \"_STARTUP.EMC\" script");
|
|
|
|
}
|
|
|
|
_scriptInterpreter->initScript(_scriptMain, _npcScriptData);
|
|
|
|
if (!_scriptInterpreter->startScript(_scriptMain, 0)) {
|
|
|
|
error("Could not start script function 0 of script \"_STARTUP.EMC\"");
|
|
|
|
}
|
|
|
|
while (_scriptInterpreter->validScript(_scriptMain)) {
|
|
|
|
_scriptInterpreter->runScript(_scriptMain);
|
|
|
|
}
|
|
|
|
|
|
|
|
_scriptInterpreter->unloadScript(_npcScriptData);
|
|
|
|
if (!_scriptInterpreter->loadScript("_NPC.EMC", _npcScriptData, _opcodeTable, _opcodeTableSize, 0)) {
|
|
|
|
error("Could not load \"_NPC.EMC\" script");
|
|
|
|
}
|
|
|
|
|
2006-03-12 17:08:46 +00:00
|
|
|
snd_playTheme(1);
|
2005-10-29 18:37:40 +00:00
|
|
|
enterNewScene(_currentCharacter->sceneId, _currentCharacter->facing, 0, 0, 1);
|
2006-01-27 08:23:53 +00:00
|
|
|
|
2006-02-09 12:19:53 +00:00
|
|
|
if (_abortIntroFlag && _skipFlag) {
|
2006-01-27 08:23:53 +00:00
|
|
|
_menuDirectlyToLoad = true;
|
|
|
|
_screen->setMouseCursor(1, 1, _shapes[4]);
|
|
|
|
buttonMenuCallback(0);
|
|
|
|
_menuDirectlyToLoad = false;
|
|
|
|
} else
|
|
|
|
saveGame(getSavegameFilename(0), "New game");
|
2005-09-10 00:15:40 +00:00
|
|
|
}
|
|
|
|
|
2006-02-09 12:19:53 +00:00
|
|
|
void KyraEngine::mainLoop() {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::mainLoop()");
|
2006-02-09 12:19:53 +00:00
|
|
|
|
|
|
|
while (!_quitFlag) {
|
|
|
|
int32 frameTime = (int32)_system->getMillis();
|
|
|
|
_skipFlag = false;
|
|
|
|
|
|
|
|
if (_currentCharacter->sceneId == 210) {
|
2006-02-11 08:31:13 +00:00
|
|
|
updateKyragemFading();
|
2006-02-09 12:19:53 +00:00
|
|
|
if (seq_playEnd()) {
|
|
|
|
if (_deathHandler != 8)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_deathHandler != 0xFF) {
|
2006-03-07 14:16:52 +00:00
|
|
|
snd_playWanderScoreViaMap(0, 1);
|
2006-03-14 14:25:13 +00:00
|
|
|
snd_playSoundEffect(49);
|
2006-03-19 05:55:26 +00:00
|
|
|
_screen->hideMouse();
|
|
|
|
_screen->setMouseCursor(1, 1, _shapes[4]);
|
|
|
|
destroyMouseItem();
|
|
|
|
_screen->showMouse();
|
2006-03-07 14:16:52 +00:00
|
|
|
buttonMenuCallback(0);
|
2006-03-19 08:35:43 +00:00
|
|
|
_deathHandler = 0xFF;
|
2006-02-09 12:19:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_brandonStatusBit & 2) {
|
|
|
|
if (_brandonStatusBit0x02Flag)
|
2006-02-11 08:31:13 +00:00
|
|
|
_animator->animRefreshNPC(0);
|
2006-02-09 12:19:53 +00:00
|
|
|
}
|
|
|
|
if (_brandonStatusBit & 0x20) {
|
|
|
|
if (_brandonStatusBit0x20Flag) {
|
2006-02-11 08:31:13 +00:00
|
|
|
_animator->animRefreshNPC(0);
|
2006-02-09 12:19:53 +00:00
|
|
|
_brandonStatusBit0x20Flag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_screen->showMouse();
|
|
|
|
|
|
|
|
processButtonList(_buttonList);
|
|
|
|
updateMousePointer();
|
|
|
|
updateGameTimers();
|
|
|
|
updateTextFade();
|
|
|
|
|
|
|
|
_handleInput = true;
|
|
|
|
delay((frameTime + _gameSpeed) - _system->getMillis(), true, true);
|
|
|
|
_handleInput = false;
|
2006-03-21 17:17:24 +00:00
|
|
|
|
|
|
|
_sound->process();
|
2006-02-09 12:19:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::quitGame() {
|
2006-03-07 14:16:52 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::quitGame()");
|
|
|
|
|
2006-02-09 12:19:53 +00:00
|
|
|
for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) {
|
|
|
|
_movieObjects[i]->close();
|
|
|
|
delete _movieObjects[i];
|
|
|
|
_movieObjects[i] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
_system->quit();
|
|
|
|
}
|
|
|
|
|
2006-01-12 14:53:23 +00:00
|
|
|
void KyraEngine::delay(uint32 amount, bool update, bool isMainLoop) {
|
2005-10-03 20:21:18 +00:00
|
|
|
OSystem::Event event;
|
2005-12-10 17:51:40 +00:00
|
|
|
char saveLoadSlot[20];
|
2006-01-22 09:34:12 +00:00
|
|
|
char savegameName[14];
|
2005-12-10 17:51:40 +00:00
|
|
|
|
2005-10-03 20:21:18 +00:00
|
|
|
uint32 start = _system->getMillis();
|
|
|
|
do {
|
|
|
|
while (_system->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case OSystem::EVENT_KEYDOWN:
|
2006-01-27 08:23:53 +00:00
|
|
|
if (event.kbd.keycode >= '1' && event.kbd.keycode <= '9' &&
|
2006-01-12 14:53:23 +00:00
|
|
|
(event.kbd.flags == OSystem::KBD_CTRL || event.kbd.flags == OSystem::KBD_ALT) && isMainLoop) {
|
2006-01-03 23:41:52 +00:00
|
|
|
sprintf(saveLoadSlot, "%s.00%d", _targetName.c_str(), event.kbd.keycode - '0');
|
2005-12-10 17:51:40 +00:00
|
|
|
if (event.kbd.flags == OSystem::KBD_CTRL)
|
|
|
|
loadGame(saveLoadSlot);
|
2006-01-22 09:34:12 +00:00
|
|
|
else {
|
|
|
|
sprintf(savegameName, "Quicksave %d", event.kbd.keycode - '0');
|
|
|
|
saveGame(saveLoadSlot, savegameName);
|
|
|
|
}
|
2006-01-21 23:43:58 +00:00
|
|
|
} else if (event.kbd.flags == OSystem::KBD_CTRL) {
|
2006-02-09 12:19:53 +00:00
|
|
|
if (event.kbd.keycode == 'd')
|
2006-01-21 23:43:58 +00:00
|
|
|
_debugger->attach();
|
2006-01-22 09:34:12 +00:00
|
|
|
else if (event.kbd.keycode == 'q')
|
|
|
|
_quitFlag = true;
|
2006-02-09 12:19:53 +00:00
|
|
|
} else if (event.kbd.keycode == '.')
|
|
|
|
_skipFlag = true;
|
|
|
|
else if (event.kbd.keycode == 13 || event.kbd.keycode == 32 || event.kbd.keycode == 27) {
|
|
|
|
_abortIntroFlag = true;
|
|
|
|
_skipFlag = true;
|
2005-10-03 20:21:18 +00:00
|
|
|
}
|
2006-02-09 12:19:53 +00:00
|
|
|
|
2005-10-03 20:21:18 +00:00
|
|
|
break;
|
2005-10-22 00:24:07 +00:00
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
2006-03-15 12:44:41 +00:00
|
|
|
_system->updateScreen();
|
2005-10-22 00:24:07 +00:00
|
|
|
break;
|
2005-10-03 20:21:18 +00:00
|
|
|
case OSystem::EVENT_QUIT:
|
2005-11-11 22:17:06 +00:00
|
|
|
quitGame();
|
2005-10-03 20:21:18 +00:00
|
|
|
break;
|
2005-11-18 23:55:31 +00:00
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
2005-12-24 18:00:35 +00:00
|
|
|
_mousePressFlag = true;
|
2006-03-19 05:55:26 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONUP:
|
|
|
|
_mousePressFlag = false;
|
2005-12-13 15:10:20 +00:00
|
|
|
if (_abortWalkFlag2) {
|
|
|
|
_abortWalkFlag = true;
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
|
|
|
}
|
2005-11-18 23:55:31 +00:00
|
|
|
if (_handleInput) {
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
|
|
|
_handleInput = false;
|
|
|
|
processInput(_mouseX, _mouseY);
|
|
|
|
_handleInput = true;
|
2006-02-09 12:19:53 +00:00
|
|
|
} else
|
|
|
|
_skipFlag = true;
|
2005-11-18 23:55:31 +00:00
|
|
|
break;
|
2005-10-03 20:21:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-12-09 14:52:31 +00:00
|
|
|
if (_debugger->isAttached())
|
|
|
|
_debugger->onFrame();
|
|
|
|
|
2006-03-13 17:19:19 +00:00
|
|
|
if (update) {
|
2006-02-09 12:19:53 +00:00
|
|
|
_sprites->updateSceneAnims();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2006-03-13 17:19:19 +00:00
|
|
|
}
|
2005-11-11 22:17:06 +00:00
|
|
|
|
2006-03-13 17:19:19 +00:00
|
|
|
if (_currentCharacter && _currentCharacter->sceneId == 210 && update) {
|
2006-02-11 08:31:13 +00:00
|
|
|
updateKyragemFading();
|
2005-11-11 22:17:06 +00:00
|
|
|
}
|
|
|
|
|
2006-02-09 12:19:53 +00:00
|
|
|
if (amount > 0 && !_skipFlag) {
|
2005-10-03 20:21:18 +00:00
|
|
|
_system->delayMillis((amount > 10) ? 10 : amount);
|
|
|
|
}
|
2006-02-09 12:19:53 +00:00
|
|
|
} while (!_skipFlag && _system->getMillis() < start + amount);
|
|
|
|
|
2005-10-03 20:21:18 +00:00
|
|
|
}
|
|
|
|
|
2005-12-10 19:02:56 +00:00
|
|
|
void KyraEngine::waitForEvent() {
|
|
|
|
bool finished = false;
|
|
|
|
OSystem::Event event;
|
|
|
|
while (!finished) {
|
|
|
|
while (_system->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case OSystem::EVENT_KEYDOWN:
|
|
|
|
finished = true;
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_MOUSEMOVE:
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_QUIT:
|
|
|
|
quitGame();
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
|
|
|
finished = true;
|
2006-02-09 12:19:53 +00:00
|
|
|
_skipFlag = true;
|
2005-12-10 19:02:56 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_debugger->isAttached())
|
|
|
|
_debugger->onFrame();
|
|
|
|
|
|
|
|
_system->delayMillis(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-24 18:00:35 +00:00
|
|
|
void KyraEngine::delayWithTicks(int ticks) {
|
|
|
|
uint32 nextTime = _system->getMillis() + ticks * _tickLength;
|
2006-03-07 14:16:52 +00:00
|
|
|
while (_system->getMillis() < nextTime) {
|
2005-12-24 18:00:35 +00:00
|
|
|
_sprites->updateSceneAnims();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2006-01-03 19:03:09 +00:00
|
|
|
if (_currentCharacter->sceneId == 210) {
|
2006-02-11 08:31:13 +00:00
|
|
|
updateKyragemFading();
|
2006-01-06 10:45:42 +00:00
|
|
|
seq_playEnd();
|
2006-01-03 19:03:09 +00:00
|
|
|
}
|
2006-03-07 14:16:52 +00:00
|
|
|
if (_skipFlag)
|
|
|
|
break;
|
2005-12-24 18:00:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-09 07:37:19 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark - Animation/shape specific code
|
|
|
|
#pragma mark -
|
2005-09-08 19:09:52 +00:00
|
|
|
|
2006-02-09 07:37:19 +00:00
|
|
|
void KyraEngine::setupShapes123(const Shape *shapeTable, int endShape, int flags) {
|
2006-03-08 11:37:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::setupShapes123(%p, %d, %d)", (const void *)shapeTable, endShape, flags);
|
2006-02-09 07:37:19 +00:00
|
|
|
for (int i = 123; i <= 172; ++i) {
|
|
|
|
_shapes[4+i] = NULL;
|
2005-12-26 14:53:51 +00:00
|
|
|
}
|
|
|
|
uint8 curImage = 0xFF;
|
|
|
|
int curPageBackUp = _screen->_curPage;
|
|
|
|
_screen->_curPage = 8; // we are using page 8 here in the original page 2 was backuped and then used for this stuff
|
|
|
|
int shapeFlags = 2;
|
|
|
|
if (flags)
|
|
|
|
shapeFlags = 3;
|
|
|
|
for (int i = 123; i < 123+endShape; ++i) {
|
|
|
|
uint8 newImage = shapeTable[i-123].imageIndex;
|
2005-12-29 22:18:40 +00:00
|
|
|
if (newImage != curImage && newImage != 0xFF) {
|
2005-12-26 14:53:51 +00:00
|
|
|
assert(_characterImageTable);
|
|
|
|
loadBitmap(_characterImageTable[newImage], 8, 8, 0);
|
|
|
|
curImage = newImage;
|
|
|
|
}
|
2005-12-29 22:18:40 +00:00
|
|
|
_shapes[4+i] = _screen->encodeShape(shapeTable[i-123].x<<3, shapeTable[i-123].y, shapeTable[i-123].w<<3, shapeTable[i-123].h, shapeFlags);
|
2005-12-26 14:53:51 +00:00
|
|
|
assert(i-7 < _defaultShapeTableSize);
|
|
|
|
_defaultShapeTable[i-7].xOffset = shapeTable[i-123].xOffset;
|
|
|
|
_defaultShapeTable[i-7].yOffset = shapeTable[i-123].yOffset;
|
|
|
|
_defaultShapeTable[i-7].w = shapeTable[i-123].w;
|
|
|
|
_defaultShapeTable[i-7].h = shapeTable[i-123].h;
|
|
|
|
}
|
|
|
|
_screen->_curPage = curPageBackUp;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::freeShapes123() {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::freeShapes123()");
|
2005-12-26 14:53:51 +00:00
|
|
|
for (int i = 123; i <= 172; ++i) {
|
|
|
|
free(_shapes[4+i]);
|
|
|
|
_shapes[4+i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-30 19:58:51 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark - Misc stuff
|
2006-02-09 07:37:19 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
Movie *KyraEngine::createWSAMovie() {
|
|
|
|
// for kyra2 here could be added then WSAMovieV2
|
|
|
|
return new WSAMovieV1(this);
|
2005-12-08 17:19:18 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 08:31:13 +00:00
|
|
|
int KyraEngine::setGameFlag(int flag) {
|
|
|
|
_flagsTable[flag >> 3] |= (1 << (flag & 7));
|
|
|
|
return 1;
|
2005-12-10 15:52:38 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 08:31:13 +00:00
|
|
|
int KyraEngine::queryGameFlag(int flag) {
|
|
|
|
return ((_flagsTable[flag >> 3] >> (flag & 7)) & 1);
|
2005-12-10 15:52:38 +00:00
|
|
|
}
|
|
|
|
|
2006-02-11 08:31:13 +00:00
|
|
|
int KyraEngine::resetGameFlag(int flag) {
|
|
|
|
_flagsTable[flag >> 3] &= ~(1 << (flag & 7));
|
|
|
|
return 0;
|
2005-12-26 14:53:51 +00:00
|
|
|
}
|
|
|
|
|
2005-12-28 21:34:40 +00:00
|
|
|
void KyraEngine::setBrandonPoisonFlags(int reset) {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::setBrandonPoisonFlags(%d)", reset);
|
2005-12-28 21:34:40 +00:00
|
|
|
_brandonStatusBit |= 1;
|
|
|
|
if (reset)
|
|
|
|
_poisonDeathCounter = 0;
|
|
|
|
for (int i = 0; i < 0x100; ++i) {
|
|
|
|
_brandonPoisonFlagsGFX[i] = i;
|
|
|
|
}
|
|
|
|
_brandonPoisonFlagsGFX[0x99] = 0x34;
|
|
|
|
_brandonPoisonFlagsGFX[0x9A] = 0x35;
|
|
|
|
_brandonPoisonFlagsGFX[0x9B] = 0x37;
|
|
|
|
_brandonPoisonFlagsGFX[0x9C] = 0x38;
|
|
|
|
_brandonPoisonFlagsGFX[0x9D] = 0x2B;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::resetBrandonPoisonFlags() {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::resetBrandonPoisonFlags()");
|
2005-12-28 21:34:40 +00:00
|
|
|
_brandonStatusBit = 0;
|
|
|
|
for (int i = 0; i < 0x100; ++i) {
|
|
|
|
_brandonPoisonFlagsGFX[i] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark - Input
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
void KyraEngine::processInput(int xpos, int ypos) {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::processInput(%d, %d)", xpos, ypos);
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag2 = false;
|
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
if (processInputHelper(xpos, ypos)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
uint8 item = findItemAtPos(xpos, ypos);
|
|
|
|
if (item == 0xFF) {
|
2005-12-24 18:00:35 +00:00
|
|
|
_changedScene = false;
|
2005-12-26 17:31:42 +00:00
|
|
|
int handled = clickEventHandler(xpos, ypos);
|
|
|
|
if (_changedScene || handled)
|
2005-11-18 23:55:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX _deathHandler specific
|
|
|
|
if (ypos <= 158) {
|
|
|
|
uint16 exit = 0xFFFF;
|
|
|
|
if (xpos < 12) {
|
|
|
|
exit = _walkBlockWest;
|
|
|
|
} else if (xpos >= 308) {
|
|
|
|
exit = _walkBlockEast;
|
|
|
|
} else if (ypos >= 136) {
|
|
|
|
exit = _walkBlockSouth;
|
|
|
|
} else if (ypos < 12) {
|
|
|
|
exit = _walkBlockNorth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exit != 0xFFFF) {
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag2 = true;
|
2005-11-18 23:55:31 +00:00
|
|
|
handleSceneChange(xpos, ypos, 1, 1);
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag2 = false;
|
2005-11-18 23:55:31 +00:00
|
|
|
return;
|
2005-12-09 19:49:47 +00:00
|
|
|
} else {
|
2005-12-09 23:02:16 +00:00
|
|
|
int script = checkForNPCScriptRun(xpos, ypos);
|
|
|
|
if (script >= 0) {
|
|
|
|
runNpcScript(script);
|
|
|
|
return;
|
|
|
|
}
|
2005-12-09 19:49:47 +00:00
|
|
|
if (_itemInHand != -1) {
|
|
|
|
if (ypos < 155) {
|
|
|
|
if (hasClickedOnExit(xpos, ypos)) {
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag2 = true;
|
2005-12-09 19:49:47 +00:00
|
|
|
handleSceneChange(xpos, ypos, 1, 1);
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag2 = false;
|
2005-12-09 19:49:47 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
dropItem(0, _itemInHand, xpos, ypos, 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (ypos <= 155) {
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag2 = true;
|
2005-12-09 19:49:47 +00:00
|
|
|
handleSceneChange(xpos, ypos, 1, 1);
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag2 = false;
|
2005-12-09 19:49:47 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-18 23:55:31 +00:00
|
|
|
}
|
2005-12-09 17:36:57 +00:00
|
|
|
}
|
2005-11-18 23:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::processInputHelper(int xpos, int ypos) {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::processInputHelper(%d, %d)", xpos, ypos);
|
2005-12-09 17:36:57 +00:00
|
|
|
uint8 item = findItemAtPos(xpos, ypos);
|
|
|
|
if (item != 0xFF) {
|
|
|
|
if (_itemInHand == -1) {
|
|
|
|
_screen->hideMouse();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->animRemoveGameItem(item);
|
2006-01-12 13:16:42 +00:00
|
|
|
snd_playSoundEffect(53);
|
2005-12-09 17:36:57 +00:00
|
|
|
assert(_currentCharacter->sceneId < _roomTableSize);
|
|
|
|
Room *currentRoom = &_roomTable[_currentCharacter->sceneId];
|
|
|
|
int item2 = currentRoom->itemsTable[item];
|
|
|
|
currentRoom->itemsTable[item] = 0xFF;
|
|
|
|
setMouseItem(item2);
|
2005-12-14 14:08:30 +00:00
|
|
|
assert(_itemList && _takenList);
|
|
|
|
updateSentenceCommand(_itemList[item2], _takenList[0], 179);
|
2005-12-09 17:36:57 +00:00
|
|
|
_itemInHand = item2;
|
|
|
|
_screen->showMouse();
|
|
|
|
clickEventHandler2();
|
|
|
|
return 1;
|
|
|
|
} else {
|
|
|
|
exchangeItemWithMouseItem(_currentCharacter->sceneId, item);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2005-11-18 23:55:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::clickEventHandler(int xpos, int ypos) {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::clickEventHandler(%d, %d)", xpos, ypos);
|
2005-11-18 23:55:31 +00:00
|
|
|
_scriptInterpreter->initScript(_scriptClick, _scriptClickData);
|
|
|
|
_scriptClick->variables[1] = xpos;
|
|
|
|
_scriptClick->variables[2] = ypos;
|
|
|
|
_scriptClick->variables[3] = 0;
|
|
|
|
_scriptClick->variables[4] = _itemInHand;
|
|
|
|
_scriptInterpreter->startScript(_scriptClick, 1);
|
2005-12-24 18:00:35 +00:00
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
while (_scriptInterpreter->validScript(_scriptClick)) {
|
|
|
|
_scriptInterpreter->runScript(_scriptClick);
|
|
|
|
}
|
2005-12-24 18:00:35 +00:00
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
return _scriptClick->variables[3];
|
|
|
|
}
|
|
|
|
|
2005-12-13 15:10:20 +00:00
|
|
|
void KyraEngine::updateMousePointer(bool forceUpdate) {
|
2005-11-18 23:55:31 +00:00
|
|
|
int shape = 0;
|
|
|
|
|
|
|
|
int newMouseState = 0;
|
2005-12-08 17:19:18 +00:00
|
|
|
int newX = 0;
|
|
|
|
int newY = 0;
|
2005-11-18 23:55:31 +00:00
|
|
|
if (_mouseY <= 158) {
|
|
|
|
if (_mouseX >= 12) {
|
|
|
|
if (_mouseX >= 308) {
|
|
|
|
if (_walkBlockEast == 0xFFFF) {
|
|
|
|
newMouseState = -2;
|
|
|
|
} else {
|
|
|
|
newMouseState = -5;
|
|
|
|
shape = 3;
|
|
|
|
newX = 7;
|
|
|
|
newY = 5;
|
|
|
|
}
|
|
|
|
} else if (_mouseY >= 136) {
|
|
|
|
if (_walkBlockSouth == 0xFFFF) {
|
|
|
|
newMouseState = -2;
|
|
|
|
} else {
|
|
|
|
newMouseState = -4;
|
|
|
|
shape = 4;
|
|
|
|
newX = 5;
|
|
|
|
newY = 7;
|
|
|
|
}
|
|
|
|
} else if (_mouseY < 12) {
|
|
|
|
if (_walkBlockNorth == 0xFFFF) {
|
|
|
|
newMouseState = -2;
|
|
|
|
} else {
|
|
|
|
newMouseState = -6;
|
|
|
|
shape = 2;
|
|
|
|
newX = 5;
|
|
|
|
newY = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_walkBlockWest == 0xFFFF) {
|
|
|
|
newMouseState = -2;
|
|
|
|
} else {
|
|
|
|
newMouseState = -3;
|
|
|
|
newX = 1;
|
|
|
|
newY = shape = 5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_mouseX >= _entranceMouseCursorTracks[0] && _mouseY >= _entranceMouseCursorTracks[1]
|
|
|
|
&& _mouseX <= _entranceMouseCursorTracks[2] && _mouseY <= _entranceMouseCursorTracks[3]) {
|
|
|
|
switch (_entranceMouseCursorTracks[4]) {
|
|
|
|
case 0:
|
|
|
|
newMouseState = -6;
|
|
|
|
shape = 2;
|
|
|
|
newX = 5;
|
|
|
|
newY = 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
newMouseState = -5;
|
|
|
|
shape = 3;
|
|
|
|
newX = 7;
|
|
|
|
newY = 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
newMouseState = -4;
|
|
|
|
shape = 4;
|
|
|
|
newX = 5;
|
|
|
|
newY = 7;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
newMouseState = -3;
|
|
|
|
shape = 5;
|
|
|
|
newX = 1;
|
|
|
|
newY = 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newMouseState == -2) {
|
|
|
|
shape = 6;
|
|
|
|
newX = 4;
|
|
|
|
newY = 4;
|
|
|
|
}
|
|
|
|
|
2005-12-13 15:10:20 +00:00
|
|
|
if ((newMouseState && _mouseState != newMouseState) || (newMouseState && forceUpdate)) {
|
2005-11-18 23:55:31 +00:00
|
|
|
_mouseState = newMouseState;
|
|
|
|
_screen->hideMouse();
|
|
|
|
_screen->setMouseCursor(newX, newY, _shapes[4+shape]);
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!newMouseState) {
|
2005-12-13 15:10:20 +00:00
|
|
|
if (_mouseState != _itemInHand || forceUpdate) {
|
|
|
|
if (_mouseY > 158 || (_mouseX >= 12 && _mouseX < 308 && _mouseY < 136 && _mouseY >= 12) || forceUpdate) {
|
2005-11-18 23:55:31 +00:00
|
|
|
_mouseState = _itemInHand;
|
|
|
|
_screen->hideMouse();
|
|
|
|
if (_itemInHand == -1) {
|
|
|
|
_screen->setMouseCursor(1, 1, _shapes[4]);
|
|
|
|
} else {
|
|
|
|
_screen->setMouseCursor(8, 15, _shapes[220+_itemInHand]);
|
|
|
|
}
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-09 19:49:47 +00:00
|
|
|
bool KyraEngine::hasClickedOnExit(int xpos, int ypos) {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::hasClickedOnExit(%d, %d)", xpos, ypos);
|
2005-12-09 19:49:47 +00:00
|
|
|
if (xpos < 16 || xpos >= 304) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (ypos < 8)
|
|
|
|
return true;
|
|
|
|
if (ypos < 136 || ypos > 155) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2005-12-08 17:19:18 +00:00
|
|
|
void KyraEngine::clickEventHandler2() {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::clickEventHandler2()");
|
2005-12-08 17:19:18 +00:00
|
|
|
_scriptInterpreter->initScript(_scriptClick, _scriptClickData);
|
|
|
|
_scriptClick->variables[0] = _currentCharacter->sceneId;
|
|
|
|
_scriptClick->variables[1] = _mouseX;
|
|
|
|
_scriptClick->variables[2] = _mouseY;
|
|
|
|
_scriptClick->variables[4] = _itemInHand;
|
|
|
|
_scriptInterpreter->startScript(_scriptClick, 6);
|
|
|
|
|
|
|
|
while (_scriptInterpreter->validScript(_scriptClick)) {
|
|
|
|
_scriptInterpreter->runScript(_scriptClick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-09 23:02:16 +00:00
|
|
|
int KyraEngine::checkForNPCScriptRun(int xpos, int ypos) {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::checkForNPCScriptRun(%d, %d)", xpos, ypos);
|
2005-12-09 23:02:16 +00:00
|
|
|
int returnValue = -1;
|
|
|
|
const Character *currentChar = _currentCharacter;
|
|
|
|
int charLeft = 0, charRight = 0, charTop = 0, charBottom = 0;
|
|
|
|
|
|
|
|
int scaleFactor = _scaleTable[currentChar->y1];
|
|
|
|
int addX = (((scaleFactor*8)*3)>>8)>>1;
|
|
|
|
int addY = ((scaleFactor*3)<<4)>>8;
|
|
|
|
|
|
|
|
charLeft = currentChar->x1 - addX;
|
|
|
|
charRight = currentChar->x1 + addX;
|
|
|
|
charTop = currentChar->y1 - addY;
|
|
|
|
charBottom = currentChar->y1;
|
|
|
|
|
|
|
|
if (xpos >= charLeft && charRight >= xpos && charTop <= ypos && charBottom >= ypos) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xpos > 304 || xpos < 16) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 1; i < 5; ++i) {
|
|
|
|
currentChar = &_characterList[i];
|
|
|
|
|
|
|
|
if (currentChar->sceneId != _currentCharacter->sceneId)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
charLeft = currentChar->x1 - 12;
|
|
|
|
charRight = currentChar->x1 + 11;
|
|
|
|
charTop = currentChar->y1 - 48;
|
|
|
|
// if (!i) {
|
|
|
|
// charBottom = currentChar->y2 - 16;
|
|
|
|
// } else {
|
|
|
|
charBottom = currentChar->y1;
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (xpos < charLeft || xpos > charRight || ypos < charTop || charBottom < ypos) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (returnValue != -1) {
|
|
|
|
if (currentChar->y1 >= _characterList[returnValue].y1) {
|
|
|
|
returnValue = i;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
returnValue = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::runNpcScript(int func) {
|
2006-02-14 23:31:25 +00:00
|
|
|
debugC(9, kDebugLevelMain, "KyraEngine::runNpcScript(%d)", func);
|
2005-12-09 23:02:16 +00:00
|
|
|
_scriptInterpreter->initScript(_npcScript, _npcScriptData);
|
|
|
|
_scriptInterpreter->startScript(_npcScript, func);
|
|
|
|
_npcScript->variables[0] = _currentCharacter->sceneId;
|
|
|
|
_npcScript->variables[4] = _itemInHand;
|
|
|
|
_npcScript->variables[5] = func;
|
|
|
|
|
|
|
|
while (_scriptInterpreter->validScript(_npcScript)) {
|
|
|
|
_scriptInterpreter->runScript(_npcScript);
|
|
|
|
}
|
|
|
|
}
|
2005-08-19 22:12:09 +00:00
|
|
|
} // End of namespace Kyra
|