2008-04-20 14:43:56 +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.
|
|
|
|
*
|
2021-12-26 18:47:58 +01: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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2008-04-20 14:43:56 +00:00
|
|
|
* 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.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2008-04-20 14:43:56 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-04-20 14:43:56 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "made/made.h"
|
2011-10-09 22:58:37 +02:00
|
|
|
#include "made/console.h"
|
2008-04-20 14:43:56 +00:00
|
|
|
#include "made/pmvplayer.h"
|
|
|
|
#include "made/resource.h"
|
|
|
|
#include "made/screen.h"
|
2011-10-09 22:58:37 +02:00
|
|
|
#include "made/database.h"
|
2008-04-20 14:43:56 +00:00
|
|
|
#include "made/script.h"
|
2008-04-23 23:22:02 +00:00
|
|
|
#include "made/music.h"
|
2011-10-09 22:58:37 +02:00
|
|
|
|
|
|
|
#include "common/config-manager.h"
|
|
|
|
#include "common/events.h"
|
|
|
|
#include "common/system.h"
|
|
|
|
#include "common/error.h"
|
|
|
|
|
|
|
|
#include "engines/util.h"
|
|
|
|
|
|
|
|
#include "backends/audiocd/audiocd.h"
|
2008-04-20 14:43:56 +00:00
|
|
|
|
|
|
|
namespace Made {
|
|
|
|
|
|
|
|
MadeEngine::MadeEngine(OSystem *syst, const MadeGameDescription *gameDesc) : Engine(syst), _gameDescription(gameDesc) {
|
|
|
|
|
2016-05-02 17:27:49 +02:00
|
|
|
_eventNum = 0;
|
|
|
|
_eventMouseX = _eventMouseY = 0;
|
|
|
|
_eventKey = 0;
|
|
|
|
_autoStopSound = false;
|
|
|
|
_soundEnergyIndex = 0;
|
2021-11-13 23:40:32 +02:00
|
|
|
_soundEnergyArray = nullptr;
|
2016-05-02 17:27:49 +02:00
|
|
|
_musicBeatStart = 0;
|
|
|
|
_cdTimeStart = 0;
|
2021-10-06 22:21:06 +02:00
|
|
|
_introMusicDigital = true;
|
|
|
|
if (ConfMan.hasKey("intro_music_digital"))
|
|
|
|
_introMusicDigital = ConfMan.getBool("intro_music_digital");
|
2016-05-02 17:27:49 +02:00
|
|
|
|
2011-05-16 16:35:10 +02:00
|
|
|
_rnd = new Common::RandomSource("made");
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2020-02-08 22:11:56 -08:00
|
|
|
setDebugger(new MadeConsole(this));
|
2010-11-08 12:17:19 +00:00
|
|
|
|
2015-10-06 22:10:34 -04:00
|
|
|
_system->getAudioCDManager()->open();
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-04-21 18:40:28 +00:00
|
|
|
_pmvPlayer = new PmvPlayer(this, _mixer);
|
2009-01-16 23:20:17 +00:00
|
|
|
_res = new ResourceReader();
|
2008-04-20 15:36:40 +00:00
|
|
|
_screen = new Screen(this);
|
2008-05-28 20:16:22 +00:00
|
|
|
|
2008-06-12 11:09:04 +00:00
|
|
|
if (getGameID() == GID_LGOP2 || getGameID() == GID_MANHOLE || getGameID() == GID_RODNEY) {
|
2008-05-28 20:16:22 +00:00
|
|
|
_dat = new GameDatabaseV2(this);
|
|
|
|
} else if (getGameID() == GID_RTZ) {
|
|
|
|
_dat = new GameDatabaseV3(this);
|
|
|
|
} else {
|
|
|
|
error("Unknown GameID");
|
|
|
|
}
|
|
|
|
|
2008-04-20 15:36:40 +00:00
|
|
|
_script = new ScriptInterpreter(this);
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2013-11-03 19:14:29 +01:00
|
|
|
_music = nullptr;
|
2008-04-23 23:22:02 +00:00
|
|
|
|
2016-05-02 17:27:49 +02:00
|
|
|
_soundRate = 0;
|
|
|
|
|
2008-05-26 07:27:46 +00:00
|
|
|
// Set default sound frequency
|
2009-01-16 23:20:17 +00:00
|
|
|
switch (getGameID()) {
|
|
|
|
case GID_RODNEY:
|
2008-05-26 07:27:46 +00:00
|
|
|
_soundRate = 11025;
|
2009-01-16 23:20:17 +00:00
|
|
|
break;
|
|
|
|
case GID_MANHOLE:
|
2009-01-25 01:58:16 +00:00
|
|
|
_soundRate = 11025;
|
2009-01-16 23:20:17 +00:00
|
|
|
break;
|
|
|
|
case GID_LGOP2:
|
2008-05-26 07:27:46 +00:00
|
|
|
_soundRate = 8000;
|
2009-01-16 23:20:17 +00:00
|
|
|
break;
|
|
|
|
case GID_RTZ:
|
|
|
|
// Return to Zork sets it itself via a script funtion
|
|
|
|
break;
|
2019-11-15 10:20:05 +00:00
|
|
|
default:
|
|
|
|
break;
|
2008-05-26 07:27:46 +00:00
|
|
|
}
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MadeEngine::~MadeEngine() {
|
2010-06-15 04:13:12 +00:00
|
|
|
_system->getAudioCDManager()->stop();
|
2009-08-18 15:31:26 +00:00
|
|
|
|
2008-04-20 14:43:56 +00:00
|
|
|
delete _rnd;
|
|
|
|
delete _pmvPlayer;
|
|
|
|
delete _res;
|
|
|
|
delete _screen;
|
|
|
|
delete _dat;
|
|
|
|
delete _script;
|
2008-04-23 23:22:02 +00:00
|
|
|
delete _music;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2008-11-10 00:19:43 +00:00
|
|
|
void MadeEngine::syncSoundSettings() {
|
2011-03-19 15:02:36 +01:00
|
|
|
Engine::syncSoundSettings();
|
|
|
|
|
2021-09-25 22:07:02 +02:00
|
|
|
_music->syncSoundSettings();
|
2008-11-10 00:19:43 +00:00
|
|
|
}
|
|
|
|
|
2008-06-18 11:01:51 +00:00
|
|
|
int16 MadeEngine::getTicks() {
|
|
|
|
return g_system->getMillis() * 30 / 1000;
|
|
|
|
}
|
|
|
|
|
2008-04-20 14:43:56 +00:00
|
|
|
int16 MadeEngine::getTimer(int16 timerNum) {
|
2008-05-12 09:49:10 +00:00
|
|
|
if (timerNum > 0 && timerNum <= ARRAYSIZE(_timers) && _timers[timerNum - 1] != -1)
|
2008-06-18 11:01:51 +00:00
|
|
|
return (getTicks() - _timers[timerNum - 1]);
|
2008-05-12 09:49:10 +00:00
|
|
|
else
|
|
|
|
return 32000;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MadeEngine::setTimer(int16 timerNum, int16 value) {
|
2008-05-12 09:49:10 +00:00
|
|
|
if (timerNum > 0 && timerNum <= ARRAYSIZE(_timers))
|
2008-06-18 11:01:51 +00:00
|
|
|
_timers[timerNum - 1] = value;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MadeEngine::resetTimer(int16 timerNum) {
|
2008-05-12 09:49:10 +00:00
|
|
|
if (timerNum > 0 && timerNum <= ARRAYSIZE(_timers))
|
2008-06-18 11:01:51 +00:00
|
|
|
_timers[timerNum - 1] = getTicks();
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int16 MadeEngine::allocTimer() {
|
|
|
|
for (int i = 0; i < ARRAYSIZE(_timers); i++) {
|
2008-04-20 15:36:40 +00:00
|
|
|
if (_timers[i] == -1) {
|
2008-06-18 11:01:51 +00:00
|
|
|
_timers[i] = getTicks();
|
2008-04-20 15:36:40 +00:00
|
|
|
return i + 1;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MadeEngine::freeTimer(int16 timerNum) {
|
2008-05-12 09:49:10 +00:00
|
|
|
if (timerNum > 0 && timerNum <= ARRAYSIZE(_timers))
|
|
|
|
_timers[timerNum - 1] = -1;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2008-12-15 09:01:43 +00:00
|
|
|
void MadeEngine::resetAllTimers() {
|
|
|
|
for (int i = 0; i < ARRAYSIZE(_timers); i++)
|
|
|
|
_timers[i] = -1;
|
|
|
|
}
|
|
|
|
|
2008-05-07 08:25:13 +00:00
|
|
|
Common::String MadeEngine::getSavegameFilename(int16 saveNum) {
|
2011-06-02 10:49:09 +02:00
|
|
|
return Common::String::format("%s.%03d", getTargetName().c_str(), saveNum);
|
2008-05-07 08:25:13 +00:00
|
|
|
}
|
|
|
|
|
2008-05-21 10:07:33 +00:00
|
|
|
void MadeEngine::handleEvents() {
|
|
|
|
|
|
|
|
Common::Event event;
|
|
|
|
Common::EventManager *eventMan = _system->getEventManager();
|
|
|
|
|
2008-05-26 07:27:46 +00:00
|
|
|
// NOTE: Don't reset _eventNum to 0 here or no events will get through to the scripts.
|
2008-05-21 10:07:33 +00:00
|
|
|
|
|
|
|
while (eventMan->pollEvent(event)) {
|
|
|
|
switch (event.type) {
|
|
|
|
|
|
|
|
case Common::EVENT_MOUSEMOVE:
|
|
|
|
_eventMouseX = event.mouse.x;
|
|
|
|
_eventMouseY = event.mouse.y;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_LBUTTONDOWN:
|
2008-06-18 11:01:51 +00:00
|
|
|
_eventNum = 2;
|
2008-05-21 10:07:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_LBUTTONUP:
|
2008-06-18 11:01:51 +00:00
|
|
|
_eventNum = 1;
|
2008-05-21 10:07:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_RBUTTONDOWN:
|
2008-06-18 11:01:51 +00:00
|
|
|
_eventNum = 4;
|
2008-05-21 10:07:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_RBUTTONUP:
|
2008-06-18 11:01:51 +00:00
|
|
|
_eventNum = 3;
|
2008-05-21 10:07:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case Common::EVENT_KEYDOWN:
|
2010-11-29 10:20:45 +00:00
|
|
|
// Handle any special keys here
|
2022-05-18 01:36:59 +02:00
|
|
|
// Supported keys taken from https://web.archive.org/web/20141114142447/http://www.allgame.com/game.php?id=13542&tab=controls
|
2010-11-29 10:20:45 +00:00
|
|
|
|
|
|
|
switch (event.kbd.keycode) {
|
|
|
|
case Common::KEYCODE_KP_PLUS: // action (same as left mouse click)
|
|
|
|
_eventNum = 1; // left mouse button up
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_KP_MINUS: // inventory (same as right mouse click)
|
|
|
|
_eventNum = 3; // right mouse button up
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_UP:
|
|
|
|
case Common::KEYCODE_KP8:
|
|
|
|
_eventMouseY = MAX<int16>(0, _eventMouseY - 1);
|
|
|
|
g_system->warpMouse(_eventMouseX, _eventMouseY);
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_DOWN:
|
|
|
|
case Common::KEYCODE_KP2:
|
|
|
|
_eventMouseY = MIN<int16>(199, _eventMouseY + 1);
|
|
|
|
g_system->warpMouse(_eventMouseX, _eventMouseY);
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_LEFT:
|
|
|
|
case Common::KEYCODE_KP4:
|
|
|
|
_eventMouseX = MAX<int16>(0, _eventMouseX - 1);
|
|
|
|
g_system->warpMouse(_eventMouseX, _eventMouseY);
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_RIGHT:
|
|
|
|
case Common::KEYCODE_KP6:
|
|
|
|
_eventMouseX = MIN<int16>(319, _eventMouseX + 1);
|
|
|
|
g_system->warpMouse(_eventMouseX, _eventMouseY);
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_F1: // menu
|
|
|
|
case Common::KEYCODE_F2: // save game
|
|
|
|
case Common::KEYCODE_F3: // load game
|
|
|
|
case Common::KEYCODE_F4: // repeat last message
|
|
|
|
_eventNum = 5;
|
|
|
|
_eventKey = (event.kbd.keycode - Common::KEYCODE_F1) + 21;
|
|
|
|
break;
|
|
|
|
case Common::KEYCODE_BACKSPACE:
|
|
|
|
_eventNum = 5;
|
2008-05-21 10:07:33 +00:00
|
|
|
_eventKey = 9;
|
2010-11-29 10:20:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
_eventNum = 5;
|
|
|
|
_eventKey = event.kbd.ascii;
|
|
|
|
break;
|
|
|
|
}
|
2008-05-21 10:07:33 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2008-06-18 11:01:51 +00:00
|
|
|
|
2015-10-06 22:10:34 -04:00
|
|
|
_system->getAudioCDManager()->update();
|
2008-05-21 10:07:33 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2009-03-01 04:42:46 +00:00
|
|
|
Common::Error MadeEngine::run() {
|
2021-10-05 22:31:34 +02:00
|
|
|
_music = new MusicPlayer(this, getGameID() == GID_RTZ);
|
2013-11-03 19:14:29 +01:00
|
|
|
syncSoundSettings();
|
2009-03-01 04:42:46 +00:00
|
|
|
|
|
|
|
// Initialize backend
|
2017-10-01 00:56:01 -05:00
|
|
|
initGraphics(320, 200);
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-12-15 09:01:43 +00:00
|
|
|
resetAllTimers();
|
2008-06-12 11:09:04 +00:00
|
|
|
|
2008-05-02 12:08:06 +00:00
|
|
|
if (getGameID() == GID_RTZ) {
|
|
|
|
if (getFeatures() & GF_DEMO) {
|
|
|
|
_dat->open("demo.dat");
|
|
|
|
_res->open("demo.prj");
|
|
|
|
} else if (getFeatures() & GF_CD) {
|
|
|
|
_dat->open("rtzcd.dat");
|
|
|
|
_res->open("rtzcd.prj");
|
|
|
|
} else if (getFeatures() & GF_CD_COMPRESSED) {
|
|
|
|
_dat->openFromRed("rtzcd.red", "rtzcd.dat");
|
|
|
|
_res->open("rtzcd.prj");
|
|
|
|
} else if (getFeatures() & GF_FLOPPY) {
|
|
|
|
_dat->open("rtz.dat");
|
|
|
|
_res->open("rtz.prj");
|
|
|
|
} else {
|
|
|
|
error("Unknown RTZ game features");
|
|
|
|
}
|
|
|
|
} else if (getGameID() == GID_MANHOLE) {
|
|
|
|
_dat->open("manhole.dat");
|
2009-01-16 23:20:17 +00:00
|
|
|
|
|
|
|
if (getVersion() == 2) {
|
|
|
|
_res->open("manhole.prj");
|
|
|
|
} else {
|
|
|
|
_res->openResourceBlocks();
|
|
|
|
}
|
2008-05-02 12:08:06 +00:00
|
|
|
} else if (getGameID() == GID_LGOP2) {
|
|
|
|
_dat->open("lgop2.dat");
|
|
|
|
_res->open("lgop2.prj");
|
2008-06-12 11:09:04 +00:00
|
|
|
} else if (getGameID() == GID_RODNEY) {
|
|
|
|
_dat->open("rodneys.dat");
|
|
|
|
_res->open("rodneys.prj");
|
2008-04-23 18:22:06 +00:00
|
|
|
} else {
|
2008-05-02 12:08:06 +00:00
|
|
|
error ("Unknown MADE game");
|
2008-04-21 08:51:25 +00:00
|
|
|
}
|
2009-05-24 15:17:42 +00:00
|
|
|
|
2021-07-24 22:16:45 +03:00
|
|
|
if ((getFeatures() & GF_CD) || (getFeatures() & GF_CD_COMPRESSED)) {
|
|
|
|
if (!existExtractedCDAudioFiles()
|
|
|
|
&& !isDataAndCDAudioReadFromSameCD()) {
|
|
|
|
warnMissingExtractedCDAudio();
|
|
|
|
}
|
|
|
|
}
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2008-05-28 22:15:10 +00:00
|
|
|
_autoStopSound = false;
|
2008-05-21 10:07:33 +00:00
|
|
|
_eventNum = _eventKey = _eventMouseX = _eventMouseY = 0;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-05-20 20:00:10 +00:00
|
|
|
#ifdef DUMP_SCRIPTS
|
|
|
|
_script->dumpAllScripts();
|
|
|
|
#else
|
2008-05-26 07:27:46 +00:00
|
|
|
_screen->setDefaultMouseCursor();
|
2008-04-20 15:36:40 +00:00
|
|
|
_script->runScript(_dat->getMainCodeObjectIndex());
|
2008-05-20 20:00:10 +00:00
|
|
|
#endif
|
2008-04-20 14:43:56 +00:00
|
|
|
|
2021-10-05 22:31:34 +02:00
|
|
|
_music->close();
|
|
|
|
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kNoError;
|
2008-04-20 14:43:56 +00:00
|
|
|
}
|
|
|
|
|
2021-09-29 23:08:06 +02:00
|
|
|
void MadeEngine::pauseEngineIntern(bool pause) {
|
|
|
|
Engine::pauseEngineIntern(pause);
|
|
|
|
|
|
|
|
if (pause) {
|
|
|
|
if (_music)
|
|
|
|
_music->pause();
|
|
|
|
} else {
|
|
|
|
if (_music)
|
|
|
|
_music->resume();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-04-20 14:43:56 +00:00
|
|
|
} // End of namespace Made
|