2005-01-09 16:06:29 +00:00
|
|
|
/* ScummVM - Scumm Interpreter
|
|
|
|
* Copyright (C) 2004-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
|
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
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
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"
|
2005-10-12 19:15:32 +00:00
|
|
|
#include "sound/voc.h"
|
|
|
|
#include "sound/audiostream.h"
|
2004-04-09 12:36:06 +00:00
|
|
|
|
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 {
|
2004-10-16 22:28:29 +00:00
|
|
|
const char *name;
|
|
|
|
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-16 22:28:29 +00:00
|
|
|
GameSettings toGameSettings() const {
|
|
|
|
GameSettings dummy = { name, description, features };
|
|
|
|
return dummy;
|
|
|
|
}
|
2004-10-15 06:06:47 +00:00
|
|
|
};
|
|
|
|
|
2005-10-13 21:12:47 +00:00
|
|
|
static const KyraGameSettings kyra_games[] = {
|
2005-11-09 22:26:12 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia (Floppy, English)", GI_KYRA1, GF_ENGLISH | GF_FLOPPY, // english floppy 1.0 from Malice
|
|
|
|
"3c244298395520bb62b5edfe41688879", "GEMCUT.EMC" },
|
2005-10-14 11:25:48 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia (Floppy, English)", GI_KYRA1, GF_ENGLISH | GF_FLOPPY,
|
2005-10-13 21:12:47 +00:00
|
|
|
"796e44863dd22fa635b042df1bf16673", "GEMCUT.EMC" },
|
2005-10-19 10:29:34 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia (Floppy, French)", GI_KYRA1, GF_FRENCH | GF_FLOPPY,
|
2005-10-13 21:12:47 +00:00
|
|
|
"abf8eb360e79a6c2a837751fbd4d3d24", "GEMCUT.EMC" },
|
2005-10-19 10:29:34 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia (Floppy, German)", GI_KYRA1, GF_GERMAN | GF_FLOPPY,
|
2005-10-13 21:12:47 +00:00
|
|
|
"6018e1dfeaca7fe83f8d0b00eb0dd049", "GEMCUT.EMC"},
|
2005-10-19 10:29:34 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia (Floppy, Spanish)", GI_KYRA1, GF_SPANISH | GF_FLOPPY, // from VooD
|
2005-10-18 19:59:51 +00:00
|
|
|
"8909b41596913b3f5deaf3c9f1017b01", "GEMCUT.EMC"},
|
2005-11-19 00:16:45 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia (Floppy, Spanish)", GI_KYRA1, GF_SPANISH | GF_FLOPPY, // floppy 1.8 from clemmy
|
|
|
|
"747861d2a9c643c59fdab570df5b9093", "GEMCUT.EMC"},
|
2005-10-14 11:25:48 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia (CD, English)", GI_KYRA1, GF_ENGLISH | GF_TALKIE,
|
2005-10-13 21:12:47 +00:00
|
|
|
"fac399fe62f98671e56a005c5e94e39f", "GEMCUT.PAK" },
|
2005-10-14 11:25:48 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia (CD, German)", GI_KYRA1, GF_GERMAN | GF_TALKIE,
|
2005-10-13 21:12:47 +00:00
|
|
|
"230f54e6afc007ab4117159181a1c722", "GEMCUT.PAK" },
|
2005-10-14 11:25:48 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia (CD, French)", GI_KYRA1, GF_FRENCH | GF_TALKIE,
|
2005-10-13 21:12:47 +00:00
|
|
|
"b037c41768b652a040360ffa3556fd2a", "GEMCUT.PAK" },
|
2005-10-18 19:59:51 +00:00
|
|
|
{ "kyra1", "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
|
|
|
|
struct KyraGameList {
|
|
|
|
const char *name;
|
|
|
|
const char *description;
|
|
|
|
uint32 features;
|
|
|
|
GameSettings toGameSettings() const {
|
|
|
|
GameSettings dummy = { name, description, features };
|
|
|
|
return dummy;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const KyraGameList kyra_list[] = {
|
2005-10-18 19:59:51 +00:00
|
|
|
{ "kyra1", "Legend of Kyrandia", 0 },
|
2005-10-13 21:12:47 +00:00
|
|
|
{ 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;
|
2005-10-13 21:12:47 +00:00
|
|
|
const KyraGameList *g = kyra_list;
|
|
|
|
|
2004-10-16 22:28:29 +00:00
|
|
|
while (g->name) {
|
|
|
|
games.push_back(g->toGameSettings());
|
|
|
|
g++;
|
|
|
|
}
|
|
|
|
return games;
|
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;
|
|
|
|
|
2005-10-13 21:12:47 +00:00
|
|
|
for (g = kyra_games; g->name; g++) {
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
for (g = kyra_games; g->name; g++) {
|
|
|
|
if (strcmp(g->md5sum, (char *)md5str) == 0) {
|
|
|
|
detectedGames.push_back(g->toGameSettings());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (detectedGames.isEmpty()) {
|
2005-10-14 11:25:48 +00:00
|
|
|
debug("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
|
|
|
|
|
|
|
const KyraGameList *g1 = kyra_list;
|
|
|
|
while (g1->name) {
|
|
|
|
detectedGames.push_back(g1->toGameSettings());
|
|
|
|
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
|
|
|
|
|
|
|
_defaultShapeTable = _healingShapeTable = _healingShape2Table = 0;
|
|
|
|
_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;
|
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
|
|
|
|
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
|
|
|
|
|
|
|
for (g = kyra_games; g->name; g++) {
|
|
|
|
if (!Common::File::exists(g->checkFile))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (Common::md5_file(g->checkFile, md5sum, ConfMan.get("path").c_str(), kMD5FileSizeLimit)) {
|
|
|
|
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) {
|
|
|
|
debug("Unknown MD5 (%s)! Please report the details (language, platform, etc.) of this game to the ScummVM team", md5str);
|
2005-10-18 19:59:51 +00:00
|
|
|
_features = GF_LNGUNK;
|
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;
|
|
|
|
}
|
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) {
|
2005-10-12 19:15:32 +00:00
|
|
|
_currentVocFile = 0;
|
2004-11-24 00:14:21 +00:00
|
|
|
_system->beginGFXTransaction();
|
|
|
|
initCommonGFX(detector);
|
|
|
|
_system->initSize(320, 200);
|
|
|
|
_system->endGFXTransaction();
|
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
// for now we prefer MIDI-to-Adlib conversion over native midi
|
2005-12-30 16:36:53 +00:00
|
|
|
int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB/* | MDT_PREFER_MIDI*/);
|
|
|
|
bool native_mt32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
|
2004-11-14 14:11:54 +00:00
|
|
|
|
2005-12-30 16:36:53 +00:00
|
|
|
MidiDriver *driver = MidiDriver::createMidi(midiDriver);
|
2005-12-30 14:18:21 +00:00
|
|
|
if (midiDriver == MD_ADLIB) {
|
2004-11-14 14:11:54 +00:00
|
|
|
// In this case we should play the Adlib tracks, but for now
|
|
|
|
// the automagic MIDI-to-Adlib conversion will do.
|
2005-08-19 22:12:09 +00:00
|
|
|
} else if (native_mt32) {
|
2004-11-14 14:11:54 +00:00
|
|
|
driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2004-11-14 14:11:54 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
_midi = new MusicPlayer(driver, this);
|
|
|
|
assert(_midi);
|
|
|
|
_midi->hasNativeMT32(native_mt32);
|
|
|
|
_midi->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);
|
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-08-19 22:12:09 +00:00
|
|
|
_fastMode = false;
|
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;
|
|
|
|
_brandonDrawFrame = 113;
|
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
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
_configTalkspeed = 1;
|
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
|
|
|
|
|
|
|
_hidPage = _screenPage = 0;
|
2005-12-13 16:56:33 +00:00
|
|
|
|
|
|
|
_unkScreenVar1 = 1;
|
|
|
|
_unkScreenVar2 = 0;
|
|
|
|
_unkScreenVar3 = 0;
|
2005-12-22 18:14:52 +00:00
|
|
|
|
|
|
|
memset(_specialPalettes, 0, sizeof(_specialPalettes));
|
2005-12-24 18:00:35 +00:00
|
|
|
_mousePressFlag = false;
|
2006-01-03 23:41:52 +00:00
|
|
|
|
|
|
|
_targetName = detector._targetName;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2004-11-23 00:03:25 +00:00
|
|
|
return 0;
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
KyraEngine::~KyraEngine() {
|
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;
|
|
|
|
delete _midi;
|
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;
|
|
|
|
|
2005-12-24 18:00:35 +00:00
|
|
|
free(_buttonShape0);
|
|
|
|
free(_buttonShape1);
|
|
|
|
free(_buttonShape2);
|
|
|
|
free(_buttonShape3);
|
|
|
|
free(_buttonShape4);
|
|
|
|
free(_buttonShape5);
|
|
|
|
|
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
|
|
|
}
|
2005-12-10 19:02:56 +00:00
|
|
|
free(_unkPtr1);
|
|
|
|
free(_unkPtr2);
|
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
|
|
|
|
2005-10-18 19:59:51 +00:00
|
|
|
res_loadResources();
|
2005-10-13 21:12:47 +00:00
|
|
|
if (_features & GF_FLOPPY) {
|
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();
|
|
|
|
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() {
|
|
|
|
debug(9, "KyraEngine::startup()");
|
|
|
|
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)
|
|
|
|
setCharacterDefaultFrame(i);
|
|
|
|
for (int i = 5; i <= 10; ++i)
|
|
|
|
setCharactersPositions(i);
|
|
|
|
setCharactersHeight();
|
|
|
|
resetBrandonPosionFlags();
|
|
|
|
_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
|
|
|
_unkPtr1 = (uint8*)malloc(_screen->getRectSize(1, 144));
|
|
|
|
memset(_unkPtr1, 0, _screen->getRectSize(1, 144));
|
|
|
|
_unkPtr2 = (uint8*)malloc(_screen->getRectSize(1, 144));
|
|
|
|
memset(_unkPtr2, 0, _screen->getRectSize(1, 144));
|
|
|
|
_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
|
|
|
|
initAnimStateList();
|
|
|
|
setCharactersInDefaultScene();
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2005-11-09 22:26:12 +00:00
|
|
|
_gameSpeed = 50;
|
2005-11-11 22:17:06 +00:00
|
|
|
_tickLength = (uint8)(1000.0 / _gameSpeed);
|
|
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_playTheme(1);
|
2005-11-09 22:26:12 +00:00
|
|
|
snd_setSoundEffectFile(1);
|
2005-10-29 18:37:40 +00:00
|
|
|
enterNewScene(_currentCharacter->sceneId, _currentCharacter->facing, 0, 0, 1);
|
2005-09-10 00:15:40 +00:00
|
|
|
}
|
|
|
|
|
2005-12-20 10:58:07 +00:00
|
|
|
void KyraEngine::delay(uint32 amount, bool update) {
|
2005-10-03 20:21:18 +00:00
|
|
|
OSystem::Event event;
|
2005-12-10 17:51:40 +00:00
|
|
|
char saveLoadSlot[20];
|
|
|
|
|
2005-12-24 18:00:35 +00:00
|
|
|
_mousePressFlag = false;
|
2005-10-03 20:21:18 +00:00
|
|
|
uint32 start = _system->getMillis();
|
|
|
|
do {
|
|
|
|
while (_system->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case OSystem::EVENT_KEYDOWN:
|
|
|
|
if (event.kbd.keycode == 'q' || event.kbd.keycode == 27) {
|
|
|
|
_quitFlag = true;
|
2005-12-09 14:52:31 +00:00
|
|
|
} else if (event.kbd.keycode == 'd' && !_debugger->isAttached()) {
|
|
|
|
_debugger->attach();
|
2005-12-10 17:51:40 +00:00
|
|
|
} else if (event.kbd.keycode >= '0' && event.kbd.keycode <= '9' &&
|
|
|
|
(event.kbd.flags == OSystem::KBD_CTRL || event.kbd.flags == OSystem::KBD_ALT)) {
|
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-01 11:47:33 +00:00
|
|
|
else
|
|
|
|
saveGame(saveLoadSlot, saveLoadSlot);
|
2005-12-10 17:51:40 +00:00
|
|
|
} else if (event.kbd.flags == OSystem::KBD_CTRL && event.kbd.keycode == 'f') {
|
|
|
|
_fastMode = !_fastMode;
|
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;
|
|
|
|
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;
|
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;
|
|
|
|
}
|
|
|
|
break;
|
2005-10-03 20:21:18 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-12-09 14:52:31 +00:00
|
|
|
|
|
|
|
if (_debugger->isAttached())
|
|
|
|
_debugger->onFrame();
|
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
_sprites->updateSceneAnims();
|
2005-12-20 10:58:07 +00:00
|
|
|
if (update)
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-11-11 22:17:06 +00:00
|
|
|
|
|
|
|
if (_currentCharacter->sceneId == 210) {
|
2006-01-03 19:03:09 +00:00
|
|
|
_animator->updateKyragemFading();
|
2005-11-11 22:17:06 +00:00
|
|
|
}
|
|
|
|
|
2005-10-03 20:21:18 +00:00
|
|
|
if (amount > 0) {
|
|
|
|
_system->delayMillis((amount > 10) ? 10 : amount);
|
|
|
|
}
|
2005-12-10 17:51:40 +00:00
|
|
|
} while (!_fastMode && _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;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_debugger->isAttached())
|
|
|
|
_debugger->onFrame();
|
|
|
|
|
|
|
|
_system->delayMillis(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-10 00:15:40 +00:00
|
|
|
void KyraEngine::mainLoop() {
|
|
|
|
debug(9, "KyraEngine::mainLoop()");
|
2005-10-03 20:21:18 +00:00
|
|
|
|
|
|
|
while (!_quitFlag) {
|
|
|
|
int32 frameTime = (int32)_system->getMillis();
|
2006-01-03 19:03:09 +00:00
|
|
|
if (_currentCharacter->sceneId == 210) {
|
|
|
|
_animator->updateKyragemFading();
|
|
|
|
// XXX
|
|
|
|
}
|
2005-12-29 22:18:40 +00:00
|
|
|
|
|
|
|
if (_brandonStatusBit & 2) {
|
|
|
|
if (_brandonStatusBit0x02Flag)
|
|
|
|
animRefreshNPC(0);
|
|
|
|
}
|
|
|
|
if (_brandonStatusBit & 0x20) {
|
|
|
|
if (_brandonStatusBit0x20Flag) {
|
|
|
|
animRefreshNPC(0);
|
|
|
|
_brandonStatusBit0x20Flag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-24 18:00:35 +00:00
|
|
|
processButtonList(_buttonList);
|
2005-11-18 23:55:31 +00:00
|
|
|
updateMousePointer();
|
2005-11-11 22:17:06 +00:00
|
|
|
updateGameTimers();
|
2005-11-18 23:55:31 +00:00
|
|
|
_sprites->updateSceneAnims();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-12-09 14:52:31 +00:00
|
|
|
updateTextFade();
|
2005-10-03 20:21:18 +00:00
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
_handleInput = true;
|
2005-12-20 10:58:07 +00:00
|
|
|
delay((frameTime + _gameSpeed) - _system->getMillis(), true);
|
2005-11-18 23:55:31 +00:00
|
|
|
_handleInput = false;
|
2005-10-03 20:21:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
void KyraEngine::quitGame() {
|
|
|
|
res_unloadResources();
|
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) {
|
|
|
|
_movieObjects[i]->close();
|
|
|
|
delete _movieObjects[i];
|
|
|
|
_movieObjects[i] = 0;
|
|
|
|
}
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
_system->quit();
|
|
|
|
}
|
|
|
|
|
2005-10-03 20:21:18 +00:00
|
|
|
void KyraEngine::loadPalette(const char *filename, uint8 *palData) {
|
|
|
|
debug(9, "KyraEngine::loadPalette('%s' 0x%X)", filename, palData);
|
|
|
|
uint32 fileSize = 0;
|
|
|
|
uint8 *srcData = _res->fileData(filename, &fileSize);
|
|
|
|
|
|
|
|
if (palData && fileSize) {
|
2005-10-13 21:12:47 +00:00
|
|
|
debug(9, "Loading a palette of size %i from '%s'", fileSize, filename);
|
2006-01-02 13:20:02 +00:00
|
|
|
memcpy(palData, srcData, fileSize);
|
2005-10-03 20:21:18 +00:00
|
|
|
}
|
2006-01-02 13:20:02 +00:00
|
|
|
delete [] srcData;
|
2005-09-10 00:15:40 +00:00
|
|
|
}
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
void KyraEngine::loadBitmap(const char *filename, int tempPage, int dstPage, uint8 *palData) {
|
|
|
|
debug(9, "KyraEngine::copyBitmap('%s', %d, %d, 0x%X)", filename, tempPage, dstPage, palData);
|
|
|
|
uint32 fileSize;
|
|
|
|
uint8 *srcData = _res->fileData(filename, &fileSize);
|
|
|
|
uint8 compType = srcData[2];
|
|
|
|
uint32 imgSize = READ_LE_UINT32(srcData + 4);
|
|
|
|
uint16 palSize = READ_LE_UINT16(srcData + 8);
|
|
|
|
if (palData && palSize) {
|
2005-10-03 20:21:18 +00:00
|
|
|
debug(9, "Loading a palette of size %i from %s", palSize, filename);
|
2005-08-19 22:12:09 +00:00
|
|
|
memcpy(palData, srcData + 10, palSize);
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2005-08-22 15:39:07 +00:00
|
|
|
uint8 *srcPtr = srcData + 10 + palSize;
|
2005-08-19 22:12:09 +00:00
|
|
|
uint8 *dstData = _screen->getPagePtr(dstPage);
|
|
|
|
switch (compType) {
|
|
|
|
case 0:
|
2005-08-22 15:39:07 +00:00
|
|
|
memcpy(dstData, srcPtr, imgSize);
|
2005-08-19 22:12:09 +00:00
|
|
|
break;
|
|
|
|
case 3:
|
2005-08-22 15:39:07 +00:00
|
|
|
Screen::decodeFrame3(srcPtr, dstData, imgSize);
|
2005-08-19 22:12:09 +00:00
|
|
|
break;
|
|
|
|
case 4:
|
2005-08-22 15:39:07 +00:00
|
|
|
Screen::decodeFrame4(srcPtr, dstData, imgSize);
|
2005-08-19 22:12:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
error("Unhandled bitmap compression %d", compType);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
delete[] srcData;
|
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
void KyraEngine::waitTicks(int ticks) {
|
|
|
|
debug(9, "KyraEngine::waitTicks(%d)", ticks);
|
|
|
|
const uint32 end = _system->getMillis() + ticks * 1000 / 60;
|
|
|
|
do {
|
|
|
|
OSystem::Event event;
|
|
|
|
while (_system->pollEvent(event)) {
|
2004-12-05 17:42:20 +00:00
|
|
|
switch (event.type) {
|
2005-08-19 22:12:09 +00:00
|
|
|
case OSystem::EVENT_QUIT:
|
|
|
|
_quitFlag = true;
|
2005-11-10 14:08:50 +00:00
|
|
|
quitGame();
|
2005-08-19 22:12:09 +00:00
|
|
|
break;
|
|
|
|
case OSystem::EVENT_KEYDOWN:
|
|
|
|
if (event.kbd.flags == OSystem::KBD_CTRL) {
|
|
|
|
if (event.kbd.keycode == 'f') {
|
|
|
|
_fastMode = !_fastMode;
|
|
|
|
}
|
2005-10-03 20:21:18 +00:00
|
|
|
} else if (event.kbd.keycode == 13 || event.kbd.keycode == 32 || event.kbd.keycode == 27) {
|
|
|
|
_abortIntroFlag = true;
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
_system->delayMillis(10);
|
2005-08-19 22:12:09 +00:00
|
|
|
} while (!_fastMode && _system->getMillis() < end);
|
|
|
|
}
|
|
|
|
|
2005-12-24 18:00:35 +00:00
|
|
|
void KyraEngine::delayWithTicks(int ticks) {
|
|
|
|
uint32 nextTime = _system->getMillis() + ticks * _tickLength;
|
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
_sprites->updateSceneAnims();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2006-01-03 19:03:09 +00:00
|
|
|
if (_currentCharacter->sceneId == 210) {
|
|
|
|
_animator->updateKyragemFading();
|
2005-12-24 18:00:35 +00:00
|
|
|
// seq_playEnd();
|
2006-01-03 19:03:09 +00:00
|
|
|
}
|
2005-12-24 18:00:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-10 06:40:20 +00:00
|
|
|
void KyraEngine::seq_demo() {
|
|
|
|
debug(9, "KyraEngine::seq_demo()");
|
|
|
|
|
2005-09-12 10:49:52 +00:00
|
|
|
snd_playTheme(MUSIC_INTRO, 2);
|
|
|
|
|
|
|
|
loadBitmap("START.CPS", 7, 7, _screen->_currentPalette);
|
|
|
|
_screen->copyRegion(0, 0, 0, 0, 320, 200, 6, 0);
|
|
|
|
_system->copyRectToScreen(_screen->getPagePtr(0), 320, 0, 0, 320, 200);
|
|
|
|
_screen->fadeFromBlack();
|
|
|
|
waitTicks(60);
|
|
|
|
_screen->fadeToBlack();
|
2005-09-10 06:40:20 +00:00
|
|
|
|
|
|
|
_screen->clearPage(0);
|
2005-09-10 07:46:18 +00:00
|
|
|
loadBitmap("TOP.CPS", 7, 7, NULL);
|
2005-09-10 06:40:20 +00:00
|
|
|
loadBitmap("BOTTOM.CPS", 5, 5, _screen->_currentPalette);
|
|
|
|
_screen->copyRegion(0, 91, 0, 8, 320, 103, 6, 0);
|
|
|
|
_screen->copyRegion(0, 0, 0, 111, 320, 64, 6, 0);
|
2005-09-10 07:46:18 +00:00
|
|
|
_system->copyRectToScreen(_screen->getPagePtr(0), 320, 0, 0, 320, 200);
|
2005-09-10 06:40:20 +00:00
|
|
|
_screen->fadeFromBlack();
|
|
|
|
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_WestwoodLogo, true);
|
2005-09-10 06:40:20 +00:00
|
|
|
waitTicks(60);
|
|
|
|
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_KyrandiaLogo, true);
|
2005-09-10 06:40:20 +00:00
|
|
|
|
|
|
|
_screen->fadeToBlack();
|
|
|
|
_screen->clearPage(2);
|
|
|
|
_screen->clearPage(0);
|
|
|
|
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_Demo1, true);
|
2005-09-10 06:40:20 +00:00
|
|
|
|
|
|
|
_screen->clearPage(0);
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_Demo2, true);
|
2005-09-10 06:40:20 +00:00
|
|
|
|
|
|
|
_screen->clearPage(0);
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_Demo3, true);
|
2005-09-10 06:40:20 +00:00
|
|
|
|
|
|
|
_screen->clearPage(0);
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_Demo4, true);
|
2005-09-10 06:40:20 +00:00
|
|
|
|
2005-09-12 10:49:52 +00:00
|
|
|
_screen->clearPage(0);
|
|
|
|
loadBitmap("FINAL.CPS", 7, 7, _screen->_currentPalette);
|
|
|
|
_screen->_curPage = 0;
|
|
|
|
_screen->copyRegion(0, 0, 0, 0, 320, 200, 6, 0);
|
|
|
|
_system->copyRectToScreen(_screen->getPagePtr(0), 320, 0, 0, 320, 200);
|
|
|
|
_screen->fadeFromBlack();
|
|
|
|
waitTicks(60);
|
|
|
|
_screen->fadeToBlack();
|
2005-10-03 20:21:18 +00:00
|
|
|
_midi->stopMusic();
|
2005-09-10 06:40:20 +00:00
|
|
|
}
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
void KyraEngine::seq_intro() {
|
|
|
|
debug(9, "KyraEngine::seq_intro()");
|
2005-10-13 21:12:47 +00:00
|
|
|
if (_features & GF_TALKIE) {
|
2005-10-18 19:59:51 +00:00
|
|
|
_res->loadPakFile("INTRO.VRM");
|
2005-10-12 19:15:32 +00:00
|
|
|
}
|
2005-10-18 19:59:51 +00:00
|
|
|
|
2005-09-08 19:09:52 +00:00
|
|
|
static const IntroProc introProcTable[] = {
|
|
|
|
&KyraEngine::seq_introLogos,
|
2005-10-13 21:12:47 +00:00
|
|
|
&KyraEngine::seq_introStory,
|
2005-10-18 19:59:51 +00:00
|
|
|
&KyraEngine::seq_introMalcolmTree,
|
2005-09-08 19:09:52 +00:00
|
|
|
&KyraEngine::seq_introKallakWriting,
|
2005-10-18 19:59:51 +00:00
|
|
|
&KyraEngine::seq_introKallakMalcolm
|
2005-09-08 19:09:52 +00:00
|
|
|
};
|
2005-10-29 18:37:40 +00:00
|
|
|
_skipIntroFlag = true; // only true if user already saved the game once
|
2005-10-06 11:57:02 +00:00
|
|
|
_seq->setCopyViewOffs(true);
|
2005-09-08 19:09:52 +00:00
|
|
|
_screen->setFont(Screen::FID_8_FNT);
|
2005-09-11 14:35:34 +00:00
|
|
|
snd_playTheme(MUSIC_INTRO, 2);
|
|
|
|
snd_setSoundEffectFile(MUSIC_INTRO);
|
2006-01-02 22:58:59 +00:00
|
|
|
_text->setTalkCoords(144);
|
2005-09-08 19:09:52 +00:00
|
|
|
for (int i = 0; i < ARRAYSIZE(introProcTable) && !seq_skipSequence(); ++i) {
|
|
|
|
(this->*introProcTable[i])();
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
2006-01-02 22:58:59 +00:00
|
|
|
_text->setTalkCoords(136);
|
2005-09-11 14:35:34 +00:00
|
|
|
waitTicks(30);
|
2005-10-06 11:57:02 +00:00
|
|
|
_seq->setCopyViewOffs(false);
|
2005-10-03 20:21:18 +00:00
|
|
|
_midi->stopMusic();
|
2005-10-13 21:12:47 +00:00
|
|
|
if (_features & GF_TALKIE) {
|
2005-10-19 10:29:34 +00:00
|
|
|
_res->unloadPakFile("INTRO.VRM");
|
2005-10-12 19:15:32 +00:00
|
|
|
}
|
2005-10-18 19:59:51 +00:00
|
|
|
res_unloadResources(RES_INTRO);
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
void KyraEngine::seq_introLogos() {
|
|
|
|
debug(9, "KyraEngine::seq_introLogos()");
|
|
|
|
_screen->clearPage(0);
|
2005-09-10 07:46:18 +00:00
|
|
|
loadBitmap("TOP.CPS", 7, 7, NULL);
|
2005-09-08 19:09:52 +00:00
|
|
|
loadBitmap("BOTTOM.CPS", 5, 5, _screen->_currentPalette);
|
2005-08-19 22:12:09 +00:00
|
|
|
_screen->_curPage = 0;
|
|
|
|
_screen->copyRegion(0, 91, 0, 8, 320, 103, 6, 0);
|
|
|
|
_screen->copyRegion(0, 0, 0, 111, 320, 64, 6, 0);
|
2005-09-10 07:46:18 +00:00
|
|
|
_system->copyRectToScreen(_screen->getPagePtr(0), 320, 0, 0, 320, 200);
|
2005-08-19 22:12:09 +00:00
|
|
|
_screen->fadeFromBlack();
|
|
|
|
|
2005-10-18 19:59:51 +00:00
|
|
|
if (_seq->playSequence(_seq_WestwoodLogo, _skipIntroFlag)) {
|
|
|
|
_screen->fadeToBlack();
|
|
|
|
_screen->clearPage(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
waitTicks(60);
|
|
|
|
if (_seq->playSequence(_seq_KyrandiaLogo, _skipIntroFlag)) {
|
|
|
|
_screen->fadeToBlack();
|
|
|
|
_screen->clearPage(0);
|
|
|
|
return;
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
|
|
|
_screen->fillRect(0, 179, 319, 199, 0);
|
|
|
|
|
|
|
|
int y1 = 8;
|
|
|
|
int h1 = 175;
|
|
|
|
int y2 = 176;
|
|
|
|
int h2 = 0;
|
|
|
|
_screen->copyRegion(0, 91, 0, 8, 320, 103, 6, 2);
|
|
|
|
_screen->copyRegion(0, 0, 0, 111, 320, 64, 6, 2);
|
|
|
|
do {
|
|
|
|
if (h1 > 0) {
|
|
|
|
_screen->copyRegion(0, y1, 0, 8, 320, h1, 2, 0);
|
|
|
|
}
|
|
|
|
++y1;
|
|
|
|
--h1;
|
|
|
|
if (h2 > 0) {
|
|
|
|
_screen->copyRegion(0, 64, 0, y2, 320, h2, 4, 0);
|
|
|
|
}
|
|
|
|
--y2;
|
|
|
|
++h2;
|
|
|
|
_screen->updateScreen();
|
|
|
|
waitTicks(1);
|
|
|
|
} while (y2 >= 64);
|
2005-07-30 21:11:48 +00:00
|
|
|
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_Forest, true);
|
2004-04-09 12:36:06 +00:00
|
|
|
}
|
|
|
|
|
2005-09-08 19:09:52 +00:00
|
|
|
void KyraEngine::seq_introStory() {
|
|
|
|
debug(9, "KyraEngine::seq_introStory()");
|
2005-10-18 19:59:51 +00:00
|
|
|
_screen->clearPage(3);
|
|
|
|
_screen->clearPage(0);
|
2005-10-19 15:59:40 +00:00
|
|
|
if ((_features & GF_ENGLISH) && (_features & GF_TALKIE)) {
|
|
|
|
loadBitmap("TEXT_ENG.CPS", 3, 3, 0);
|
2005-10-18 19:59:51 +00:00
|
|
|
} else if (_features & GF_GERMAN) {
|
|
|
|
loadBitmap("TEXT_GER.CPS", 3, 3, 0);
|
|
|
|
} else if (_features & GF_FRENCH) {
|
|
|
|
loadBitmap("TEXT_FRE.CPS", 3, 3, 0);
|
|
|
|
} else if (_features & GF_SPANISH) {
|
|
|
|
loadBitmap("TEXT_SPA.CPS", 3, 3, 0);
|
2005-10-19 15:59:40 +00:00
|
|
|
} else if ((_features & GF_ENGLISH) && (_features & GF_FLOPPY)) {
|
|
|
|
loadBitmap("TEXT.CPS", 3, 3, 0);
|
2005-10-18 19:59:51 +00:00
|
|
|
} else {
|
|
|
|
warning("no story graphics file found");
|
2005-10-13 21:12:47 +00:00
|
|
|
}
|
2005-10-18 19:59:51 +00:00
|
|
|
_screen->copyRegion(0, 0, 0, 0, 320, 200, 3, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
waitTicks(360);
|
2005-09-08 19:09:52 +00:00
|
|
|
}
|
|
|
|
|
2005-10-18 19:59:51 +00:00
|
|
|
void KyraEngine::seq_introMalcolmTree() {
|
|
|
|
debug(9, "KyraEngine::seq_introMalcolmTree()");
|
2005-09-08 19:09:52 +00:00
|
|
|
_screen->_curPage = 0;
|
|
|
|
_screen->clearPage(3);
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_MalcolmTree, true);
|
2005-09-08 19:09:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_introKallakWriting() {
|
|
|
|
debug(9, "KyraEngine::seq_introKallakWriting()");
|
2005-10-06 11:57:02 +00:00
|
|
|
_seq->makeHandShapes();
|
2005-09-10 00:15:40 +00:00
|
|
|
_screen->setAnimBlockPtr(5060);
|
2005-09-08 19:09:52 +00:00
|
|
|
_screen->_charWidth = -2;
|
|
|
|
_screen->clearPage(3);
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_KallakWriting, true);
|
2005-09-08 19:09:52 +00:00
|
|
|
}
|
|
|
|
|
2005-10-18 19:59:51 +00:00
|
|
|
void KyraEngine::seq_introKallakMalcolm() {
|
|
|
|
debug(9, "KyraEngine::seq_introKallakMalcolm()");
|
2005-09-08 19:09:52 +00:00
|
|
|
_screen->clearPage(3);
|
2005-10-18 19:59:51 +00:00
|
|
|
_seq->playSequence(_seq_KallakMalcolm, true);
|
2004-10-15 06:06:47 +00:00
|
|
|
}
|
|
|
|
|
2005-12-24 18:00:35 +00:00
|
|
|
void KyraEngine::seq_createAmuletJewel(int jewel, int page, int noSound, int drawOnly) {
|
|
|
|
debug(9, "seq_createAmuletJewel(%d, %d, %d, %d)", jewel, page, noSound, drawOnly);
|
|
|
|
const static uint16 specialJewelTable[] = {
|
|
|
|
0x167, 0x162, 0x15D, 0x158, 0x153, 0xFFFF
|
|
|
|
};
|
|
|
|
const static uint16 specialJewelTable1[] = {
|
|
|
|
0x14F, 0x154, 0x159, 0x15E, 0x163, 0xFFFF
|
|
|
|
};
|
|
|
|
const static uint16 specialJewelTable2[] = {
|
|
|
|
0x150, 0x155, 0x15A, 0x15F, 0x164, 0xFFFF
|
|
|
|
};
|
|
|
|
const static uint16 specialJewelTable3[] = {
|
|
|
|
0x151, 0x156, 0x15B, 0x160, 0x165, 0xFFFF
|
|
|
|
};
|
|
|
|
const static uint16 specialJewelTable4[] = {
|
|
|
|
0x152, 0x157, 0x15C, 0x161, 0x166, 0xFFFF
|
|
|
|
};
|
|
|
|
if (!noSound)
|
|
|
|
// snd_playSoundEffect(0x5F)
|
|
|
|
_screen->hideMouse();
|
|
|
|
if (!drawOnly) {
|
|
|
|
for (int i = 0; specialJewelTable[i] != 0xFFFF; ++i) {
|
|
|
|
_screen->drawShape(page, _shapes[4+specialJewelTable[i]], _amuletX2[jewel], _amuletY2[jewel], 0, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
delayWithTicks(3);
|
|
|
|
}
|
|
|
|
|
|
|
|
const uint16 *opcodes = 0;
|
|
|
|
switch (jewel - 1) {
|
|
|
|
case 0:
|
|
|
|
opcodes = specialJewelTable1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
opcodes = specialJewelTable2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
opcodes = specialJewelTable3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
opcodes = specialJewelTable4;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (opcodes) {
|
|
|
|
for (int i = 0; opcodes[i] != 0xFFFF; ++i) {
|
|
|
|
_screen->drawShape(page, _shapes[4+opcodes[i]], _amuletX2[jewel], _amuletY2[jewel], 0, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
delayWithTicks(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_screen->drawShape(page, _shapes[327+jewel], _amuletX2[jewel], _amuletY2[jewel], 0, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
_screen->showMouse();
|
|
|
|
setGameFlag(0x55+jewel);
|
|
|
|
}
|
|
|
|
|
2005-12-26 14:53:51 +00:00
|
|
|
void KyraEngine::seq_brandonHealing() {
|
|
|
|
debug(9, "seq_brandonHealing()");
|
|
|
|
if (!(_deathHandler & 8))
|
|
|
|
return;
|
|
|
|
if (_currentCharacter->sceneId == 210) {
|
|
|
|
//if (_unkSceneVar == 4 || _unkSceneVar == 6)
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
_screen->hideMouse();
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
assert(_healingShapeTable);
|
|
|
|
setupShapes123(_healingShapeTable, 22, 0);
|
|
|
|
setBrandonAnimSeqSize(3, 48);
|
|
|
|
// snd_playSoundEffect(0x53);
|
|
|
|
for (int i = 123; i <= 144; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
for (int i = 125; i >= 123; --i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
resetBrandonAnimSeqSize();
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
freeShapes123();
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
2005-12-28 21:34:40 +00:00
|
|
|
void KyraEngine::seq_brandonHealing2() {
|
|
|
|
debug(9, "seq_brandonHealing2()");
|
|
|
|
_screen->hideMouse();
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
assert(_healingShape2Table);
|
|
|
|
setupShapes123(_healingShape2Table, 30, 0);
|
|
|
|
resetBrandonPoisonFlags();
|
|
|
|
setBrandonAnimSeqSize(3, 48);
|
|
|
|
// snd_playSoundEffect(0x50);
|
|
|
|
for (int i = 123; i <= 152; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
resetBrandonAnimSeqSize();
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
freeShapes123();
|
|
|
|
_screen->showMouse();
|
|
|
|
assert(_poisonGone);
|
|
|
|
characterSays(_poisonGone[0], 0, -2);
|
|
|
|
characterSays(_poisonGone[1], 0, -2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_poisonDeathNow(int now) {
|
|
|
|
debug(9, "seq_poisonDeathNow(%d)", now);
|
|
|
|
if (!(_brandonStatusBit & 1))
|
|
|
|
return;
|
|
|
|
++_poisonDeathCounter;
|
|
|
|
if (now)
|
|
|
|
_poisonDeathCounter = 2;
|
|
|
|
if (_poisonDeathCounter >= 2) {
|
|
|
|
// XXX
|
|
|
|
assert(_thePoison);
|
|
|
|
characterSays(_thePoison[0], 0, -2);
|
|
|
|
characterSays(_thePoison[1], 0, -2);
|
|
|
|
seq_poisonDeathNowAnim();
|
|
|
|
_deathHandler = 3;
|
|
|
|
} else {
|
|
|
|
assert(_thePoison);
|
|
|
|
characterSays(_thePoison[2], 0, -2);
|
|
|
|
characterSays(_thePoison[3], 0, -2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_poisonDeathNowAnim() {
|
|
|
|
debug(9, "seq_poisonDeathNowAnim()");
|
|
|
|
_screen->hideMouse();
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
assert(_posionDeathShapeTable);
|
|
|
|
setupShapes123(_posionDeathShapeTable, 20, 0);
|
|
|
|
setBrandonAnimSeqSize(8, 48);
|
|
|
|
|
|
|
|
_currentCharacter->currentAnimFrame = 124;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(30);
|
|
|
|
|
|
|
|
_currentCharacter->currentAnimFrame = 123;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(30);
|
|
|
|
|
|
|
|
for (int i = 125; i <= 139; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
delayWithTicks(60);
|
|
|
|
|
|
|
|
for (int i = 140; i <= 142; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
delayWithTicks(60);
|
|
|
|
|
|
|
|
resetBrandonAnimSeqSize();
|
|
|
|
freeShapes123();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->restoreAllObjectBackgrounds();
|
2005-12-28 21:34:40 +00:00
|
|
|
_currentCharacter->x1 = _currentCharacter->x2 = -1;
|
|
|
|
_currentCharacter->y1 = _currentCharacter->y2 = -1;
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->preserveAllBackgrounds();
|
2005-12-28 21:34:40 +00:00
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_playFluteAnimation() {
|
|
|
|
debug(9, "seq_playFluteAnimation()");
|
|
|
|
_screen->hideMouse();
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
setupShapes123(_fluteAnimShapeTable, 36, 0);
|
|
|
|
setBrandonAnimSeqSize(3, 75);
|
|
|
|
for (int i = 123; i <= 130; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
int delayTime = 0, soundType = 0;
|
|
|
|
if (queryGameFlag(0x85)) {
|
|
|
|
// snd_playSoundEffect(0x63);
|
|
|
|
delayTime = 9;
|
|
|
|
soundType = 3;
|
|
|
|
} else if (queryGameFlag(0x86)) {
|
|
|
|
// snd_playSoundEffect(0x61);
|
|
|
|
delayTime = 2;
|
|
|
|
soundType = 1;
|
|
|
|
} else {
|
|
|
|
// snd_playSoundEffect(0x62);
|
|
|
|
delayTime = 2;
|
|
|
|
soundType = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 131; i <= 158; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(delayTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 126; i >= 123; --i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(delayTime);
|
|
|
|
}
|
|
|
|
resetBrandonAnimSeqSize();
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
freeShapes123();
|
|
|
|
_screen->showMouse();
|
|
|
|
|
|
|
|
if (soundType == 1) {
|
|
|
|
assert(_fluteString);
|
|
|
|
characterSays(_fluteString[0], 0, -2);
|
|
|
|
} else if (soundType == 2) {
|
|
|
|
assert(_fluteString);
|
|
|
|
characterSays(_fluteString[1], 0, -2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-29 22:18:40 +00:00
|
|
|
void KyraEngine::seq_winterScroll1() {
|
|
|
|
debug(9, "seq_winterScroll1()");
|
|
|
|
_screen->hideMouse();
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
assert(_winterScrollTable);
|
|
|
|
assert(_winterScroll1Table);
|
|
|
|
assert(_winterScroll2Table);
|
|
|
|
setupShapes123(_winterScrollTable, 7, 0);
|
|
|
|
setBrandonAnimSeqSize(5, 66);
|
|
|
|
|
|
|
|
for (int i = 123; i <= 129; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
freeShapes123();
|
|
|
|
// snd_playSoundEffect(0x20);
|
|
|
|
setupShapes123(_winterScroll1Table, 35, 0);
|
|
|
|
|
|
|
|
for (int i = 123; i <= 146; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_currentCharacter->sceneId == 41 && !queryGameFlag(0xA2)) {
|
|
|
|
// snd_playSoundEffect(0x20);
|
|
|
|
_sprites->_anims[0].play = false;
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->sprites()[0].active = 0;
|
2005-12-29 22:18:40 +00:00
|
|
|
_sprites->_anims[1].play = true;
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->sprites()[1].active = 1;
|
2005-12-29 22:18:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 147; i <= 157; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_currentCharacter->sceneId == 117 && !queryGameFlag(0xB3)) {
|
|
|
|
for (int i = 0; i <= 7; ++i) {
|
|
|
|
_sprites->_anims[i].play = false;
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->sprites()[i].active = 0;
|
2005-12-29 22:18:40 +00:00
|
|
|
}
|
|
|
|
uint8 tmpPal[768];
|
|
|
|
memcpy(tmpPal, _screen->_currentPalette, 768);
|
|
|
|
memcpy(&tmpPal[684], palTable2()[0], 60);
|
|
|
|
_screen->fadePalette(tmpPal, 72);
|
|
|
|
} else {
|
|
|
|
delayWithTicks(120);
|
|
|
|
}
|
|
|
|
|
|
|
|
freeShapes123();
|
|
|
|
setupShapes123(_winterScroll2Table, 4, 0);
|
|
|
|
|
|
|
|
for (int i = 123; i <= 126; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetBrandonAnimSeqSize();
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
freeShapes123();
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_winterScroll2() {
|
|
|
|
debug(9, "seq_winterScroll2()");
|
|
|
|
_screen->hideMouse();
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
assert(_winterScrollTable);
|
|
|
|
setupShapes123(_winterScrollTable, 7, 0);
|
|
|
|
setBrandonAnimSeqSize(5, 66);
|
|
|
|
|
|
|
|
for (int i = 123; i <= 128; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
delayWithTicks(120);
|
|
|
|
|
|
|
|
for (int i = 127; i >= 123; --i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetBrandonAnimSeqSize();
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
freeShapes123();
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_makeBrandonInv() {
|
|
|
|
debug(9, "seq_makeBrandonInv()");
|
|
|
|
if (_deathHandler == 8)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_currentCharacter->sceneId == 210) {
|
|
|
|
//if (_unkSceneVar == 4 || _unkSceneVar == 6)
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_screen->hideMouse();
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
_brandonStatusBit |= 0x20;
|
|
|
|
setTimerCountdown(18, 2700);
|
|
|
|
_brandonStatusBit |= 0x40;
|
|
|
|
// snd_playSoundEffect(0x77);
|
|
|
|
_brandonInvFlag = 0;
|
|
|
|
while (_brandonInvFlag <= 0x100) {
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(10);
|
|
|
|
_brandonInvFlag += 0x10;
|
|
|
|
}
|
|
|
|
_brandonStatusBit &= 0xFFBF;
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_makeBrandonNormal() {
|
|
|
|
debug(9, "seq_makeBrandonNormal()");
|
|
|
|
_screen->hideMouse();
|
|
|
|
_brandonStatusBit |= 0x40;
|
|
|
|
// snd_playSoundEffect(0x77);
|
|
|
|
_brandonInvFlag = 0x100;
|
|
|
|
while (_brandonInvFlag >= 0) {
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(10);
|
|
|
|
_brandonInvFlag -= 0x10;
|
|
|
|
}
|
2006-01-03 23:41:52 +00:00
|
|
|
_brandonInvFlag = 0;
|
2005-12-29 22:18:40 +00:00
|
|
|
_brandonStatusBit &= 0xFF9F;
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_makeBrandonNormal2() {
|
|
|
|
debug(9, "seq_makeBrandonNormal2()");
|
|
|
|
_screen->hideMouse();
|
|
|
|
assert(_brandonToWispTable);
|
|
|
|
setupShapes123(_brandonToWispTable, 26, 0);
|
|
|
|
setBrandonAnimSeqSize(5, 48);
|
|
|
|
_brandonStatusBit &= 0xFFFD;
|
|
|
|
// snd_playSoundEffect(0x6C);
|
|
|
|
for (int i = 138; i >= 123; --i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
setBrandonAnimSeqSize(4, 48);
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
if (_currentCharacter->sceneId >= 229 && _currentCharacter->sceneId <= 245) {
|
|
|
|
_screen->fadeSpecialPalette(31, 234, 13, 4);
|
|
|
|
} else if (_currentCharacter->sceneId >= 118 && _currentCharacter->sceneId <= 186) {
|
|
|
|
_screen->fadeSpecialPalette(14, 228, 15, 4);
|
|
|
|
}
|
|
|
|
freeShapes123();
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_makeBrandonWisp() {
|
|
|
|
debug(9, "seq_makeBrandonWisp()");
|
|
|
|
if (_deathHandler == 8)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (_currentCharacter->sceneId == 210) {
|
|
|
|
//if (_unkSceneVar == 4 || _unkSceneVar == 6)
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
_screen->hideMouse();
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
assert(_brandonToWispTable);
|
|
|
|
setupShapes123(_brandonToWispTable, 26, 0);
|
|
|
|
setBrandonAnimSeqSize(5, 48);
|
|
|
|
// snd_playSoundEffect(0x6C);
|
|
|
|
for (int i = 123; i <= 138; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
_brandonStatusBit |= 2;
|
|
|
|
if (_currentCharacter->sceneId >= 109 && _currentCharacter->sceneId <= 198) {
|
|
|
|
setTimerCountdown(14, 18000);
|
|
|
|
} else {
|
|
|
|
setTimerCountdown(14, 7200);
|
|
|
|
}
|
|
|
|
_brandonDrawFrame = 113;
|
|
|
|
_brandonStatusBit0x02Flag = 1;
|
|
|
|
_currentCharacter->currentAnimFrame = 113;
|
|
|
|
animRefreshNPC(0);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-12-29 22:18:40 +00:00
|
|
|
if (_currentCharacter->sceneId >= 229 && _currentCharacter->sceneId <= 245) {
|
|
|
|
_screen->fadeSpecialPalette(30, 234, 13, 4);
|
|
|
|
} else if (_currentCharacter->sceneId >= 118 && _currentCharacter->sceneId <= 186) {
|
|
|
|
_screen->fadeSpecialPalette(14, 228, 15, 4);
|
|
|
|
}
|
|
|
|
freeShapes123();
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_dispelMagicAnimation() {
|
|
|
|
debug(9, "seq_dispelMagicAnimation()");
|
|
|
|
if (_deathHandler == 8)
|
|
|
|
return;
|
|
|
|
if (_currentCharacter->sceneId == 210) {
|
|
|
|
//if (_unkSceneVar == 4 || _unkSceneVar == 6)
|
|
|
|
// return;
|
|
|
|
}
|
|
|
|
_screen->hideMouse();
|
|
|
|
if (_currentCharacter->sceneId == 210 && _currentCharacter->sceneId < 160)
|
|
|
|
_currentCharacter->facing = 3;
|
|
|
|
// XXX
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
setGameFlag(0xEE);
|
|
|
|
assert(_magicAnimationTable);
|
|
|
|
setupShapes123(_magicAnimationTable, 5, 0);
|
|
|
|
setBrandonAnimSeqSize(8, 49);
|
|
|
|
// snd_playSoundEffect(0x15);
|
|
|
|
for (int i = 123; i <= 127; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(8);
|
|
|
|
}
|
|
|
|
|
|
|
|
delayWithTicks(120);
|
|
|
|
|
|
|
|
for (int i = 127; i >= 123; --i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(10);
|
|
|
|
}
|
|
|
|
resetBrandonAnimSeqSize();
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
freeShapes123();
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
2005-12-31 17:25:47 +00:00
|
|
|
void KyraEngine::seq_fillFlaskWithWater(int item, int type) {
|
|
|
|
debug(9, "seq_fillFlaskWithWater(%d, %d)", item, type);
|
|
|
|
int newItem = -1;
|
|
|
|
static const uint8 flaskTable1[] = { 0x46, 0x48, 0x4A, 0x4C };
|
|
|
|
static const uint8 flaskTable2[] = { 0x47, 0x49, 0x4B, 0x4D };
|
|
|
|
|
|
|
|
if (item >= 60 && item <= 77) {
|
|
|
|
assert(_flaskFull);
|
|
|
|
characterSays(_flaskFull[0], 0, -2);
|
|
|
|
} else if (item == 78) {
|
|
|
|
assert(type >= 0 && type < ARRAYSIZE(flaskTable1));
|
|
|
|
newItem = flaskTable1[type];
|
|
|
|
} else if (item == 79) {
|
|
|
|
assert(type >= 0 && type < ARRAYSIZE(flaskTable2));
|
|
|
|
newItem = flaskTable2[type];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newItem == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
_screen->hideMouse();
|
|
|
|
setMouseItem(newItem);
|
|
|
|
_screen->showMouse();
|
|
|
|
_itemInHand = newItem;
|
|
|
|
assert(_fullFlask);
|
|
|
|
assert(type < _fullFlask_Size && type >= 0);
|
|
|
|
characterSays(_fullFlask[type], 0, -2);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::seq_playDrinkPotionAnim(int unk1, int unk2, int flags) {
|
|
|
|
debug(9, "seq_playDrinkPotionAnim(%d, %d, %d)", unk1, unk2, flags);
|
|
|
|
// XXX
|
|
|
|
_screen->hideMouse();
|
|
|
|
checkAmuletAnimFlags();
|
|
|
|
_currentCharacter->facing = 5;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
assert(_drinkAnimationTable);
|
|
|
|
setupShapes123(_drinkAnimationTable, 9, flags);
|
|
|
|
setBrandonAnimSeqSize(5, 54);
|
|
|
|
|
|
|
|
for (int i = 123; i <= 131; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(5);
|
|
|
|
}
|
|
|
|
// snd_playSoundEffect(0x34);
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
_currentCharacter->currentAnimFrame = 130;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(7);
|
|
|
|
_currentCharacter->currentAnimFrame = 131;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(7);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unk2) {
|
|
|
|
// XXX
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 131; i >= 123; --i) {
|
|
|
|
_currentCharacter->currentAnimFrame = i;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
delayWithTicks(5);
|
|
|
|
}
|
|
|
|
|
|
|
|
resetBrandonAnimSeqSize();
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
|
|
|
freeShapes123();
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
2005-08-19 22:12:09 +00:00
|
|
|
bool KyraEngine::seq_skipSequence() const {
|
2005-08-31 20:14:20 +00:00
|
|
|
debug(9, "KyraEngine::seq_skipSequence()");
|
2005-10-03 20:21:18 +00:00
|
|
|
return _quitFlag || _abortIntroFlag;
|
2005-08-19 22:12:09 +00:00
|
|
|
}
|
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
void KyraEngine::snd_playTheme(int file, int track) {
|
|
|
|
debug(9, "KyraEngine::snd_playTheme(%d)", file);
|
|
|
|
assert(file < _xmidiFilesCount);
|
2005-10-29 18:37:40 +00:00
|
|
|
_curMusicTheme = _newMusicTheme = file;
|
2005-09-11 17:23:04 +00:00
|
|
|
_midi->playMusic(_xmidiFiles[file]);
|
2005-09-11 14:35:34 +00:00
|
|
|
_midi->playTrack(track, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::snd_playTrack(int track) {
|
|
|
|
debug(9, "KyraEngine::snd_playTrack(%d)", track);
|
|
|
|
_midi->playTrack(track, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::snd_setSoundEffectFile(int file) {
|
|
|
|
debug(9, "KyraEngine::snd_setSoundEffectFile(%d)", file);
|
|
|
|
assert(file < _xmidiFilesCount);
|
|
|
|
_midi->loadSoundEffectFile(_xmidiFiles[file]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::snd_playSoundEffect(int track) {
|
|
|
|
debug(9, "KyraEngine::snd_playSoundEffect(%d)", track);
|
|
|
|
_midi->playSoundEffect(track);
|
|
|
|
}
|
|
|
|
|
2005-10-12 19:15:32 +00:00
|
|
|
void KyraEngine::snd_playVoiceFile(int id) {
|
|
|
|
debug(9, "KyraEngine::snd_playVoiceFile(%d)", id);
|
2005-12-12 19:22:49 +00:00
|
|
|
char vocFile[9];
|
2005-12-12 17:39:01 +00:00
|
|
|
assert(id >= 0 && id < 9999);
|
2005-10-15 06:26:53 +00:00
|
|
|
sprintf(vocFile, "%03d.VOC", id);
|
2005-10-12 19:15:32 +00:00
|
|
|
uint32 fileSize = 0;
|
|
|
|
byte *fileData = 0;
|
|
|
|
fileData = _res->fileData(vocFile, &fileSize);
|
|
|
|
assert(fileData);
|
|
|
|
Common::MemoryReadStream vocStream(fileData, fileSize);
|
|
|
|
_mixer->stopHandle(_vocHandle);
|
|
|
|
_currentVocFile = makeVOCStream(vocStream);
|
|
|
|
if (_currentVocFile)
|
|
|
|
_mixer->playInputStream(Audio::Mixer::kSpeechSoundType, &_vocHandle, _currentVocFile);
|
|
|
|
delete fileData;
|
|
|
|
fileSize = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KyraEngine::snd_voicePlaying() {
|
|
|
|
return _mixer->isSoundHandleActive(_vocHandle);
|
|
|
|
}
|
|
|
|
|
2005-09-11 14:35:34 +00:00
|
|
|
void KyraEngine::snd_startTrack() {
|
|
|
|
debug(9, "KyraEngine::snd_startTrack()");
|
|
|
|
_midi->startTrack();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::snd_haltTrack() {
|
|
|
|
debug(9, "KyraEngine::snd_haltTrack()");
|
|
|
|
_midi->haltTrack();
|
|
|
|
}
|
|
|
|
|
2005-10-22 00:24:07 +00:00
|
|
|
void KyraEngine::loadMouseShapes() {
|
|
|
|
loadBitmap("MOUSE.CPS", 3, 3, 0);
|
|
|
|
_screen->_curPage = 2;
|
2005-10-29 18:37:40 +00:00
|
|
|
_shapes[4] = _screen->encodeShape(0, 0, 8, 10, 0);
|
|
|
|
_shapes[5] = _screen->encodeShape(0, 0x17, 0x20, 7, 0);
|
|
|
|
_shapes[6] = _screen->encodeShape(0x50, 0x12, 0x10, 9, 0);
|
|
|
|
_shapes[7] = _screen->encodeShape(0x60, 0x12, 0x10, 11, 0);
|
|
|
|
_shapes[8] = _screen->encodeShape(0x70, 0x12, 0x10, 9, 0);
|
|
|
|
_shapes[9] = _screen->encodeShape(0x80, 0x12, 0x10, 11, 0);
|
|
|
|
_shapes[10] = _screen->encodeShape(0x90, 0x12, 0x10, 10, 0);
|
|
|
|
_shapes[364] = _screen->encodeShape(0x28, 0, 0x10, 13, 0);
|
2005-10-22 00:24:07 +00:00
|
|
|
_screen->setMouseCursor(1, 1, 0);
|
2005-10-29 18:37:40 +00:00
|
|
|
_screen->setMouseCursor(1, 1, _shapes[4]);
|
2005-11-01 14:19:50 +00:00
|
|
|
_screen->setShapePages(5, 3);
|
2005-10-22 00:24:07 +00:00
|
|
|
}
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
void KyraEngine::loadCharacterShapes() {
|
|
|
|
int curImage = 0xFF;
|
|
|
|
int videoPage = _screen->_curPage;
|
|
|
|
_screen->_curPage = 2;
|
|
|
|
for (int i = 0; i < 115; ++i) {
|
|
|
|
assert(i < _defaultShapeTableSize);
|
|
|
|
Shape *shape = &_defaultShapeTable[i];
|
|
|
|
if (shape->imageIndex == 0xFF) {
|
2005-10-30 19:58:51 +00:00
|
|
|
_shapes[i+7+4] = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (shape->imageIndex != curImage) {
|
|
|
|
assert(shape->imageIndex < _characterImageTableSize);
|
|
|
|
loadBitmap(_characterImageTable[shape->imageIndex], 3, 3, 0);
|
|
|
|
curImage = shape->imageIndex;
|
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
_shapes[i+7+4] = _screen->encodeShape(shape->x<<3, shape->y, shape->w<<3, shape->h, 1);
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
_screen->_curPage = videoPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::loadSpecialEffectShapes() {
|
|
|
|
loadBitmap("EFFECTS.CPS", 3, 3, 0);
|
|
|
|
_screen->_curPage = 2;
|
|
|
|
|
|
|
|
int currShape;
|
|
|
|
for (currShape = 173; currShape < 183; currShape++)
|
|
|
|
_shapes[4 + currShape] = _screen->encodeShape((currShape-173) * 24, 0, 24, 24, 1);
|
|
|
|
|
|
|
|
for (currShape = 183; currShape < 190; currShape++)
|
|
|
|
_shapes[4 + currShape] = _screen->encodeShape((currShape-183) * 24, 24, 24, 24, 1);
|
|
|
|
|
|
|
|
for (currShape = 190; currShape < 201; currShape++)
|
|
|
|
_shapes[4 + currShape] = _screen->encodeShape((currShape-190) * 24, 48, 24, 24, 1);
|
|
|
|
|
|
|
|
for (currShape = 201; currShape < 206; currShape++)
|
|
|
|
_shapes[4 + currShape] = _screen->encodeShape((currShape-201) * 16, 106, 16, 16, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::findDuplicateItemShape(int shape) {
|
|
|
|
static uint8 dupTable[] = {
|
|
|
|
0x48, 0x46, 0x49, 0x47, 0x4a, 0x46, 0x4b, 0x47,
|
|
|
|
0x4c, 0x46, 0x4d, 0x47, 0x5b, 0x5a, 0x5c, 0x5a,
|
|
|
|
0x5d, 0x5a, 0x5e, 0x5a, 0xFF, 0xFF
|
|
|
|
};
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
|
|
|
while (dupTable[i] != 0xFF) {
|
|
|
|
if (dupTable[i] == shape)
|
|
|
|
return dupTable[i+1];
|
|
|
|
i += 2;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::loadItems() {
|
|
|
|
int shape;
|
|
|
|
|
|
|
|
loadBitmap("JEWELS3.CPS", 3, 3, 0);
|
|
|
|
_screen->_curPage = 2;
|
|
|
|
|
|
|
|
_shapes[327] = 0;
|
|
|
|
|
|
|
|
for (shape = 1; shape < 6; shape++ )
|
|
|
|
_shapes[327 + shape] = _screen->encodeShape((shape - 1) * 32, 0, 32, 17, 0);
|
|
|
|
|
|
|
|
for (shape = 330; shape <= 334; shape++)
|
|
|
|
_shapes[4 + shape] = _screen->encodeShape((shape-330) * 32, 102, 32, 17, 0);
|
|
|
|
|
|
|
|
for (shape = 335; shape <= 339; shape++)
|
|
|
|
_shapes[4 + shape] = _screen->encodeShape((shape-335) * 32, 17, 32, 17, 0);
|
|
|
|
|
|
|
|
for (shape = 340; shape <= 344; shape++)
|
|
|
|
_shapes[4 + shape] = _screen->encodeShape((shape-340) * 32, 34, 32, 17, 0);
|
|
|
|
|
|
|
|
for (shape = 345; shape <= 349; shape++)
|
|
|
|
_shapes[4 + shape] = _screen->encodeShape((shape-345) * 32, 51, 32, 17, 0);
|
|
|
|
|
|
|
|
for (shape = 350; shape <= 354; shape++)
|
|
|
|
_shapes[4 + shape] = _screen->encodeShape((shape-350) * 32, 68, 32, 17, 0);
|
|
|
|
|
|
|
|
for (shape = 355; shape <= 359; shape++)
|
|
|
|
_shapes[4 + shape] = _screen->encodeShape((shape-355) * 32, 85, 32, 17, 0);
|
|
|
|
|
|
|
|
|
|
|
|
loadBitmap("ITEMS.CPS", 3, 3, 0);
|
|
|
|
_screen->_curPage = 2;
|
|
|
|
|
|
|
|
for (int i = 0; i < 107; i++) {
|
|
|
|
shape = findDuplicateItemShape(i);
|
|
|
|
|
|
|
|
if (shape != -1)
|
|
|
|
_shapes[220 + i] = _shapes[220 + shape];
|
|
|
|
else
|
|
|
|
_shapes[220 + i] = _screen->encodeShape( (i % 20) * 16, i/20 * 16, 16, 16, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32 size;
|
|
|
|
uint8 *fileData = _res->fileData("_ITEM_HT.DAT", &size);
|
|
|
|
assert(fileData);
|
|
|
|
|
|
|
|
for (int i = 0; i < 107; i++) {
|
|
|
|
_itemTable[i].height = fileData[i];
|
|
|
|
_itemTable[i].unk1 = _itemTable[i].unk2 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete[] fileData;
|
|
|
|
}
|
|
|
|
|
2005-12-24 18:00:35 +00:00
|
|
|
void KyraEngine::loadButtonShapes() {
|
|
|
|
loadBitmap("BUTTONS2.CPS", 3, 3, 0);
|
|
|
|
_screen->_curPage = 2;
|
|
|
|
_buttonShape0 = _screen->encodeShape(0, 0, 24, 14, 1);
|
|
|
|
_buttonShape1 = _screen->encodeShape(24, 0, 24, 14, 1);
|
|
|
|
_buttonShape2 = _screen->encodeShape(48, 0, 24, 14, 1);
|
|
|
|
_buttonShape3 = _screen->encodeShape(0, 15, 24, 14, 1);
|
|
|
|
_buttonShape4 = _screen->encodeShape(24, 15, 24, 14, 1);
|
|
|
|
_buttonShape5 = _screen->encodeShape(48, 15, 24, 14, 1);
|
|
|
|
_screen->_curPage = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::initMainButtonList() {
|
|
|
|
_buttonList = &_buttonData[0];
|
|
|
|
for (int i = 0; _buttonDataListPtr[i]; ++i) {
|
|
|
|
_buttonList = initButton(_buttonList, _buttonDataListPtr[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-03 23:41:52 +00:00
|
|
|
void KyraEngine::loadMainScreen(int page) {
|
2005-10-29 18:37:40 +00:00
|
|
|
if ((_features & GF_ENGLISH) && (_features & GF_TALKIE))
|
2006-01-03 23:41:52 +00:00
|
|
|
loadBitmap("MAIN_ENG.CPS", page, page, 0);
|
2005-10-29 18:37:40 +00:00
|
|
|
else if(_features & GF_FRENCH)
|
2006-01-03 23:41:52 +00:00
|
|
|
loadBitmap("MAIN_FRE.CPS", page, page, 0);
|
2005-10-29 18:37:40 +00:00
|
|
|
else if(_features & GF_GERMAN)
|
2006-01-03 23:41:52 +00:00
|
|
|
loadBitmap("MAIN_GER.CPS", page, page, 0);
|
2005-10-29 18:37:40 +00:00
|
|
|
else if ((_features & GF_ENGLISH) && (_features & GF_FLOPPY))
|
2006-01-03 23:41:52 +00:00
|
|
|
loadBitmap("MAIN15.CPS", page, page, 0);
|
2005-10-29 18:37:40 +00:00
|
|
|
else if (_features & GF_SPANISH)
|
2006-01-03 23:41:52 +00:00
|
|
|
loadBitmap("MAIN_SPA.CPS", page, page, 0);
|
2005-10-29 18:37:40 +00:00
|
|
|
else
|
|
|
|
warning("no main graphics file found");
|
|
|
|
|
2006-01-03 23:41:52 +00:00
|
|
|
uint8 *_pageSrc = _screen->getPagePtr(page);
|
|
|
|
uint8 *_pageDst = _screen->getPagePtr(0);
|
|
|
|
memcpy(_pageDst, _pageSrc, 320*200);
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::setCharactersInDefaultScene() {
|
2006-01-03 23:41:52 +00:00
|
|
|
static const uint32 defaultSceneTable[][4] = {
|
2005-10-29 18:37:40 +00:00
|
|
|
{ 0xFFFF, 0x0004, 0x0003, 0xFFFF },
|
|
|
|
{ 0xFFFF, 0x0022, 0xFFFF, 0x0000 },
|
|
|
|
{ 0xFFFF, 0x001D, 0x0021, 0xFFFF },
|
|
|
|
{ 0xFFFF, 0x0000, 0x0000, 0xFFFF }
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 1; i < 5; ++i) {
|
|
|
|
Character *cur = &_characterList[i];
|
2006-01-03 23:41:52 +00:00
|
|
|
//cur->field_20 = 0;
|
|
|
|
const uint32 *curTable = defaultSceneTable[i-1];
|
2005-10-29 18:37:40 +00:00
|
|
|
cur->sceneId = curTable[0];
|
|
|
|
if (cur->sceneId == _currentCharacter->sceneId) {
|
2006-01-03 23:41:52 +00:00
|
|
|
//++cur->field_20;
|
|
|
|
cur->sceneId = curTable[1/*cur->field_20*/];
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
2006-01-03 23:41:52 +00:00
|
|
|
//cur->field_23 = curTable[cur->field_20+1];
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::setCharacterDefaultFrame(int character) {
|
|
|
|
static uint16 initFrameTable[] = {
|
2005-11-01 14:19:50 +00:00
|
|
|
7, 41, 77, 0, 0
|
2005-10-29 18:37:40 +00:00
|
|
|
};
|
|
|
|
assert(character < ARRAYSIZE(initFrameTable));
|
|
|
|
Character *edit = &_characterList[character];
|
|
|
|
edit->sceneId = 0xFFFF;
|
|
|
|
edit->facing = 0;
|
|
|
|
edit->currentAnimFrame = initFrameTable[character];
|
2006-01-03 23:41:52 +00:00
|
|
|
// edit->unk6 = 1;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::setCharactersPositions(int character) {
|
2005-11-01 14:19:50 +00:00
|
|
|
static uint16 initXPosTable[] = {
|
2005-10-29 18:37:40 +00:00
|
|
|
0x3200, 0x0024, 0x2230, 0x2F00, 0x0020, 0x002B,
|
2005-11-01 14:19:50 +00:00
|
|
|
0x00CA, 0x00F0, 0x0082, 0x00A2, 0x0042
|
2005-10-29 18:37:40 +00:00
|
|
|
};
|
2005-11-01 14:19:50 +00:00
|
|
|
static uint8 initYPosTable[] = {
|
2005-10-29 18:37:40 +00:00
|
|
|
0x00, 0xA2, 0x00, 0x42, 0x00,
|
|
|
|
0x67, 0x67, 0x60, 0x5A, 0x71,
|
|
|
|
0x76
|
|
|
|
};
|
|
|
|
assert(character < ARRAYSIZE(initXPosTable));
|
|
|
|
Character *edit = &_characterList[character];
|
|
|
|
edit->x1 = edit->x2 = initXPosTable[character];
|
|
|
|
edit->y1 = edit->y2 = initYPosTable[character];
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::setCharactersHeight() {
|
|
|
|
static int8 initHeightTable[] = {
|
2005-11-01 14:19:50 +00:00
|
|
|
48, 40, 48, 47, 56,
|
|
|
|
44, 42, 47, 38, 35,
|
|
|
|
40
|
2005-10-29 18:37:40 +00:00
|
|
|
};
|
|
|
|
for (int i = 0; i < 11; ++i) {
|
|
|
|
_characterList[i].height = initHeightTable[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::setGameFlag(int flag) {
|
|
|
|
_flagsTable[flag >> 3] |= (1 << (flag & 7));
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::queryGameFlag(int flag) {
|
|
|
|
return ((_flagsTable[flag >> 3] >> (flag & 7)) & 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::resetGameFlag(int flag) {
|
|
|
|
_flagsTable[flag >> 3] &= ~(1 << (flag & 7));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::enterNewScene(int sceneId, int facing, int unk1, int unk2, int brandonAlive) {
|
2005-11-01 14:19:50 +00:00
|
|
|
debug(9, "enterNewScene(%d, %d, %d, %d, %d)", sceneId, facing, unk1, unk2, brandonAlive);
|
2005-10-29 18:37:40 +00:00
|
|
|
int unkVar1 = 1;
|
|
|
|
_screen->hideMouse();
|
2005-12-24 18:00:35 +00:00
|
|
|
_handleInput = false;
|
|
|
|
_abortWalkFlag = false;
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag2 = false;
|
2005-10-29 18:37:40 +00:00
|
|
|
if (_currentCharacter->sceneId == 7 && sceneId == 24) {
|
|
|
|
_newMusicTheme = 2;
|
|
|
|
} else if (_currentCharacter->sceneId == 25 && sceneId == 109) {
|
|
|
|
_newMusicTheme = 3;
|
|
|
|
} else if (_currentCharacter->sceneId == 120 && sceneId == 37) {
|
|
|
|
_newMusicTheme = 4;
|
|
|
|
} else if (_currentCharacter->sceneId == 52 && sceneId == 199) {
|
|
|
|
_newMusicTheme = 5;
|
|
|
|
} else if (_currentCharacter->sceneId == 37 && sceneId == 120) {
|
|
|
|
_newMusicTheme = 3;
|
|
|
|
} else if (_currentCharacter->sceneId == 109 && sceneId == 25) {
|
|
|
|
_newMusicTheme = 2;
|
|
|
|
} else if (_currentCharacter->sceneId == 24 && sceneId == 7) {
|
|
|
|
_newMusicTheme = 1;
|
|
|
|
}
|
|
|
|
if (_newMusicTheme != _curMusicTheme) {
|
|
|
|
snd_playTheme(_newMusicTheme);
|
|
|
|
}
|
2005-11-13 19:35:01 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
switch (_currentCharacter->sceneId) {
|
|
|
|
case 1:
|
|
|
|
if (sceneId == 0) {
|
|
|
|
moveCharacterToPos(0, 0, _currentCharacter->x1, 84);
|
|
|
|
unkVar1 = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
if (sceneId == 2) {
|
|
|
|
moveCharacterToPos(0, 6, 155, _currentCharacter->y1);
|
|
|
|
unkVar1 = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 26:
|
|
|
|
if (sceneId == 27) {
|
|
|
|
moveCharacterToPos(0, 6, 155, _currentCharacter->y1);
|
|
|
|
unkVar1 = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 44:
|
|
|
|
if (sceneId == 45) {
|
|
|
|
moveCharacterToPos(0, 2, 192, _currentCharacter->y1);
|
|
|
|
unkVar1 = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unkVar1 && unk1) {
|
|
|
|
int xpos = _currentCharacter->x1;
|
|
|
|
int ypos = _currentCharacter->y1;
|
|
|
|
switch (facing) {
|
|
|
|
case 0:
|
|
|
|
ypos = _currentCharacter->y1 - 6;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
xpos = 336;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
ypos = 143;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
xpos = -16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
moveCharacterToPos(0, facing, xpos, ypos);
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
for (int i = 0; i < ARRAYSIZE(_movieObjects); ++i) {
|
|
|
|
_movieObjects[i]->close();
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!brandonAlive) {
|
|
|
|
_scriptInterpreter->initScript(_scriptClick, _scriptClickData);
|
|
|
|
_scriptInterpreter->startScript(_scriptClick, 5);
|
|
|
|
while (_scriptInterpreter->validScript(_scriptClick)) {
|
|
|
|
_scriptInterpreter->runScript(_scriptClick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
memset(_entranceMouseCursorTracks, 0xFFFF, sizeof(uint16)*4);
|
|
|
|
_currentCharacter->sceneId = sceneId;
|
|
|
|
|
|
|
|
assert(sceneId < _roomTableSize);
|
2005-12-09 14:52:31 +00:00
|
|
|
assert(_roomTable[sceneId].nameIndex < _roomFilenameTableSize);
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
Room *currentRoom = &_roomTable[sceneId];
|
2005-11-27 10:02:23 +00:00
|
|
|
|
|
|
|
if (_currentRoom != 0xFFFF && (_features & GF_TALKIE)) {
|
|
|
|
char file[32];
|
|
|
|
assert(_currentRoom < _roomTableSize);
|
|
|
|
int tableId = _roomTable[_currentRoom].nameIndex;
|
|
|
|
assert(tableId < _roomFilenameTableSize);
|
|
|
|
strcpy(file, _roomFilenameTable[tableId]);
|
|
|
|
strcat(file, ".VRM");
|
|
|
|
_res->unloadPakFile(file);
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentRoom = sceneId;
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
int tableId = _roomTable[_currentCharacter->sceneId].nameIndex;
|
2005-11-27 10:02:23 +00:00
|
|
|
char fileNameBuffer[32];
|
|
|
|
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
|
|
|
|
strcat(fileNameBuffer, ".DAT");
|
|
|
|
_sprites->loadDAT(fileNameBuffer, _sceneExits);
|
2005-11-10 14:08:50 +00:00
|
|
|
_sprites->setupSceneAnims();
|
2005-11-09 22:26:12 +00:00
|
|
|
_scriptInterpreter->unloadScript(_scriptClickData);
|
2005-10-29 18:37:40 +00:00
|
|
|
loadSceneMSC();
|
|
|
|
|
2005-11-27 10:02:23 +00:00
|
|
|
if ((_features & GF_TALKIE)) {
|
|
|
|
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
|
|
|
|
strcat(fileNameBuffer, ".VRM");
|
|
|
|
_res->loadPakFile(fileNameBuffer);
|
|
|
|
}
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
_walkBlockNorth = currentRoom->northExit;
|
|
|
|
_walkBlockEast = currentRoom->eastExit;
|
|
|
|
_walkBlockSouth = currentRoom->southExit;
|
|
|
|
_walkBlockWest = currentRoom->westExit;
|
|
|
|
|
|
|
|
if (_walkBlockNorth == 0xFFFF) {
|
|
|
|
blockOutRegion(0, 0, 320, (_northExitHeight & 0xFF)+3);
|
|
|
|
}
|
|
|
|
if (_walkBlockEast == 0xFFFF) {
|
|
|
|
blockOutRegion(312, 0, 8, 139);
|
|
|
|
}
|
|
|
|
if (_walkBlockSouth == 0xFFFF) {
|
|
|
|
blockOutRegion(0, 135, 320, 8);
|
|
|
|
}
|
|
|
|
if (_walkBlockWest == 0xFFFF) {
|
|
|
|
blockOutRegion(0, 0, 8, 139);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!brandonAlive) {
|
2005-12-23 17:49:14 +00:00
|
|
|
updatePlayerItemsForScene();
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
2005-12-09 14:52:31 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
startSceneScript(brandonAlive);
|
2005-12-08 17:19:18 +00:00
|
|
|
setupSceneItems();
|
2005-12-09 14:52:31 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
initSceneData(facing, unk2, brandonAlive);
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
_loopFlag2 = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
_screen->showMouse();
|
|
|
|
if (!brandonAlive) {
|
2005-12-28 21:34:40 +00:00
|
|
|
seq_poisonDeathNow(0);
|
2005-12-24 18:00:35 +00:00
|
|
|
}
|
2005-12-13 15:10:20 +00:00
|
|
|
updateMousePointer(true);
|
2005-12-24 18:00:35 +00:00
|
|
|
_changedScene = true;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
2005-12-09 23:02:16 +00:00
|
|
|
void KyraEngine::transcendScenes(int roomIndex, int roomName) {
|
2005-12-22 19:31:38 +00:00
|
|
|
debug(9, "transcendScenes(%d, %d)", roomIndex, roomName);
|
2005-12-09 23:02:16 +00:00
|
|
|
assert(roomIndex < _roomTableSize);
|
2005-12-13 13:27:58 +00:00
|
|
|
if (_features & GF_TALKIE) {
|
|
|
|
char file[32];
|
|
|
|
assert(roomIndex < _roomTableSize);
|
|
|
|
int tableId = _roomTable[roomIndex].nameIndex;
|
|
|
|
assert(tableId < _roomFilenameTableSize);
|
|
|
|
strcpy(file, _roomFilenameTable[tableId]);
|
|
|
|
strcat(file, ".VRM");
|
|
|
|
_res->unloadPakFile(file);
|
|
|
|
}
|
2005-12-09 23:02:16 +00:00
|
|
|
_roomTable[roomIndex].nameIndex = roomName;
|
2005-12-13 16:56:33 +00:00
|
|
|
_unkScreenVar2 = 1;
|
|
|
|
_unkScreenVar3 = 1;
|
|
|
|
_unkScreenVar1 = 0;
|
2005-12-09 23:02:16 +00:00
|
|
|
_brandonPosX = _currentCharacter->x1;
|
|
|
|
_brandonPosY = _currentCharacter->y1;
|
|
|
|
enterNewScene(roomIndex, _currentCharacter->facing, 0, 0, 0);
|
2005-12-13 16:56:33 +00:00
|
|
|
_unkScreenVar1 = 1;
|
|
|
|
_unkScreenVar2 = 0;
|
|
|
|
_unkScreenVar3 = 0;
|
2005-12-09 23:02:16 +00:00
|
|
|
}
|
|
|
|
|
2005-12-22 19:31:38 +00:00
|
|
|
void KyraEngine::setSceneFile(int roomIndex, int roomName) {
|
|
|
|
debug(9, "setSceneFile(%d, %d)", roomIndex, roomName);
|
|
|
|
assert(roomIndex < _roomTableSize);
|
|
|
|
_roomTable[roomIndex].nameIndex = roomName;
|
|
|
|
}
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
void KyraEngine::moveCharacterToPos(int character, int facing, int xpos, int ypos) {
|
|
|
|
debug(9, "moveCharacterToPos(%d, %d, %d, %d)", character, facing, xpos, ypos);
|
|
|
|
Character *ch = &_characterList[character];
|
2005-11-13 19:35:01 +00:00
|
|
|
ch->facing = facing;
|
2005-10-29 18:37:40 +00:00
|
|
|
_screen->hideMouse();
|
2005-12-09 23:02:16 +00:00
|
|
|
xpos = (int16)(xpos & 0xFFFC);
|
|
|
|
ypos = (int16)(ypos & 0xFFFE);
|
2005-11-13 19:35:01 +00:00
|
|
|
disableTimer(19);
|
|
|
|
disableTimer(14);
|
|
|
|
disableTimer(18);
|
2005-11-18 23:55:31 +00:00
|
|
|
uint32 nextFrame = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
switch (facing) {
|
|
|
|
case 0:
|
2005-11-13 19:35:01 +00:00
|
|
|
while (ypos < ch->y1) {
|
2005-11-18 23:55:31 +00:00
|
|
|
nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis();
|
2005-10-29 18:37:40 +00:00
|
|
|
setCharacterPositionWithUpdate(character);
|
2005-11-18 23:55:31 +00:00
|
|
|
while (_system->getMillis() < nextFrame) { updateGameTimers(); }
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
2005-11-13 19:35:01 +00:00
|
|
|
while (ch->x1 < xpos) {
|
2005-11-18 23:55:31 +00:00
|
|
|
nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis();
|
2005-10-29 18:37:40 +00:00
|
|
|
setCharacterPositionWithUpdate(character);
|
2005-11-18 23:55:31 +00:00
|
|
|
while (_system->getMillis() < nextFrame) { updateGameTimers(); }
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2005-11-13 19:35:01 +00:00
|
|
|
while (ypos > ch->y1) {
|
2005-11-18 23:55:31 +00:00
|
|
|
nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis();
|
2005-10-29 18:37:40 +00:00
|
|
|
setCharacterPositionWithUpdate(character);
|
2005-11-18 23:55:31 +00:00
|
|
|
while (_system->getMillis() < nextFrame) { updateGameTimers(); }
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
2005-11-13 19:35:01 +00:00
|
|
|
while (ch->x1 > xpos) {
|
2005-11-18 23:55:31 +00:00
|
|
|
nextFrame = getTimerDelay(5 + character) * _tickLength + _system->getMillis();
|
2005-10-29 18:37:40 +00:00
|
|
|
setCharacterPositionWithUpdate(character);
|
2005-11-18 23:55:31 +00:00
|
|
|
while (_system->getMillis() < nextFrame) { updateGameTimers(); }
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2005-11-13 19:35:01 +00:00
|
|
|
enableTimer(19);
|
|
|
|
enableTimer(14);
|
|
|
|
enableTimer(18);
|
2005-10-29 18:37:40 +00:00
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::setCharacterPositionWithUpdate(int character) {
|
|
|
|
debug(9, "setCharacterPositionWithUpdate(%d)", character);
|
|
|
|
setCharacterPosition(character, 0);
|
2005-11-13 19:35:01 +00:00
|
|
|
_sprites->updateSceneAnims();
|
|
|
|
updateGameTimers();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-12-09 14:52:31 +00:00
|
|
|
updateTextFade();
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
if (_currentCharacter->sceneId == 210) {
|
2006-01-03 19:03:09 +00:00
|
|
|
_animator->updateKyragemFading();
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-09 22:26:12 +00:00
|
|
|
int KyraEngine::setCharacterPosition(int character, int *facingTable) {
|
|
|
|
debug(9, "setCharacterPosition(%d, 0x%X)", character, facingTable);
|
2005-10-29 18:37:40 +00:00
|
|
|
if (character == 0) {
|
2005-11-01 14:19:50 +00:00
|
|
|
_currentCharacter->x1 += _charXPosTable[_currentCharacter->facing];
|
|
|
|
_currentCharacter->y1 += _charYPosTable[_currentCharacter->facing];
|
2005-11-09 22:26:12 +00:00
|
|
|
setCharacterPositionHelper(0, facingTable);
|
2005-11-01 14:19:50 +00:00
|
|
|
return 1;
|
2005-10-29 18:37:40 +00:00
|
|
|
} else {
|
2005-11-09 22:26:12 +00:00
|
|
|
_characterList[character].x1 += _charXPosTable[_characterList[character].facing];
|
|
|
|
_characterList[character].y1 += _charYPosTable[_characterList[character].facing];
|
2005-10-29 18:37:40 +00:00
|
|
|
if (_characterList[character].sceneId == _currentCharacter->sceneId) {
|
|
|
|
setCharacterPositionHelper(character, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-09 22:26:12 +00:00
|
|
|
void KyraEngine::setCharacterPositionHelper(int character, int *facingTable) {
|
|
|
|
debug(9, "setCharacterPositionHelper(%d, 0x%X)", character, facingTable);
|
2005-10-29 18:37:40 +00:00
|
|
|
Character *ch = &_characterList[character];
|
2005-11-01 14:19:50 +00:00
|
|
|
++ch->currentAnimFrame;
|
2005-10-29 18:37:40 +00:00
|
|
|
int facing = ch->facing;
|
2005-11-09 22:26:12 +00:00
|
|
|
if (facingTable) {
|
|
|
|
if (*facingTable != *(facingTable - 1)) {
|
|
|
|
if (*(facingTable - 1) == *(facingTable + 1)) {
|
|
|
|
facing = getOppositeFacingDirection(*(facingTable - 1));
|
|
|
|
*facingTable = *(facingTable - 1);
|
|
|
|
}
|
|
|
|
}
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
2005-11-01 14:19:50 +00:00
|
|
|
static uint8 facingIsZero[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
|
|
|
static uint8 facingIsFour[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
|
2005-10-29 18:37:40 +00:00
|
|
|
|
|
|
|
if (facing == 0) {
|
|
|
|
++facingIsZero[character];
|
|
|
|
} else {
|
|
|
|
bool resetTables = false;
|
|
|
|
if (facing != 7) {
|
|
|
|
if (facing - 1 != 0) {
|
|
|
|
if (facing != 4) {
|
|
|
|
if (facing == 3 || facing == 5) {
|
2005-11-26 16:37:20 +00:00
|
|
|
if (facingIsFour[character] > 2) {
|
2005-10-29 18:37:40 +00:00
|
|
|
facing = 4;
|
|
|
|
}
|
|
|
|
resetTables = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
++facingIsFour[character];
|
|
|
|
}
|
|
|
|
} else {
|
2005-11-09 22:26:12 +00:00
|
|
|
if (facingIsZero[character] > 2) {
|
2005-10-29 18:37:40 +00:00
|
|
|
facing = 0;
|
|
|
|
}
|
|
|
|
resetTables = true;
|
|
|
|
}
|
2005-11-26 16:37:20 +00:00
|
|
|
} else {
|
|
|
|
if (facingIsZero[character] > 2) {
|
|
|
|
facing = 0;
|
|
|
|
}
|
|
|
|
resetTables = true;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (resetTables) {
|
|
|
|
facingIsZero[character] = 0;
|
|
|
|
facingIsFour[character] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-09 22:26:12 +00:00
|
|
|
static const uint16 maxAnimationFrame[] = {
|
2005-10-29 18:37:40 +00:00
|
|
|
0x000F, 0x0031, 0x0055, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0008, 0x002A, 0x004E, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0022, 0x0046, 0x006A, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x001D, 0x0041, 0x0065, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x001F, 0x0043, 0x0067, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0028, 0x004C, 0x0070, 0x0000, 0x0000, 0x0000,
|
|
|
|
0x0023, 0x0047, 0x006B, 0x0000, 0x0000, 0x0000
|
|
|
|
};
|
|
|
|
|
|
|
|
if (facing == 0) {
|
2005-11-13 19:35:01 +00:00
|
|
|
if (maxAnimationFrame[36+character] > ch->currentAnimFrame) {
|
2005-10-29 18:37:40 +00:00
|
|
|
ch->currentAnimFrame = maxAnimationFrame[36+character];
|
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
if (maxAnimationFrame[30+character] < ch->currentAnimFrame) {
|
2005-10-29 18:37:40 +00:00
|
|
|
ch->currentAnimFrame = maxAnimationFrame[36+character];
|
|
|
|
}
|
|
|
|
} else if (facing == 4) {
|
2005-11-13 19:35:01 +00:00
|
|
|
if (maxAnimationFrame[18+character] > ch->currentAnimFrame) {
|
2005-10-29 18:37:40 +00:00
|
|
|
ch->currentAnimFrame = maxAnimationFrame[18+character];
|
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
if (maxAnimationFrame[12+character] < ch->currentAnimFrame) {
|
2005-10-29 18:37:40 +00:00
|
|
|
ch->currentAnimFrame = maxAnimationFrame[18+character];
|
|
|
|
}
|
|
|
|
} else {
|
2005-11-09 22:26:12 +00:00
|
|
|
if (maxAnimationFrame[18+character] < ch->currentAnimFrame) {
|
2005-10-29 18:37:40 +00:00
|
|
|
ch->currentAnimFrame = maxAnimationFrame[30+character];
|
|
|
|
}
|
|
|
|
if (maxAnimationFrame[character] == ch->currentAnimFrame) {
|
|
|
|
ch->currentAnimFrame = maxAnimationFrame[6+character];
|
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
if (maxAnimationFrame[character] < ch->currentAnimFrame) {
|
2005-10-29 18:37:40 +00:00
|
|
|
ch->currentAnimFrame = maxAnimationFrame[6+character]+2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (character == 0) {
|
|
|
|
if (_brandonStatusBit & 0x10)
|
|
|
|
ch->currentAnimFrame = 88;
|
|
|
|
}
|
|
|
|
|
|
|
|
animRefreshNPC(character);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::getOppositeFacingDirection(int dir) {
|
2005-11-13 19:35:01 +00:00
|
|
|
debug(9, "getOppositeFacingDirection(%d)", dir);
|
2005-10-29 18:37:40 +00:00
|
|
|
switch (dir) {
|
|
|
|
case 0:
|
|
|
|
return 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1:
|
|
|
|
return 1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
return 7;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
return 6;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 5:
|
|
|
|
return 5;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
return 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
|
|
|
return 3;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::loadSceneMSC() {
|
|
|
|
assert(_currentCharacter->sceneId < _roomTableSize);
|
|
|
|
int tableId = _roomTable[_currentCharacter->sceneId].nameIndex;
|
|
|
|
assert(tableId < _roomFilenameTableSize);
|
|
|
|
char fileNameBuffer[32];
|
|
|
|
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
|
|
|
|
strcat(fileNameBuffer, ".MSC");
|
2005-11-13 19:35:01 +00:00
|
|
|
_screen->fillRect(0, 0, 319, 199, 0, 5);
|
2005-10-29 18:37:40 +00:00
|
|
|
loadBitmap(fileNameBuffer, 3, 5, 0);
|
|
|
|
}
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
// maybe move these two functions to Screen
|
2005-10-29 18:37:40 +00:00
|
|
|
void KyraEngine::blockInRegion(int x, int y, int width, int height) {
|
2005-11-10 21:42:42 +00:00
|
|
|
debug(9, "blockInRegion(%d, %d, %d, %d)", x, y, width, height);
|
2005-10-29 18:37:40 +00:00
|
|
|
assert(_screen->_shapePages[0]);
|
|
|
|
byte *toPtr = _screen->_shapePages[0] + (y * 320 + x);
|
|
|
|
for (int i = 0; i < height; ++i) {
|
|
|
|
byte *backUpTo = toPtr;
|
|
|
|
for (int i2 = 0; i2 < width; ++i2) {
|
|
|
|
*toPtr++ &= 0x7F;
|
|
|
|
}
|
|
|
|
toPtr = (backUpTo + 320);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::blockOutRegion(int x, int y, int width, int height) {
|
2005-11-10 21:42:42 +00:00
|
|
|
debug(9, "blockOutRegion(%d, %d, %d, %d)", x, y, width, height);
|
2005-10-29 18:37:40 +00:00
|
|
|
assert(_screen->_shapePages[0]);
|
|
|
|
byte *toPtr = _screen->_shapePages[0] + (y * 320 + x);
|
|
|
|
for (int i = 0; i < height; ++i) {
|
|
|
|
byte *backUpTo = toPtr;
|
|
|
|
for (int i2 = 0; i2 < width; ++i2) {
|
|
|
|
*toPtr++ |= 0x80;
|
|
|
|
}
|
|
|
|
toPtr = (backUpTo + 320);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::startSceneScript(int brandonAlive) {
|
|
|
|
debug(9, "startSceneScript(%d)", brandonAlive);
|
|
|
|
assert(_currentCharacter->sceneId < _roomTableSize);
|
|
|
|
int tableId = _roomTable[_currentCharacter->sceneId].nameIndex;
|
|
|
|
assert(tableId < _roomFilenameTableSize);
|
|
|
|
char fileNameBuffer[32];
|
|
|
|
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
|
|
|
|
strcat(fileNameBuffer, ".CPS");
|
|
|
|
loadBitmap(fileNameBuffer, 3, 3, 0);
|
|
|
|
_sprites->loadSceneShapes();
|
2005-11-13 19:35:01 +00:00
|
|
|
_exitListPtr = 0;
|
2005-11-11 22:17:06 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
_screen->setScreenPalette(_screen->_currentPalette);
|
2005-12-13 16:56:33 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
_scaleMode = 1;
|
|
|
|
for (int i = 0; i < 145; ++i) {
|
|
|
|
_scaleTable[i] = 256;
|
|
|
|
}
|
|
|
|
|
|
|
|
clearNoDropRects();
|
|
|
|
_scriptInterpreter->initScript(_scriptClick, _scriptClickData);
|
|
|
|
strcpy(fileNameBuffer, _roomFilenameTable[tableId]);
|
|
|
|
strcat(fileNameBuffer, ".EMC");
|
|
|
|
_scriptInterpreter->unloadScript(_scriptClickData);
|
|
|
|
_scriptInterpreter->loadScript(fileNameBuffer, _scriptClickData, _opcodeTable, _opcodeTableSize, 0);
|
|
|
|
_scriptInterpreter->startScript(_scriptClick, 0);
|
|
|
|
_scriptClick->variables[0] = _currentCharacter->sceneId;
|
|
|
|
_scriptClick->variables[7] = brandonAlive;
|
|
|
|
|
|
|
|
while (_scriptInterpreter->validScript(_scriptClick)) {
|
|
|
|
_scriptInterpreter->runScript(_scriptClick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::initSceneData(int facing, int unk1, int brandonAlive) {
|
|
|
|
debug(9, "initSceneData(%d, %d, %d)", facing, unk1, brandonAlive);
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
int16 xpos2 = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
int setFacing = 1;
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
int16 xpos = 0, ypos = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
|
|
|
|
if (_brandonPosX == -1 && _brandonPosY == -1) {
|
2005-11-13 19:35:01 +00:00
|
|
|
switch (facing+1) {
|
2005-10-29 18:37:40 +00:00
|
|
|
case 0:
|
|
|
|
xpos = ypos = -1;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 1: case 2: case 8:
|
2005-11-09 22:26:12 +00:00
|
|
|
xpos = _sceneExits.southXPos;
|
|
|
|
ypos = _sceneExits.southYPos;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
2005-11-09 22:26:12 +00:00
|
|
|
xpos = _sceneExits.westXPos;
|
|
|
|
ypos = _sceneExits.westYPos;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 4: case 5: case 6:
|
2005-11-09 22:26:12 +00:00
|
|
|
xpos = _sceneExits.northXPos;
|
|
|
|
ypos = _sceneExits.northYPos;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 7:
|
2005-11-09 22:26:12 +00:00
|
|
|
xpos = _sceneExits.eastXPos;
|
|
|
|
ypos = _sceneExits.eastYPos;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-12-22 19:31:38 +00:00
|
|
|
if ((uint8)(_northExitHeight & 0xFF) + 2 >= ypos) {
|
|
|
|
ypos = (_northExitHeight & 0xFF) + 4;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
if (xpos >= 308) {
|
|
|
|
xpos = 304;
|
|
|
|
}
|
2005-11-13 19:35:01 +00:00
|
|
|
if ((uint8)(_northExitHeight >> 8) - 2 <= ypos) {
|
2005-10-29 18:37:40 +00:00
|
|
|
ypos = (_northExitHeight >> 8) - 4;
|
|
|
|
}
|
|
|
|
if (xpos <= 12) {
|
|
|
|
xpos = 16;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_brandonPosX > -1) {
|
|
|
|
xpos = _brandonPosX;
|
|
|
|
}
|
|
|
|
if (_brandonPosY > -1) {
|
|
|
|
ypos = _brandonPosY;
|
|
|
|
}
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
int16 ypos2 = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
if (_brandonPosX > -1 && _brandonPosY > -1) {
|
|
|
|
switch (_currentCharacter->sceneId) {
|
|
|
|
case 1:
|
|
|
|
_currentCharacter->x1 = xpos;
|
|
|
|
_currentCharacter->x2 = xpos;
|
|
|
|
_currentCharacter->y1 = ypos;
|
|
|
|
_currentCharacter->y2 = ypos;
|
|
|
|
facing = 4;
|
|
|
|
xpos2 = 192;
|
|
|
|
ypos2 = 104;
|
2005-11-13 19:35:01 +00:00
|
|
|
setFacing = 0;
|
|
|
|
unk1 = 1;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 3:
|
|
|
|
_currentCharacter->x1 = xpos;
|
|
|
|
_currentCharacter->x2 = xpos;
|
|
|
|
_currentCharacter->y1 = ypos;
|
|
|
|
_currentCharacter->y2 = ypos;
|
|
|
|
facing = 2;
|
|
|
|
xpos2 = 204;
|
|
|
|
ypos2 = 94;
|
2005-11-13 19:35:01 +00:00
|
|
|
setFacing = 0;
|
|
|
|
unk1 = 1;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 26:
|
|
|
|
_currentCharacter->x1 = xpos;
|
|
|
|
_currentCharacter->x2 = xpos;
|
|
|
|
_currentCharacter->y1 = ypos;
|
|
|
|
_currentCharacter->y2 = ypos;
|
2005-12-22 19:31:38 +00:00
|
|
|
facing = 2;
|
2005-10-29 18:37:40 +00:00
|
|
|
xpos2 = 192;
|
|
|
|
ypos2 = 128;
|
2005-11-13 19:35:01 +00:00
|
|
|
setFacing = 0;
|
|
|
|
unk1 = 1;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 44:
|
|
|
|
_currentCharacter->x1 = xpos;
|
|
|
|
_currentCharacter->x2 = xpos;
|
|
|
|
_currentCharacter->y1 = ypos;
|
|
|
|
_currentCharacter->y2 = ypos;
|
|
|
|
facing = 6;
|
|
|
|
xpos2 = 156;
|
|
|
|
ypos2 = 96;
|
2005-11-13 19:35:01 +00:00
|
|
|
setFacing = 0;
|
|
|
|
unk1 = 1;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 37:
|
|
|
|
_currentCharacter->x1 = xpos;
|
|
|
|
_currentCharacter->x2 = xpos;
|
|
|
|
_currentCharacter->y1 = ypos;
|
|
|
|
_currentCharacter->y2 = ypos;
|
|
|
|
facing = 2;
|
|
|
|
xpos2 = 148;
|
|
|
|
ypos2 = 114;
|
2005-11-13 19:35:01 +00:00
|
|
|
setFacing = 0;
|
|
|
|
unk1 = 1;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_brandonPosX = _brandonPosY = -1;
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
if (unk1 && setFacing) {
|
|
|
|
ypos2 = ypos;
|
2005-10-29 18:37:40 +00:00
|
|
|
xpos2 = xpos;
|
|
|
|
switch (facing) {
|
|
|
|
case 0:
|
|
|
|
ypos = 142;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
xpos = -16;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
2005-11-13 19:35:01 +00:00
|
|
|
ypos = (uint8)(_northExitHeight & 0xFF) - 4;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
2005-11-13 19:35:01 +00:00
|
|
|
xpos = 336;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-09 23:02:16 +00:00
|
|
|
xpos2 = (int16)(xpos2 & 0xFFFC);
|
|
|
|
ypos2 = (int16)(ypos2 & 0xFFFE);
|
|
|
|
xpos = (int16)(xpos & 0xFFFC);
|
|
|
|
ypos = (int16)(ypos & 0xFFFE);
|
2005-10-29 18:37:40 +00:00
|
|
|
_currentCharacter->facing = facing;
|
|
|
|
_currentCharacter->x1 = xpos;
|
|
|
|
_currentCharacter->x2 = xpos;
|
|
|
|
_currentCharacter->y1 = ypos;
|
|
|
|
_currentCharacter->y2 = ypos;
|
|
|
|
|
|
|
|
initSceneObjectList(brandonAlive);
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
if (unk1 && brandonAlive == 0) {
|
2005-10-29 18:37:40 +00:00
|
|
|
moveCharacterToPos(0, facing, xpos2, ypos2);
|
|
|
|
}
|
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
_scriptClick->variables[4] = _itemInHand;
|
2005-10-29 18:37:40 +00:00
|
|
|
_scriptClick->variables[7] = brandonAlive;
|
|
|
|
_scriptInterpreter->startScript(_scriptClick, 3);
|
|
|
|
while (_scriptInterpreter->validScript(_scriptClick)) {
|
|
|
|
_scriptInterpreter->runScript(_scriptClick);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::resetBrandonPosionFlags() {
|
|
|
|
_brandonStatusBit = 0;
|
|
|
|
for (int i = 0; i < 256; ++i) {
|
2005-12-28 21:34:40 +00:00
|
|
|
_brandonPoisonFlagsGFX[i] = i;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::initAnimStateList() {
|
2006-01-02 22:58:59 +00:00
|
|
|
AnimObject *animStates = _animator->objects();
|
|
|
|
animStates[0].index = 0;
|
|
|
|
animStates[0].active = 1;
|
|
|
|
animStates[0].flags = 0x800;
|
|
|
|
animStates[0].background = _shapes[2];
|
|
|
|
animStates[0].rectSize = _screen->getRectSize(4, 48);
|
|
|
|
animStates[0].width = 4;
|
|
|
|
animStates[0].height = 48;
|
|
|
|
animStates[0].width2 = 4;
|
|
|
|
animStates[0].height2 = 3;
|
2005-10-29 18:37:40 +00:00
|
|
|
|
|
|
|
for (int i = 1; i <= 4; ++i) {
|
2006-01-02 22:58:59 +00:00
|
|
|
animStates[i].index = i;
|
|
|
|
animStates[i].active = 0;
|
|
|
|
animStates[i].flags = 0x800;
|
|
|
|
animStates[i].background = _shapes[3];
|
|
|
|
animStates[i].rectSize = _screen->getRectSize(4, 64);
|
|
|
|
animStates[i].width = 4;
|
|
|
|
animStates[i].height = 48;
|
|
|
|
animStates[i].width2 = 4;
|
|
|
|
animStates[i].height2 = 3;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 5; i < 16; ++i) {
|
2006-01-02 22:58:59 +00:00
|
|
|
animStates[i].index = i;
|
|
|
|
animStates[i].active = 0;
|
|
|
|
animStates[i].flags = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 16; i < 28; ++i) {
|
2006-01-02 22:58:59 +00:00
|
|
|
animStates[i].index = i;
|
|
|
|
animStates[i].flags = 0;
|
|
|
|
animStates[i].background = _shapes[349+i];
|
|
|
|
animStates[i].rectSize = _screen->getRectSize(3, 24);
|
|
|
|
animStates[i].width = 3;
|
|
|
|
animStates[i].height = 16;
|
|
|
|
animStates[i].width2 = 0;
|
|
|
|
animStates[i].height2 = 0;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::initSceneObjectList(int brandonAlive) {
|
2005-10-30 19:58:51 +00:00
|
|
|
debug(9, "initSceneObjectList(%d)", brandonAlive);
|
|
|
|
for (int i = 0; i < 31; ++i) {
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->actors()[i].active = 0;
|
2005-10-30 19:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int startAnimFrame = 0;
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
AnimObject *curAnimState = _animator->actors();
|
2005-10-30 19:58:51 +00:00
|
|
|
curAnimState->active = 1;
|
|
|
|
curAnimState->drawY = _currentCharacter->y1;
|
|
|
|
curAnimState->sceneAnimPtr = _shapes[4+_currentCharacter->currentAnimFrame];
|
|
|
|
curAnimState->animFrameNumber = _currentCharacter->currentAnimFrame;
|
|
|
|
startAnimFrame = _currentCharacter->currentAnimFrame-7;
|
|
|
|
int xOffset = _defaultShapeTable[startAnimFrame].xOffset;
|
|
|
|
int yOffset = _defaultShapeTable[startAnimFrame].yOffset;
|
|
|
|
if (_scaleMode) {
|
|
|
|
curAnimState->x1 = _currentCharacter->x1;
|
|
|
|
curAnimState->y1 = _currentCharacter->y1;
|
|
|
|
|
|
|
|
_brandonScaleX = _scaleTable[_currentCharacter->y1];
|
|
|
|
_brandonScaleY = _scaleTable[_currentCharacter->y1];
|
|
|
|
|
|
|
|
curAnimState->x1 += (_brandonScaleX * xOffset) >> 8;
|
|
|
|
curAnimState->y1 += (_brandonScaleY * yOffset) >> 8;
|
|
|
|
} else {
|
2005-11-09 22:26:12 +00:00
|
|
|
curAnimState->x1 = _currentCharacter->x1 + xOffset;
|
|
|
|
curAnimState->y1 = _currentCharacter->y1 + yOffset;
|
2005-10-30 19:58:51 +00:00
|
|
|
}
|
|
|
|
curAnimState->x2 = curAnimState->x1;
|
|
|
|
curAnimState->y2 = curAnimState->y1;
|
|
|
|
curAnimState->refreshFlag = 1;
|
|
|
|
curAnimState->bkgdChangeFlag = 1;
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->clearQueue();
|
|
|
|
_animator->addObjectToQueue(curAnimState);
|
2005-10-30 19:58:51 +00:00
|
|
|
|
|
|
|
int listAdded = 0;
|
|
|
|
int addedObjects = 1;
|
|
|
|
|
|
|
|
for (int i = 1; i < 5; ++i) {
|
|
|
|
Character *ch = &_characterList[i];
|
2006-01-02 22:58:59 +00:00
|
|
|
curAnimState = &_animator->actors()[addedObjects];
|
2005-10-30 19:58:51 +00:00
|
|
|
if (ch->sceneId != _currentCharacter->sceneId) {
|
2005-12-20 10:58:07 +00:00
|
|
|
curAnimState->active = 0;
|
|
|
|
curAnimState->refreshFlag = 0;
|
|
|
|
curAnimState->bkgdChangeFlag = 0;
|
2005-10-30 19:58:51 +00:00
|
|
|
++addedObjects;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
curAnimState->drawY = ch->y1;
|
|
|
|
curAnimState->sceneAnimPtr = _shapes[4+ch->currentAnimFrame];
|
|
|
|
curAnimState->animFrameNumber = ch->currentAnimFrame;
|
|
|
|
startAnimFrame = ch->currentAnimFrame-7;
|
|
|
|
xOffset = _defaultShapeTable[startAnimFrame].xOffset;
|
|
|
|
yOffset = _defaultShapeTable[startAnimFrame].yOffset;
|
|
|
|
if (_scaleMode) {
|
|
|
|
curAnimState->x1 = ch->x1;
|
|
|
|
curAnimState->y1 = ch->y1;
|
|
|
|
|
|
|
|
_brandonScaleX = _scaleTable[ch->y1];
|
|
|
|
_brandonScaleY = _scaleTable[ch->y1];
|
|
|
|
|
|
|
|
curAnimState->x1 += (_brandonScaleX * xOffset) >> 8;
|
|
|
|
curAnimState->y1 += (_brandonScaleY * yOffset) >> 8;
|
|
|
|
} else {
|
2005-11-09 22:26:12 +00:00
|
|
|
curAnimState->x1 = ch->x1 + xOffset;
|
|
|
|
curAnimState->y1 = ch->y1 + yOffset;
|
2005-10-30 19:58:51 +00:00
|
|
|
}
|
|
|
|
curAnimState->x2 = curAnimState->x1;
|
|
|
|
curAnimState->y2 = curAnimState->y1;
|
|
|
|
curAnimState->active = 1;
|
|
|
|
curAnimState->refreshFlag = 1;
|
|
|
|
curAnimState->bkgdChangeFlag = 1;
|
|
|
|
|
|
|
|
if (ch->facing >= 1 && ch->facing <= 3) {
|
|
|
|
curAnimState->flags |= 1;
|
|
|
|
} else if (ch->facing >= 5 && ch->facing <= 7) {
|
|
|
|
curAnimState->flags &= 0xFFFFFFFE;
|
|
|
|
}
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->addObjectToQueue(curAnimState);
|
2005-10-30 19:58:51 +00:00
|
|
|
|
|
|
|
++addedObjects;
|
|
|
|
++listAdded;
|
|
|
|
if (listAdded < 2)
|
|
|
|
i = 5;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 11; ++i) {
|
2006-01-02 22:58:59 +00:00
|
|
|
curAnimState = &_animator->sprites()[i];
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if (_sprites->_anims[i].play) {
|
|
|
|
curAnimState->active = 1;
|
|
|
|
curAnimState->refreshFlag = 1;
|
|
|
|
curAnimState->bkgdChangeFlag = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
curAnimState->active = 0;
|
|
|
|
curAnimState->refreshFlag = 0;
|
|
|
|
curAnimState->bkgdChangeFlag = 0;
|
|
|
|
}
|
|
|
|
curAnimState->height = _sprites->_anims[i].height;
|
|
|
|
curAnimState->height2 = _sprites->_anims[i].height2;
|
|
|
|
curAnimState->width = _sprites->_anims[i].width + 1;
|
|
|
|
curAnimState->width2 = _sprites->_anims[i].width2;
|
|
|
|
curAnimState->drawY = _sprites->_anims[i].drawY;
|
|
|
|
curAnimState->x1 = curAnimState->x2 = _sprites->_anims[i].x;
|
|
|
|
curAnimState->y1 = curAnimState->y2 = _sprites->_anims[i].y;
|
|
|
|
curAnimState->background = _sprites->_anims[i].background;
|
|
|
|
curAnimState->sceneAnimPtr = _sprites->_sceneShapes[_sprites->_anims[i].sprite];
|
|
|
|
|
|
|
|
if(_sprites->_anims[i].unk2)
|
|
|
|
curAnimState->flags = 0x800;
|
|
|
|
else
|
|
|
|
curAnimState->flags = 0;
|
|
|
|
|
|
|
|
if (_sprites->_anims[i].flipX)
|
|
|
|
curAnimState->flags |= 0x1;
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->addObjectToQueue(curAnimState);
|
2005-10-30 19:58:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; ++i) {
|
2006-01-02 22:58:59 +00:00
|
|
|
curAnimState = &_animator->items()[i];
|
2005-10-30 19:58:51 +00:00
|
|
|
Room *curRoom = &_roomTable[_currentCharacter->sceneId];
|
|
|
|
byte curItem = curRoom->itemsTable[i];
|
|
|
|
if (curItem != 0xFF) {
|
|
|
|
curAnimState->drawY = curRoom->itemsYPos[i];
|
2005-12-09 23:02:16 +00:00
|
|
|
curAnimState->sceneAnimPtr = _shapes[220+curItem];
|
2006-01-01 10:49:27 +00:00
|
|
|
curAnimState->animFrameNumber = (int16)0xFFFF;
|
2005-10-30 19:58:51 +00:00
|
|
|
curAnimState->y1 = curRoom->itemsYPos[i];
|
|
|
|
curAnimState->x1 = curRoom->itemsXPos[i];
|
|
|
|
|
2005-12-08 17:19:18 +00:00
|
|
|
curAnimState->x1 -= (fetchAnimWidth(curAnimState->sceneAnimPtr, _scaleTable[curAnimState->drawY])) >> 1;
|
|
|
|
curAnimState->y1 -= fetchAnimHeight(curAnimState->sceneAnimPtr, _scaleTable[curAnimState->drawY]);
|
2005-10-30 19:58:51 +00:00
|
|
|
|
|
|
|
curAnimState->x2 = curAnimState->x1;
|
|
|
|
curAnimState->y2 = curAnimState->y1;
|
|
|
|
|
|
|
|
curAnimState->active = 1;
|
|
|
|
curAnimState->refreshFlag = 1;
|
|
|
|
curAnimState->bkgdChangeFlag = 1;
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->addObjectToQueue(curAnimState);
|
2005-10-30 19:58:51 +00:00
|
|
|
} else {
|
|
|
|
curAnimState->active = 0;
|
|
|
|
curAnimState->refreshFlag = 0;
|
|
|
|
curAnimState->bkgdChangeFlag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->preserveAnyChangedBackgrounds();
|
|
|
|
curAnimState = _animator->actors();
|
2005-10-30 19:58:51 +00:00
|
|
|
curAnimState->bkgdChangeFlag = 1;
|
|
|
|
curAnimState->refreshFlag = 1;
|
2005-12-20 10:58:07 +00:00
|
|
|
for (int i = 1; i < 28; ++i) {
|
2006-01-02 22:58:59 +00:00
|
|
|
curAnimState = &_animator->objects()[i];
|
2005-10-30 19:58:51 +00:00
|
|
|
if (curAnimState->active) {
|
|
|
|
curAnimState->bkgdChangeFlag = 1;
|
|
|
|
curAnimState->refreshFlag = 1;
|
|
|
|
}
|
|
|
|
}
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->restoreAllObjectBackgrounds();
|
|
|
|
_animator->preserveAnyChangedBackgrounds();
|
|
|
|
_animator->prepDrawAllObjects();
|
2005-11-10 14:08:50 +00:00
|
|
|
initSceneScreen(brandonAlive);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->copyChangedObjectsForward(0);
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
void KyraEngine::initSceneScreen(int brandonAlive) {
|
|
|
|
// XXX (Pointless?) Palette stuff
|
2005-12-13 16:56:33 +00:00
|
|
|
if (_unkScreenVar2 == 1) {
|
|
|
|
_screen->shuffleScreen(8, 8, 304, 128, 2, 0, _unkScreenVar3, false);
|
|
|
|
} else {
|
|
|
|
_screen->copyRegion(8, 8, 8, 8, 304, 128, 2, 0);
|
|
|
|
}
|
|
|
|
_screen->updateScreen();
|
2005-11-10 14:08:50 +00:00
|
|
|
// XXX More (pointless?) palette stuff
|
|
|
|
|
|
|
|
if (!_scriptInterpreter->startScript(_scriptClick, 2))
|
|
|
|
error("Could not start script function 2 of scene script");
|
|
|
|
|
|
|
|
_scriptClick->variables[7] = brandonAlive;
|
|
|
|
|
|
|
|
while (_scriptInterpreter->validScript(_scriptClick))
|
|
|
|
_scriptInterpreter->runScript(_scriptClick);
|
|
|
|
|
2005-12-09 14:52:31 +00:00
|
|
|
setTextFadeTimerCountdown(-1);
|
2005-12-23 17:49:14 +00:00
|
|
|
if (_currentCharacter->sceneId == 210) {
|
|
|
|
if (_itemInHand != -1)
|
|
|
|
magicOutMouseItem(2, -1);
|
|
|
|
|
|
|
|
_screen->hideMouse();
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
if (_currentCharacter->inventoryItems[i] != 0xFF)
|
|
|
|
magicOutMouseItem(2, i);
|
|
|
|
}
|
|
|
|
_screen->showMouse();
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
#pragma mark -
|
2005-11-10 21:42:42 +00:00
|
|
|
#pragma mark - Text handling
|
2005-10-29 18:37:40 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
2005-11-10 14:08:50 +00:00
|
|
|
void KyraEngine::waitForChatToFinish(int16 chatDuration, char *chatStr, uint8 charNum) {
|
|
|
|
debug(9, "KyraEngine::waitForChatToFinish(%i, %s, %i)", chatDuration, chatStr, charNum);
|
|
|
|
bool hasUpdatedNPCs = false;
|
|
|
|
bool runLoop = true;
|
|
|
|
uint8 currPage;
|
|
|
|
OSystem::Event event;
|
2005-11-11 22:17:06 +00:00
|
|
|
int16 delayTime;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
//while( towns_isEscKeyPressed() )
|
|
|
|
//towns_getKey();
|
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
uint32 timeToEnd = strlen(chatStr) * 8 * _tickLength + _system->getMillis();
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if (chatDuration != -1 ) {
|
2005-11-11 22:17:06 +00:00
|
|
|
switch (_configTalkspeed) {
|
2005-11-10 14:08:50 +00:00
|
|
|
case 0: chatDuration *= 2;
|
|
|
|
break;
|
|
|
|
case 2: chatDuration /= 4;
|
|
|
|
break;
|
|
|
|
case 3: chatDuration = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chatDuration != -1)
|
2005-11-11 22:17:06 +00:00
|
|
|
chatDuration *= _tickLength;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
disableTimer(14);
|
|
|
|
disableTimer(18);
|
|
|
|
disableTimer(19);
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
uint32 timeAtStart = _system->getMillis();
|
|
|
|
uint32 loopStart;
|
|
|
|
while (runLoop) {
|
|
|
|
loopStart = _system->getMillis();
|
|
|
|
/*
|
|
|
|
if (_currentCharacter.sceneId == 0xD2)
|
|
|
|
if (seq_playEnd())
|
|
|
|
break;
|
|
|
|
*/
|
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
if (_system->getMillis() > timeToEnd && !hasUpdatedNPCs) {
|
2005-11-10 14:08:50 +00:00
|
|
|
hasUpdatedNPCs = true;
|
2005-11-11 22:17:06 +00:00
|
|
|
disableTimer(15);
|
2005-12-09 14:52:31 +00:00
|
|
|
_currHeadShape = 4;
|
2005-11-10 14:08:50 +00:00
|
|
|
animRefreshNPC(0);
|
2005-12-09 14:52:31 +00:00
|
|
|
animRefreshNPC(_talkingCharNum);
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if (_charSayUnk2 != -1) {
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->sprites()[_charSayUnk2].active = 0;
|
2005-11-10 14:08:50 +00:00
|
|
|
_sprites->_anims[_charSayUnk2].play = false;
|
|
|
|
_charSayUnk2 = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
updateGameTimers();
|
2005-11-10 14:08:50 +00:00
|
|
|
_sprites->updateSceneAnims();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->restoreAllObjectBackgrounds();
|
|
|
|
_animator->preserveAnyChangedBackgrounds();
|
|
|
|
_animator->prepDrawAllObjects();
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
currPage = _screen->_curPage;
|
|
|
|
_screen->_curPage = 2;
|
2006-01-02 22:58:59 +00:00
|
|
|
_text->printCharacterText(chatStr, charNum, _characterList[charNum].x1);
|
2005-11-10 14:08:50 +00:00
|
|
|
_screen->_curPage = currPage;
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->copyChangedObjectsForward(0);
|
2005-12-09 14:52:31 +00:00
|
|
|
updateTextFade();
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if ((chatDuration < (int16)(_system->getMillis() - timeAtStart)) && chatDuration != -1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
while (_system->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case OSystem::EVENT_KEYDOWN:
|
2005-12-10 17:51:40 +00:00
|
|
|
if (event.kbd.keycode == '.')
|
2005-11-10 14:08:50 +00:00
|
|
|
runLoop = false;
|
|
|
|
break;
|
|
|
|
case OSystem::EVENT_QUIT:
|
|
|
|
quitGame();
|
|
|
|
case OSystem::EVENT_LBUTTONDOWN:
|
|
|
|
runLoop = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2005-12-10 17:51:40 +00:00
|
|
|
|
|
|
|
if (_fastMode)
|
|
|
|
runLoop = false;
|
2005-11-11 22:17:06 +00:00
|
|
|
|
|
|
|
delayTime = (loopStart + _gameSpeed) - _system->getMillis();
|
|
|
|
if (delayTime > 0)
|
|
|
|
_system->delayMillis(delayTime);
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
enableTimer(14);
|
|
|
|
enableTimer(15);
|
|
|
|
enableTimer(18);
|
|
|
|
enableTimer(19);
|
|
|
|
//clearKyrandiaButtonIO();
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::endCharacterChat(int8 charNum, int16 convoInitialized) {
|
|
|
|
_charSayUnk3 = -1;
|
|
|
|
|
|
|
|
if (charNum > 4 && charNum < 11) {
|
|
|
|
//TODO: weird _game_inventory stuff here
|
2005-12-10 17:51:40 +00:00
|
|
|
warning("STUB: endCharacterChat() for high charnums");
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (convoInitialized != 0) {
|
2005-12-09 14:52:31 +00:00
|
|
|
_talkingCharNum = -1;
|
2005-11-10 14:08:50 +00:00
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::restoreChatPartnerAnimFrame(int8 charNum) {
|
2005-12-09 14:52:31 +00:00
|
|
|
_talkingCharNum = -1;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if (charNum > 0 && charNum < 5) {
|
|
|
|
_characterList[charNum].currentAnimFrame = _currentChatPartnerBackupFrame;
|
|
|
|
animRefreshNPC(charNum);
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::backupChatPartnerAnimFrame(int8 charNum) {
|
2005-12-09 14:52:31 +00:00
|
|
|
_talkingCharNum = 0;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if (charNum < 5 && charNum > 0)
|
|
|
|
_currentChatPartnerBackupFrame = _characterList[charNum].currentAnimFrame;
|
|
|
|
|
|
|
|
if (_scaleMode != 0)
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
else
|
|
|
|
_currentCharacter->currentAnimFrame = _currentCharAnimFrame;
|
|
|
|
|
|
|
|
animRefreshNPC(0);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int8 KyraEngine::getChatPartnerNum() {
|
|
|
|
uint8 sceneTable[] = {0x2, 0x5, 0x2D, 0x7, 0x1B, 0x8, 0x22, 0x9, 0x30, 0x0A};
|
|
|
|
int pos = 0;
|
|
|
|
int partner = -1;
|
|
|
|
|
|
|
|
for (int i = 1; i < 6; i++) {
|
|
|
|
if (_currentCharacter->sceneId == sceneTable[pos]) {
|
|
|
|
partner = sceneTable[pos+1];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos += 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 1; i < 5; i++) {
|
|
|
|
if (_characterList[i].sceneId == _currentCharacter->sceneId) {
|
|
|
|
partner = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return partner;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::initCharacterChat(int8 charNum) {
|
2005-12-09 14:52:31 +00:00
|
|
|
if (_talkingCharNum == -1) {
|
|
|
|
_talkingCharNum = 0;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if (_scaleMode != 0)
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
else
|
|
|
|
_currentCharacter->currentAnimFrame = 16;
|
|
|
|
|
|
|
|
animRefreshNPC(0);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_charSayUnk2 = -1;
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->flagAllObjectsForBkgdChange();
|
|
|
|
_animator->restoreAllObjectBackgrounds();
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
if (charNum > 4 && charNum < 11) {
|
2005-11-10 14:08:50 +00:00
|
|
|
// TODO: Fill in weird _game_inventory stuff here
|
2005-12-10 17:51:40 +00:00
|
|
|
warning("STUB: initCharacterChat() for high charnums");
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->flagAllObjectsForRefresh();
|
|
|
|
_animator->flagAllObjectsForBkgdChange();
|
|
|
|
_animator->preserveAnyChangedBackgrounds();
|
2005-11-10 14:08:50 +00:00
|
|
|
_charSayUnk3 = charNum;
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::characterSays(char *chatStr, int8 charNum, int8 chatDuration) {
|
2005-12-26 14:53:51 +00:00
|
|
|
debug(9, "KyraEngine::characterSays('%s', %i, %d)", chatStr, charNum, chatDuration);
|
2005-11-10 14:08:50 +00:00
|
|
|
uint8 startAnimFrames[] = { 0x10, 0x32, 0x56, 0x0, 0x0, 0x0 };
|
|
|
|
|
|
|
|
uint16 chatTicks;
|
|
|
|
int16 convoInitialized;
|
|
|
|
int8 chatPartnerNum;
|
|
|
|
|
2005-12-26 14:53:51 +00:00
|
|
|
if (_currentCharacter->sceneId == 210)
|
2005-11-10 14:08:50 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
convoInitialized = initCharacterChat(charNum);
|
|
|
|
chatPartnerNum = getChatPartnerNum();
|
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
if (chatPartnerNum != -1 && chatPartnerNum < 5)
|
2005-11-10 14:08:50 +00:00
|
|
|
backupChatPartnerAnimFrame(chatPartnerNum);
|
|
|
|
|
|
|
|
if (charNum < 5) {
|
|
|
|
_characterList[charNum].currentAnimFrame = startAnimFrames[charNum];
|
|
|
|
_charSayUnk3 = charNum;
|
2005-12-09 14:52:31 +00:00
|
|
|
_talkingCharNum = charNum;
|
2005-11-10 14:08:50 +00:00
|
|
|
animRefreshNPC(charNum);
|
|
|
|
}
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
char *processedString = _text->preprocessString(chatStr);
|
|
|
|
int lineNum = _text->buildMessageSubstrings(processedString);
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
int16 yPos = _characterList[charNum].y1;
|
|
|
|
yPos -= _scaleTable[charNum] * _characterList[charNum].height;
|
|
|
|
yPos -= 8;
|
|
|
|
yPos -= lineNum * 10;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2005-11-11 22:17:06 +00:00
|
|
|
if (yPos < 11)
|
|
|
|
yPos = 11;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2005-12-26 14:53:51 +00:00
|
|
|
if (yPos > 100)
|
2005-11-11 22:17:06 +00:00
|
|
|
yPos = 100;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_text->_talkMessageY = yPos;
|
|
|
|
_text->_talkMessageH = lineNum * 10;
|
|
|
|
_animator->restoreAllObjectBackgrounds();
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_screen->copyRegion(1, _text->_talkMessageY, 1, 136, 319, _text->_talkMessageH, 2, 2);
|
2005-11-10 14:08:50 +00:00
|
|
|
_screen->hideMouse();
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_text->printCharacterText(processedString, charNum, _characterList[charNum].x1);
|
2005-11-10 14:08:50 +00:00
|
|
|
_screen->showMouse();
|
|
|
|
|
|
|
|
if (chatDuration == -2)
|
|
|
|
chatTicks = strlen(processedString) * 9;
|
|
|
|
else
|
|
|
|
chatTicks = chatDuration;
|
|
|
|
|
|
|
|
waitForChatToFinish(chatTicks, chatStr, charNum);
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->restoreAllObjectBackgrounds();
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_screen->copyRegion(1, 136, 1, _text->_talkMessageY, 319, _text->_talkMessageH, 2, 2);
|
|
|
|
_animator->preserveAllBackgrounds();
|
|
|
|
_animator->prepDrawAllObjects();
|
2005-11-10 14:08:50 +00:00
|
|
|
_screen->hideMouse();
|
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_screen->copyRegion(1, _text->_talkMessageY, 1, _text->_talkMessageY, 319, _text->_talkMessageH, 2, 0);
|
2005-11-10 14:08:50 +00:00
|
|
|
_screen->showMouse();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->flagAllObjectsForRefresh();
|
|
|
|
_animator->copyChangedObjectsForward(0);
|
2005-11-10 14:08:50 +00:00
|
|
|
|
|
|
|
if (chatPartnerNum != -1 && chatPartnerNum < 5)
|
|
|
|
restoreChatPartnerAnimFrame(chatPartnerNum);
|
|
|
|
|
|
|
|
endCharacterChat(charNum, convoInitialized);
|
|
|
|
}
|
|
|
|
|
2005-12-09 14:52:31 +00:00
|
|
|
void KyraEngine::drawSentenceCommand(char *sentence, int color) {
|
|
|
|
debug(9, "drawSentenceCommand('%s', %i)", sentence, color);
|
2005-11-10 14:08:50 +00:00
|
|
|
_screen->hideMouse();
|
|
|
|
_screen->fillRect(8, 143, 311, 152, 12);
|
2005-12-09 14:52:31 +00:00
|
|
|
|
|
|
|
if (_startSentencePalIndex != color || _fadeText != false) {
|
|
|
|
_currSentenceColor[0] = _screen->_currentPalette[765] = _screen->_currentPalette[color*3];
|
|
|
|
_currSentenceColor[1] = _screen->_currentPalette[766] = _screen->_currentPalette[color*3+1];
|
|
|
|
_currSentenceColor[2] = _screen->_currentPalette[767] = _screen->_currentPalette[color*3+2];
|
|
|
|
|
|
|
|
_screen->setScreenPalette(_screen->_currentPalette);
|
|
|
|
_startSentencePalIndex = 0;
|
|
|
|
}
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_text->printText(sentence, 8, 143, 0xFF, 12, 0);
|
2005-11-10 14:08:50 +00:00
|
|
|
_screen->showMouse();
|
2005-12-09 14:52:31 +00:00
|
|
|
setTextFadeTimerCountdown(15);
|
|
|
|
_fadeText = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::updateSentenceCommand(char *str1, char *str2, int color) {
|
|
|
|
debug(9, "updateSentenceCommand('%s', '%s', %i)", str1, str2, color);
|
|
|
|
char sentenceCommand[500];
|
|
|
|
strncpy(sentenceCommand, str1, 500);
|
|
|
|
if (str2)
|
|
|
|
strncat(sentenceCommand, str2, 500 - strlen(sentenceCommand));
|
|
|
|
|
|
|
|
drawSentenceCommand(sentenceCommand, color);
|
2005-12-18 18:50:15 +00:00
|
|
|
_screen->updateScreen();
|
2005-12-09 14:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::updateTextFade() {
|
|
|
|
debug(9, "updateTextFade()");
|
|
|
|
if (!_fadeText)
|
|
|
|
return;
|
|
|
|
|
|
|
|
bool finished = false;
|
|
|
|
for (int i = 0; i < 3; i++)
|
|
|
|
if (_currSentenceColor[i] > 4)
|
|
|
|
_currSentenceColor[i] -= 4;
|
|
|
|
else
|
|
|
|
if (_currSentenceColor[i]) {
|
|
|
|
_currSentenceColor[i] = 0;
|
|
|
|
finished = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
_screen->_currentPalette[765] = _currSentenceColor[0];
|
|
|
|
_screen->_currentPalette[766] = _currSentenceColor[1];
|
|
|
|
_screen->_currentPalette[767] = _currSentenceColor[2];
|
|
|
|
_screen->setScreenPalette(_screen->_currentPalette);
|
|
|
|
|
|
|
|
if (finished) {
|
|
|
|
_fadeText = false;
|
|
|
|
_startSentencePalIndex = -1;
|
|
|
|
}
|
2005-11-10 14:08:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark - Item handling
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
void KyraEngine::addToNoDropRects(int x, int y, int w, int h) {
|
|
|
|
debug(9, "addToNoDropRects(%d, %d, %d, %d)", x, y, w, h);
|
|
|
|
for (int rect = 0; rect < 11; ++rect) {
|
|
|
|
if (_noDropRects[rect].x == -1) {
|
|
|
|
_noDropRects[rect].x = x;
|
|
|
|
_noDropRects[rect].y = y;
|
|
|
|
_noDropRects[rect].x2 = x + w - 1;
|
|
|
|
_noDropRects[rect].y2 = y + h - 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::clearNoDropRects() {
|
|
|
|
debug(9, "clearNoDropRects()");
|
|
|
|
memset(_noDropRects, -1, sizeof(_noDropRects));
|
|
|
|
}
|
|
|
|
|
|
|
|
byte KyraEngine::findFreeItemInScene(int scene) {
|
|
|
|
debug(9, "findFreeItemInScene(%d)", scene);
|
|
|
|
assert(scene < _roomTableSize);
|
|
|
|
Room *room = &_roomTable[scene];
|
2005-10-29 18:37:40 +00:00
|
|
|
for (int i = 0; i < 12; ++i) {
|
2005-12-08 17:19:18 +00:00
|
|
|
if (room->itemsTable[i] == 0xFF)
|
2005-10-29 18:37:40 +00:00
|
|
|
return i;
|
|
|
|
}
|
|
|
|
return 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
byte KyraEngine::findItemAtPos(int x, int y) {
|
2005-11-09 22:26:12 +00:00
|
|
|
debug(9, "findItemAtPos(%d, %d)", x, y);
|
2005-10-29 18:37:40 +00:00
|
|
|
assert(_currentCharacter->sceneId < _roomTableSize);
|
2005-12-09 17:36:57 +00:00
|
|
|
const uint8 *itemsTable = _roomTable[_currentCharacter->sceneId].itemsTable;
|
|
|
|
const uint16 *xposOffset = _roomTable[_currentCharacter->sceneId].itemsXPos;
|
|
|
|
const uint8 *yposOffset = _roomTable[_currentCharacter->sceneId].itemsYPos;
|
2005-10-29 18:37:40 +00:00
|
|
|
|
|
|
|
int highestYPos = -1;
|
|
|
|
byte returnValue = 0xFF;
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; ++i) {
|
|
|
|
if (*itemsTable != 0xFF) {
|
2005-12-09 17:36:57 +00:00
|
|
|
int xpos = *xposOffset - 11;
|
2005-10-29 18:37:40 +00:00
|
|
|
int xpos2 = *xposOffset + 10;
|
|
|
|
if (x > xpos && x < xpos2) {
|
|
|
|
assert(*itemsTable < ARRAYSIZE(_itemTable));
|
|
|
|
int itemHeight = _itemTable[*itemsTable].height;
|
2005-12-09 17:36:57 +00:00
|
|
|
int ypos = *yposOffset + 3;
|
2005-10-29 18:37:40 +00:00
|
|
|
int ypos2 = ypos - itemHeight - 3;
|
|
|
|
|
2005-12-09 17:36:57 +00:00
|
|
|
if (y > ypos2 && ypos > y) {
|
2005-10-29 18:37:40 +00:00
|
|
|
if (highestYPos <= ypos) {
|
|
|
|
returnValue = i;
|
|
|
|
highestYPos = ypos;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-09 17:36:57 +00:00
|
|
|
++xposOffset;
|
|
|
|
++yposOffset;
|
|
|
|
++itemsTable;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::placeItemInGenericMapScene(int item, int index) {
|
|
|
|
debug(9, "placeItemInGenericMapScene(%d, %d)", item, index);
|
|
|
|
static const uint16 itemMapSceneMinTable[] = {
|
|
|
|
0x0000, 0x0011, 0x006D, 0x0025, 0x00C7, 0x0000
|
|
|
|
};
|
|
|
|
static const uint16 itemMapSceneMaxTable[] = {
|
|
|
|
0x0010, 0x0024, 0x00C6, 0x006C, 0x00F5, 0x0000
|
|
|
|
};
|
|
|
|
|
|
|
|
int minValue = itemMapSceneMinTable[index];
|
|
|
|
int maxValue = itemMapSceneMaxTable[index];
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
int room = _rnd.getRandomNumberRng(minValue, maxValue);
|
|
|
|
assert(room < _roomTableSize);
|
|
|
|
int nameIndex = _roomTable[room].nameIndex;
|
|
|
|
bool placeItem = false;
|
|
|
|
|
|
|
|
switch (nameIndex) {
|
|
|
|
case 0: case 1: case 2: case 3:
|
|
|
|
case 4: case 5: case 6: case 11:
|
|
|
|
case 12: case 16: case 17: case 20:
|
|
|
|
case 22: case 23: case 25: case 26:
|
|
|
|
case 27: case 31: case 33: case 34:
|
|
|
|
case 36: case 37: case 58: case 59:
|
|
|
|
case 60: case 61: case 83: case 84:
|
|
|
|
case 85: case 104: case 105: case 106:
|
|
|
|
placeItem = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 51:
|
|
|
|
if (room != 46) {
|
|
|
|
placeItem = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
placeItem = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (placeItem) {
|
|
|
|
Room *roomPtr = &_roomTable[room];
|
|
|
|
if (roomPtr->northExit == 0xFFFF && roomPtr->eastExit == 0xFFFF && roomPtr->southExit == 0xFFFF && roomPtr->westExit == 0xFFFF) {
|
|
|
|
placeItem = false;
|
|
|
|
} else if (_currentCharacter->sceneId == room) {
|
|
|
|
placeItem = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (placeItem) {
|
2005-12-09 19:49:47 +00:00
|
|
|
if (!processItemDrop(room, item, -1, -1, 2, 0))
|
2005-12-08 17:19:18 +00:00
|
|
|
continue;
|
2005-10-29 18:37:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
void KyraEngine::createMouseItem(int item) {
|
|
|
|
debug(9, "createMouseItem(%d)", item);
|
|
|
|
_screen->hideMouse();
|
|
|
|
setMouseItem(item);
|
|
|
|
_itemInHand = item;
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::destroyMouseItem() {
|
|
|
|
debug(9, "destroyMouseItem()");
|
|
|
|
_screen->hideMouse();
|
|
|
|
_screen->setMouseCursor(1, 1, _shapes[4]);
|
|
|
|
_itemInHand = -1;
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::setMouseItem(int item) {
|
|
|
|
debug(9, "setMouseItem(%d)", item);
|
|
|
|
if (item == -1) {
|
|
|
|
_screen->setMouseCursor(1, 1, _shapes[10]);
|
|
|
|
} else {
|
|
|
|
_screen->setMouseCursor(8, 15, _shapes[220+item]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::wipeDownMouseItem(int xpos, int ypos) {
|
|
|
|
debug(9, "wipeDownMouseItem(%d, %d)", xpos, ypos);
|
|
|
|
if (_itemInHand == -1)
|
|
|
|
return;
|
|
|
|
xpos -= 8;
|
|
|
|
ypos -= 15;
|
|
|
|
_screen->hideMouse();
|
|
|
|
backUpRect1(xpos, ypos);
|
|
|
|
int y = ypos;
|
|
|
|
int height = 16;
|
|
|
|
|
|
|
|
while (height >= 0) {
|
|
|
|
restoreRect1(xpos, ypos);
|
|
|
|
_screen->setNewShapeHeight(_shapes[220+_itemInHand], height);
|
2005-12-24 18:00:35 +00:00
|
|
|
uint32 nextTime = _system->getMillis() + 1 * _tickLength;
|
2005-11-18 23:55:31 +00:00
|
|
|
_screen->drawShape(0, _shapes[220+_itemInHand], xpos, y, 0, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
y += 2;
|
|
|
|
height -= 2;
|
2005-12-24 18:00:35 +00:00
|
|
|
while (_system->getMillis() < nextTime) {}
|
2005-11-18 23:55:31 +00:00
|
|
|
}
|
|
|
|
restoreRect1(xpos, ypos);
|
|
|
|
_screen->resetShapeHeight(_shapes[220+_itemInHand]);
|
|
|
|
destroyMouseItem();
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
2005-12-08 17:19:18 +00:00
|
|
|
void KyraEngine::setupSceneItems() {
|
|
|
|
debug(9, "setupSceneItems()");
|
|
|
|
uint16 sceneId = _currentCharacter->sceneId;
|
|
|
|
assert(sceneId < _roomTableSize);
|
|
|
|
Room *currentRoom = &_roomTable[sceneId];
|
|
|
|
for (int i = 0; i < 12; ++i) {
|
|
|
|
uint8 item = currentRoom->itemsTable[i];
|
2006-01-03 23:41:52 +00:00
|
|
|
if (item == 0xFF || !currentRoom->needInit[i]) {
|
2005-12-08 17:19:18 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xpos = 0;
|
|
|
|
int ypos = 0;
|
|
|
|
|
|
|
|
if (currentRoom->itemsXPos[i] == 0xFFFF) {
|
|
|
|
xpos = currentRoom->itemsXPos[i] = _rnd.getRandomNumberRng(24, 296);
|
|
|
|
ypos = currentRoom->itemsYPos[i] = _rnd.getRandomNumberRng(_northExitHeight & 0xFF, 130);
|
|
|
|
} else {
|
|
|
|
xpos = currentRoom->itemsXPos[i];
|
|
|
|
ypos = currentRoom->itemsYPos[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
_lastProcessedItem = i;
|
|
|
|
|
|
|
|
int stop = 0;
|
|
|
|
while (!stop) {
|
2005-12-09 19:49:47 +00:00
|
|
|
stop = processItemDrop(sceneId, item, xpos, ypos, 3, 0);
|
2005-12-08 17:19:18 +00:00
|
|
|
if (!stop) {
|
|
|
|
xpos = currentRoom->itemsXPos[i] = _rnd.getRandomNumberRng(24, 296);
|
|
|
|
ypos = currentRoom->itemsYPos[i] = _rnd.getRandomNumberRng(_northExitHeight & 0xFF, 130);
|
|
|
|
if (countItemsInScene(sceneId) >= 12) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
2006-01-03 23:41:52 +00:00
|
|
|
currentRoom->needInit[i] = 0;
|
2005-12-08 17:19:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::countItemsInScene(uint16 sceneId) {
|
|
|
|
debug(9, "countItemsInScene(%d)", sceneId);
|
|
|
|
assert(sceneId < _roomTableSize);
|
|
|
|
Room *currentRoom = &_roomTable[sceneId];
|
|
|
|
|
|
|
|
int items = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 12; ++i) {
|
|
|
|
if (currentRoom->itemsTable[i] != 0xFF) {
|
|
|
|
++items;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return items;
|
|
|
|
}
|
|
|
|
|
2005-12-09 19:49:47 +00:00
|
|
|
int KyraEngine::processItemDrop(uint16 sceneId, uint8 item, int x, int y, int unk1, int unk2) {
|
|
|
|
debug(9, "processItemDrop(%d, %d, %d, %d, %d, %d)", sceneId, item, x, y, unk1, unk2);
|
2005-12-08 17:19:18 +00:00
|
|
|
int freeItem = -1;
|
|
|
|
uint8 itemIndex = findItemAtPos(x, y);
|
|
|
|
if (unk1) {
|
|
|
|
itemIndex = 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemIndex != 0xFF) {
|
|
|
|
exchangeItemWithMouseItem(sceneId, itemIndex);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(sceneId < _roomTableSize);
|
|
|
|
Room *currentRoom = &_roomTable[sceneId];
|
|
|
|
|
|
|
|
if (unk1 != 3) {
|
|
|
|
for (int i = 0; i < 12; ++i) {
|
|
|
|
if (currentRoom->itemsTable[i] == 0xFF) {
|
|
|
|
freeItem = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
freeItem = _lastProcessedItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (freeItem == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sceneId != _currentCharacter->sceneId) {
|
|
|
|
addItemToRoom(sceneId, item, freeItem, x, y);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int itemHeight = _itemTable[item].height;
|
|
|
|
_lastProcessedItemHeight = itemHeight;
|
|
|
|
|
|
|
|
if (x == -1 && x == -1) {
|
|
|
|
x = _rnd.getRandomNumberRng(16, 304);
|
|
|
|
y = _rnd.getRandomNumberRng(_northExitHeight & 0xFF, 135);
|
|
|
|
}
|
|
|
|
|
|
|
|
int xpos = x;
|
|
|
|
int ypos = y;
|
|
|
|
int destY = -1;
|
|
|
|
int destX = -1;
|
|
|
|
int running = 1;
|
2005-12-09 19:49:47 +00:00
|
|
|
|
2005-12-08 17:19:18 +00:00
|
|
|
while (running) {
|
|
|
|
if ((_northExitHeight & 0xFF) <= ypos) {
|
|
|
|
bool running2 = true;
|
|
|
|
|
2005-12-09 19:49:47 +00:00
|
|
|
if (getDrawLayer(xpos, ypos) > 1) {
|
2005-12-08 17:19:18 +00:00
|
|
|
if (((_northExitHeight >> 8) & 0xFF) != ypos) {
|
|
|
|
running2 = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-09 19:49:47 +00:00
|
|
|
if (getDrawLayer2(xpos, ypos, itemHeight) > 1) {
|
2005-12-08 17:19:18 +00:00
|
|
|
if (((_northExitHeight >> 8) & 0xFF) != ypos) {
|
|
|
|
running2 = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isDropable(xpos, ypos)) {
|
|
|
|
if (((_northExitHeight >> 8) & 0xFF) != ypos) {
|
|
|
|
running2 = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int xpos2 = xpos;
|
|
|
|
int xpos3 = xpos;
|
|
|
|
|
|
|
|
while (running2) {
|
|
|
|
if (isDropable(xpos2, ypos)) {
|
|
|
|
if (getDrawLayer2(xpos2, ypos, itemHeight) < 7) {
|
|
|
|
if (findItemAtPos(xpos2, ypos) == 0xFF) {
|
|
|
|
destX = xpos2;
|
|
|
|
destY = ypos;
|
|
|
|
running = 0;
|
|
|
|
running2 = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isDropable(xpos3, ypos)) {
|
|
|
|
if (getDrawLayer2(xpos3, ypos, itemHeight) < 7) {
|
|
|
|
if (findItemAtPos(xpos3, ypos) == 0xFF) {
|
|
|
|
destX = xpos3;
|
|
|
|
destY = ypos;
|
|
|
|
running = 0;
|
|
|
|
running2 = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!running2)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
xpos2 -= 2;
|
|
|
|
if (xpos2 < 16) {
|
|
|
|
xpos2 = 16;
|
|
|
|
}
|
|
|
|
|
|
|
|
xpos3 += 2;
|
|
|
|
if (xpos3 > 304) {
|
|
|
|
xpos3 = 304;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xpos2 > 16)
|
|
|
|
continue;
|
|
|
|
if (xpos3 < 304)
|
|
|
|
continue;
|
|
|
|
running2 = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (((_northExitHeight >> 8) & 0xFF) == ypos) {
|
|
|
|
running = 0;
|
|
|
|
destY -= _rnd.getRandomNumberRng(0, 3);
|
|
|
|
|
|
|
|
if ((_northExitHeight & 0xFF) < destY) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
destY = (_northExitHeight & 0xFF) + 1;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ypos += 2;
|
|
|
|
if (((_northExitHeight >> 8) & 0xFF) >= ypos) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
ypos = (_northExitHeight >> 8) & 0xFF;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (destX == -1 || destY == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unk1 == 3) {
|
|
|
|
currentRoom->itemsXPos[freeItem] = destX;
|
|
|
|
currentRoom->itemsYPos[freeItem] = destY;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unk1 == 2) {
|
2005-12-22 18:14:52 +00:00
|
|
|
itemSpecialFX(x, y, item);
|
2005-12-08 17:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unk1 == 0) {
|
|
|
|
destroyMouseItem();
|
|
|
|
}
|
|
|
|
|
|
|
|
itemDropDown(x, y, destX, destY, freeItem, item);
|
|
|
|
|
|
|
|
if (unk1 == 0 && unk2 != 0) {
|
2005-12-14 14:08:30 +00:00
|
|
|
assert(_itemList && _droppedList);
|
|
|
|
updateSentenceCommand(_itemList[item], _droppedList[0], 179);
|
2005-12-08 17:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::exchangeItemWithMouseItem(uint16 sceneId, int itemIndex) {
|
|
|
|
debug(9, "exchangeItemWithMouseItem(%d, %d)", sceneId, itemIndex);
|
|
|
|
_screen->hideMouse();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->animRemoveGameItem(itemIndex);
|
2005-12-08 17:19:18 +00:00
|
|
|
assert(sceneId < _roomTableSize);
|
|
|
|
Room *currentRoom = &_roomTable[sceneId];
|
|
|
|
|
2005-12-09 17:36:57 +00:00
|
|
|
int item = currentRoom->itemsTable[itemIndex];
|
2005-12-08 17:19:18 +00:00
|
|
|
currentRoom->itemsTable[itemIndex] = _itemInHand;
|
|
|
|
_itemInHand = item;
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->animAddGameItem(itemIndex, sceneId);
|
2005-12-08 17:19:18 +00:00
|
|
|
// XXX snd_kyraPlaySound 53
|
|
|
|
|
|
|
|
setMouseItem(_itemInHand);
|
2005-12-14 14:08:30 +00:00
|
|
|
assert(_itemList && _takenList);
|
|
|
|
updateSentenceCommand(_itemList[_itemInHand], _takenList[1], 179);
|
2005-12-08 17:19:18 +00:00
|
|
|
_screen->showMouse();
|
|
|
|
clickEventHandler2();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::addItemToRoom(uint16 sceneId, uint8 item, int itemIndex, int x, int y) {
|
|
|
|
debug(9, "addItemToRoom(%d, %d, %d, %d, %d)", sceneId, item, itemIndex, x, y);
|
|
|
|
assert(sceneId < _roomTableSize);
|
|
|
|
Room *currentRoom = &_roomTable[sceneId];
|
|
|
|
currentRoom->itemsTable[itemIndex] = item;
|
|
|
|
currentRoom->itemsXPos[itemIndex] = x;
|
|
|
|
currentRoom->itemsYPos[itemIndex] = y;
|
2006-01-03 23:41:52 +00:00
|
|
|
currentRoom->needInit[itemIndex] = 1;
|
2005-12-08 17:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::checkNoDropRects(int x, int y) {
|
|
|
|
debug(9, "checkNoDropRects(%d, %d)", x, y);
|
|
|
|
if (_lastProcessedItemHeight < 1 || _lastProcessedItemHeight > 16) {
|
|
|
|
_lastProcessedItemHeight = 16;
|
|
|
|
}
|
|
|
|
if (_noDropRects[0].x == -1) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 0; i < 11; ++i) {
|
|
|
|
if (_noDropRects[i].x == -1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
int xpos = _noDropRects[i].x;
|
|
|
|
int ypos = _noDropRects[i].y;
|
|
|
|
int xpos2 = _noDropRects[i].x2;
|
|
|
|
int ypos2 = _noDropRects[i].y2;
|
|
|
|
|
|
|
|
if (xpos > x + 16)
|
|
|
|
continue;
|
|
|
|
if (xpos2 < x)
|
|
|
|
continue;
|
|
|
|
if (y < ypos)
|
|
|
|
continue;
|
|
|
|
if (ypos2 < y - _lastProcessedItemHeight)
|
|
|
|
continue;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::isDropable(int x, int y) {
|
|
|
|
debug(9, "isDropable(%d, %d)", x, y);
|
|
|
|
x -= 8;
|
|
|
|
y -= 1;
|
|
|
|
|
|
|
|
if (checkNoDropRects(x, y)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int xpos = x; xpos < x + 16; ++xpos) {
|
|
|
|
if (_screen->getShapeFlag1(xpos, y) == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::itemDropDown(int x, int y, int destX, int destY, byte freeItem, int item) {
|
|
|
|
debug(9, "itemDropDown(%d, %d, %d, %d, %d, %d)", x, y, destX, destY, freeItem, item);
|
|
|
|
assert(_currentCharacter->sceneId < _roomTableSize);
|
|
|
|
Room *currentRoom = &_roomTable[_currentCharacter->sceneId];
|
|
|
|
if (x == destX && y == destY) {
|
|
|
|
currentRoom->itemsXPos[freeItem] = destX;
|
|
|
|
currentRoom->itemsYPos[freeItem] = destY;
|
|
|
|
currentRoom->itemsTable[freeItem] = item;
|
|
|
|
// call kyraPlaySound(0x32)
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->animAddGameItem(freeItem, _currentCharacter->sceneId);
|
2005-12-08 17:19:18 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
_screen->hideMouse();
|
|
|
|
if (y <= destY) {
|
|
|
|
int tempY = y;
|
|
|
|
int addY = 2;
|
|
|
|
int drawX = x - 8;
|
|
|
|
int drawY = 0;
|
|
|
|
|
|
|
|
backUpRect0(drawX, y - 16);
|
|
|
|
|
|
|
|
while (tempY < destY) {
|
|
|
|
restoreRect0(drawX, tempY - 16);
|
|
|
|
tempY += addY;
|
|
|
|
if (tempY > destY) {
|
|
|
|
tempY = destY;
|
|
|
|
}
|
|
|
|
++addY;
|
|
|
|
drawY = tempY - 16;
|
|
|
|
backUpRect0(drawX, drawY);
|
2005-12-22 18:14:52 +00:00
|
|
|
uint32 nextTime = _system->getMillis() + 1 * _tickLength;
|
2005-12-08 17:19:18 +00:00
|
|
|
_screen->drawShape(0, _shapes[220+item], drawX, drawY, 0, 0);
|
|
|
|
_screen->updateScreen();
|
2005-12-22 18:14:52 +00:00
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
if ((nextTime - _system->getMillis()) >= 10)
|
|
|
|
delay(10);
|
|
|
|
}
|
2005-12-08 17:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool skip = false;
|
|
|
|
if (x == destX) {
|
|
|
|
if (destY - y <= 16) {
|
|
|
|
skip = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!skip) {
|
|
|
|
// call kyraPlaySound(0x47)
|
|
|
|
if (addY < 6)
|
|
|
|
addY = 6;
|
|
|
|
|
2005-12-09 19:49:47 +00:00
|
|
|
int xDiff = (destX - x) << 4;
|
2005-12-08 17:19:18 +00:00
|
|
|
xDiff /= addY;
|
|
|
|
int startAddY = addY;
|
2005-12-09 19:49:47 +00:00
|
|
|
addY >>= 1;
|
2005-12-08 17:19:18 +00:00
|
|
|
if (destY - y <= 8) {
|
|
|
|
addY >>= 1;
|
|
|
|
}
|
|
|
|
addY = -addY;
|
|
|
|
int unkX = x << 4;
|
|
|
|
while (--startAddY) {
|
|
|
|
drawX = (unkX >> 4) - 8;
|
|
|
|
drawY = tempY - 16;
|
|
|
|
restoreRect0(drawX, drawY);
|
|
|
|
tempY += addY;
|
|
|
|
unkX += xDiff;
|
|
|
|
if (tempY > destY) {
|
|
|
|
tempY = destY;
|
|
|
|
}
|
|
|
|
++addY;
|
|
|
|
drawX = (unkX >> 4) - 8;
|
|
|
|
drawY = tempY - 16;
|
|
|
|
backUpRect0(drawX, drawY);
|
2005-12-22 18:14:52 +00:00
|
|
|
uint32 nextTime = _system->getMillis() + 1 * _tickLength;
|
2005-12-08 17:19:18 +00:00
|
|
|
_screen->drawShape(0, _shapes[220+item], drawX, drawY, 0, 0);
|
|
|
|
_screen->updateScreen();
|
2005-12-22 18:14:52 +00:00
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
if ((nextTime - _system->getMillis()) >= 10)
|
|
|
|
delay(10);
|
|
|
|
}
|
2005-12-08 17:19:18 +00:00
|
|
|
}
|
2005-12-09 19:49:47 +00:00
|
|
|
restoreRect0(drawX, drawY);
|
2005-12-08 17:19:18 +00:00
|
|
|
} else {
|
|
|
|
restoreRect0(drawX, tempY - 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
currentRoom->itemsXPos[freeItem] = destX;
|
|
|
|
currentRoom->itemsYPos[freeItem] = destY;
|
|
|
|
currentRoom->itemsTable[freeItem] = item;
|
|
|
|
// call kyraPlaySound(0x32)
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->animAddGameItem(freeItem, _currentCharacter->sceneId);
|
2005-12-08 17:19:18 +00:00
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
2005-12-09 19:49:47 +00:00
|
|
|
void KyraEngine::dropItem(int unk1, int item, int x, int y, int unk2) {
|
|
|
|
debug(9, "dropItem(%d, %d, %d, %d, %d)", unk1, item, x, y, unk2);
|
|
|
|
if (processItemDrop(_currentCharacter->sceneId, item, x, y, unk1, unk2))
|
|
|
|
return;
|
|
|
|
// call kyraPlaySound(54)
|
|
|
|
if (12 == countItemsInScene(_currentCharacter->sceneId)) {
|
2005-12-14 14:08:30 +00:00
|
|
|
assert(_noDropList);
|
|
|
|
drawSentenceCommand(_noDropList[0], 6);
|
2005-12-09 19:49:47 +00:00
|
|
|
} else {
|
2005-12-14 14:08:30 +00:00
|
|
|
assert(_noDropList);
|
|
|
|
drawSentenceCommand(_noDropList[1], 6);
|
2005-12-09 19:49:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-22 18:14:52 +00:00
|
|
|
void KyraEngine::itemSpecialFX(int x, int y, int item) {
|
|
|
|
debug(9, "itemSpecialFX(%d, %d, %d)", x, y, item);
|
|
|
|
if (item == 41) {
|
|
|
|
itemSpecialFX1(x, y, item);
|
|
|
|
} else {
|
|
|
|
itemSpecialFX2(x, y, item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::itemSpecialFX1(int x, int y, int item) {
|
|
|
|
debug(9, "itemSpecialFX1(%d, %d, %d)", x, y, item);
|
|
|
|
uint8 *shape = _shapes[220+item];
|
|
|
|
x -= 8;
|
|
|
|
int startY = y;
|
|
|
|
y -= 15;
|
|
|
|
_screen->hideMouse();
|
|
|
|
backUpRect0(x, y);
|
|
|
|
for (int i = 1; i <= 16; ++i) {
|
|
|
|
_screen->setNewShapeHeight(shape, i);
|
|
|
|
--startY;
|
|
|
|
restoreRect0(x, y);
|
|
|
|
uint32 nextTime = _system->getMillis() + 1 * _tickLength;
|
|
|
|
_screen->drawShape(0, shape, x, startY, 0, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
if ((nextTime - _system->getMillis()) >= 10)
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
restoreRect0(x, y);
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::itemSpecialFX2(int x, int y, int item) {
|
|
|
|
debug(9, "itemSpecialFX2(%d, %d, %d)", x, y, item);
|
|
|
|
x -= 8;
|
|
|
|
y -= 15;
|
|
|
|
int yAdd = (int8)(((16 - _itemTable[item].height) >> 1) & 0xFF);
|
|
|
|
backUpRect0(x, y);
|
|
|
|
if (item >= 80 && item <= 89) {
|
|
|
|
// snd_kyraPlaySound(55);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 201; i <= 205; ++i) {
|
|
|
|
restoreRect0(x, y);
|
|
|
|
uint32 nextTime = _system->getMillis() + 3 * _tickLength;
|
|
|
|
_screen->drawShape(0, _shapes[4+i], x, y + yAdd, 0, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
if ((nextTime - _system->getMillis()) >= 10)
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 204; i >= 201; --i) {
|
|
|
|
restoreRect0(x, y);
|
|
|
|
uint32 nextTime = _system->getMillis() + 3 * _tickLength;
|
|
|
|
_screen->drawShape(0, _shapes[220+item], x, y, 0, 0);
|
|
|
|
_screen->drawShape(0, _shapes[4+i], x, y + yAdd, 0, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
if ((nextTime - _system->getMillis()) >= 10)
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
restoreRect0(x, y);
|
|
|
|
}
|
|
|
|
|
2005-12-23 17:49:14 +00:00
|
|
|
void KyraEngine::magicOutMouseItem(int animIndex, int itemPos) {
|
|
|
|
debug(9, "magicOutMouseItem(%d, %d)", animIndex, itemPos);
|
|
|
|
int videoPageBackUp = _screen->_curPage;
|
|
|
|
_screen->_curPage = 0;
|
|
|
|
int x = 0, y = 0;
|
|
|
|
if (itemPos == -1) {
|
|
|
|
x = _mouseX - 12;
|
|
|
|
y = _mouseY - 18;
|
|
|
|
} else {
|
|
|
|
x = _itemPosX[itemPos] - 4;
|
|
|
|
y = _itemPosY[itemPos] - 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_itemInHand == -1 && itemPos == -1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int tableIndex = 0, loopStart = 0, maxLoops = 0;
|
|
|
|
if (animIndex == 0) {
|
|
|
|
tableIndex = _rnd.getRandomNumberRng(0, 5);
|
|
|
|
loopStart = 35;
|
|
|
|
maxLoops = 9;
|
|
|
|
} else if (animIndex == 1) {
|
|
|
|
tableIndex = _rnd.getRandomNumberRng(0, 11);
|
|
|
|
loopStart = 115;
|
|
|
|
maxLoops = 8;
|
|
|
|
} else if (animIndex == 2) {
|
|
|
|
tableIndex = 0;
|
|
|
|
loopStart = 124;
|
|
|
|
maxLoops = 4;
|
|
|
|
} else {
|
|
|
|
tableIndex = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animIndex == 2) {
|
|
|
|
// snd_kyraPlaySound(0x5E);
|
|
|
|
} else {
|
|
|
|
// snd_kyraPlaySound(0x37);
|
|
|
|
}
|
|
|
|
_screen->hideMouse();
|
|
|
|
backUpRect1(x, y);
|
|
|
|
|
|
|
|
for (int shape = _magicMouseItemStartFrame[animIndex]; shape <= _magicMouseItemEndFrame[animIndex]; ++shape) {
|
|
|
|
restoreRect1(x, y);
|
|
|
|
uint32 nextTime = _system->getMillis() + 4 * _tickLength;
|
|
|
|
_screen->drawShape(0, _shapes[220+_itemInHand], x + 4, y + 3, 0, 0);
|
|
|
|
if (tableIndex == -1) {
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], x, y, 0, 0);
|
|
|
|
} else {
|
|
|
|
specialMouseItemFX(shape, x, y, animIndex, tableIndex, loopStart, maxLoops);
|
|
|
|
}
|
|
|
|
_screen->updateScreen();
|
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
if (nextTime - _system->getMillis() >= 10)
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (itemPos != -1) {
|
|
|
|
restoreRect1(x, y);
|
|
|
|
_screen->fillRect(_itemPosX[itemPos], _itemPosY[itemPos], _itemPosX[itemPos] + 15, _itemPosY[itemPos] + 15, 12, 0);
|
|
|
|
backUpRect1(x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int shape = _magicMouseItemStartFrame2[animIndex]; shape <= _magicMouseItemEndFrame2[animIndex]; ++shape) {
|
|
|
|
restoreRect1(x, y);
|
|
|
|
uint32 nextTime = _system->getMillis() + 4 * _tickLength;
|
|
|
|
_screen->drawShape(0, _shapes[220+_itemInHand], x + 4, y + 3, 0, 0);
|
|
|
|
if (tableIndex == -1) {
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], x, y, 0, 0);
|
|
|
|
} else {
|
|
|
|
specialMouseItemFX(shape, x, y, animIndex, tableIndex, loopStart, maxLoops);
|
|
|
|
}
|
|
|
|
_screen->updateScreen();
|
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
if (nextTime - _system->getMillis() >= 10)
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
restoreRect1(x, y);
|
|
|
|
if (itemPos == -1) {
|
|
|
|
_screen->setMouseCursor(1, 1, _shapes[4]);
|
|
|
|
_itemInHand = -1;
|
|
|
|
} else {
|
|
|
|
_characterList[0].inventoryItems[itemPos] = 0xFF;
|
|
|
|
_screen->hideMouse();
|
|
|
|
_screen->fillRect(_itemPosX[itemPos], _itemPosY[itemPos], _itemPosX[itemPos] + 15, _itemPosY[itemPos] + 15, 12, 0);
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
_screen->showMouse();
|
|
|
|
_screen->_curPage = videoPageBackUp;
|
|
|
|
}
|
|
|
|
|
2005-12-28 21:34:40 +00:00
|
|
|
void KyraEngine::magicInMouseItem(int animIndex, int item, int itemPos) {
|
|
|
|
debug(9, "magicInMouseItem(%d, %d, %d)", animIndex, item, itemPos);
|
|
|
|
int videoPageBackUp = _screen->_curPage;
|
|
|
|
_screen->_curPage = 0;
|
|
|
|
int x = 0, y = 0;
|
|
|
|
if (itemPos == -1) {
|
|
|
|
x = _mouseX - 12;
|
|
|
|
y = _mouseY - 18;
|
|
|
|
} else {
|
|
|
|
x = _itemPosX[itemPos] - 4;
|
|
|
|
y = _itemPosX[itemPos] - 3;
|
|
|
|
}
|
|
|
|
if (item < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int tableIndex = -1, loopStart = 0, maxLoops = 0;
|
|
|
|
if (animIndex == 0) {
|
|
|
|
tableIndex = _rnd.getRandomNumberRng(0, 5);
|
|
|
|
loopStart = 35;
|
|
|
|
maxLoops = 9;
|
|
|
|
} else if (animIndex == 1) {
|
|
|
|
tableIndex = _rnd.getRandomNumberRng(0, 11);
|
|
|
|
loopStart = 115;
|
|
|
|
maxLoops = 8;
|
|
|
|
} else if (animIndex == 2) {
|
|
|
|
tableIndex = 0;
|
|
|
|
loopStart = 124;
|
|
|
|
maxLoops = 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
_screen->hideMouse();
|
|
|
|
backUpRect1(x, y);
|
|
|
|
if (animIndex == 2) {
|
|
|
|
// snd_playSoundEffect(0x5E);
|
|
|
|
} else {
|
|
|
|
// snd_playSoundEffect(0x37);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int shape = _magicMouseItemStartFrame[animIndex]; shape <= _magicMouseItemEndFrame[animIndex]; ++shape) {
|
|
|
|
restoreRect1(x, y);
|
|
|
|
uint32 nextTime = _system->getMillis() + 4 * _tickLength;
|
|
|
|
if (tableIndex == -1) {
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], x, y, 0, 0);
|
|
|
|
} else {
|
|
|
|
specialMouseItemFX(shape, x, y, animIndex, tableIndex, loopStart, maxLoops);
|
|
|
|
}
|
|
|
|
_screen->updateScreen();
|
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
if (nextTime - _system->getMillis() >= 10)
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int shape = _magicMouseItemStartFrame2[animIndex]; shape <= _magicMouseItemEndFrame2[animIndex]; ++shape) {
|
|
|
|
restoreRect1(x, y);
|
|
|
|
uint32 nextTime = _system->getMillis() + 4 * _tickLength;
|
|
|
|
if (tableIndex == -1) {
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], x, y, 0, 0);
|
|
|
|
} else {
|
|
|
|
specialMouseItemFX(shape, x, y, animIndex, tableIndex, loopStart, maxLoops);
|
|
|
|
}
|
|
|
|
_screen->updateScreen();
|
|
|
|
while (_system->getMillis() < nextTime) {
|
|
|
|
if (nextTime - _system->getMillis() >= 10)
|
|
|
|
delay(10);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
restoreRect1(x, y);
|
|
|
|
if (itemPos == -1) {
|
|
|
|
_screen->setMouseCursor(8, 15, _shapes[220+item]);
|
|
|
|
_itemInHand = item;
|
|
|
|
} else {
|
|
|
|
_characterList[0].inventoryItems[itemPos] = item;
|
|
|
|
_screen->hideMouse();
|
|
|
|
_screen->drawShape(0, _shapes[220+item], _itemPosX[itemPos], _itemPosY[itemPos], 0, 0);
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
_screen->showMouse();
|
|
|
|
_screen->_curPage = videoPageBackUp;
|
|
|
|
}
|
|
|
|
|
2005-12-23 17:49:14 +00:00
|
|
|
void KyraEngine::specialMouseItemFX(int shape, int x, int y, int animIndex, int tableIndex, int loopStart, int maxLoops) {
|
|
|
|
debug(9, "specialMouseItemFX(%d, %d, %d, %d, %d, %d, %d)", shape, x, y, animIndex, tableIndex, loopStart, maxLoops);
|
|
|
|
static const uint8 table1[] = {
|
|
|
|
0x23, 0x45, 0x55, 0x72, 0x84, 0xCF, 0x00, 0x00
|
|
|
|
};
|
|
|
|
static const uint8 table2[] = {
|
|
|
|
0x73, 0xB5, 0x80, 0x21, 0x13, 0x39, 0x45, 0x55, 0x62, 0xB4, 0xCF, 0xD8
|
|
|
|
};
|
|
|
|
static const uint8 table3[] = {
|
|
|
|
0x7C, 0xD0, 0x74, 0x84, 0x87, 0x00, 0x00, 0x00
|
|
|
|
};
|
|
|
|
int tableValue = 0;
|
|
|
|
if (animIndex == 0) {
|
|
|
|
tableValue = table1[tableIndex];
|
|
|
|
} else if (animIndex == 1) {
|
|
|
|
tableValue = table2[tableIndex];
|
|
|
|
} else if (animIndex == 2) {
|
|
|
|
tableValue = table3[tableIndex];
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
processSpecialMouseItemFX(shape, x, y, tableValue, loopStart, maxLoops);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::processSpecialMouseItemFX(int shape, int x, int y, int tableValue, int loopStart, int maxLoops) {
|
|
|
|
debug(9, "processSpecialMouseItemFX(%d, %d, %d, %d, %d, %d)", shape, x, y, tableValue, loopStart, maxLoops);
|
|
|
|
uint8 shapeColorTable[16];
|
|
|
|
uint8 *shapePtr = _shapes[4+shape] + 10;
|
|
|
|
if (_features & GF_TALKIE)
|
|
|
|
shapePtr += 2;
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
shapeColorTable[i] = shapePtr[i];
|
|
|
|
}
|
|
|
|
for (int i = loopStart; i < loopStart + maxLoops; ++i) {
|
|
|
|
for (int i2 = 0; i2 < 16; ++i2) {
|
|
|
|
if (shapePtr[i2] == i) {
|
|
|
|
shapeColorTable[i2] = (i + tableValue) - loopStart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], x, y, 0, 0x8000, shapeColorTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::updatePlayerItemsForScene() {
|
|
|
|
debug(9, "updatePlayerItemsForScene()");
|
|
|
|
if (_itemInHand >= 29 && _itemInHand < 33) {
|
|
|
|
++_itemInHand;
|
|
|
|
if (_itemInHand > 33)
|
|
|
|
_itemInHand = 33;
|
|
|
|
_screen->hideMouse();
|
|
|
|
_screen->setMouseCursor(8, 15, _shapes[220+_itemInHand]);
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool redraw = false;
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
uint8 item = _currentCharacter->inventoryItems[i];
|
|
|
|
if (item >= 29 && item < 33) {
|
|
|
|
++item;
|
|
|
|
if (item > 33)
|
|
|
|
item = 33;
|
|
|
|
_currentCharacter->inventoryItems[i] = item;
|
|
|
|
redraw = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (redraw) {
|
|
|
|
_screen->hideMouse();
|
|
|
|
redrawInventory(0);
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_itemInHand == 33) {
|
|
|
|
magicOutMouseItem(2, -1);
|
|
|
|
}
|
|
|
|
|
|
|
|
_screen->hideMouse();
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
uint8 item = _currentCharacter->inventoryItems[i];
|
|
|
|
if (item == 33) {
|
|
|
|
magicOutMouseItem(2, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::redrawInventory(int page) {
|
|
|
|
int videoPageBackUp = _screen->_curPage;
|
|
|
|
_screen->_curPage = page;
|
|
|
|
_screen->hideMouse();
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
_screen->fillRect(_itemPosX[i], _itemPosY[i], _itemPosX[i] + 15, _itemPosY[i] + 15, 12, page);
|
|
|
|
if (_currentCharacter->inventoryItems[i] != 0xFF) {
|
|
|
|
uint8 item = _currentCharacter->inventoryItems[i];
|
|
|
|
_screen->drawShape(page, _shapes[220+item], _itemPosX[i], _itemPosY[i], 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_screen->showMouse();
|
|
|
|
_screen->_curPage = videoPageBackUp;
|
|
|
|
_screen->updateScreen();
|
|
|
|
}
|
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
#pragma mark -
|
2005-12-26 14:53:51 +00:00
|
|
|
#pragma mark - Animation/shape specific code
|
2005-10-29 18:37:40 +00:00
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
void KyraEngine::animRefreshNPC(int character) {
|
2005-11-01 14:19:50 +00:00
|
|
|
debug(9, "animRefreshNPC(%d)", character);
|
2006-01-02 22:58:59 +00:00
|
|
|
AnimObject *animObj = &_animator->actors()[character];
|
2005-10-29 18:37:40 +00:00
|
|
|
Character *ch = &_characterList[character];
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
animObj->refreshFlag = 1;
|
|
|
|
animObj->bkgdChangeFlag = 1;
|
|
|
|
int facing = ch->facing;
|
|
|
|
if (facing >= 1 && facing <= 3) {
|
2005-11-09 22:26:12 +00:00
|
|
|
animObj->flags |= 1;
|
2005-10-29 18:37:40 +00:00
|
|
|
} else if (facing >= 5 && facing <= 7) {
|
2005-11-09 22:26:12 +00:00
|
|
|
animObj->flags &= 0xFFFFFFFE;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
animObj->drawY = ch->y1;
|
|
|
|
animObj->sceneAnimPtr = _shapes[4+ch->currentAnimFrame];
|
|
|
|
animObj->animFrameNumber = ch->currentAnimFrame;
|
|
|
|
if (character == 0) {
|
|
|
|
if (_brandonStatusBit & 10) {
|
|
|
|
animObj->animFrameNumber = 88;
|
|
|
|
ch->currentAnimFrame = 88;
|
|
|
|
}
|
|
|
|
if (_brandonStatusBit & 2) {
|
|
|
|
animObj->animFrameNumber = _brandonDrawFrame;
|
|
|
|
ch->currentAnimFrame = _brandonDrawFrame;
|
|
|
|
animObj->sceneAnimPtr = _shapes[4+_brandonDrawFrame];
|
2005-12-29 22:18:40 +00:00
|
|
|
if (_brandonStatusBit0x02Flag) {
|
|
|
|
++_brandonDrawFrame;
|
|
|
|
if (_brandonDrawFrame >= 122)
|
|
|
|
_brandonDrawFrame = 113;
|
|
|
|
_brandonStatusBit0x02Flag = 0;
|
|
|
|
}
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-09 22:26:12 +00:00
|
|
|
int xOffset = _defaultShapeTable[ch->currentAnimFrame-7].xOffset;
|
|
|
|
int yOffset = _defaultShapeTable[ch->currentAnimFrame-7].yOffset;
|
2005-10-29 18:37:40 +00:00
|
|
|
|
|
|
|
if (_scaleMode) {
|
|
|
|
animObj->x1 = ch->x1;
|
|
|
|
animObj->y1 = ch->y1;
|
|
|
|
|
|
|
|
_brandonScaleX = _scaleTable[ch->y1];
|
|
|
|
_brandonScaleY = _scaleTable[ch->y1];
|
2005-11-09 22:26:12 +00:00
|
|
|
|
2005-10-29 18:37:40 +00:00
|
|
|
animObj->x1 += (_brandonScaleX * xOffset) >> 8;
|
|
|
|
animObj->y1 += (_brandonScaleY * yOffset) >> 8;
|
|
|
|
} else {
|
2005-11-09 22:26:12 +00:00
|
|
|
animObj->x1 = ch->x1 + xOffset;
|
|
|
|
animObj->y1 = ch->y1 + yOffset;
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
|
|
|
animObj->width2 = 4;
|
|
|
|
animObj->height2 = 3;
|
2005-11-10 14:08:50 +00:00
|
|
|
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->refreshObject(animObj);
|
2005-12-09 23:02:16 +00:00
|
|
|
}
|
|
|
|
|
2005-12-26 14:53:51 +00:00
|
|
|
void KyraEngine::drawJewelPress(int jewel, int drawSpecial) {
|
|
|
|
debug(9, "drawJewelPress(%d, %d)", jewel, drawSpecial);
|
|
|
|
_screen->hideMouse();
|
|
|
|
int shape = 0;
|
|
|
|
if (drawSpecial) {
|
|
|
|
shape = 0x14E;
|
|
|
|
} else {
|
|
|
|
shape = jewel + 0x149;
|
|
|
|
}
|
|
|
|
// snd_playSoundEffect(0x45);
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], _amuletX2[jewel], _amuletY2[jewel], 0, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
delayWithTicks(2);
|
|
|
|
if (drawSpecial) {
|
|
|
|
shape = 0x148;
|
|
|
|
} else {
|
|
|
|
shape = jewel + 0x143;
|
|
|
|
}
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], _amuletX2[jewel], _amuletY2[jewel], 0, 0);
|
|
|
|
_screen->updateScreen();
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::drawJewelsFadeOutStart() {
|
|
|
|
debug(9, "drawJewelsFadeOutStart()");
|
|
|
|
static const uint16 jewelTable1[] = { 0x164, 0x15F, 0x15A, 0x155, 0x150, 0xFFFF };
|
|
|
|
static const uint16 jewelTable2[] = { 0x163, 0x15E, 0x159, 0x154, 0x14F, 0xFFFF };
|
|
|
|
static const uint16 jewelTable3[] = { 0x166, 0x160, 0x15C, 0x157, 0x152, 0xFFFF };
|
|
|
|
static const uint16 jewelTable4[] = { 0x165, 0x161, 0x15B, 0x156, 0x151, 0xFFFF };
|
|
|
|
for (int i = 0; jewelTable1[i] != 0xFFFF; ++i) {
|
|
|
|
if (queryGameFlag(0x57)) {
|
|
|
|
_screen->drawShape(0, _shapes[4+jewelTable1[i]], _amuletX2[2], _amuletY2[2], 0, 0);
|
|
|
|
}
|
|
|
|
if (queryGameFlag(0x59)) {
|
|
|
|
_screen->drawShape(0, _shapes[4+jewelTable3[i]], _amuletX2[4], _amuletY2[4], 0, 0);
|
|
|
|
}
|
|
|
|
if (queryGameFlag(0x56)) {
|
|
|
|
_screen->drawShape(0, _shapes[4+jewelTable2[i]], _amuletX2[1], _amuletY2[1], 0, 0);
|
|
|
|
}
|
|
|
|
if (queryGameFlag(0x58)) {
|
|
|
|
_screen->drawShape(0, _shapes[4+jewelTable4[i]], _amuletX2[3], _amuletY2[3], 0, 0);
|
|
|
|
}
|
|
|
|
_screen->updateScreen();
|
|
|
|
delayWithTicks(3);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::drawJewelsFadeOutEnd(int jewel) {
|
|
|
|
debug(9, "drawJewelsFadeOutEnd(%d)", jewel);
|
|
|
|
static const uint16 jewelTable[] = { 0x153, 0x158, 0x15D, 0x162, 0x148, 0xFFFF };
|
|
|
|
int newDelay = 0;
|
|
|
|
switch (jewel-1) {
|
|
|
|
case 2:
|
|
|
|
if (_currentCharacter->sceneId >= 109 && _currentCharacter->sceneId <= 198) {
|
|
|
|
newDelay = 18900;
|
|
|
|
} else {
|
|
|
|
newDelay = 8100;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
newDelay = 3600;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
setGameFlag(0xF1);
|
|
|
|
setTimerCountdown(19, newDelay);
|
|
|
|
_screen->hideMouse();
|
|
|
|
for (int i = 0; jewelTable[i] != 0xFFFF; ++i) {
|
|
|
|
uint16 shape = jewelTable[i];
|
|
|
|
if (queryGameFlag(0x57)) {
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], _amuletX2[2], _amuletY2[2], 0, 0);
|
|
|
|
}
|
|
|
|
if (queryGameFlag(0x59)) {
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], _amuletX2[4], _amuletY2[4], 0, 0);
|
|
|
|
}
|
|
|
|
if (queryGameFlag(0x56)) {
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], _amuletX2[1], _amuletY2[1], 0, 0);
|
|
|
|
}
|
|
|
|
if (queryGameFlag(0x58)) {
|
|
|
|
_screen->drawShape(0, _shapes[4+shape], _amuletX2[3], _amuletY2[3], 0, 0);
|
|
|
|
}
|
|
|
|
_screen->updateScreen();
|
|
|
|
delayWithTicks(3);
|
|
|
|
}
|
|
|
|
_screen->showMouse();
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::setupShapes123(const Shape *shapeTable, int endShape, int flags) {
|
|
|
|
debug(9, "setupShapes123(0x%X, startShape, flags)", shapeTable, endShape, flags);
|
|
|
|
for (int i = 123; i <= 172; ++i) {
|
|
|
|
_shapes[4+i] = NULL;
|
|
|
|
}
|
|
|
|
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() {
|
|
|
|
debug(9, "freeShapes123()");
|
|
|
|
for (int i = 123; i <= 172; ++i) {
|
|
|
|
free(_shapes[4+i]);
|
|
|
|
_shapes[4+i] = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::setBrandonAnimSeqSize(int width, int height) {
|
|
|
|
debug(9, "setBrandonAnimSeqSize(%d, %d)", width, height);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->restoreAllObjectBackgrounds();
|
|
|
|
_brandonAnimSeqSizeWidth = _animator->actors()[0].width;
|
|
|
|
_brandonAnimSeqSizeHeight = _animator->actors()[0].height;
|
|
|
|
_animator->actors()[0].width = width + 1;
|
|
|
|
_animator->actors()[0].height = height;
|
|
|
|
_animator->preserveAllBackgrounds();
|
2005-12-26 14:53:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::resetBrandonAnimSeqSize() {
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->restoreAllObjectBackgrounds();
|
|
|
|
_animator->actors()[0].width = _brandonAnimSeqSizeWidth;
|
|
|
|
_animator->actors()[0].height = _brandonAnimSeqSizeHeight;
|
|
|
|
_animator->preserveAllBackgrounds();
|
2005-10-29 18:37:40 +00:00
|
|
|
}
|
2005-10-30 19:58:51 +00:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark - Misc stuff
|
|
|
|
#pragma mark -
|
|
|
|
|
2006-01-02 13:20:02 +00:00
|
|
|
Movie *KyraEngine::createWSAMovie() {
|
|
|
|
// for kyra2 here could be added then WSAMovieV2
|
|
|
|
return new WSAMovieV1(this);
|
|
|
|
}
|
|
|
|
|
2005-10-30 19:58:51 +00:00
|
|
|
int16 KyraEngine::fetchAnimWidth(const uint8 *shape, int16 mult) {
|
2005-11-09 22:26:12 +00:00
|
|
|
debug(9, "fetchAnimWidth(0x%X, %d)", shape, mult);
|
2005-10-30 19:58:51 +00:00
|
|
|
if (_features & GF_TALKIE)
|
|
|
|
shape += 2;
|
2005-12-08 17:19:18 +00:00
|
|
|
return (((int16)READ_LE_UINT16((shape+3))) * mult) >> 8;
|
2005-10-30 19:58:51 +00:00
|
|
|
}
|
|
|
|
|
2005-12-08 17:19:18 +00:00
|
|
|
int16 KyraEngine::fetchAnimHeight(const uint8 *shape, int16 mult) {
|
2005-11-09 22:26:12 +00:00
|
|
|
debug(9, "fetchAnimHeight(0x%X, %d)", shape, mult);
|
2005-10-30 19:58:51 +00:00
|
|
|
if (_features & GF_TALKIE)
|
|
|
|
shape += 2;
|
2005-12-08 17:19:18 +00:00
|
|
|
return (int16)(((int8)*(shape+2)) * mult) >> 8;
|
|
|
|
}
|
|
|
|
|
2005-12-09 19:49:47 +00:00
|
|
|
void KyraEngine::rectClip(int &x, int &y, int w, int h) {
|
|
|
|
if (x < 0) {
|
|
|
|
x = 0;
|
|
|
|
} else if (x + w >= 320) {
|
|
|
|
x = 320 - w;
|
|
|
|
}
|
|
|
|
if (y < 0) {
|
|
|
|
y = 0;
|
|
|
|
} else if (y + h >= 200) {
|
|
|
|
y = 200 - h;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-08 17:19:18 +00:00
|
|
|
void KyraEngine::backUpRect0(int xpos, int ypos) {
|
|
|
|
debug(9, "backUpRect0(%d, %d)", xpos, ypos);
|
2005-12-09 19:49:47 +00:00
|
|
|
rectClip(xpos, ypos, 3<<3, 24);
|
|
|
|
_screen->copyRegionToBuffer(_screen->_curPage, xpos, ypos, 3<<3, 24, _shapes[0]);
|
2005-12-08 17:19:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::restoreRect0(int xpos, int ypos) {
|
|
|
|
debug(9, "restoreRect0(%d, %d)", xpos, ypos);
|
2005-12-09 19:49:47 +00:00
|
|
|
rectClip(xpos, ypos, 3<<3, 24);
|
|
|
|
_screen->copyBlockToPage(_screen->_curPage, xpos, ypos, 3<<3, 24, _shapes[0]);
|
2005-10-30 19:58:51 +00:00
|
|
|
}
|
2005-11-01 14:19:50 +00:00
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
void KyraEngine::backUpRect1(int xpos, int ypos) {
|
|
|
|
debug(9, "backUpRect1(%d, %d)", xpos, ypos);
|
2005-12-09 19:49:47 +00:00
|
|
|
rectClip(xpos, ypos, 4<<3, 32);
|
2005-11-18 23:55:31 +00:00
|
|
|
_screen->copyRegionToBuffer(_screen->_curPage, xpos, ypos, 4<<3, 32, _shapes[1]);
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::restoreRect1(int xpos, int ypos) {
|
|
|
|
debug(9, "restoreRect1(%d, %d)", xpos, ypos);
|
2005-12-09 19:49:47 +00:00
|
|
|
rectClip(xpos, ypos, 4<<3, 32);
|
2005-11-18 23:55:31 +00:00
|
|
|
_screen->copyBlockToPage(_screen->_curPage, xpos, ypos, 4<<3, 32, _shapes[1]);
|
|
|
|
}
|
|
|
|
|
2005-12-08 17:19:18 +00:00
|
|
|
int KyraEngine::getDrawLayer(int x, int y) {
|
|
|
|
debug(9, "getDrawLayer(%d, %d)", x, y);
|
|
|
|
int xpos = x - 8;
|
|
|
|
int ypos = y - 1;
|
|
|
|
int layer = 1;
|
|
|
|
for (int curX = xpos; curX < xpos + 16; ++curX) {
|
|
|
|
int tempLayer = _screen->getShapeFlag2(curX, ypos);
|
|
|
|
if (layer < tempLayer) {
|
|
|
|
layer = tempLayer;
|
|
|
|
}
|
|
|
|
if (layer >= 7) {
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::getDrawLayer2(int x, int y, int height) {
|
|
|
|
debug(9, "getDrawLayer2(%d, %d, %d)", x, y, height);
|
|
|
|
int xpos = x - 8;
|
|
|
|
int ypos = y - 1;
|
|
|
|
int layer = 1;
|
|
|
|
|
|
|
|
for (int useX = xpos; useX < xpos + 16; ++useX) {
|
2005-12-09 19:49:47 +00:00
|
|
|
for (int useY = ypos - height; useY < ypos; ++useY) {
|
2005-12-08 17:19:18 +00:00
|
|
|
int tempLayer = _screen->getShapeFlag2(useX, useY);
|
|
|
|
if (tempLayer > layer) {
|
|
|
|
layer = tempLayer;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tempLayer >= 7) {
|
|
|
|
return 7;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return layer;
|
|
|
|
}
|
|
|
|
|
2005-12-10 15:52:38 +00:00
|
|
|
void KyraEngine::copyBackgroundBlock(int x, int page, int flag) {
|
|
|
|
debug(9, "copyBackgroundBlock(%d, %d, %d)", x, page, flag);
|
|
|
|
|
|
|
|
if (x < 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int height = 128;
|
|
|
|
if (flag)
|
|
|
|
height += 8;
|
|
|
|
if (!(x & 1))
|
|
|
|
++x;
|
|
|
|
if (x == 19)
|
|
|
|
x = 17;
|
|
|
|
uint8 *ptr1 = _unkPtr1;
|
|
|
|
uint8 *ptr2 = _unkPtr2;
|
|
|
|
int oldVideoPage = _screen->_curPage;
|
|
|
|
_screen->_curPage = page;
|
|
|
|
|
|
|
|
int curX = x;
|
|
|
|
_screen->hideMouse();
|
|
|
|
_screen->copyRegionToBuffer(_screen->_curPage, 8, 8, 8, height, ptr2);
|
|
|
|
for (int i = 0; i < 19; ++i) {
|
|
|
|
int tempX = curX + 1;
|
|
|
|
_screen->copyRegionToBuffer(_screen->_curPage, tempX<<3, 8, 8, height, ptr1);
|
|
|
|
_screen->copyBlockToPage(_screen->_curPage, tempX<<3, 8, 8, height, ptr2);
|
|
|
|
int newXPos = curX + x;
|
|
|
|
if (newXPos > 37) {
|
|
|
|
newXPos = newXPos % 38;
|
|
|
|
}
|
|
|
|
tempX = newXPos + 1;
|
|
|
|
_screen->copyRegionToBuffer(_screen->_curPage, tempX<<3, 8, 8, height, ptr2);
|
|
|
|
_screen->copyBlockToPage(_screen->_curPage, tempX<<3, 8, 8, height, ptr1);
|
|
|
|
curX += x*2;
|
|
|
|
if (curX > 37) {
|
|
|
|
curX = curX % 38;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_screen->showMouse();
|
|
|
|
_screen->_curPage = oldVideoPage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::copyBackgroundBlock2(int x) {
|
|
|
|
copyBackgroundBlock(x, 4, 1);
|
|
|
|
}
|
|
|
|
|
2005-12-26 14:53:51 +00:00
|
|
|
void KyraEngine::makeBrandonFaceMouse() {
|
|
|
|
debug(9, "makeBrandonFaceMouse()");
|
|
|
|
if (_mouseX >= _currentCharacter->x1) {
|
|
|
|
_currentCharacter->facing = 3;
|
|
|
|
} else {
|
|
|
|
_currentCharacter->facing = 5;
|
|
|
|
}
|
|
|
|
animRefreshNPC(0);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-12-26 14:53:51 +00:00
|
|
|
}
|
|
|
|
|
2005-12-28 21:34:40 +00:00
|
|
|
void KyraEngine::setBrandonPoisonFlags(int reset) {
|
|
|
|
debug(9, "setBrandonPoisonFlags(%d)", reset);
|
|
|
|
_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() {
|
|
|
|
debug(9, "resetBrandonPoisonFlags()");
|
|
|
|
_brandonStatusBit = 0;
|
|
|
|
for (int i = 0; i < 0x100; ++i) {
|
|
|
|
_brandonPoisonFlagsGFX[i] = i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-01 14:19:50 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark - Pathfinder
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
int KyraEngine::findWay(int x, int y, int toX, int toY, int *moveTable, int moveTableSize) {
|
|
|
|
debug(9, "findWay(%d, %d, %d, %d, 0x%X, %d)", x, y, toX, toY, moveTable, moveTableSize);
|
|
|
|
x &= 0xFFFC; toX &= 0xFFFC;
|
|
|
|
y &= 0xFFFE; toY &= 0xFFFE;
|
2005-12-09 23:02:16 +00:00
|
|
|
x = (int16)x; y = (int16)y; toX = (int16)toX; toY = (int16)toY;
|
2005-11-01 14:19:50 +00:00
|
|
|
|
|
|
|
if (x == toY && y == toY) {
|
|
|
|
moveTable[0] = 8;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int curX = x;
|
|
|
|
int curY = y;
|
|
|
|
int lastUsedEntry = 0;
|
|
|
|
int tempValue = 0;
|
|
|
|
int *pathTable1 = new int[0x7D0];
|
|
|
|
int *pathTable2 = new int[0x7D0];
|
2005-11-10 21:42:42 +00:00
|
|
|
assert(pathTable1 && pathTable2);
|
2005-11-01 14:19:50 +00:00
|
|
|
|
|
|
|
while (true) {
|
|
|
|
int newFacing = getFacingFromPointToPoint(x, y, toX, toY);
|
|
|
|
changePosTowardsFacing(curX, curY, newFacing);
|
|
|
|
|
|
|
|
if (curX == toX && curY == toY) {
|
|
|
|
if (!lineIsPassable(curX, curY))
|
|
|
|
break;
|
|
|
|
moveTable[lastUsedEntry++] = newFacing;
|
|
|
|
break;
|
2005-11-10 21:42:42 +00:00
|
|
|
}
|
2005-11-01 14:19:50 +00:00
|
|
|
|
|
|
|
if (lineIsPassable(curX, curY)) {
|
|
|
|
if (lastUsedEntry == moveTableSize) {
|
|
|
|
delete [] pathTable1;
|
|
|
|
delete [] pathTable2;
|
|
|
|
return 0x7D00;
|
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
// debug drawing
|
|
|
|
//if (curX >= 0 && curY >= 0 && curX < 320 && curY < 200) {
|
|
|
|
// _screen->setPagePixel(0, curX, curY, 11);
|
|
|
|
// _screen->updateScreen();
|
|
|
|
// waitTicks(5);
|
|
|
|
//}
|
2005-11-01 14:19:50 +00:00
|
|
|
moveTable[lastUsedEntry++] = newFacing;
|
|
|
|
x = curX;
|
|
|
|
y = curY;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int temp = 0;
|
|
|
|
while (true) {
|
|
|
|
newFacing = getFacingFromPointToPoint(curX, curY, toX, toY);
|
|
|
|
changePosTowardsFacing(curX, curY, newFacing);
|
2005-11-09 22:26:12 +00:00
|
|
|
// debug drawing
|
|
|
|
//if (curX >= 0 && curY >= 0 && curX < 320 && curY < 200) {
|
|
|
|
// _screen->setPagePixel(0, curX, curY, 8);
|
|
|
|
// _screen->updateScreen();
|
|
|
|
// waitTicks(5);
|
|
|
|
//}
|
2005-11-01 14:19:50 +00:00
|
|
|
|
|
|
|
if (!lineIsPassable(curX, curY)) {
|
|
|
|
if (curX != toX || curY != toY)
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curX == toX && curY == toY) {
|
|
|
|
if (!lineIsPassable(curX, curY)) {
|
|
|
|
tempValue = 0;
|
|
|
|
temp = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
temp = findSubPath(x, y, curX, curY, pathTable1, 1, 0x7D0);
|
|
|
|
tempValue = findSubPath(x, y, curX, curY, pathTable2, 0, 0x7D0);
|
|
|
|
if (curX == toX && curY == toY) {
|
|
|
|
if (temp == 0x7D00 && tempValue == 0x7D00) {
|
|
|
|
delete [] pathTable1;
|
|
|
|
delete [] pathTable2;
|
|
|
|
return 0x7D00;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-09 22:26:12 +00:00
|
|
|
if (temp != 0x7D00 || tempValue != 0x7D00) {
|
2005-11-01 14:19:50 +00:00
|
|
|
break;
|
2005-11-09 22:26:12 +00:00
|
|
|
}
|
2005-11-01 14:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (temp < tempValue) {
|
|
|
|
if (lastUsedEntry + temp > moveTableSize) {
|
|
|
|
delete [] pathTable1;
|
|
|
|
delete [] pathTable2;
|
|
|
|
return 0x7D00;
|
|
|
|
}
|
2005-11-26 16:37:20 +00:00
|
|
|
memcpy(&moveTable[lastUsedEntry], pathTable1, temp*sizeof(int));
|
2005-11-01 14:19:50 +00:00
|
|
|
lastUsedEntry += temp;
|
|
|
|
} else {
|
|
|
|
if (lastUsedEntry + tempValue > moveTableSize) {
|
|
|
|
delete [] pathTable1;
|
|
|
|
delete [] pathTable2;
|
|
|
|
return 0x7D00;
|
|
|
|
}
|
2005-11-26 16:37:20 +00:00
|
|
|
memcpy(&moveTable[lastUsedEntry], pathTable2, tempValue*sizeof(int));
|
2005-11-09 22:26:12 +00:00
|
|
|
lastUsedEntry += tempValue;
|
2005-11-01 14:19:50 +00:00
|
|
|
}
|
|
|
|
x = curX;
|
|
|
|
y = curY;
|
|
|
|
if (curX == toX && curY == toY) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete [] pathTable1;
|
|
|
|
delete [] pathTable2;
|
2005-11-10 21:42:42 +00:00
|
|
|
moveTable[lastUsedEntry] = 8;
|
2005-11-01 14:19:50 +00:00
|
|
|
return getMoveTableSize(moveTable);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::findSubPath(int x, int y, int toX, int toY, int *moveTable, int start, int end) {
|
|
|
|
debug(9, "findSubPath(%d, %d, %d, %d, 0x%X, %d, %d)", x, y, toX, toY, moveTable, start, end);
|
2005-11-09 22:26:12 +00:00
|
|
|
// only used for debug specific code
|
|
|
|
//static uint16 unkTable[] = { 8, 5 };
|
2005-11-01 14:19:50 +00:00
|
|
|
static const int8 facingTable1[] = { 7, 0, 1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 7, 0 };
|
|
|
|
static const int8 facingTable2[] = { -1, 0, -1, 2, -1, 4, -1, 6, -1, 2, -1, 4, -1, 6, -1, 0 };
|
|
|
|
static const int8 facingTable3[] = { 2, 4, 4, 6, 6, 0, 0, 2, 6, 6, 0, 0, 2, 2, 4, 4 };
|
2005-11-26 16:37:20 +00:00
|
|
|
static const int8 addPosTableX[] = { -1, 0, -1, 4, -1, 0, -1, -4, -1, -4, -1, 0, -1, 4, -1, 0 };
|
|
|
|
static const int8 addPosTableY[] = { -1, 2, -1, 0, -1, -2, -1, 0, -1, 0, -1, 2, -1, 0, -1, -2 };
|
2005-11-01 14:19:50 +00:00
|
|
|
|
2005-11-09 22:26:12 +00:00
|
|
|
// debug specific
|
2005-11-10 21:42:42 +00:00
|
|
|
//++unkTable[start];
|
2005-11-09 22:26:12 +00:00
|
|
|
//while (_screen->getPalette(0)[unkTable[start]] != 0x0F) {
|
|
|
|
// ++unkTable[start];
|
|
|
|
//}
|
2005-11-01 14:19:50 +00:00
|
|
|
|
|
|
|
int xpos1 = x, xpos2 = x;
|
|
|
|
int ypos1 = y, ypos2 = y;
|
|
|
|
int newFacing = getFacingFromPointToPoint(x, y, toX, toY);
|
|
|
|
int position = 0;
|
|
|
|
|
|
|
|
while (position != end) {
|
2005-11-10 21:42:42 +00:00
|
|
|
int newFacing2 = newFacing;
|
2005-11-01 14:19:50 +00:00
|
|
|
while (true) {
|
2005-11-10 21:42:42 +00:00
|
|
|
changePosTowardsFacing(xpos1, ypos1, facingTable1[start*8 + newFacing2]);
|
2005-11-01 14:19:50 +00:00
|
|
|
if (!lineIsPassable(xpos1, ypos1)) {
|
2005-11-10 21:42:42 +00:00
|
|
|
if (facingTable1[start*8 + newFacing2] == newFacing) {
|
2005-11-01 14:19:50 +00:00
|
|
|
return 0x7D00;
|
|
|
|
}
|
2005-11-10 21:42:42 +00:00
|
|
|
newFacing2 = facingTable1[start*8 + newFacing2];
|
2005-11-01 14:19:50 +00:00
|
|
|
xpos1 = x;
|
2005-11-10 21:42:42 +00:00
|
|
|
ypos1 = y;
|
2005-11-01 14:19:50 +00:00
|
|
|
continue;
|
|
|
|
}
|
2005-11-26 16:37:20 +00:00
|
|
|
newFacing = facingTable1[start*8 + newFacing2];
|
2005-11-01 14:19:50 +00:00
|
|
|
break;
|
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
// debug drawing
|
|
|
|
//if (xpos1 >= 0 && ypos1 >= 0 && xpos1 < 320 && ypos1 < 200) {
|
2005-11-26 16:37:20 +00:00
|
|
|
// _screen->setPagePixel(0, xpos1, ypos1, unkTable[start]);
|
2005-11-09 22:26:12 +00:00
|
|
|
// _screen->updateScreen();
|
|
|
|
// waitTicks(5);
|
|
|
|
//}
|
2005-11-01 14:19:50 +00:00
|
|
|
if (newFacing & 1) {
|
2005-11-26 16:37:20 +00:00
|
|
|
int temp = xpos1 + addPosTableX[newFacing + start * 8];
|
2005-11-01 14:19:50 +00:00
|
|
|
if (toX == temp) {
|
2005-11-26 16:37:20 +00:00
|
|
|
temp = ypos1 + addPosTableY[newFacing + start * 8];
|
2005-11-01 14:19:50 +00:00
|
|
|
if (toY == temp) {
|
|
|
|
moveTable[position++] = facingTable2[newFacing + start * 8];
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moveTable[position++] = newFacing;
|
|
|
|
x = xpos1;
|
|
|
|
y = ypos1;
|
|
|
|
if (x == toX && y == toY) {
|
|
|
|
return position;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xpos1 == xpos2 && ypos1 == ypos2) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-11-10 21:42:42 +00:00
|
|
|
newFacing = facingTable3[start*8 + newFacing];
|
2005-11-01 14:19:50 +00:00
|
|
|
}
|
|
|
|
return 0x7D00;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::getFacingFromPointToPoint(int x, int y, int toX, int toY) {
|
|
|
|
debug(9, "getFacingFromPointToPoint(%d, %d, %d, %d)", x, y, toX, toY);
|
|
|
|
static const int facingTable[] = {
|
|
|
|
1, 0, 1, 2, 3, 4, 3, 2, 7, 0, 7, 6, 5, 4, 5, 6
|
|
|
|
};
|
|
|
|
|
|
|
|
int facingEntry = 0;
|
|
|
|
int ydiff = y - toY;
|
|
|
|
if (ydiff < 0) {
|
|
|
|
++facingEntry;
|
|
|
|
ydiff = -ydiff;
|
|
|
|
}
|
|
|
|
facingEntry <<= 1;
|
|
|
|
|
|
|
|
int xdiff = toX - x;
|
|
|
|
if (xdiff < 0) {
|
|
|
|
++facingEntry;
|
|
|
|
xdiff = -xdiff;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xdiff >= ydiff) {
|
2005-11-13 19:35:01 +00:00
|
|
|
int temp = ydiff;
|
2005-11-01 14:19:50 +00:00
|
|
|
ydiff = xdiff;
|
|
|
|
xdiff = temp;
|
|
|
|
|
|
|
|
facingEntry <<= 1;
|
|
|
|
} else {
|
|
|
|
facingEntry <<= 1;
|
|
|
|
facingEntry += 1;
|
|
|
|
}
|
|
|
|
int temp = (ydiff + 1) >> 1;
|
|
|
|
|
|
|
|
if (xdiff < temp) {
|
|
|
|
facingEntry <<= 1;
|
|
|
|
facingEntry += 1;
|
|
|
|
} else {
|
|
|
|
facingEntry <<= 1;
|
|
|
|
}
|
|
|
|
assert(facingEntry < ARRAYSIZE(facingTable));
|
|
|
|
return facingTable[facingEntry];
|
|
|
|
}
|
|
|
|
|
|
|
|
void KyraEngine::changePosTowardsFacing(int &x, int &y, int facing) {
|
|
|
|
debug(9, "changePosTowardsFacing(%d, %d, %d)", x, y, facing);
|
|
|
|
x += _addXPosTable[facing];
|
|
|
|
y += _addYPosTable[facing];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool KyraEngine::lineIsPassable(int x, int y) {
|
|
|
|
debug(9, "lineIsPassable(%d, %d)", x, y);
|
|
|
|
if (queryGameFlag(0xEF)) {
|
|
|
|
if (_currentCharacter->sceneId == 5)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_pathfinderFlag & 2) {
|
|
|
|
if (x >= 312)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_pathfinderFlag & 4) {
|
|
|
|
if (y >= 136)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_pathfinderFlag & 8) {
|
|
|
|
if (x < 8)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_pathfinderFlag2) {
|
|
|
|
if (x <= 8 || x >= 312)
|
|
|
|
return true;
|
2005-11-10 21:42:42 +00:00
|
|
|
if (y < (_northExitHeight & 0xFF) || y > 135)
|
2005-11-01 14:19:50 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (y > 137) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int ypos = 8;
|
|
|
|
if (_scaleMode) {
|
2005-11-13 19:35:01 +00:00
|
|
|
ypos = (_scaleTable[y] >> 5) + 1;
|
|
|
|
if (8 < ypos)
|
|
|
|
ypos = 8;
|
2005-11-01 14:19:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
x -= (ypos >> 1);
|
|
|
|
if (y < 0)
|
|
|
|
y = 0;
|
|
|
|
|
|
|
|
int xpos = x;
|
|
|
|
int xtemp = xpos + ypos - 1;
|
2005-11-13 19:35:01 +00:00
|
|
|
if (x < 0)
|
2005-11-01 14:19:50 +00:00
|
|
|
xpos = 0;
|
|
|
|
|
|
|
|
if (xtemp > 319)
|
|
|
|
xtemp = 319;
|
2005-11-10 21:42:42 +00:00
|
|
|
|
2005-11-01 14:19:50 +00:00
|
|
|
for (; xpos < xtemp; ++xpos) {
|
2005-11-10 21:42:42 +00:00
|
|
|
if (!_screen->getShapeFlag1(xpos, y))
|
2005-11-01 14:19:50 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::getMoveTableSize(int *moveTable) {
|
2005-11-18 23:55:31 +00:00
|
|
|
debug(9, "getMoveTableSize(0x%X)", moveTable);
|
2005-11-01 14:19:50 +00:00
|
|
|
int retValue = 0;
|
|
|
|
if (moveTable[0] == 8)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
static const int facingTable[] = {
|
|
|
|
4, 5, 6, 7, 0, 1, 2, 3
|
|
|
|
};
|
|
|
|
static const int unkTable[] = {
|
|
|
|
-1, -1, 1, 2, -1, 6, 7, -1,
|
|
|
|
-1, -1, -1, -1, 2, -1, 0, -1,
|
|
|
|
1, -1, -1, -1, 3, 4, -1, 0,
|
|
|
|
2, -1, -1, -1, -1, -1, 4, -1,
|
|
|
|
-1, 2, 3, -1, -1, -1, 5, 6,
|
|
|
|
6, -1, 4, -1, -1, -1, -1, -1,
|
|
|
|
7, 0, -1, 4, 5, -1, -1, -1,
|
|
|
|
-1, -1, 0, -1, 6, -1, -1, -1
|
|
|
|
};
|
|
|
|
|
|
|
|
int *oldPosition = moveTable;
|
|
|
|
int *tempPosition = moveTable;
|
2005-11-26 16:37:20 +00:00
|
|
|
int *curPosition = moveTable + 1;
|
|
|
|
retValue = 1;
|
2005-11-01 14:19:50 +00:00
|
|
|
|
|
|
|
while (*curPosition != 8) {
|
2005-11-18 23:55:31 +00:00
|
|
|
if (*oldPosition == facingTable[*curPosition]) {
|
2005-11-01 14:19:50 +00:00
|
|
|
retValue -= 2;
|
|
|
|
*oldPosition = 9;
|
|
|
|
*curPosition = 9;
|
|
|
|
|
|
|
|
while (tempPosition != moveTable) {
|
|
|
|
--tempPosition;
|
|
|
|
if (*tempPosition != 9)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tempPosition == moveTable && *tempPosition == 9) {
|
2005-11-18 23:55:31 +00:00
|
|
|
while (*tempPosition != 8 && *tempPosition == 9) {
|
2005-11-01 14:19:50 +00:00
|
|
|
++tempPosition;
|
|
|
|
}
|
|
|
|
if (*tempPosition == 8) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
oldPosition = tempPosition;
|
|
|
|
curPosition = oldPosition+1;
|
|
|
|
while (*curPosition != 8 && *curPosition == 9) {
|
2005-11-01 14:19:50 +00:00
|
|
|
++curPosition;
|
|
|
|
}
|
2005-11-18 23:55:31 +00:00
|
|
|
continue;
|
2005-11-01 14:19:50 +00:00
|
|
|
}
|
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
if (unkTable[*curPosition+((*oldPosition)*8)] != -1) {
|
2005-11-01 14:19:50 +00:00
|
|
|
--retValue;
|
2005-11-18 23:55:31 +00:00
|
|
|
*oldPosition = unkTable[*curPosition+((*oldPosition)*8)];
|
2005-11-01 14:19:50 +00:00
|
|
|
*curPosition = 9;
|
|
|
|
|
|
|
|
if (tempPosition != oldPosition) {
|
|
|
|
curPosition = oldPosition;
|
|
|
|
oldPosition = tempPosition;
|
2005-11-26 16:37:20 +00:00
|
|
|
while (true) {
|
|
|
|
if (tempPosition == moveTable) {
|
|
|
|
break;
|
|
|
|
}
|
2005-11-01 14:19:50 +00:00
|
|
|
--tempPosition;
|
2005-11-26 16:37:20 +00:00
|
|
|
if (*tempPosition != 9) {
|
|
|
|
break;
|
2005-11-01 14:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2005-11-26 16:37:20 +00:00
|
|
|
while (true) {
|
2005-11-01 14:19:50 +00:00
|
|
|
++curPosition;
|
2005-11-26 16:37:20 +00:00
|
|
|
if (*curPosition != 9) {
|
|
|
|
break;
|
|
|
|
}
|
2005-11-01 14:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
tempPosition = oldPosition;
|
|
|
|
oldPosition = curPosition;
|
|
|
|
++retValue;
|
2005-11-26 16:37:20 +00:00
|
|
|
while (true) {
|
2005-11-01 14:19:50 +00:00
|
|
|
++curPosition;
|
2005-11-26 16:37:20 +00:00
|
|
|
if (*curPosition != 9) {
|
|
|
|
break;
|
|
|
|
}
|
2005-11-01 14:19:50 +00:00
|
|
|
}
|
|
|
|
}
|
2005-11-26 16:37:20 +00:00
|
|
|
|
2005-11-01 14:19:50 +00:00
|
|
|
return retValue;
|
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
#pragma mark - Scene handling
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
int KyraEngine::handleSceneChange(int xpos, int ypos, int unk1, int frameReset) {
|
|
|
|
debug(9, "handleSceneChange(%d, %d, %d, %d)", xpos, ypos, unk1, frameReset);
|
2005-11-13 19:35:01 +00:00
|
|
|
if (queryGameFlag(0xEF)) {
|
2005-11-09 22:26:12 +00:00
|
|
|
unk1 = 0;
|
|
|
|
}
|
|
|
|
int sceneId = _currentCharacter->sceneId;
|
|
|
|
_pathfinderFlag = 0;
|
|
|
|
if (xpos < 12) {
|
|
|
|
if (_roomTable[sceneId].westExit != 0xFFFF) {
|
|
|
|
xpos = 12;
|
|
|
|
ypos = _sceneExits.westYPos;
|
|
|
|
_pathfinderFlag = 7;
|
|
|
|
}
|
|
|
|
} else if(xpos >= 308) {
|
|
|
|
if (_roomTable[sceneId].eastExit != 0xFFFF) {
|
|
|
|
xpos = 307;
|
|
|
|
ypos = _sceneExits.eastYPos;
|
|
|
|
_pathfinderFlag = 13;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
if (ypos <= (_northExitHeight&0xFF)+2) {
|
2005-11-09 22:26:12 +00:00
|
|
|
if (_roomTable[sceneId].northExit != 0xFFFF) {
|
2005-11-13 19:35:01 +00:00
|
|
|
xpos = _sceneExits.northXPos;
|
|
|
|
ypos = _northExitHeight & 0xFF;
|
2005-11-09 22:26:12 +00:00
|
|
|
_pathfinderFlag = 14;
|
|
|
|
}
|
|
|
|
} else if (ypos >= 136) {
|
|
|
|
if (_roomTable[sceneId].southExit != 0xFFFF) {
|
2005-11-13 19:35:01 +00:00
|
|
|
xpos = _sceneExits.southXPos;
|
|
|
|
ypos = 136;
|
2005-11-09 22:26:12 +00:00
|
|
|
_pathfinderFlag = 11;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int temp = xpos - _currentCharacter->x1;
|
|
|
|
if (ABS(temp) < 4) {
|
|
|
|
temp = ypos - _currentCharacter->y1;
|
|
|
|
if (ABS(temp) < 2) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-12-09 23:02:16 +00:00
|
|
|
int x = (int16)(_currentCharacter->x1 & 0xFFFC);
|
|
|
|
int y = (int16)(_currentCharacter->y1 & 0xFFFE);
|
|
|
|
xpos = (int16)(xpos & 0xFFFC);
|
|
|
|
ypos = (int16)(ypos & 0xFFFE);
|
2005-11-09 22:26:12 +00:00
|
|
|
int ret = findWay(x, y, xpos, ypos, _movFacingTable, 150);
|
|
|
|
_pathfinderFlag = 0;
|
|
|
|
if (ret >= _lastFindWayRet) {
|
|
|
|
_lastFindWayRet = ret;
|
|
|
|
}
|
|
|
|
if (ret == 0x7D00 || ret == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return processSceneChange(_movFacingTable, unk1, frameReset);
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::processSceneChange(int *table, int unk1, int frameReset) {
|
2005-11-26 16:37:20 +00:00
|
|
|
debug(9, "processSceneChange(0x%X, %d, %d)", table, unk1, frameReset);
|
2005-11-09 22:26:12 +00:00
|
|
|
if (queryGameFlag(0xEF)) {
|
|
|
|
unk1 = 0;
|
|
|
|
}
|
|
|
|
int *tableStart = table;
|
|
|
|
_sceneChangeState = 0;
|
|
|
|
_loopFlag2 = 0;
|
|
|
|
bool running = true;
|
|
|
|
int returnValue = 0;
|
2005-11-26 16:37:20 +00:00
|
|
|
uint32 nextFrame = 0;
|
2005-12-13 15:10:20 +00:00
|
|
|
_abortWalkFlag = false;
|
2005-12-24 18:00:35 +00:00
|
|
|
_mousePressFlag = false;
|
2005-11-09 22:26:12 +00:00
|
|
|
while (running) {
|
2005-12-13 15:10:20 +00:00
|
|
|
if (_abortWalkFlag) {
|
|
|
|
*table = 8;
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
animRefreshNPC(0);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-12-13 15:10:20 +00:00
|
|
|
processInput(_mouseX, _mouseY);
|
|
|
|
return 0;
|
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
bool forceContinue = false;
|
|
|
|
switch (*table) {
|
|
|
|
case 0: case 1: case 2:
|
|
|
|
case 3: case 4: case 5:
|
|
|
|
case 6: case 7:
|
|
|
|
_currentCharacter->facing = getOppositeFacingDirection(*table);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 8:
|
|
|
|
forceContinue = true;
|
|
|
|
running = false;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
++table;
|
|
|
|
forceContinue = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-12-24 18:00:35 +00:00
|
|
|
returnValue = changeScene(_currentCharacter->facing);
|
2005-11-13 19:35:01 +00:00
|
|
|
if (returnValue) {
|
|
|
|
running = false;
|
2005-12-24 18:00:35 +00:00
|
|
|
_abortWalkFlag = false;
|
2005-11-13 19:35:01 +00:00
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
|
|
|
|
if (unk1) {
|
2005-12-24 18:00:35 +00:00
|
|
|
if (_mousePressFlag) {
|
|
|
|
running = false;
|
|
|
|
_sceneChangeState = 1;
|
|
|
|
}
|
2005-11-09 22:26:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (forceContinue || !running) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int temp = 0;
|
2005-11-26 16:37:20 +00:00
|
|
|
if (table == tableStart || table[1] == 8) {
|
2005-11-09 22:26:12 +00:00
|
|
|
temp = setCharacterPosition(0, 0);
|
|
|
|
} else {
|
|
|
|
temp = setCharacterPosition(0, table);
|
|
|
|
}
|
2005-11-26 16:37:20 +00:00
|
|
|
if (temp) {
|
|
|
|
++table;
|
2005-11-18 23:55:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
nextFrame = getTimerDelay(5) * _tickLength + _system->getMillis();
|
|
|
|
while (_system->getMillis() < nextFrame) {
|
|
|
|
_sprites->updateSceneAnims();
|
|
|
|
updateMousePointer();
|
|
|
|
updateGameTimers();
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-12-09 14:52:31 +00:00
|
|
|
updateTextFade();
|
2005-11-18 23:55:31 +00:00
|
|
|
if (_currentCharacter->sceneId == 210) {
|
2006-01-03 19:03:09 +00:00
|
|
|
_animator->updateKyragemFading();
|
2005-11-18 23:55:31 +00:00
|
|
|
// XXX playEnd
|
|
|
|
// XXX
|
|
|
|
}
|
|
|
|
if ((nextFrame - _system->getMillis()) >= 10)
|
|
|
|
delay(10);
|
2005-11-09 22:26:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frameReset && !(_brandonStatusBit & 2)) {
|
|
|
|
_currentCharacter->currentAnimFrame = 7;
|
|
|
|
}
|
|
|
|
animRefreshNPC(0);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-11-09 22:26:12 +00:00
|
|
|
return returnValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
int KyraEngine::changeScene(int facing) {
|
2005-11-13 19:35:01 +00:00
|
|
|
debug(9, "changeScene(%d)", facing);
|
2005-11-09 22:26:12 +00:00
|
|
|
if (queryGameFlag(0xEF)) {
|
|
|
|
if (_currentCharacter->sceneId == 5) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int xpos = _charXPosTable[facing] + _currentCharacter->x1;
|
|
|
|
int ypos = _charYPosTable[facing] + _currentCharacter->y1;
|
|
|
|
|
|
|
|
if (xpos >= 12 && xpos <= 308) {
|
|
|
|
if (!lineIsPassable(xpos, ypos))
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_exitListPtr) {
|
2005-11-13 19:35:01 +00:00
|
|
|
int16 *ptr = _exitListPtr;
|
2005-11-09 22:26:12 +00:00
|
|
|
// this loop should be only entered on time, seems to be some hack in the original
|
|
|
|
while (true) {
|
2005-11-13 19:35:01 +00:00
|
|
|
if (*ptr == -1)
|
2005-11-09 22:26:12 +00:00
|
|
|
break;
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
if (*ptr > _currentCharacter->x1 || _currentCharacter->y1 < ptr[1] || _currentCharacter->x1 > ptr[2] || _currentCharacter->y1 > ptr[3]) {
|
2005-11-09 22:26:12 +00:00
|
|
|
ptr += 10;
|
2005-11-10 21:42:42 +00:00
|
|
|
break;
|
2005-11-09 22:26:12 +00:00
|
|
|
}
|
2005-11-13 19:35:01 +00:00
|
|
|
_brandonPosX = ptr[6];
|
|
|
|
_brandonPosY = ptr[7];
|
|
|
|
uint16 sceneId = ptr[5];
|
|
|
|
facing = ptr[4];
|
|
|
|
int unk1 = ptr[8];
|
|
|
|
int unk2 = ptr[9];
|
2005-11-09 22:26:12 +00:00
|
|
|
if (sceneId == 0xFFFF) {
|
|
|
|
switch (facing) {
|
|
|
|
case 0:
|
|
|
|
sceneId = _roomTable[_currentCharacter->sceneId].northExit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
sceneId = _roomTable[_currentCharacter->sceneId].eastExit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
sceneId = _roomTable[_currentCharacter->sceneId].southExit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 6:
|
|
|
|
sceneId = _roomTable[_currentCharacter->sceneId].westExit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
_currentCharacter->facing = facing;
|
|
|
|
animRefreshNPC(0);
|
2006-01-02 22:58:59 +00:00
|
|
|
_animator->updateAllObjectShapes();
|
2005-11-09 22:26:12 +00:00
|
|
|
enterNewScene(sceneId, facing, unk1, unk2, 0);
|
2005-11-10 21:42:42 +00:00
|
|
|
resetGameFlag(0xEE);
|
2005-11-09 22:26:12 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int returnValue = 0;
|
|
|
|
facing = 0;
|
|
|
|
|
|
|
|
if ((_northExitHeight & 0xFF) + 2 >= ypos || (_northExitHeight & 0xFF) + 2 >= _currentCharacter->y1) {
|
|
|
|
facing = 0;
|
|
|
|
returnValue = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xpos >= 308 || (_currentCharacter->x1 + 4) >= 308) {
|
|
|
|
facing = 2;
|
|
|
|
returnValue = 1;
|
|
|
|
}
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
if (((_northExitHeight >> 8) & 0xFF) - 2 < ypos || ((_northExitHeight >> 8) & 0xFF) - 2 < _currentCharacter->y1) {
|
2005-11-09 22:26:12 +00:00
|
|
|
facing = 4;
|
|
|
|
returnValue = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (xpos <= 12 || _currentCharacter->y1 <= 12) {
|
|
|
|
facing = 6;
|
|
|
|
returnValue = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!returnValue)
|
|
|
|
return 0;
|
|
|
|
|
2005-11-13 19:35:01 +00:00
|
|
|
uint16 sceneId = 0xFFFF;
|
2005-11-09 22:26:12 +00:00
|
|
|
switch (facing) {
|
|
|
|
case 0:
|
|
|
|
sceneId = _roomTable[_currentCharacter->sceneId].northExit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 2:
|
|
|
|
sceneId = _roomTable[_currentCharacter->sceneId].eastExit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 4:
|
|
|
|
sceneId = _roomTable[_currentCharacter->sceneId].southExit;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
sceneId = _roomTable[_currentCharacter->sceneId].westExit;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sceneId == 0xFFFF)
|
|
|
|
return 0;
|
2005-11-13 19:35:01 +00:00
|
|
|
|
2005-11-09 22:26:12 +00:00
|
|
|
enterNewScene(sceneId, facing, 1, 1, 0);
|
|
|
|
return returnValue;
|
|
|
|
}
|
2005-11-11 22:17:06 +00:00
|
|
|
|
2005-11-18 23:55:31 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark - Input
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
void KyraEngine::processInput(int xpos, int ypos) {
|
|
|
|
debug(9, "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) {
|
|
|
|
debug(9, "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);
|
2005-12-09 17:36:57 +00:00
|
|
|
// XXX call kyraPlaySound(53)
|
|
|
|
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) {
|
|
|
|
debug(9, "clickEventHandler(%d, %d)", xpos, ypos);
|
|
|
|
_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) {
|
|
|
|
debug(9, "hasClickedOnExit(%d, %d)", xpos, ypos);
|
|
|
|
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() {
|
|
|
|
debug(9, "clickEventHandler2()");
|
|
|
|
_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) {
|
|
|
|
debug(9, "checkForNPCScriptRun(%d, %d)", xpos, ypos);
|
|
|
|
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) {
|
|
|
|
debug(9, "runNpcScript(%d)", func);
|
|
|
|
_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
|