2007-05-30 21:56:52 +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.
|
2005-04-05 18:08:02 +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
|
|
|
|
* 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
|
2005-04-09 19:19:54 +00:00
|
|
|
* 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.
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
2006-02-11 10:11:37 +00:00
|
|
|
* $URL$
|
|
|
|
* $Id$
|
2005-04-05 18:08:02 +00:00
|
|
|
*
|
|
|
|
*/
|
2006-03-29 15:59:37 +00:00
|
|
|
|
|
|
|
#include "common/stdafx.h"
|
|
|
|
#include "common/endian.h"
|
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
#include "gob/gob.h"
|
|
|
|
#include "gob/init.h"
|
2007-03-20 14:51:57 +00:00
|
|
|
#include "gob/global.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
#include "gob/util.h"
|
2007-03-20 14:51:57 +00:00
|
|
|
#include "gob/dataio.h"
|
2005-04-13 18:27:29 +00:00
|
|
|
#include "gob/cdrom.h"
|
2007-03-20 14:51:57 +00:00
|
|
|
#include "gob/draw.h"
|
|
|
|
#include "gob/game.h"
|
2007-04-05 13:37:20 +00:00
|
|
|
#include "gob/palanim.h"
|
2007-03-20 14:51:57 +00:00
|
|
|
#include "gob/sound.h"
|
|
|
|
#include "gob/video.h"
|
2007-07-30 15:53:38 +00:00
|
|
|
#include "gob/videoplayer.h"
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
namespace Gob {
|
|
|
|
|
2006-01-04 01:48:15 +00:00
|
|
|
const char *Init::_fontNames[] = { "jeulet1.let", "jeulet2.let", "jeucar1.let", "jeumath.let" };
|
2006-01-03 23:14:39 +00:00
|
|
|
|
|
|
|
Init::Init(GobEngine *vm) : _vm(vm) {
|
2006-01-04 01:48:15 +00:00
|
|
|
_palDesc = 0;
|
2006-01-03 23:14:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Init::cleanup(void) {
|
|
|
|
_vm->_video->freeDriver();
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_global->_primarySurfDesc = 0;
|
2006-01-29 02:27:10 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_snd->speakerOff();
|
|
|
|
_vm->_snd->stopSound(0);
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_dataIO->closeDataFile();
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2007-04-02 11:05:09 +00:00
|
|
|
void Init::initGame(const char *totName) {
|
2005-04-05 15:07:40 +00:00
|
|
|
int16 handle2;
|
|
|
|
int16 handle;
|
2007-03-29 17:55:39 +00:00
|
|
|
int16 imdHandle;
|
2005-04-05 15:07:40 +00:00
|
|
|
char *infBuf;
|
|
|
|
char *infPtr;
|
|
|
|
char *infEnd;
|
|
|
|
char buffer[20];
|
|
|
|
int32 varsCount;
|
2007-03-20 14:51:57 +00:00
|
|
|
|
|
|
|
initVideo();
|
|
|
|
|
2007-08-13 07:55:47 +00:00
|
|
|
// The Lost In Time demo uses different file prefix
|
|
|
|
if (_vm->getGameType() == kGameTypeLostInTime) {
|
|
|
|
handle2 = _vm->_dataIO->openData("demo.stk");
|
|
|
|
if (handle2 >= 0) {
|
|
|
|
_vm->_dataIO->closeData(handle2);
|
|
|
|
_vm->_dataIO->openDataFile("demo.stk");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
handle2 = _vm->_dataIO->openData("intro.stk");
|
2005-04-05 15:07:40 +00:00
|
|
|
if (handle2 >= 0) {
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_dataIO->closeData(handle2);
|
|
|
|
_vm->_dataIO->openDataFile("intro.stk");
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_util->initInput();
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-04 01:48:15 +00:00
|
|
|
_vm->_video->initPrimary(_vm->_global->_videoMode);
|
|
|
|
_vm->_global->_mouseXShift = 1;
|
|
|
|
_vm->_global->_mouseYShift = 1;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_game->_totTextData = 0;
|
|
|
|
_vm->_game->_totFileData = 0;
|
|
|
|
_vm->_game->_totResourceTable = 0;
|
2006-01-04 01:48:15 +00:00
|
|
|
_vm->_global->_inter_variables = 0;
|
2006-11-27 14:19:30 +00:00
|
|
|
_vm->_global->_inter_variablesSizes = 0;
|
2006-01-29 02:27:10 +00:00
|
|
|
_palDesc = new Video::PalDesc;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->validateVideoMode(_vm->_global->_videoMode);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_global->_setAllPalette = true;
|
2006-01-07 22:28:54 +00:00
|
|
|
_palDesc->vgaPal = _vm->_draw->_vgaPalette;
|
|
|
|
_palDesc->unused1 = _vm->_draw->_unusedPalette1;
|
|
|
|
_palDesc->unused2 = _vm->_draw->_unusedPalette2;
|
2006-01-04 01:48:15 +00:00
|
|
|
_vm->_video->setFullPalette(_palDesc);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = 0; i < 8; i++)
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_draw->_fonts[i] = 0;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
handle = _vm->_dataIO->openData("intro.inf");
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (handle < 0) {
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
handle2 = _vm->_dataIO->openData(_fontNames[i]);
|
2005-04-05 15:07:40 +00:00
|
|
|
if (handle2 >= 0) {
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_dataIO->closeData(handle2);
|
|
|
|
_vm->_draw->_fonts[i] = _vm->_util->loadFont(_fontNames[i]);
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_dataIO->closeData(handle);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-04-02 11:05:09 +00:00
|
|
|
infPtr = (char *) _vm->_dataIO->getData("intro.inf");
|
2005-04-05 15:07:40 +00:00
|
|
|
infBuf = infPtr;
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
infEnd = infBuf + _vm->_dataIO->getDataSize("intro.inf");
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = 0; i < 4; i++, infPtr++) {
|
|
|
|
int j;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
for (j = 0; infPtr < infEnd && *infPtr >= ' '; j++, infPtr++)
|
|
|
|
buffer[j] = *infPtr;
|
2005-04-05 15:07:40 +00:00
|
|
|
buffer[j] = 0;
|
2007-03-20 14:51:57 +00:00
|
|
|
|
2005-04-05 15:07:40 +00:00
|
|
|
strcat(buffer, ".let");
|
2007-03-20 14:51:57 +00:00
|
|
|
handle2 = _vm->_dataIO->openData(buffer);
|
2005-04-05 15:07:40 +00:00
|
|
|
if (handle2 >= 0) {
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_dataIO->closeData(handle2);
|
2006-01-07 22:28:54 +00:00
|
|
|
_vm->_draw->_fonts[i] = _vm->_util->loadFont(buffer);
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
if ((infPtr + 1) >= infEnd)
|
2005-04-05 15:07:40 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
infPtr++;
|
|
|
|
}
|
2006-01-29 02:27:10 +00:00
|
|
|
delete[] infBuf;
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
if (totName) {
|
2007-03-30 17:52:31 +00:00
|
|
|
strncpy0(buffer, totName, 15);
|
2005-04-05 15:07:40 +00:00
|
|
|
strcat(buffer, ".tot");
|
2007-03-20 14:51:57 +00:00
|
|
|
} else
|
2007-03-30 17:52:31 +00:00
|
|
|
strncpy0(buffer, _vm->_startTot, 19);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
handle = _vm->_dataIO->openData(buffer);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
|
|
|
if (handle >= 0) {
|
2007-07-31 01:43:32 +00:00
|
|
|
DataStream *stream = _vm->_dataIO->openAsStream(handle, true);
|
|
|
|
|
|
|
|
stream->seek(0x2C);
|
|
|
|
varsCount = stream->readUint16LE();
|
|
|
|
|
|
|
|
delete stream;
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2007-04-02 11:05:09 +00:00
|
|
|
_vm->_global->_inter_variables = new byte[varsCount * 4];
|
2006-11-27 14:19:30 +00:00
|
|
|
_vm->_global->_inter_variablesSizes = new byte[varsCount * 4];
|
2007-01-06 11:17:20 +00:00
|
|
|
_vm->_global->clearVars(varsCount);
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-07 22:28:54 +00:00
|
|
|
strcpy(_vm->_game->_curTotFile, buffer);
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_cdrom->testCD(1, "GOB");
|
|
|
|
_vm->_cdrom->readLIC("gob.lic");
|
2007-03-29 17:55:39 +00:00
|
|
|
|
2007-04-05 13:37:20 +00:00
|
|
|
// Search for a Coktel logo animation or image to display
|
2007-03-29 19:28:47 +00:00
|
|
|
imdHandle = _vm->_dataIO->openData("coktel.imd");
|
2007-03-29 17:55:39 +00:00
|
|
|
if (imdHandle >= 0) {
|
|
|
|
_vm->_dataIO->closeData(imdHandle);
|
|
|
|
_vm->_draw->initScreen();
|
2007-04-05 13:37:20 +00:00
|
|
|
_vm->_draw->_cursorIndex = -1;
|
2007-07-30 15:53:38 +00:00
|
|
|
|
2007-03-31 15:25:54 +00:00
|
|
|
_vm->_util->longDelay(200); // Letting everything settle
|
2007-07-30 15:53:38 +00:00
|
|
|
|
|
|
|
if (_vm->_vidPlayer->openVideo("coktel.imd")) {
|
|
|
|
_vm->_vidPlayer->play();
|
|
|
|
_vm->_vidPlayer->closeVideo();
|
|
|
|
}
|
|
|
|
|
2007-03-29 17:55:39 +00:00
|
|
|
_vm->_draw->closeScreen();
|
2007-04-05 13:37:20 +00:00
|
|
|
} else if ((imdHandle = _vm->_dataIO->openData("coktel.clt")) >= 0) {
|
|
|
|
_vm->_draw->initScreen();
|
2007-07-31 01:43:32 +00:00
|
|
|
|
|
|
|
stream = _vm->_dataIO->openAsStream(imdHandle, true);
|
2007-04-05 13:37:20 +00:00
|
|
|
_vm->_util->clearPalette();
|
2007-07-31 01:43:32 +00:00
|
|
|
stream->read((byte *) _vm->_draw->_vgaPalette, 768);
|
|
|
|
delete stream;
|
|
|
|
|
2007-04-05 13:37:20 +00:00
|
|
|
imdHandle = _vm->_dataIO->openData("coktel.ims");
|
|
|
|
if (imdHandle >= 0) {
|
|
|
|
byte *sprBuf;
|
|
|
|
|
|
|
|
_vm->_dataIO->closeData(imdHandle);
|
|
|
|
sprBuf = _vm->_dataIO->getData("coktel.ims");
|
|
|
|
_vm->_video->drawPackedSprite(sprBuf, 320, 200, 0, 0, 0,
|
|
|
|
_vm->_draw->_frontSurface);
|
|
|
|
_vm->_palAnim->fade(_palDesc, 0, 0);
|
|
|
|
_vm->_util->delay(500);
|
|
|
|
|
|
|
|
delete[] sprBuf;
|
|
|
|
}
|
|
|
|
_vm->_draw->closeScreen();
|
2007-03-29 17:55:39 +00:00
|
|
|
}
|
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_game->start();
|
2005-04-05 15:07:40 +00:00
|
|
|
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_cdrom->stopPlaying();
|
|
|
|
_vm->_cdrom->freeLICbuffer();
|
2005-04-13 18:27:29 +00:00
|
|
|
|
2006-01-29 02:27:10 +00:00
|
|
|
delete[] _vm->_global->_inter_variables;
|
2006-11-27 14:19:30 +00:00
|
|
|
delete[] _vm->_global->_inter_variablesSizes;
|
2006-01-29 02:27:10 +00:00
|
|
|
delete[] _vm->_game->_totFileData;
|
2006-06-13 08:10:54 +00:00
|
|
|
if (_vm->_game->_totTextData) {
|
|
|
|
if (_vm->_game->_totTextData->items)
|
|
|
|
delete[] _vm->_game->_totTextData->items;
|
|
|
|
delete _vm->_game->_totTextData;
|
|
|
|
}
|
|
|
|
if (_vm->_game->_totResourceTable) {
|
|
|
|
delete[] _vm->_game->_totResourceTable->items;
|
|
|
|
delete _vm->_game->_totResourceTable;
|
|
|
|
}
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
for (int i = 0; i < 4; i++) {
|
2006-01-07 22:28:54 +00:00
|
|
|
if (_vm->_draw->_fonts[i] != 0)
|
|
|
|
_vm->_util->freeFont(_vm->_draw->_fonts[i]);
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2006-01-29 02:27:10 +00:00
|
|
|
delete _palDesc;
|
2007-03-20 14:51:57 +00:00
|
|
|
_vm->_dataIO->closeDataFile();
|
2006-01-03 23:14:39 +00:00
|
|
|
_vm->_video->initPrimary(-1);
|
|
|
|
cleanup();
|
2005-04-05 15:07:40 +00:00
|
|
|
}
|
|
|
|
|
2007-03-20 14:51:57 +00:00
|
|
|
} // End of namespace Gob
|