2007-05-30 21:56:52 +00:00
|
|
|
/* ScummVM - Graphic Adventure Engine
|
2006-02-22 22:40:53 +00:00
|
|
|
*
|
2007-05-30 21:56:52 +00:00
|
|
|
* 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.
|
2006-02-22 22:40:53 +00:00
|
|
|
*
|
2021-12-26 17:47:58 +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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2014-02-18 01:34:18 +00:00
|
|
|
*
|
2006-02-22 22:40:53 +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 01:34:18 +00:00
|
|
|
*
|
2006-02-22 22:40:53 +00:00
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-12-26 17:47:58 +00:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-02-22 22:40:53 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/config-manager.h"
|
2010-05-04 11:59:22 +00:00
|
|
|
#include "common/debug-channels.h"
|
2015-09-17 20:19:36 +00:00
|
|
|
#include "common/events.h"
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-05-04 11:58:12 +00:00
|
|
|
#include "engines/util.h"
|
|
|
|
|
2006-05-25 22:51:42 +00:00
|
|
|
#include "graphics/cursorman.h"
|
2024-02-07 00:52:58 +00:00
|
|
|
#include "graphics/paletteman.h"
|
2015-09-17 20:19:36 +00:00
|
|
|
|
|
|
|
#include "image/iff.h"
|
2006-05-25 22:51:42 +00:00
|
|
|
|
2006-02-22 22:40:53 +00:00
|
|
|
#include "cine/cine.h"
|
2006-11-08 21:46:57 +00:00
|
|
|
#include "cine/bg_list.h"
|
2006-02-25 01:01:27 +00:00
|
|
|
#include "cine/main_loop.h"
|
2006-02-25 01:18:01 +00:00
|
|
|
#include "cine/object.h"
|
2006-11-13 21:16:50 +00:00
|
|
|
#include "cine/texte.h"
|
2007-05-19 12:08:41 +00:00
|
|
|
#include "cine/sound.h"
|
2006-02-25 01:18:01 +00:00
|
|
|
#include "cine/various.h"
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2006-02-25 00:26:14 +00:00
|
|
|
namespace Cine {
|
|
|
|
|
2021-11-13 21:40:19 +00:00
|
|
|
Sound *g_sound = nullptr;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2021-11-13 21:40:19 +00:00
|
|
|
CineEngine *g_cine = nullptr;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2011-05-16 14:35:10 +00:00
|
|
|
CineEngine::CineEngine(OSystem *syst, const CINEGameDescription *gameDesc)
|
|
|
|
: Engine(syst),
|
|
|
|
_gameDescription(gameDesc),
|
|
|
|
_rnd("cine") {
|
2016-07-28 08:33:15 +00:00
|
|
|
|
|
|
|
// Setup mixer
|
|
|
|
syncSoundSettings();
|
|
|
|
|
2020-02-09 04:56:37 +00:00
|
|
|
setDebugger(new CineConsole(this));
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2006-10-15 01:06:44 +00:00
|
|
|
g_cine = this;
|
2014-03-16 13:51:55 +00:00
|
|
|
|
|
|
|
for (int i = 0; i < NUM_FONT_CHARS; i++) {
|
|
|
|
_textHandler.fontParamTable[i].characterIdx = 0;
|
|
|
|
_textHandler.fontParamTable[i].characterWidth = 0;
|
|
|
|
}
|
|
|
|
_restartRequested = false;
|
|
|
|
_preLoad = false;
|
2020-07-12 20:48:11 +00:00
|
|
|
setDefaultGameSpeed();
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CineEngine::~CineEngine() {
|
2010-07-16 21:56:50 +00:00
|
|
|
if (getGameType() == Cine::GType_OS) {
|
2006-11-13 21:16:50 +00:00
|
|
|
freeErrmessDat();
|
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2011-03-19 13:51:28 +00:00
|
|
|
void CineEngine::syncSoundSettings() {
|
|
|
|
Engine::syncSoundSettings();
|
|
|
|
|
|
|
|
bool mute = false;
|
|
|
|
if (ConfMan.hasKey("mute"))
|
|
|
|
mute = ConfMan.getBool("mute");
|
|
|
|
|
|
|
|
// Use music volume for plain sound types (At least the AdLib player uses a plain sound type
|
|
|
|
// so previously the music and sfx volume controls didn't affect it at all).
|
|
|
|
// FIXME: Make AdLib player differentiate between playing sound effects and music and remove this.
|
|
|
|
_mixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType,
|
|
|
|
mute ? 0 : ConfMan.getInt("music_volume"));
|
|
|
|
}
|
|
|
|
|
2009-03-01 04:42:46 +00:00
|
|
|
Common::Error CineEngine::run() {
|
2017-10-01 21:23:22 +00:00
|
|
|
Graphics::ModeList modes;
|
|
|
|
modes.push_back(Graphics::Mode(320, 200));
|
2015-09-17 20:19:36 +00:00
|
|
|
if (g_cine->getGameType() == GType_FW && (g_cine->getFeatures() & GF_CD)) {
|
2017-10-01 21:23:22 +00:00
|
|
|
modes.push_back(Graphics::Mode(640, 480));
|
|
|
|
initGraphicsModes(modes);
|
2015-09-17 20:19:36 +00:00
|
|
|
showSplashScreen();
|
2017-10-01 21:23:22 +00:00
|
|
|
} else {
|
|
|
|
initGraphicsModes(modes);
|
2015-09-17 20:19:36 +00:00
|
|
|
}
|
|
|
|
|
2006-02-22 22:40:53 +00:00
|
|
|
// Initialize backend
|
2017-10-01 05:56:01 +00:00
|
|
|
initGraphics(320, 200);
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2021-07-24 19:16:45 +00:00
|
|
|
if (g_cine->getGameType() == GType_FW && (g_cine->getFeatures() & GF_CD)) {
|
2023-04-07 13:59:01 +00:00
|
|
|
if (!existExtractedCDAudioFiles(19) // tracks <19 are not used
|
2021-07-24 19:16:45 +00:00
|
|
|
&& !isDataAndCDAudioReadFromSameCD()) {
|
|
|
|
warnMissingExtractedCDAudio();
|
|
|
|
}
|
|
|
|
}
|
2015-09-13 04:23:59 +00:00
|
|
|
|
2013-05-02 22:26:58 +00:00
|
|
|
if (getPlatform() == Common::kPlatformDOS) {
|
2007-05-19 12:08:41 +00:00
|
|
|
g_sound = new PCSound(_mixer, this);
|
2006-03-09 22:37:19 +00:00
|
|
|
} else {
|
2007-05-13 16:11:19 +00:00
|
|
|
// Paula chipset for Amiga and Atari versions
|
2007-05-19 12:08:41 +00:00
|
|
|
g_sound = new PaulaSound(_mixer, this);
|
2006-03-09 22:37:19 +00:00
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-05-19 12:34:10 +00:00
|
|
|
_restartRequested = false;
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-05-19 12:34:10 +00:00
|
|
|
do {
|
|
|
|
initialize();
|
|
|
|
|
|
|
|
_restartRequested = false;
|
|
|
|
|
|
|
|
CursorMan.showMouse(true);
|
2020-07-12 20:48:11 +00:00
|
|
|
mainLoop(BOOT_SCRIPT_INDEX);
|
2010-05-19 12:34:10 +00:00
|
|
|
|
|
|
|
delete renderer;
|
|
|
|
delete[] collisionPage;
|
2021-08-26 18:11:02 +00:00
|
|
|
delete _scriptInfo;
|
2010-05-19 12:34:10 +00:00
|
|
|
} while (_restartRequested);
|
2008-05-24 22:11:41 +00:00
|
|
|
|
2007-05-19 12:08:41 +00:00
|
|
|
delete g_sound;
|
2009-01-01 15:06:43 +00:00
|
|
|
|
2008-11-06 17:05:54 +00:00
|
|
|
return Common::kNoError;
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
|
|
|
|
2020-07-12 20:48:11 +00:00
|
|
|
uint32 CineEngine::getTimerDelay() const {
|
2008-08-07 21:46:56 +00:00
|
|
|
return (10923000 * _timerDelayMultiplier) / 1193180;
|
|
|
|
}
|
|
|
|
|
2010-04-21 21:22:43 +00:00
|
|
|
/**
|
|
|
|
* Modify game speed
|
|
|
|
* @param speedChange Negative values slow game down, positive values speed it up, zero does nothing
|
|
|
|
* @return Timer delay multiplier's value after the game speed change
|
2008-08-07 21:46:56 +00:00
|
|
|
*/
|
|
|
|
int CineEngine::modifyGameSpeed(int speedChange) {
|
|
|
|
// If we want more speed we decrement the timer delay multiplier and vice versa.
|
|
|
|
_timerDelayMultiplier = CLIP(_timerDelayMultiplier - speedChange, 1, 50);
|
|
|
|
return _timerDelayMultiplier;
|
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2020-07-12 20:48:11 +00:00
|
|
|
void CineEngine::setDefaultGameSpeed() {
|
|
|
|
_timerDelayMultiplier = 12;
|
|
|
|
}
|
|
|
|
|
2006-11-25 09:28:00 +00:00
|
|
|
void CineEngine::initialize() {
|
2020-07-12 20:48:11 +00:00
|
|
|
setTotalPlayTime(0); // Reset total play time
|
2010-08-09 11:38:01 +00:00
|
|
|
_globalVars.reinit(NUM_MAX_VAR + 1);
|
|
|
|
|
2009-08-03 17:52:07 +00:00
|
|
|
// Initialize all savegames' descriptions to empty strings
|
|
|
|
memset(currentSaveName, 0, sizeof(currentSaveName));
|
|
|
|
|
2008-08-09 20:50:10 +00:00
|
|
|
// Resize object table to its correct size and reset all its elements
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_objectTable.resize(NUM_MAX_OBJECT);
|
2008-08-09 20:50:10 +00:00
|
|
|
resetObjectTable();
|
|
|
|
|
2008-08-09 20:55:01 +00:00
|
|
|
// Resize animation data table to its correct size and reset all its elements
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_animDataTable.resize(NUM_MAX_ANIMDATA);
|
2008-08-09 20:55:01 +00:00
|
|
|
freeAnimDataTable();
|
|
|
|
|
2008-08-09 22:38:03 +00:00
|
|
|
// Resize zone data table to its correct size and reset all its elements
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_zoneData.resize(NUM_MAX_ZONE);
|
2011-11-16 17:06:30 +00:00
|
|
|
Common::fill(g_cine->_zoneData.begin(), g_cine->_zoneData.end(), 0);
|
2008-08-09 22:38:03 +00:00
|
|
|
|
|
|
|
// Resize zone query table to its correct size and reset all its elements
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_zoneQuery.resize(NUM_MAX_ZONE);
|
2011-11-16 17:06:30 +00:00
|
|
|
Common::fill(g_cine->_zoneQuery.begin(), g_cine->_zoneQuery.end(), 0);
|
2008-08-09 22:38:03 +00:00
|
|
|
|
2020-07-12 20:48:11 +00:00
|
|
|
setDefaultGameSpeed();
|
2021-08-26 18:11:02 +00:00
|
|
|
_scriptInfo = setupOpcodes();
|
2006-04-08 13:20:40 +00:00
|
|
|
|
2010-07-16 21:56:50 +00:00
|
|
|
initLanguage(getLanguage());
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-07-16 21:56:50 +00:00
|
|
|
if (getGameType() == Cine::GType_OS) {
|
2008-05-24 22:11:41 +00:00
|
|
|
renderer = new OSRenderer;
|
|
|
|
} else {
|
|
|
|
renderer = new FWRenderer;
|
|
|
|
}
|
|
|
|
|
2009-08-25 23:11:17 +00:00
|
|
|
renderer->initialize();
|
2020-07-12 20:48:11 +00:00
|
|
|
forbidBgPalReload = 0;
|
|
|
|
reloadBgPalOnNextFlip = 0;
|
|
|
|
gfxFadeOutCompleted = 0;
|
|
|
|
gfxFadeInRequested = 0;
|
2020-08-30 20:11:21 +00:00
|
|
|
safeControlsLastAccessedMs = 0;
|
|
|
|
lastSafeControlObjIdx = -1;
|
2020-07-12 20:48:11 +00:00
|
|
|
currentDisk = 1;
|
2009-08-25 23:11:17 +00:00
|
|
|
|
2021-11-02 06:48:45 +00:00
|
|
|
collisionPage = new byte[320 * 200]();
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2008-08-11 20:41:13 +00:00
|
|
|
// Clear part buffer as there's nothing loaded into it yet.
|
|
|
|
// Its size will change when loading data into it with the loadPart function.
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_partBuffer.clear();
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2010-07-16 21:56:50 +00:00
|
|
|
if (getGameType() == Cine::GType_OS) {
|
2007-12-07 20:45:51 +00:00
|
|
|
readVolCnf();
|
|
|
|
}
|
|
|
|
|
2008-08-11 21:26:41 +00:00
|
|
|
loadTextData("texte.dat");
|
2006-04-13 15:42:52 +00:00
|
|
|
|
2010-07-16 21:56:50 +00:00
|
|
|
if (getGameType() == Cine::GType_OS && !(getFeatures() & GF_DEMO)) {
|
2007-05-13 16:07:33 +00:00
|
|
|
loadPoldatDat("poldat.dat");
|
|
|
|
loadErrmessDat("errmess.dat");
|
2006-04-13 15:42:52 +00:00
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2008-04-07 20:24:40 +00:00
|
|
|
// in case ScummVM engines can be restarted in the future
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_scriptTable.clear();
|
|
|
|
g_cine->_relTable.clear();
|
|
|
|
g_cine->_objectScripts.clear();
|
|
|
|
g_cine->_globalScripts.clear();
|
|
|
|
g_cine->_bgIncrustList.clear();
|
2008-04-07 20:24:40 +00:00
|
|
|
freeAnimDataTable();
|
2010-08-09 11:38:01 +00:00
|
|
|
g_cine->_overlayList.clear();
|
|
|
|
g_cine->_messageTable.clear();
|
2008-08-09 20:50:10 +00:00
|
|
|
resetObjectTable();
|
2020-07-12 20:48:11 +00:00
|
|
|
g_cine->_seqList.clear();
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2012-09-07 20:27:20 +00:00
|
|
|
if (getGameType() == Cine::GType_OS) {
|
|
|
|
disableSystemMenu = 1;
|
|
|
|
} else {
|
|
|
|
// WORKAROUND: We do not save this variable in FW's savegames.
|
|
|
|
// Initializing this to 1, like we do it in the OS case, will
|
|
|
|
// cause the menu disabled when loading from the launcher or
|
|
|
|
// command line.
|
|
|
|
// A proper fix here would be to save this variable in FW's saves.
|
|
|
|
// Since it seems these are unversioned so far, there would be need
|
|
|
|
// to properly add versioning to them first.
|
2020-08-01 15:12:24 +00:00
|
|
|
//
|
|
|
|
// Adding versioning to FW saves didn't solve this problem. Setting
|
|
|
|
// disableSystemMenu according to the saved value still caused the
|
|
|
|
// action menu (EXAMINE, TAKE, INVENTORY, ...) sometimes to be
|
|
|
|
// disabled when it wasn't supposed to be disabled when
|
|
|
|
// loading from the launcher or command line.
|
2012-09-07 20:27:20 +00:00
|
|
|
disableSystemMenu = 0;
|
|
|
|
}
|
2012-08-14 06:58:32 +00:00
|
|
|
|
2006-02-22 22:40:53 +00:00
|
|
|
var8 = 0;
|
2020-07-12 20:48:11 +00:00
|
|
|
bgVar0 = 0;
|
|
|
|
var2 = var3 = var4 = lastType20OverlayBgIdx = 0;
|
2009-05-11 19:31:55 +00:00
|
|
|
musicIsPlaying = 0;
|
|
|
|
currentDatName[0] = 0;
|
2020-07-12 20:48:11 +00:00
|
|
|
_keyInputList.clear();
|
|
|
|
|
|
|
|
// Used for making sound effects work using Roland MT-32 and AdLib in
|
|
|
|
// Operation Stealth after loading a savegame. The sound effects are loaded
|
|
|
|
// in AUTO00.PRC using a combination of o2_loadAbs and o2_playSample(1, ...)
|
2020-09-03 22:22:48 +00:00
|
|
|
// before o1_freePartRange(0, 200). In the original game AUTO00.PRC
|
2020-07-12 20:48:11 +00:00
|
|
|
// was run when starting or restarting the game and one could not load a savegame
|
|
|
|
// before passing the copy protection. Thus, we try to emulate that behaviour by
|
|
|
|
// running at least part of AUTO00.PRC before loading a savegame.
|
2020-09-03 22:22:48 +00:00
|
|
|
//
|
|
|
|
// Confirmed that DOS and Atari ST versions do have these commands in their AUTO00.PRC files.
|
|
|
|
// Confirmed that Amiga and demo versions do not have these commands in their AUTO00.PRC files.
|
|
|
|
if (getGameType() == Cine::GType_OS && !(getFeatures() & GF_DEMO) &&
|
|
|
|
(getPlatform() == Common::kPlatformDOS || getPlatform() == Common::kPlatformAtariST)) {
|
2020-07-12 20:48:11 +00:00
|
|
|
loadPrc(BOOT_PRC_NAME);
|
2022-09-24 10:30:57 +00:00
|
|
|
Common::strcpy_s(currentPrcName, BOOT_PRC_NAME);
|
2020-07-12 20:48:11 +00:00
|
|
|
addScriptToGlobalScripts(BOOT_SCRIPT_INDEX);
|
2020-09-03 22:22:48 +00:00
|
|
|
runOnlyUntilFreePartRangeFirst200 = true;
|
2020-07-12 20:48:11 +00:00
|
|
|
executeGlobalScripts();
|
|
|
|
}
|
2009-05-11 19:31:55 +00:00
|
|
|
|
2006-11-25 09:28:00 +00:00
|
|
|
_preLoad = false;
|
2010-05-19 12:34:10 +00:00
|
|
|
if (ConfMan.hasKey("save_slot") && !_restartRequested) {
|
2020-07-12 20:48:11 +00:00
|
|
|
Common::Error loadError = loadGameState(ConfMan.getInt("save_slot"));
|
2006-02-22 22:40:53 +00:00
|
|
|
|
2020-07-12 20:48:11 +00:00
|
|
|
if (loadError.getCode() == Common::kNoError)
|
2006-11-25 09:28:00 +00:00
|
|
|
_preLoad = true;
|
|
|
|
}
|
2007-09-19 08:40:12 +00:00
|
|
|
|
2006-11-25 09:28:00 +00:00
|
|
|
if (!_preLoad) {
|
|
|
|
loadPrc(BOOT_PRC_NAME);
|
2022-09-24 10:30:57 +00:00
|
|
|
Common::strcpy_s(currentPrcName, BOOT_PRC_NAME);
|
2006-11-25 09:28:00 +00:00
|
|
|
setMouseCursor(MOUSE_CURSOR_NORMAL);
|
|
|
|
}
|
2006-02-22 22:40:53 +00:00
|
|
|
}
|
2006-02-25 00:26:14 +00:00
|
|
|
|
2015-09-17 20:19:36 +00:00
|
|
|
void CineEngine::showSplashScreen() {
|
|
|
|
Common::File file;
|
|
|
|
if (!file.open("sony.lbm"))
|
|
|
|
return;
|
|
|
|
|
|
|
|
Image::IFFDecoder decoder;
|
|
|
|
if (!decoder.loadStream(file))
|
|
|
|
return;
|
|
|
|
|
|
|
|
const Graphics::Surface *surface = decoder.getSurface();
|
|
|
|
if (surface->w == 640 && surface->h == 480) {
|
2017-10-01 05:56:01 +00:00
|
|
|
initGraphics(640, 480);
|
2015-09-17 20:19:36 +00:00
|
|
|
|
|
|
|
const byte *palette = decoder.getPalette();
|
|
|
|
int paletteColorCount = decoder.getPaletteColorCount();
|
|
|
|
g_system->getPaletteManager()->setPalette(palette, 0, paletteColorCount);
|
|
|
|
|
|
|
|
g_system->copyRectToScreen(surface->getPixels(), 640, 0, 0, 640, 480);
|
|
|
|
g_system->updateScreen();
|
|
|
|
|
|
|
|
Common::EventManager *eventMan = g_system->getEventManager();
|
|
|
|
|
|
|
|
bool done = false;
|
|
|
|
uint32 now = g_system->getMillis();
|
|
|
|
|
|
|
|
while (!done && g_system->getMillis() - now < 2000) {
|
|
|
|
Common::Event event;
|
|
|
|
while (eventMan->pollEvent(event)) {
|
|
|
|
if (event.type == Common::EVENT_KEYDOWN && event.kbd.keycode == Common::KEYCODE_ESCAPE) {
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (shouldQuit())
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
decoder.destroy();
|
|
|
|
}
|
|
|
|
|
2006-02-25 00:26:14 +00:00
|
|
|
} // End of namespace Cine
|