2008-08-04 11:28:57 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
|
|
|
*
|
|
|
|
* ScummVM is the legal property of its developers, whose names
|
|
|
|
* are too numerous to list here. Please refer to the COPYRIGHT
|
|
|
|
* file distributed with this source distribution.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/config-manager.h"
|
2011-05-18 15:08:03 +00:00
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/random.h"
|
2008-08-04 11:28:57 +00:00
|
|
|
#include "common/str.h"
|
2011-04-30 00:09:02 +00:00
|
|
|
#include "common/error.h"
|
|
|
|
#include "common/textconsole.h"
|
2008-08-04 11:28:57 +00:00
|
|
|
|
|
|
|
#include "base/plugins.h"
|
|
|
|
#include "base/version.h"
|
|
|
|
|
|
|
|
#include "graphics/cursorman.h"
|
|
|
|
|
2010-05-10 08:32:32 +00:00
|
|
|
#include "engines/util.h"
|
|
|
|
|
2011-02-09 03:03:46 +00:00
|
|
|
#include "audio/mixer.h"
|
2008-08-04 11:28:57 +00:00
|
|
|
|
|
|
|
#include "toltecs/toltecs.h"
|
|
|
|
#include "toltecs/animation.h"
|
2013-01-02 18:01:00 +00:00
|
|
|
#include "toltecs/console.h"
|
2008-09-16 07:20:44 +00:00
|
|
|
#include "toltecs/menu.h"
|
|
|
|
#include "toltecs/movie.h"
|
2011-10-20 23:08:46 +00:00
|
|
|
#include "toltecs/music.h"
|
2008-08-04 11:28:57 +00:00
|
|
|
#include "toltecs/palette.h"
|
2008-09-20 19:06:41 +00:00
|
|
|
#include "toltecs/render.h"
|
2008-08-04 11:28:57 +00:00
|
|
|
#include "toltecs/resource.h"
|
|
|
|
#include "toltecs/script.h"
|
|
|
|
#include "toltecs/screen.h"
|
|
|
|
#include "toltecs/segmap.h"
|
2008-10-14 21:12:52 +00:00
|
|
|
#include "toltecs/sound.h"
|
2008-09-16 07:20:44 +00:00
|
|
|
#include "toltecs/microtiles.h"
|
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
namespace Toltecs {
|
|
|
|
|
|
|
|
struct GameSettings {
|
|
|
|
const char *gameid;
|
|
|
|
const char *description;
|
|
|
|
byte id;
|
|
|
|
uint32 features;
|
|
|
|
const char *detectname;
|
|
|
|
};
|
|
|
|
|
|
|
|
ToltecsEngine::ToltecsEngine(OSystem *syst, const ToltecsGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
|
2013-01-02 14:48:52 +00:00
|
|
|
// Assign default values to the config manager, in case settings are missing
|
|
|
|
ConfMan.registerDefault("originalsaveload", "false");
|
|
|
|
|
2011-05-18 15:02:59 +00:00
|
|
|
_rnd = new Common::RandomSource("toltecs");
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ToltecsEngine::~ToltecsEngine() {
|
|
|
|
delete _rnd;
|
|
|
|
}
|
|
|
|
|
2009-03-01 09:59:58 +00:00
|
|
|
Common::Error ToltecsEngine::run() {
|
2011-08-21 23:43:14 +00:00
|
|
|
initGraphics(640, 400, true);
|
2008-11-13 00:16:13 +00:00
|
|
|
|
|
|
|
_isSaveAllowed = true;
|
2008-08-04 11:28:57 +00:00
|
|
|
|
|
|
|
_counter01 = 0;
|
|
|
|
_counter02 = 0;
|
|
|
|
_movieSceneFlag = false;
|
|
|
|
_flag01 = 0;
|
2010-11-03 11:58:17 +00:00
|
|
|
|
|
|
|
_saveLoadRequested = 0;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
_cameraX = 0;
|
|
|
|
_cameraY = 0;
|
|
|
|
_newCameraX = 0;
|
|
|
|
_newCameraY = 0;
|
|
|
|
_cameraHeight = 0;
|
2008-08-12 12:28:28 +00:00
|
|
|
|
|
|
|
_guiHeight = 26;
|
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
_sceneWidth = 0;
|
|
|
|
_sceneHeight = 0;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
_doSpeech = true;
|
|
|
|
_doText = true;
|
|
|
|
|
2008-08-04 12:18:15 +00:00
|
|
|
_walkSpeedY = 5;
|
2008-08-04 11:28:57 +00:00
|
|
|
_walkSpeedX = 1;
|
|
|
|
|
2008-08-14 07:57:07 +00:00
|
|
|
_mouseX = 0;
|
|
|
|
_mouseY = 0;
|
2010-10-31 19:38:22 +00:00
|
|
|
_mouseDblClickTicks = 60;
|
|
|
|
_mouseWaitForRelease = false;
|
2008-08-14 07:57:07 +00:00
|
|
|
_mouseButton = 0;
|
|
|
|
_mouseDisabled = 0;
|
|
|
|
_leftButtonDown = false;
|
|
|
|
_rightButtonDown = false;
|
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
_arc = new ArchiveReader();
|
|
|
|
_arc->openArchive("WESTERN");
|
|
|
|
|
|
|
|
_res = new ResourceCache(this);
|
|
|
|
|
|
|
|
_screen = new Screen(this);
|
|
|
|
|
|
|
|
_script = new ScriptInterpreter(this);
|
|
|
|
_anim = new AnimationPlayer(this);
|
|
|
|
_palette = new Palette(this);
|
|
|
|
_segmap = new SegmentMap(this);
|
2008-09-16 07:20:44 +00:00
|
|
|
_moviePlayer = new MoviePlayer(this);
|
2011-11-23 22:01:29 +00:00
|
|
|
_music = new Music(_arc);
|
2008-09-16 07:20:44 +00:00
|
|
|
_menuSystem = new MenuSystem(this);
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-10-14 21:12:52 +00:00
|
|
|
_sound = new Sound(this);
|
2013-01-02 18:01:00 +00:00
|
|
|
_console = new Console(this);
|
2008-08-04 11:28:57 +00:00
|
|
|
|
2012-09-10 18:53:00 +00:00
|
|
|
_cfgText = ConfMan.getBool("subtitles");
|
|
|
|
_cfgVoices = !ConfMan.getBool("speech_mute");
|
|
|
|
|
|
|
|
bool mute = false;
|
|
|
|
if (ConfMan.hasKey("mute"))
|
|
|
|
mute = ConfMan.getBool("mute");
|
|
|
|
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, mute ? 0 : ConfMan.getInt("speech_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, mute ? 0 : ConfMan.getInt("music_volume"));
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, mute ? 0 : ConfMan.getInt("sfx_volume"));
|
2009-07-06 10:59:42 +00:00
|
|
|
syncSoundSettings();
|
|
|
|
|
2011-02-07 08:22:32 +00:00
|
|
|
CursorMan.showMouse(true);
|
2010-11-03 11:58:17 +00:00
|
|
|
|
2010-10-31 19:38:22 +00:00
|
|
|
setupSysStrings();
|
|
|
|
|
2012-09-10 18:53:00 +00:00
|
|
|
#if 0
|
|
|
|
// Menu test
|
2008-09-16 07:20:44 +00:00
|
|
|
_screen->registerFont(0, 0x0D);
|
|
|
|
_screen->registerFont(1, 0x0E);
|
|
|
|
_screen->loadMouseCursor(12);
|
|
|
|
_palette->loadAddPalette(9, 224);
|
|
|
|
_palette->setDeltaPalette(_palette->getMainPalette(), 7, 0, 31, 224);
|
2008-10-14 21:12:52 +00:00
|
|
|
_screen->finishTalkTextItems();
|
2008-09-16 07:20:44 +00:00
|
|
|
_screen->clearSprites();
|
2009-12-15 08:26:46 +00:00
|
|
|
_menuSystem->run();
|
|
|
|
/*
|
2008-09-16 07:20:44 +00:00
|
|
|
while (1) {
|
2009-12-15 08:26:46 +00:00
|
|
|
//updateInput();
|
2008-09-16 07:20:44 +00:00
|
|
|
_menuSystem->update();
|
|
|
|
updateScreen();
|
|
|
|
}
|
2009-12-15 08:26:46 +00:00
|
|
|
*/
|
2010-01-09 17:23:04 +00:00
|
|
|
return Common::kNoError;
|
2008-09-16 07:20:44 +00:00
|
|
|
#endif
|
2008-08-04 11:28:57 +00:00
|
|
|
|
2010-12-05 15:29:42 +00:00
|
|
|
// Start main game loop
|
2011-11-21 20:29:44 +00:00
|
|
|
setTotalPlayTime(0);
|
2008-08-04 11:28:57 +00:00
|
|
|
_script->loadScript(0, 0);
|
2010-10-18 11:00:17 +00:00
|
|
|
_script->setMainScript(0);
|
|
|
|
if (ConfMan.hasKey("save_slot")) {
|
|
|
|
int saveSlot = ConfMan.getInt("save_slot");
|
|
|
|
if (saveSlot >= 0 && saveSlot <= 99) {
|
2011-10-01 12:45:26 +00:00
|
|
|
_screen->loadMouseCursor(12);
|
2010-10-18 11:00:17 +00:00
|
|
|
loadGameState(saveSlot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_script->runScript();
|
2008-08-04 11:28:57 +00:00
|
|
|
|
2011-11-23 22:01:29 +00:00
|
|
|
_music->stopSequence();
|
2011-10-23 00:23:15 +00:00
|
|
|
_sound->stopAll();
|
|
|
|
|
2013-01-02 18:01:00 +00:00
|
|
|
delete _console;
|
2008-08-04 11:28:57 +00:00
|
|
|
delete _arc;
|
|
|
|
delete _res;
|
|
|
|
delete _screen;
|
|
|
|
delete _script;
|
|
|
|
delete _anim;
|
|
|
|
delete _palette;
|
|
|
|
delete _segmap;
|
2011-11-23 22:01:29 +00:00
|
|
|
delete _music;
|
2008-09-16 07:20:44 +00:00
|
|
|
delete _moviePlayer;
|
|
|
|
delete _menuSystem;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-10-14 21:12:52 +00:00
|
|
|
delete _sound;
|
2008-08-04 11:28:57 +00:00
|
|
|
|
2008-11-13 00:16:13 +00:00
|
|
|
return Common::kNoError;
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 19:38:22 +00:00
|
|
|
void ToltecsEngine::setupSysStrings() {
|
|
|
|
Resource *sysStringsResource = _res->load(15);
|
|
|
|
const char *sysStrings = (const char*)sysStringsResource->data;
|
|
|
|
for (int i = 0; i < kSysStrCount; i++) {
|
|
|
|
debug(1, "sysStrings[%d] = [%s]", i, sysStrings);
|
|
|
|
_sysStrings[i] = sysStrings;
|
|
|
|
sysStrings += strlen(sysStrings) + 1;
|
|
|
|
}
|
|
|
|
// TODO: Set yes/no chars
|
|
|
|
}
|
|
|
|
|
2010-11-03 11:58:17 +00:00
|
|
|
void ToltecsEngine::requestSavegame(int slotNum, Common::String &description) {
|
|
|
|
_saveLoadRequested = 2;
|
|
|
|
_saveLoadSlot = slotNum;
|
|
|
|
_saveLoadDescription = description;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToltecsEngine::requestLoadgame(int slotNum) {
|
|
|
|
_saveLoadRequested = 1;
|
|
|
|
_saveLoadSlot = slotNum;
|
|
|
|
}
|
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
void ToltecsEngine::loadScene(uint resIndex) {
|
2009-06-18 08:22:52 +00:00
|
|
|
Resource *sceneResource = _res->load(resIndex);
|
|
|
|
byte *scene = sceneResource->data;
|
2008-08-04 11:28:57 +00:00
|
|
|
|
|
|
|
uint32 imageSize = READ_LE_UINT32(scene);
|
2008-08-04 12:18:15 +00:00
|
|
|
_sceneResIndex = resIndex;
|
2008-08-04 11:28:57 +00:00
|
|
|
_sceneHeight = READ_LE_UINT16(scene + 4);
|
|
|
|
_sceneWidth = READ_LE_UINT16(scene + 6);
|
|
|
|
|
|
|
|
// Load scene palette
|
|
|
|
_palette->loadAddPaletteFrom(scene + 8, 0, 128);
|
|
|
|
|
|
|
|
// Load scene background
|
|
|
|
byte *source = scene + 392;
|
|
|
|
byte *destp = _screen->_backScreen;
|
|
|
|
byte *destEnd = destp + _sceneWidth * _sceneHeight;
|
|
|
|
while (destp < destEnd) {
|
|
|
|
int count = 1;
|
|
|
|
byte pixel = *source++;
|
|
|
|
if (pixel & 0x80) {
|
|
|
|
pixel &= 0x7F;
|
|
|
|
count = *source++;
|
|
|
|
count += 2;
|
|
|
|
}
|
|
|
|
memset(destp, pixel, count);
|
|
|
|
destp += count;
|
|
|
|
}
|
|
|
|
|
|
|
|
debug(0, "_sceneWidth = %d; _sceneHeight = %d", _sceneWidth, _sceneHeight);
|
|
|
|
|
|
|
|
// Load scene segmap
|
|
|
|
_segmap->load(scene + imageSize + 4);
|
|
|
|
|
2008-09-20 19:06:41 +00:00
|
|
|
_screen->_fullRefresh = true;
|
|
|
|
_screen->_renderQueue->clear();
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToltecsEngine::updateScreen() {
|
2010-10-31 20:03:54 +00:00
|
|
|
_sound->updateSpeech();
|
|
|
|
_screen->updateShakeScreen();
|
|
|
|
|
|
|
|
// TODO: Set quit flag
|
|
|
|
if (shouldQuit())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (!_movieSceneFlag)
|
|
|
|
updateInput();
|
|
|
|
else
|
|
|
|
_mouseButton = 0;
|
|
|
|
|
|
|
|
// TODO? Check keyb
|
|
|
|
|
|
|
|
_counter01--;
|
|
|
|
if (_counter01 <= 0) {
|
|
|
|
_counter01 = MIN(_counter02, 30);
|
|
|
|
_counter02 = 0;
|
|
|
|
drawScreen();
|
|
|
|
_flag01 = 1;
|
|
|
|
_counter02 = 1;
|
|
|
|
} else {
|
|
|
|
_screen->clearSprites();
|
|
|
|
_flag01 = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint32 prevUpdateTime = 0;
|
|
|
|
uint32 currUpdateTime;
|
|
|
|
do {
|
|
|
|
currUpdateTime = _system->getMillis();
|
|
|
|
_counter02 = (currUpdateTime - prevUpdateTime) / 13;
|
|
|
|
} while (_counter02 == 0);
|
|
|
|
prevUpdateTime = currUpdateTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToltecsEngine::drawScreen() {
|
2008-08-25 12:53:39 +00:00
|
|
|
// FIXME: Quick hack, sometimes cameraY was negative (the code in updateCamera was at fault)
|
|
|
|
if (_cameraY < 0) _cameraY = 0;
|
|
|
|
|
2008-09-20 19:06:41 +00:00
|
|
|
_segmap->addMasksToRenderQueue();
|
|
|
|
_screen->addTalkTextItemsToRenderQueue();
|
2008-08-04 11:28:57 +00:00
|
|
|
|
2008-09-20 19:06:41 +00:00
|
|
|
_screen->_renderQueue->update();
|
|
|
|
|
2011-05-04 04:52:04 +00:00
|
|
|
//debug("_guiHeight = %d\n", _guiHeight);
|
2008-08-04 11:28:57 +00:00
|
|
|
|
2008-09-20 19:06:41 +00:00
|
|
|
if (_screen->_guiRefresh && _guiHeight > 0 && _cameraHeight > 0) {
|
2010-06-18 14:18:44 +00:00
|
|
|
// Update the GUI when needed and it's visible
|
2012-06-16 00:37:55 +00:00
|
|
|
_system->copyRectToScreen(_screen->_frontScreen + _cameraHeight * 640,
|
2008-09-20 19:06:41 +00:00
|
|
|
640, 0, _cameraHeight, 640, _guiHeight);
|
|
|
|
_screen->_guiRefresh = false;
|
|
|
|
}
|
2008-08-04 11:28:57 +00:00
|
|
|
|
2013-01-02 18:01:00 +00:00
|
|
|
_console->onFrame();
|
2008-08-04 11:28:57 +00:00
|
|
|
_system->updateScreen();
|
2012-10-05 21:13:50 +00:00
|
|
|
_system->delayMillis(10);
|
2008-08-04 11:28:57 +00:00
|
|
|
|
|
|
|
updateCamera();
|
|
|
|
}
|
|
|
|
|
2008-08-14 07:57:07 +00:00
|
|
|
void ToltecsEngine::updateInput() {
|
|
|
|
Common::Event event;
|
|
|
|
Common::EventManager *eventMan = _system->getEventManager();
|
|
|
|
while (eventMan->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
case Common::EVENT_KEYDOWN:
|
2010-06-18 14:18:44 +00:00
|
|
|
_keyState = event.kbd;
|
|
|
|
|
|
|
|
//debug("key: flags = %02X; keycode = %d", _keyState.flags, _keyState.keycode);
|
2008-08-14 07:57:07 +00:00
|
|
|
|
2013-01-02 18:01:00 +00:00
|
|
|
if (event.kbd.hasFlags(Common::KBD_CTRL) && event.kbd.keycode == Common::KEYCODE_d)
|
|
|
|
_console->attach();
|
|
|
|
|
2008-08-14 07:57:07 +00:00
|
|
|
switch (event.kbd.keycode) {
|
2012-09-10 19:11:16 +00:00
|
|
|
case Common::KEYCODE_F5:
|
|
|
|
showMenu(kMenuIdSave);
|
2008-08-14 07:57:07 +00:00
|
|
|
break;
|
2012-09-10 19:11:16 +00:00
|
|
|
case Common::KEYCODE_F7:
|
|
|
|
showMenu(kMenuIdLoad);
|
2008-08-14 07:57:07 +00:00
|
|
|
break;
|
2012-09-10 19:11:16 +00:00
|
|
|
case Common::KEYCODE_SPACE:
|
2011-10-19 20:02:02 +00:00
|
|
|
// Skip current dialog line, if a dialog is active
|
2013-01-04 01:27:56 +00:00
|
|
|
if (_screen->getTalkTextDuration() > 0) {
|
2011-10-19 20:02:02 +00:00
|
|
|
_sound->stopSpeech();
|
|
|
|
_screen->finishTalkTextItems();
|
|
|
|
_keyState.reset(); // event consumed
|
|
|
|
}
|
|
|
|
break;
|
2008-08-14 07:57:07 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2010-06-18 14:18:44 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_KEYUP:
|
|
|
|
_keyState.reset();
|
2008-08-14 07:57:07 +00:00
|
|
|
break;
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
|
|
|
_leftButtonDown = true;
|
|
|
|
break;
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
|
|
|
_leftButtonDown = false;
|
|
|
|
break;
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
|
|
|
_rightButtonDown = true;
|
|
|
|
break;
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
|
|
|
_mouseX = event.mouse.x;
|
|
|
|
_mouseY = event.mouse.y;
|
|
|
|
_rightButtonDown = false;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-31 19:38:22 +00:00
|
|
|
if (!_mouseDisabled) {
|
2008-08-14 07:57:07 +00:00
|
|
|
|
2010-10-31 19:38:22 +00:00
|
|
|
if (_mouseDblClickTicks > 0)
|
|
|
|
_mouseDblClickTicks--;
|
2008-08-14 07:57:07 +00:00
|
|
|
|
|
|
|
byte mouseButtons = 0;
|
|
|
|
if (_leftButtonDown)
|
|
|
|
mouseButtons |= 1;
|
|
|
|
if (_rightButtonDown)
|
|
|
|
mouseButtons |= 2;
|
|
|
|
|
|
|
|
if (mouseButtons != 0) {
|
2010-10-31 19:38:22 +00:00
|
|
|
if (!_mouseWaitForRelease) {
|
2008-08-14 07:57:07 +00:00
|
|
|
_mouseButton = mouseButtons;
|
2010-10-31 19:38:22 +00:00
|
|
|
if (_mouseDblClickTicks > 0)
|
|
|
|
_mouseButton = 0x80;
|
|
|
|
//if (_mouseButton == 0x80) debug("DBL!");
|
|
|
|
_mouseDblClickTicks = 30; // maybe TODO
|
|
|
|
_mouseWaitForRelease = true;
|
2008-08-14 07:57:07 +00:00
|
|
|
} else {
|
|
|
|
_mouseButton = 0;
|
|
|
|
}
|
|
|
|
} else {
|
2010-10-31 19:38:22 +00:00
|
|
|
_mouseWaitForRelease = false;
|
2008-08-14 07:57:07 +00:00
|
|
|
_mouseButton = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-20 19:06:41 +00:00
|
|
|
void ToltecsEngine::setGuiHeight(int16 guiHeight) {
|
|
|
|
if (guiHeight != _guiHeight) {
|
|
|
|
_guiHeight = guiHeight;
|
|
|
|
_cameraHeight = 400 - _guiHeight;
|
2008-12-15 08:04:06 +00:00
|
|
|
_screen->_guiRefresh = true;
|
2008-09-20 19:06:41 +00:00
|
|
|
debug(0, "ToltecsEngine::setGuiHeight() _guiHeight = %d; _cameraHeight = %d", _guiHeight, _cameraHeight);
|
|
|
|
// TODO: clearScreen();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
void ToltecsEngine::setCamera(int16 x, int16 y) {
|
2008-10-14 21:12:52 +00:00
|
|
|
_screen->finishTalkTextItems();
|
2008-08-25 12:53:39 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
_screen->clearSprites();
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
_cameraX = x;
|
|
|
|
_newCameraX = x;
|
|
|
|
|
|
|
|
_cameraY = y;
|
|
|
|
_newCameraY = y;
|
|
|
|
}
|
|
|
|
|
2011-04-11 11:36:53 +00:00
|
|
|
bool ToltecsEngine::getCameraChanged() {
|
|
|
|
return _cameraX != _newCameraX || _cameraY != _newCameraY;
|
|
|
|
}
|
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
void ToltecsEngine::scrollCameraUp(int16 delta) {
|
|
|
|
if (_newCameraY > 0) {
|
|
|
|
if (_newCameraY < delta)
|
|
|
|
_newCameraY = 0;
|
|
|
|
else
|
|
|
|
_newCameraY -= delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToltecsEngine::scrollCameraDown(int16 delta) {
|
|
|
|
debug(0, "ToltecsEngine::scrollCameraDown(%d)", delta);
|
|
|
|
if (_newCameraY != _sceneHeight - _cameraHeight) {
|
|
|
|
if (_sceneHeight - _cameraHeight < _newCameraY + delta)
|
|
|
|
delta += (_sceneHeight - _cameraHeight) - (delta + _newCameraY);
|
|
|
|
_newCameraY += delta;
|
|
|
|
debug(0, "ToltecsEngine::scrollCameraDown() _newCameraY = %d; delta = %d", _newCameraY, delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToltecsEngine::scrollCameraLeft(int16 delta) {
|
|
|
|
if (_newCameraX > 0) {
|
|
|
|
if (_newCameraX < delta)
|
|
|
|
_newCameraX = 0;
|
|
|
|
else
|
|
|
|
_newCameraX -= delta;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToltecsEngine::scrollCameraRight(int16 delta) {
|
|
|
|
debug(0, "ToltecsEngine::scrollCameraRight(%d)", delta);
|
|
|
|
if (_newCameraX != _sceneWidth - 640) {
|
|
|
|
if (_sceneWidth - 640 < delta + _newCameraX)
|
|
|
|
delta += (_sceneWidth - 640) - (delta + _newCameraX);
|
|
|
|
_newCameraX += delta;
|
|
|
|
debug(0, "ToltecsEngine::scrollCameraRight() _newCameraX = %d; delta = %d", _newCameraY, delta);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToltecsEngine::updateCamera() {
|
2008-08-12 12:28:28 +00:00
|
|
|
if (_cameraX != _newCameraX) {
|
|
|
|
_cameraX = _newCameraX;
|
2008-09-20 19:06:41 +00:00
|
|
|
_screen->_fullRefresh = true;
|
2008-10-14 21:12:52 +00:00
|
|
|
_screen->finishTalkTextItems();
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
2008-08-12 12:28:28 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
if (_cameraY != _newCameraY) {
|
2008-08-12 12:28:28 +00:00
|
|
|
_cameraY = _newCameraY;
|
2008-09-20 19:06:41 +00:00
|
|
|
_screen->_fullRefresh = true;
|
2008-10-14 21:12:52 +00:00
|
|
|
_screen->finishTalkTextItems();
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
2010-10-31 19:38:22 +00:00
|
|
|
//debug(0, "ToltecsEngine::updateCamera() _cameraX = %d; _cameraY = %d", _cameraX, _cameraY);
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ToltecsEngine::talk(int16 slotIndex, int16 slotOffset) {
|
|
|
|
byte *scanData = _script->getSlotData(slotIndex) + slotOffset;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
while (*scanData < 0xF0) {
|
2008-08-04 12:18:15 +00:00
|
|
|
if (*scanData == 0x19) {
|
|
|
|
scanData++;
|
2008-08-04 11:28:57 +00:00
|
|
|
} else if (*scanData == 0x14) {
|
2008-08-04 12:18:15 +00:00
|
|
|
scanData++;
|
2008-08-04 11:28:57 +00:00
|
|
|
} else if (*scanData == 0x0A) {
|
2008-08-04 12:18:15 +00:00
|
|
|
scanData += 4;
|
2008-08-04 11:28:57 +00:00
|
|
|
} else if (*scanData < 0x0A) {
|
2008-08-04 12:18:15 +00:00
|
|
|
scanData++;
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
2008-08-04 12:18:15 +00:00
|
|
|
scanData++;
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
if (*scanData == 0xFE) {
|
2008-08-04 12:18:15 +00:00
|
|
|
if (_doSpeech) {
|
|
|
|
int16 resIndex = READ_LE_UINT16(scanData + 1);
|
|
|
|
debug(0, "ToltecsEngine::talk() playSound(resIndex: %d)", resIndex);
|
2008-10-14 21:12:52 +00:00
|
|
|
_sound->playSpeech(resIndex);
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
if (_doText) {
|
2013-01-13 13:39:00 +00:00
|
|
|
_screen->updateTalkText(slotIndex, slotOffset, false);
|
2008-08-04 11:28:57 +00:00
|
|
|
} else {
|
2009-06-22 16:11:49 +00:00
|
|
|
_screen->keepTalkTextItemsAlive();
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2013-01-13 13:39:00 +00:00
|
|
|
_screen->updateTalkText(slotIndex, slotOffset, true);
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ToltecsEngine::walk(byte *walkData) {
|
|
|
|
int16 xdelta, ydelta, v8, v10, v11;
|
|
|
|
int16 xstep, ystep;
|
|
|
|
ScriptWalk walkInfo;
|
|
|
|
|
|
|
|
walkInfo.y = READ_LE_UINT16(walkData + 0);
|
|
|
|
walkInfo.x = READ_LE_UINT16(walkData + 2);
|
|
|
|
walkInfo.y1 = READ_LE_UINT16(walkData + 4);
|
|
|
|
walkInfo.x1 = READ_LE_UINT16(walkData + 6);
|
|
|
|
walkInfo.y2 = READ_LE_UINT16(walkData + 8);
|
|
|
|
walkInfo.x2 = READ_LE_UINT16(walkData + 10);
|
|
|
|
walkInfo.yerror = READ_LE_UINT16(walkData + 12);
|
|
|
|
walkInfo.xerror = READ_LE_UINT16(walkData + 14);
|
|
|
|
walkInfo.mulValue = READ_LE_UINT16(walkData + 16);
|
|
|
|
walkInfo.scaling = READ_LE_UINT16(walkData + 18);
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
walkInfo.scaling = -_segmap->getScalingAtPoint(walkInfo.x, walkInfo.y);
|
|
|
|
|
|
|
|
if (walkInfo.y1 < walkInfo.y2)
|
2008-08-04 12:18:15 +00:00
|
|
|
ystep = -1;
|
2008-08-04 11:28:57 +00:00
|
|
|
else
|
|
|
|
ystep = 1;
|
|
|
|
ydelta = ABS(walkInfo.y1 - walkInfo.y2) * _walkSpeedY;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
if (walkInfo.x1 < walkInfo.x2)
|
2008-08-04 12:18:15 +00:00
|
|
|
xstep = -1;
|
2008-08-04 11:28:57 +00:00
|
|
|
else
|
|
|
|
xstep = 1;
|
|
|
|
xdelta = ABS(walkInfo.x1 - walkInfo.x2) * _walkSpeedX;
|
|
|
|
|
2008-08-04 12:18:15 +00:00
|
|
|
debug(0, "ToltecsEngine::walk() xdelta = %d; ydelta = %d", xdelta, ydelta);
|
2008-08-04 11:28:57 +00:00
|
|
|
|
|
|
|
if (xdelta > ydelta)
|
2008-08-04 12:18:15 +00:00
|
|
|
SWAP(xdelta, ydelta);
|
2008-08-04 11:28:57 +00:00
|
|
|
|
|
|
|
v8 = 100 * xdelta;
|
|
|
|
if (v8 != 0) {
|
|
|
|
if (walkInfo.scaling > 0)
|
|
|
|
v8 -= v8 * ABS(walkInfo.scaling) / 100;
|
|
|
|
else
|
|
|
|
v8 += v8 * ABS(walkInfo.scaling) / 100;
|
|
|
|
if (ydelta != 0)
|
|
|
|
v8 /= ydelta;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ydelta > ABS(walkInfo.x1 - walkInfo.x2) * _walkSpeedX) {
|
2008-08-04 12:18:15 +00:00
|
|
|
v10 = 100 - walkInfo.scaling;
|
|
|
|
v11 = v8;
|
2008-08-04 11:28:57 +00:00
|
|
|
} else {
|
|
|
|
v10 = v8;
|
|
|
|
v11 = 100 - walkInfo.scaling;
|
|
|
|
}
|
|
|
|
|
|
|
|
walkInfo.yerror += walkInfo.mulValue * v10;
|
|
|
|
while (walkInfo.yerror >= 100 * _walkSpeedY) {
|
|
|
|
walkInfo.yerror -= 100 * _walkSpeedY;
|
|
|
|
if (walkInfo.y == walkInfo.y1) {
|
|
|
|
walkInfo.x = walkInfo.x1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
walkInfo.y += ystep;
|
|
|
|
}
|
|
|
|
|
|
|
|
walkInfo.xerror += walkInfo.mulValue * v11;
|
|
|
|
while (walkInfo.xerror >= 100 * _walkSpeedX) {
|
|
|
|
walkInfo.xerror -= 100 * _walkSpeedX;
|
|
|
|
if (walkInfo.x == walkInfo.x1) {
|
|
|
|
walkInfo.y = walkInfo.y1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
walkInfo.x += xstep;
|
|
|
|
}
|
|
|
|
|
|
|
|
WRITE_LE_UINT16(walkData + 0, walkInfo.y);
|
|
|
|
WRITE_LE_UINT16(walkData + 2, walkInfo.x);
|
|
|
|
WRITE_LE_UINT16(walkData + 4, walkInfo.y1);
|
|
|
|
WRITE_LE_UINT16(walkData + 6, walkInfo.x1);
|
|
|
|
WRITE_LE_UINT16(walkData + 8, walkInfo.y2);
|
|
|
|
WRITE_LE_UINT16(walkData + 10, walkInfo.x2);
|
|
|
|
WRITE_LE_UINT16(walkData + 12, walkInfo.yerror);
|
|
|
|
WRITE_LE_UINT16(walkData + 14, walkInfo.xerror);
|
|
|
|
WRITE_LE_UINT16(walkData + 16, walkInfo.mulValue);
|
|
|
|
WRITE_LE_UINT16(walkData + 18, walkInfo.scaling);
|
|
|
|
}
|
|
|
|
|
2012-09-26 02:17:31 +00:00
|
|
|
int16 ToltecsEngine::findRectAtPoint(byte *rectData, int16 x, int16 y, int16 index, int16 itemSize,
|
2010-06-18 14:18:44 +00:00
|
|
|
byte *rectDataEnd) {
|
2008-08-04 11:28:57 +00:00
|
|
|
|
|
|
|
rectData += index * itemSize;
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2010-06-18 14:18:44 +00:00
|
|
|
while (rectData < rectDataEnd) {
|
2008-08-04 12:18:15 +00:00
|
|
|
int16 rectY = READ_LE_UINT16(rectData);
|
|
|
|
if (rectY == -10)
|
|
|
|
break;
|
|
|
|
int16 rectX = READ_LE_UINT16(rectData + 2);
|
|
|
|
int16 rectH = READ_LE_UINT16(rectData + 4);
|
|
|
|
int16 rectW = READ_LE_UINT16(rectData + 6);
|
|
|
|
|
|
|
|
debug(0, "x = %d; y = %d; x1 = %d; y2 = %d; w = %d; h = %d",
|
|
|
|
x, y, rectX, rectY, rectW, rectH);
|
|
|
|
|
|
|
|
if (x >= rectX && x <= rectX + rectW && y >= rectY && y <= rectY + rectH) {
|
|
|
|
return index;
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
index++;
|
|
|
|
rectData += itemSize;
|
|
|
|
}
|
2012-09-26 02:17:31 +00:00
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
return -1;
|
2012-09-10 19:11:16 +00:00
|
|
|
}
|
2008-08-04 11:28:57 +00:00
|
|
|
|
2012-09-10 19:11:16 +00:00
|
|
|
void ToltecsEngine::showMenu(MenuID menuId) {
|
|
|
|
_screen->loadMouseCursor(12);
|
|
|
|
_palette->loadAddPalette(9, 224);
|
|
|
|
_palette->setDeltaPalette(_palette->getMainPalette(), 7, 0, 31, 224);
|
|
|
|
_screen->finishTalkTextItems();
|
|
|
|
_screen->clearSprites();
|
|
|
|
CursorMan.showMouse(true);
|
|
|
|
_menuSystem->run(menuId);
|
|
|
|
_keyState.reset();
|
|
|
|
_script->setSwitchLocalDataNear(true);
|
2008-08-04 11:28:57 +00:00
|
|
|
}
|
|
|
|
|
2012-09-10 18:53:00 +00:00
|
|
|
void ToltecsEngine::syncSoundSettings() {
|
|
|
|
Engine::syncSoundSettings();
|
|
|
|
|
|
|
|
bool mute = false;
|
|
|
|
if (ConfMan.hasKey("mute"))
|
|
|
|
mute = ConfMan.getBool("mute");
|
|
|
|
|
|
|
|
_cfgVoicesVolume = (mute ? 0 : ConfMan.getInt("speech_volume")) * 20 / Audio::Mixer::kMaxChannelVolume;
|
|
|
|
_cfgMusicVolume = (mute ? 0 : ConfMan.getInt("music_volume")) * 20 / Audio::Mixer::kMaxChannelVolume;
|
|
|
|
_cfgSoundFXVolume = (mute ? 0 : ConfMan.getInt("sfx_volume")) * 20 / Audio::Mixer::kMaxChannelVolume;
|
|
|
|
}
|
|
|
|
|
2008-08-04 11:28:57 +00:00
|
|
|
} // End of namespace Toltecs
|