2008-11-10 20:38:54 +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.
|
|
|
|
*
|
|
|
|
* $URL$
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common/file.h"
|
|
|
|
|
|
|
|
#include "sound/audiostream.h"
|
|
|
|
#include "sound/flac.h"
|
|
|
|
#include "sound/mp3.h"
|
|
|
|
#include "sound/vorbis.h"
|
|
|
|
#include "sound/wave.h"
|
|
|
|
|
|
|
|
#include "tucker/tucker.h"
|
|
|
|
#include "tucker/graphics.h"
|
|
|
|
|
|
|
|
namespace Tucker {
|
|
|
|
|
|
|
|
enum {
|
|
|
|
kCurrentCompressedSoundDataVersion = 1,
|
|
|
|
kCompressedSoundDataFileHeaderSize = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
struct CompressedSoundFile {
|
|
|
|
const char *filename;
|
|
|
|
Audio::AudioStream *(*makeStream)(Common::SeekableReadStream *stream, bool disposeAfterUse, uint32 startTime, uint32 duration, uint numLoops);
|
|
|
|
};
|
|
|
|
|
|
|
|
static const CompressedSoundFile compressedSoundFilesTable[] = {
|
|
|
|
#ifdef USE_FLAC
|
|
|
|
{ "TUCKER.SOF", Audio::makeFlacStream },
|
|
|
|
#endif
|
|
|
|
#ifdef USE_VORBIS
|
|
|
|
{ "TUCKER.SOG", Audio::makeVorbisStream },
|
|
|
|
#endif
|
|
|
|
#ifdef USE_MAD
|
|
|
|
{ "TUCKER.SO3", Audio::makeMP3Stream },
|
|
|
|
#endif
|
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static void decodeData(uint8 *data, int dataSize) {
|
|
|
|
for (int i = 0; i < dataSize; ++i) {
|
|
|
|
data[i] -= 0x80;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void stripData(uint8 *data, int dataSize) {
|
|
|
|
bool clearChr = false;
|
|
|
|
for (int i = 0; i < dataSize; ++i) {
|
|
|
|
if (!clearChr && data[i] == '/') {
|
|
|
|
clearChr = true;
|
|
|
|
}
|
|
|
|
if (clearChr) {
|
|
|
|
if (data[i] == '\n') {
|
|
|
|
clearChr = false;
|
|
|
|
}
|
|
|
|
data[i] = ' ';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum DataToken {
|
|
|
|
kDataTokenDw,
|
|
|
|
kDataTokenEx
|
|
|
|
};
|
|
|
|
|
|
|
|
class DataTokenizer {
|
|
|
|
public:
|
|
|
|
|
|
|
|
DataTokenizer(uint8 *data, int dataSize, bool stripComments = false)
|
|
|
|
: _data(data), _dataSize(dataSize), _pos(0) {
|
|
|
|
if (stripComments) {
|
|
|
|
stripData(_data, _dataSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int getNextInteger() {
|
|
|
|
bool negate = false;
|
|
|
|
int state = 0;
|
|
|
|
int num = 0;
|
|
|
|
while (_pos < _dataSize && state != 2) {
|
|
|
|
switch (state) {
|
|
|
|
case 0:
|
|
|
|
if (_data[_pos] == '-') {
|
|
|
|
state = 1;
|
|
|
|
negate = true;
|
|
|
|
} else if (_data[_pos] >= '0' && _data[_pos] <= '9') {
|
|
|
|
state = 1;
|
|
|
|
num = _data[_pos] - '0';
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (_data[_pos] >= '0' && _data[_pos] <= '9') {
|
|
|
|
num *= 10;
|
|
|
|
num += _data[_pos] - '0';
|
|
|
|
} else {
|
|
|
|
state = 2;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++_pos;
|
|
|
|
}
|
|
|
|
return negate ? -num : num;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool findNextToken(DataToken t) {
|
|
|
|
const char *token = 0;
|
|
|
|
switch (t) {
|
|
|
|
case kDataTokenDw:
|
|
|
|
token = "dw";
|
|
|
|
break;
|
|
|
|
case kDataTokenEx:
|
|
|
|
token = "!!";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int tokenLen = strlen(token);
|
|
|
|
while (_pos < _dataSize - tokenLen) {
|
|
|
|
if (memcmp(_data + _pos, token, tokenLen) == 0) {
|
|
|
|
_pos += tokenLen;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
++_pos;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool findIndex(int num) {
|
|
|
|
int i = -1;
|
|
|
|
while (findNextToken(kDataTokenEx)) {
|
|
|
|
i = getNextInteger();
|
|
|
|
if (i >= num) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return i == num;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8 *_data;
|
|
|
|
int _dataSize;
|
|
|
|
int _pos;
|
|
|
|
};
|
|
|
|
|
2009-01-16 21:08:55 +00:00
|
|
|
uint8 *TuckerEngine::loadFile(const char *fname, uint8 *p) {
|
|
|
|
char filename[80];
|
|
|
|
strcpy(filename, fname);
|
2008-12-16 21:06:20 +00:00
|
|
|
if (_gameLang == Common::DE_DEU) {
|
2009-01-16 21:08:55 +00:00
|
|
|
if (strcmp(filename, "bgtext.c") == 0) {
|
|
|
|
strcpy(filename, "bgtextgr.c");
|
|
|
|
} else if (strcmp(filename, "charname.c") == 0) {
|
|
|
|
strcpy(filename, "charnmgr.c");
|
|
|
|
} else if (strcmp(filename, "data5.c") == 0) {
|
|
|
|
strcpy(filename, "data5gr.c");
|
|
|
|
} else if (strcmp(filename, "infobar.txt") == 0) {
|
|
|
|
strcpy(filename, "infobrgr.txt");
|
|
|
|
} else if (strcmp(filename, "charsize.dta") == 0) {
|
|
|
|
strcpy(filename, "charszgr.dta");
|
|
|
|
} else if (strncmp(filename, "objtxt", 6) == 0) {
|
|
|
|
const char num = filename[6];
|
|
|
|
snprintf(filename, sizeof(filename), "objtx%cgr.c", num);
|
|
|
|
} else if (strncmp(filename, "pt", 2) == 0) {
|
|
|
|
const char num = filename[2];
|
|
|
|
snprintf(filename, sizeof(filename), "pt%ctxtgr.c", num);
|
2008-12-12 21:42:38 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-10 20:38:54 +00:00
|
|
|
_fileLoadSize = 0;
|
2008-11-10 23:29:08 +00:00
|
|
|
bool decode = false;
|
2008-12-16 21:06:20 +00:00
|
|
|
if (_gameFlags & kGameFlagEncodedData) {
|
2009-01-16 21:08:55 +00:00
|
|
|
char *ext = strrchr(filename, '.');
|
2008-11-10 20:38:54 +00:00
|
|
|
if (ext && strcmp(ext + 1, "c") == 0) {
|
|
|
|
strcpy(ext + 1, "enc");
|
2008-11-10 23:29:08 +00:00
|
|
|
decode = true;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Common::File f;
|
2009-01-16 21:08:55 +00:00
|
|
|
if (!f.open(filename)) {
|
|
|
|
warning("Unable to open '%s'", filename);
|
2008-11-10 20:38:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
const int sz = f.size();
|
|
|
|
if (!p) {
|
|
|
|
p = (uint8 *)malloc(sz);
|
|
|
|
}
|
|
|
|
if (p) {
|
|
|
|
f.read(p, sz);
|
2008-11-10 23:29:08 +00:00
|
|
|
if (decode) {
|
2008-11-10 20:38:54 +00:00
|
|
|
decodeData(p, sz);
|
|
|
|
}
|
|
|
|
_fileLoadSize = sz;
|
|
|
|
}
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2009-08-25 21:28:29 +00:00
|
|
|
void CompressedSound::openFile() {
|
2008-11-10 20:38:54 +00:00
|
|
|
_compressedSoundType = -1;
|
|
|
|
for (int i = 0; compressedSoundFilesTable[i].filename; ++i) {
|
|
|
|
if (_fCompressedSound.open(compressedSoundFilesTable[i].filename)) {
|
|
|
|
int version = _fCompressedSound.readUint16LE();
|
|
|
|
if (version == kCurrentCompressedSoundDataVersion) {
|
|
|
|
_compressedSoundType = i;
|
2009-08-25 21:28:29 +00:00
|
|
|
_compressedSoundFlags = _fCompressedSound.readUint16LE();
|
2009-06-14 15:07:34 +00:00
|
|
|
debug(1, "Using compressed sound file '%s'", compressedSoundFilesTable[i].filename);
|
2008-11-10 20:38:54 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
warning("Unhandled version %d for compressed sound file '%s'", version, compressedSoundFilesTable[i].filename);
|
2009-09-27 10:36:30 +00:00
|
|
|
_fCompressedSound.close();
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-08-25 21:28:29 +00:00
|
|
|
void CompressedSound::closeFile() {
|
2008-11-11 13:10:34 +00:00
|
|
|
_fCompressedSound.close();
|
|
|
|
}
|
|
|
|
|
2009-08-25 21:28:29 +00:00
|
|
|
Audio::AudioStream *CompressedSound::load(CompressedSoundType type, int num, bool loop) {
|
|
|
|
if (_compressedSoundType < 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
int offset = 0;
|
|
|
|
switch (type) {
|
|
|
|
case kSoundTypeFx:
|
|
|
|
offset = kCompressedSoundDataFileHeaderSize;
|
|
|
|
break;
|
|
|
|
case kSoundTypeMusic:
|
|
|
|
offset = kCompressedSoundDataFileHeaderSize + 8;
|
|
|
|
break;
|
|
|
|
case kSoundTypeSpeech:
|
|
|
|
offset = kCompressedSoundDataFileHeaderSize + 16;
|
|
|
|
break;
|
|
|
|
case kSoundTypeIntro:
|
|
|
|
if (_compressedSoundFlags & 1) {
|
|
|
|
offset = kCompressedSoundDataFileHeaderSize + 24;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-08-25 21:42:12 +00:00
|
|
|
if (offset == 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2009-08-25 21:28:29 +00:00
|
|
|
Audio::AudioStream *stream = 0;
|
|
|
|
_fCompressedSound.seek(offset);
|
|
|
|
int dirOffset = _fCompressedSound.readUint32LE();
|
|
|
|
int dirSize = _fCompressedSound.readUint32LE();
|
|
|
|
if (num < dirSize) {
|
|
|
|
const int dirHeaderSize = (_compressedSoundFlags & 1) ? 4 * 8 : 3 * 8;
|
|
|
|
dirOffset += kCompressedSoundDataFileHeaderSize + dirHeaderSize;
|
|
|
|
_fCompressedSound.seek(dirOffset + num * 8);
|
|
|
|
int soundOffset = _fCompressedSound.readUint32LE();
|
|
|
|
int soundSize = _fCompressedSound.readUint32LE();
|
|
|
|
if (soundSize != 0) {
|
|
|
|
_fCompressedSound.seek(dirOffset + dirSize * 8 + soundOffset);
|
|
|
|
Common::MemoryReadStream *tmp = _fCompressedSound.readStream(soundSize);
|
|
|
|
if (tmp) {
|
|
|
|
stream = (compressedSoundFilesTable[_compressedSoundType].makeStream)(tmp, true, 0, 0, loop ? 0 : 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return stream;
|
|
|
|
}
|
|
|
|
|
2009-01-16 21:08:55 +00:00
|
|
|
void TuckerEngine::loadImage(const char *fname, uint8 *dst, int type) {
|
|
|
|
char filename[80];
|
|
|
|
strcpy(filename, fname);
|
|
|
|
|
2008-11-10 20:38:54 +00:00
|
|
|
Common::File f;
|
2009-01-16 21:08:55 +00:00
|
|
|
if (!f.open(filename)) {
|
2008-11-23 03:42:01 +00:00
|
|
|
// workaround for "paper-3.pcx" / "paper_3.pcx"
|
|
|
|
bool tryOpen = false;
|
2009-01-16 21:08:55 +00:00
|
|
|
for (char *p = filename; *p; ++p) {
|
2008-11-23 03:42:01 +00:00
|
|
|
switch (*p) {
|
|
|
|
case '-':
|
|
|
|
*p = '_';
|
|
|
|
tryOpen = true;
|
|
|
|
break;
|
|
|
|
case '_':
|
|
|
|
*p = '-';
|
|
|
|
tryOpen = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-01-16 21:08:55 +00:00
|
|
|
if (!tryOpen || !f.open(filename)) {
|
|
|
|
warning("Unable to open '%s'", filename);
|
2008-11-23 03:42:01 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
f.seek(128, SEEK_SET);
|
2008-11-16 20:51:10 +00:00
|
|
|
int size = 0;
|
2008-11-10 20:38:54 +00:00
|
|
|
while (size < 64000) {
|
|
|
|
int code = f.readByte();
|
|
|
|
if (code >= 0xC0) {
|
|
|
|
const int sz = code - 0xC0;
|
|
|
|
code = f.readByte();
|
|
|
|
memset(dst + size, code, sz);
|
|
|
|
size += sz;
|
|
|
|
} else {
|
|
|
|
dst[size++] = code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (type != 0) {
|
2009-02-16 06:43:33 +00:00
|
|
|
if (f.readByte() != 12)
|
|
|
|
return;
|
2009-01-18 03:22:33 +00:00
|
|
|
f.read(_currentPalette, 768);
|
2008-11-10 20:38:54 +00:00
|
|
|
setBlackPalette();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadCursor() {
|
2009-01-16 21:08:55 +00:00
|
|
|
loadImage("pointer.pcx", _loadTempBuf, 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
for (int cursor = 0; cursor < 7; ++cursor) {
|
|
|
|
Graphics::encodeRAW(_loadTempBuf + cursor * 320 * 16, _cursorGfxBuf + cursor * 256, 16, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadCharset() {
|
2009-01-16 21:08:55 +00:00
|
|
|
loadImage("charset.pcx", _loadTempBuf, 0);
|
2008-12-16 21:06:20 +00:00
|
|
|
switch (_gameLang) {
|
2008-12-16 22:05:16 +00:00
|
|
|
case Common::EN_ANY:
|
|
|
|
Graphics::setCharset(kCharsetTypeEng);
|
2008-11-30 11:30:29 +00:00
|
|
|
break;
|
|
|
|
default:
|
2008-12-16 22:05:16 +00:00
|
|
|
Graphics::setCharset(kCharsetTypeDefault);
|
2008-11-30 11:30:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-11 13:10:34 +00:00
|
|
|
loadCharsetHelper();
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadCharset2() {
|
|
|
|
_charWidthTable[58] = 7;
|
|
|
|
_charWidthTable[32] = 15;
|
2008-11-10 23:29:08 +00:00
|
|
|
memcpy(_charWidthTable + 65, _charWidthCharset2, 58);
|
2009-01-16 21:08:55 +00:00
|
|
|
loadImage("char2.pcx", _loadTempBuf, 0);
|
2008-11-28 23:56:25 +00:00
|
|
|
Graphics::setCharset(kCharsetTypeCredits);
|
2008-11-11 13:10:34 +00:00
|
|
|
loadCharsetHelper();
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
2008-11-11 13:10:34 +00:00
|
|
|
void TuckerEngine::loadCharsetHelper() {
|
2008-11-28 23:56:25 +00:00
|
|
|
const int charW = Graphics::_charset.charW;
|
|
|
|
const int charH = Graphics::_charset.charH;
|
2008-11-10 20:38:54 +00:00
|
|
|
int offset = 0;
|
2008-11-28 23:56:25 +00:00
|
|
|
for (int y = 0; y < Graphics::_charset.yCount; ++y) {
|
|
|
|
for (int x = 0; x < Graphics::_charset.xCount; ++x) {
|
2008-11-10 20:38:54 +00:00
|
|
|
offset += Graphics::encodeRAW(_loadTempBuf + (y * 320) * charH + x * charW, _charsetGfxBuf + offset, charW, charH);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadCharSizeDta() {
|
2009-01-16 21:08:55 +00:00
|
|
|
loadFile("charsize.dta", _loadTempBuf);
|
2008-11-10 23:29:08 +00:00
|
|
|
if (_fileLoadSize != 0) {
|
|
|
|
DataTokenizer t(_loadTempBuf, _fileLoadSize, true);
|
|
|
|
for (int i = 0; i < 256; ++i) {
|
|
|
|
_charWidthTable[i] = t.getNextInteger();
|
|
|
|
}
|
2009-01-29 21:31:44 +00:00
|
|
|
if (_gameLang == Common::FR_FRA) {
|
|
|
|
_charWidthTable[225] = 0;
|
|
|
|
}
|
2008-11-10 23:29:08 +00:00
|
|
|
} else {
|
|
|
|
memcpy(_charWidthTable + 32, _charWidthCharset1, 224);
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadPanel() {
|
2009-01-16 21:19:30 +00:00
|
|
|
loadImage((_panelNum == 0) ? "panel1.pcx" : "panel2.pcx", _panelGfxBuf, 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadBudSpr(int startOffset) {
|
2009-03-01 00:51:59 +00:00
|
|
|
int endOffset = loadCTable01(0, startOffset);
|
2008-11-10 20:38:54 +00:00
|
|
|
loadCTable02(0);
|
|
|
|
int frame = 0;
|
|
|
|
int spriteOffset = 0;
|
|
|
|
for (int i = startOffset; i < endOffset; ++i) {
|
|
|
|
if (_ctable01Table_sprite[frame] == i) {
|
2009-01-16 21:19:30 +00:00
|
|
|
char filename[40];
|
2008-11-10 20:38:54 +00:00
|
|
|
switch (_flagsTable[137]) {
|
|
|
|
case 0:
|
2009-01-24 21:03:44 +00:00
|
|
|
if ((_gameFlags & kGameFlagDemo) != 0) {
|
|
|
|
sprintf(filename, "budl00_%d.pcx", frame + 1);
|
|
|
|
} else {
|
|
|
|
sprintf(filename, "bud_%d.pcx", frame + 1);
|
|
|
|
}
|
2008-11-10 20:38:54 +00:00
|
|
|
break;
|
|
|
|
case 1:
|
2009-01-16 21:19:30 +00:00
|
|
|
sprintf(filename, "peg_%d.pcx", frame + 1);
|
2008-11-10 20:38:54 +00:00
|
|
|
break;
|
|
|
|
default:
|
2009-01-16 21:19:30 +00:00
|
|
|
sprintf(filename, "mac_%d.pcx", frame + 1);
|
2008-11-10 20:38:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-01-16 21:19:30 +00:00
|
|
|
loadImage(filename, _loadTempBuf, 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
++frame;
|
|
|
|
}
|
|
|
|
int sz = Graphics::encodeRLE(_loadTempBuf + _spriteFramesTable[i].sourceOffset, _spritesGfxBuf + spriteOffset, _spriteFramesTable[i].xSize, _spriteFramesTable[i].ySize);
|
|
|
|
_spriteFramesTable[i].sourceOffset = spriteOffset;
|
|
|
|
spriteOffset += sz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-01 00:51:59 +00:00
|
|
|
int TuckerEngine::loadCTable01(int index, int firstSpriteNum) {
|
2009-01-16 21:08:55 +00:00
|
|
|
loadFile("ctable01.c", _loadTempBuf);
|
2008-11-10 20:38:54 +00:00
|
|
|
DataTokenizer t(_loadTempBuf, _fileLoadSize);
|
2009-03-01 00:51:59 +00:00
|
|
|
int lastSpriteNum = firstSpriteNum;
|
2008-11-10 20:38:54 +00:00
|
|
|
int count = 0;
|
2009-03-01 00:51:59 +00:00
|
|
|
if (t.findIndex(index)) {
|
2008-11-10 20:38:54 +00:00
|
|
|
while (t.findNextToken(kDataTokenDw)) {
|
|
|
|
const int x = t.getNextInteger();
|
|
|
|
if (x < 0) {
|
|
|
|
break;
|
|
|
|
} else if (x == 999) {
|
|
|
|
_ctable01Table_sprite[count] = lastSpriteNum;
|
|
|
|
++count;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
const int y = t.getNextInteger();
|
|
|
|
SpriteFrame *c = &_spriteFramesTable[lastSpriteNum++];
|
|
|
|
c->sourceOffset = y * 320 + x;
|
|
|
|
c->xSize = t.getNextInteger();
|
|
|
|
c->ySize = t.getNextInteger();
|
|
|
|
c->xOffset = t.getNextInteger();
|
|
|
|
if (c->xOffset > 300) {
|
|
|
|
c->xOffset -= 500;
|
|
|
|
}
|
|
|
|
c->yOffset = t.getNextInteger();
|
|
|
|
if (c->yOffset > 300) {
|
|
|
|
c->yOffset -= 500;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ctable01Table_sprite[count] = -1;
|
2009-03-01 00:51:59 +00:00
|
|
|
return lastSpriteNum;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadCTable02(int fl) {
|
|
|
|
assert(fl == 0);
|
|
|
|
int entry = 0;
|
|
|
|
int i = 0;
|
2009-01-16 21:08:55 +00:00
|
|
|
loadFile("ctable02.c", _loadTempBuf);
|
2008-11-10 20:38:54 +00:00
|
|
|
DataTokenizer t(_loadTempBuf, _fileLoadSize);
|
|
|
|
while (t.findNextToken(kDataTokenDw)) {
|
|
|
|
_spriteAnimationsTable[entry].numParts = t.getNextInteger();
|
|
|
|
if (_spriteAnimationsTable[entry].numParts < 1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_spriteAnimationsTable[entry].rotateFlag = t.getNextInteger();
|
|
|
|
int num = t.getNextInteger();
|
|
|
|
if (num != fl) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
int start = 0;
|
|
|
|
_spriteAnimationsTable[entry].firstFrameIndex = i;
|
2009-01-25 18:08:26 +00:00
|
|
|
while (start != 999) {
|
2008-11-10 20:38:54 +00:00
|
|
|
start = t.getNextInteger();
|
2009-01-25 18:08:26 +00:00
|
|
|
if (start == 9999) { // end marker in the demo version
|
|
|
|
start = 999;
|
|
|
|
}
|
2008-11-10 20:38:54 +00:00
|
|
|
_spriteAnimationFramesTable[i] = start;
|
|
|
|
++i;
|
|
|
|
}
|
|
|
|
++entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadLoc() {
|
2009-01-16 21:19:30 +00:00
|
|
|
char filename[40];
|
|
|
|
|
2008-11-10 20:38:54 +00:00
|
|
|
int i = _locationWidthTable[_locationNum];
|
|
|
|
_locationHeight = (_locationNum < 73) ? 140 : 200;
|
2009-01-16 21:19:30 +00:00
|
|
|
sprintf(filename, (i == 1) ? "loc%02d.pcx" : "loc%02da.pcx", _locationNum);
|
|
|
|
copyLocBitmap(filename, 0, false);
|
2009-01-18 04:00:11 +00:00
|
|
|
Graphics::copyRect(_quadBackgroundGfxBuf, 320, _locationBackgroundGfxBuf, 640, 320, _locationHeight);
|
2008-11-10 20:38:54 +00:00
|
|
|
if (_locationHeight == 200) {
|
|
|
|
return;
|
|
|
|
}
|
2009-01-16 21:19:30 +00:00
|
|
|
sprintf(filename, (i != 2) ? "path%02d.pcx" : "path%02da.pcx", _locationNum);
|
|
|
|
copyLocBitmap(filename, 0, true);
|
2008-11-10 20:38:54 +00:00
|
|
|
if (i > 1) {
|
2009-01-16 21:19:30 +00:00
|
|
|
sprintf(filename, "loc%02db.pcx", _locationNum);
|
|
|
|
copyLocBitmap(filename, 320, false);
|
2009-01-18 04:00:11 +00:00
|
|
|
Graphics::copyRect(_quadBackgroundGfxBuf + 44800, 320, _locationBackgroundGfxBuf + 320, 640, 320, _locationHeight);
|
2008-11-10 20:38:54 +00:00
|
|
|
if (i == 2) {
|
2009-01-16 21:19:30 +00:00
|
|
|
sprintf(filename, "path%02db.pcx", _locationNum);
|
|
|
|
copyLocBitmap(filename, 320, true);
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i > 2) {
|
2009-01-16 21:19:30 +00:00
|
|
|
sprintf(filename, "loc%02dc.pcx", _locationNum);
|
|
|
|
copyLocBitmap(filename, 0, false);
|
2009-01-18 04:00:11 +00:00
|
|
|
Graphics::copyRect(_quadBackgroundGfxBuf + 89600, 320, _locationBackgroundGfxBuf, 640, 320, 140);
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-01-25 18:08:26 +00:00
|
|
|
if (_locationNum == 1) {
|
2008-11-10 20:38:54 +00:00
|
|
|
_loadLocBufPtr = _quadBackgroundGfxBuf + 89600;
|
2009-01-16 21:08:55 +00:00
|
|
|
loadImage("rochpath.pcx", _loadLocBufPtr, 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
if (i > 3) {
|
2009-01-16 21:19:30 +00:00
|
|
|
sprintf(filename, "loc%02dd.pcx", _locationNum);
|
|
|
|
copyLocBitmap(filename, 0, false);
|
2009-01-18 04:00:11 +00:00
|
|
|
Graphics::copyRect(_quadBackgroundGfxBuf + 134400, 320, _locationBackgroundGfxBuf + 320, 640, 320, 140);
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-07-13 22:11:54 +00:00
|
|
|
_fullRedraw = true;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadObj() {
|
|
|
|
if (_locationNum == 99) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_locationNum < 24) {
|
|
|
|
_partNum = 1;
|
|
|
|
_speechSoundBaseNum = 2639;
|
2008-11-23 03:42:01 +00:00
|
|
|
} else if (_locationNum < 41 || (_locationNum > 69 && _locationNum < 73) || (_locationNum > 78 && _locationNum < 83)) {
|
2008-11-10 20:38:54 +00:00
|
|
|
_partNum = 2;
|
|
|
|
_speechSoundBaseNum = 2679;
|
|
|
|
} else {
|
|
|
|
_partNum = 3;
|
|
|
|
_speechSoundBaseNum = 2719;
|
|
|
|
}
|
|
|
|
if (_partNum == _currentPartNum) {
|
|
|
|
return;
|
|
|
|
}
|
2008-11-23 03:42:01 +00:00
|
|
|
debug(2, "loadObj() partNum %d locationNum %d", _partNum, _locationNum);
|
2009-01-24 21:03:44 +00:00
|
|
|
if ((_gameFlags & kGameFlagDemo) == 0) {
|
|
|
|
handleNewPartSequence();
|
|
|
|
}
|
2008-11-10 20:38:54 +00:00
|
|
|
_currentPartNum = _partNum;
|
2009-01-16 21:19:30 +00:00
|
|
|
|
|
|
|
char filename[40];
|
|
|
|
sprintf(filename, "objtxt%d.c", _partNum);
|
2008-11-10 20:38:54 +00:00
|
|
|
free(_objTxtBuf);
|
2009-01-16 21:19:30 +00:00
|
|
|
_objTxtBuf = loadFile(filename, 0);
|
|
|
|
sprintf(filename, "pt%dtext.c", _partNum);
|
2008-11-10 20:38:54 +00:00
|
|
|
free(_ptTextBuf);
|
2009-01-16 21:19:30 +00:00
|
|
|
_ptTextBuf = loadFile(filename, 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
loadData();
|
|
|
|
loadPanObj();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadData() {
|
|
|
|
int objNum = _partNum * 10;
|
2009-01-16 21:08:55 +00:00
|
|
|
loadFile("data.c", _loadTempBuf);
|
2008-11-10 20:38:54 +00:00
|
|
|
DataTokenizer t(_loadTempBuf, _fileLoadSize);
|
|
|
|
_dataCount = 0;
|
|
|
|
int count = 0;
|
|
|
|
int maxCount = 0;
|
2009-05-17 13:25:08 +00:00
|
|
|
while (t.findIndex(objNum)) {
|
|
|
|
while (t.findNextToken(kDataTokenDw)) {
|
2008-11-10 20:38:54 +00:00
|
|
|
_dataCount = t.getNextInteger();
|
|
|
|
if (_dataCount < 0) {
|
2009-05-17 13:25:08 +00:00
|
|
|
break;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
if (_dataCount > maxCount) {
|
|
|
|
maxCount = _dataCount;
|
|
|
|
}
|
|
|
|
const int x = t.getNextInteger();
|
|
|
|
const int y = t.getNextInteger();
|
2008-12-12 21:42:38 +00:00
|
|
|
Data *d = &_dataTable[_dataCount];
|
|
|
|
d->sourceOffset = y * 320 + x;
|
|
|
|
d->xSize = t.getNextInteger();
|
|
|
|
d->ySize = t.getNextInteger();
|
|
|
|
d->xDest = t.getNextInteger();
|
|
|
|
d->yDest = t.getNextInteger();
|
|
|
|
d->index = count;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-05-17 13:25:08 +00:00
|
|
|
++objNum;
|
|
|
|
++count;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
_dataCount = maxCount;
|
|
|
|
int offset = 0;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
2009-01-16 21:19:30 +00:00
|
|
|
char filename[40];
|
|
|
|
sprintf(filename, "scrobj%d%d.pcx", _partNum, i);
|
|
|
|
loadImage(filename, _loadTempBuf, 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
offset = loadDataHelper(offset, i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int TuckerEngine::loadDataHelper(int offset, int index) {
|
|
|
|
for (int i = 0; i < _dataCount + 1; ++i) {
|
|
|
|
if (_dataTable[i].index == index) {
|
|
|
|
int sz = Graphics::encodeRLE(_loadTempBuf + _dataTable[i].sourceOffset, _data3GfxBuf + offset, _dataTable[i].xSize, _dataTable[i].ySize);
|
|
|
|
_dataTable[i].sourceOffset = offset;
|
|
|
|
offset += sz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadPanObj() {
|
2009-01-16 21:19:30 +00:00
|
|
|
char filename[40];
|
|
|
|
sprintf(filename, "panobjs%d.pcx", _partNum);
|
|
|
|
loadImage(filename, _loadTempBuf, 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
int offset = 0;
|
|
|
|
for (int y = 0; y < 5; ++y) {
|
|
|
|
for (int x = 0; x < 10; ++x) {
|
|
|
|
const int i = y * 10 + x;
|
|
|
|
_panelObjectsOffsetTable[i] = offset;
|
|
|
|
offset += Graphics::encodeRLE(_loadTempBuf + (y * 240 + x) * 32, _panelObjectsGfxBuf + offset, 32, 24);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadData3() {
|
2009-01-16 21:08:55 +00:00
|
|
|
loadFile("data3.c", _loadTempBuf);
|
2008-11-10 20:38:54 +00:00
|
|
|
DataTokenizer t(_loadTempBuf, _fileLoadSize);
|
|
|
|
_locationAnimationsCount = 0;
|
|
|
|
if (t.findIndex(_locationNum)) {
|
|
|
|
while (t.findNextToken(kDataTokenDw)) {
|
|
|
|
int num = t.getNextInteger();
|
|
|
|
if (num < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(_locationAnimationsCount < kLocationAnimationsTableSize);
|
|
|
|
LocationAnimation *d = &_locationAnimationsTable[_locationAnimationsCount++];
|
|
|
|
d->graphicNum = num;
|
|
|
|
const int seqNum = t.getNextInteger();
|
|
|
|
if (seqNum > 0) {
|
2009-03-01 00:51:59 +00:00
|
|
|
int anim = 0;
|
|
|
|
for (int i = 1; i < seqNum; ++i) {
|
|
|
|
while (_staticData3Table[anim] != 999) {
|
|
|
|
++anim;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-03-01 00:51:59 +00:00
|
|
|
++anim;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-03-01 00:51:59 +00:00
|
|
|
d->animCurrentCounter = d->animInitCounter = anim;
|
|
|
|
while (_staticData3Table[anim + 1] != 999) {
|
|
|
|
++anim;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-03-01 00:51:59 +00:00
|
|
|
d->animLastCounter = anim;
|
2008-11-10 20:38:54 +00:00
|
|
|
} else {
|
|
|
|
d->animLastCounter = 0;
|
|
|
|
}
|
|
|
|
d->getFlag = t.getNextInteger();
|
|
|
|
d->inventoryNum = t.getNextInteger();
|
|
|
|
d->flagNum = t.getNextInteger();
|
|
|
|
d->flagValue = t.getNextInteger();
|
|
|
|
d->selectable = t.getNextInteger();
|
|
|
|
d->standX = t.getNextInteger();
|
|
|
|
d->standY = t.getNextInteger();
|
|
|
|
d->drawFlag = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadData4() {
|
2009-01-16 21:08:55 +00:00
|
|
|
loadFile("data4.c", _loadTempBuf);
|
2008-11-10 20:38:54 +00:00
|
|
|
DataTokenizer t(_loadTempBuf, _fileLoadSize);
|
|
|
|
t.findNextToken(kDataTokenDw);
|
2008-11-16 20:51:10 +00:00
|
|
|
_gameDebug = t.getNextInteger() != 0;
|
|
|
|
_displayGameHints = t.getNextInteger() != 0;
|
2008-11-10 20:38:54 +00:00
|
|
|
// forces game hints feature
|
2008-11-16 20:51:10 +00:00
|
|
|
// _displayGameHints = true;
|
2008-11-10 20:38:54 +00:00
|
|
|
_locationObjectsCount = 0;
|
|
|
|
if (t.findIndex(_locationNum)) {
|
|
|
|
while (t.findNextToken(kDataTokenDw)) {
|
|
|
|
int i = t.getNextInteger();
|
|
|
|
if (i < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(_locationObjectsCount < kLocationObjectsTableSize);
|
|
|
|
LocationObject *d = &_locationObjectsTable[_locationObjectsCount++];
|
|
|
|
d->xPos = i;
|
|
|
|
d->yPos = t.getNextInteger();
|
|
|
|
d->xSize = t.getNextInteger();
|
|
|
|
d->ySize = t.getNextInteger();
|
|
|
|
d->standX = t.getNextInteger();
|
|
|
|
d->standY = t.getNextInteger();
|
|
|
|
d->textNum = t.getNextInteger();
|
|
|
|
d->cursorNum = t.getNextInteger();
|
|
|
|
d->locationNum = t.getNextInteger();
|
|
|
|
if (d->locationNum > 0) {
|
|
|
|
d->toX = t.getNextInteger();
|
|
|
|
d->toY = t.getNextInteger();
|
|
|
|
d->toX2 = t.getNextInteger();
|
|
|
|
d->toY2 = t.getNextInteger();
|
|
|
|
d->toWalkX2 = t.getNextInteger();
|
|
|
|
d->toWalkY2 = t.getNextInteger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadActionFile() {
|
2009-01-16 21:19:30 +00:00
|
|
|
char filename[40];
|
2009-01-24 21:03:44 +00:00
|
|
|
if ((_gameFlags & kGameFlagDemo) != 0) {
|
|
|
|
strcpy(filename, "action.c");
|
|
|
|
} else {
|
|
|
|
switch (_partNum) {
|
|
|
|
case 1:
|
|
|
|
strcpy(filename, "action1.c");
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
strcpy(filename, "action2.c");
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(filename, "action3.c");
|
|
|
|
break;
|
|
|
|
}
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-01-16 21:19:30 +00:00
|
|
|
loadFile(filename, _loadTempBuf);
|
|
|
|
|
2008-11-10 20:38:54 +00:00
|
|
|
DataTokenizer t(_loadTempBuf, _fileLoadSize);
|
|
|
|
_actionsCount = 0;
|
|
|
|
if (t.findIndex(_locationNum)) {
|
|
|
|
while (t.findNextToken(kDataTokenDw)) {
|
|
|
|
int keyA = t.getNextInteger();
|
|
|
|
if (keyA < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
int keyB = t.getNextInteger();
|
|
|
|
int keyC = t.getNextInteger();
|
|
|
|
int keyD = t.getNextInteger();
|
|
|
|
int keyE = t.getNextInteger();
|
|
|
|
Action *action = &_actionsTable[_actionsCount++];
|
|
|
|
action->key = keyE * 1000000 + keyD * 100000 + keyA * 10000 + keyB * 1000 + keyC;
|
|
|
|
action->testFlag1Num = t.getNextInteger();
|
|
|
|
action->testFlag1Value = t.getNextInteger();
|
|
|
|
action->testFlag2Num = t.getNextInteger();
|
|
|
|
action->testFlag2Value = t.getNextInteger();
|
|
|
|
action->speech = t.getNextInteger();
|
|
|
|
action->flipX = t.getNextInteger();
|
|
|
|
action->index = t.getNextInteger();
|
|
|
|
action->delay = t.getNextInteger();
|
|
|
|
action->setFlagNum = t.getNextInteger();
|
2009-05-11 14:04:44 +00:00
|
|
|
assert(action->setFlagNum >= 0 && action->setFlagNum < kFlagsTableSize);
|
2008-11-10 20:38:54 +00:00
|
|
|
action->setFlagValue = t.getNextInteger();
|
|
|
|
action->fxNum = t.getNextInteger();
|
|
|
|
action->fxDelay = t.getNextInteger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadCharPos() {
|
2009-01-16 21:08:55 +00:00
|
|
|
loadFile("charpos.c", _loadTempBuf);
|
2008-11-10 20:38:54 +00:00
|
|
|
DataTokenizer t(_loadTempBuf, _fileLoadSize);
|
|
|
|
_charPosCount = 0;
|
|
|
|
if (t.findIndex(_locationNum)) {
|
|
|
|
while (t.findNextToken(kDataTokenDw)) {
|
|
|
|
const int i = t.getNextInteger();
|
|
|
|
if (i < 0) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
assert(_charPosCount < 4);
|
|
|
|
CharPos *charPos = &_charPosTable[_charPosCount++];
|
|
|
|
charPos->xPos = i;
|
|
|
|
charPos->yPos = t.getNextInteger();
|
|
|
|
charPos->xSize = t.getNextInteger();
|
|
|
|
charPos->ySize = t.getNextInteger();
|
|
|
|
charPos->xWalkTo = t.getNextInteger();
|
|
|
|
charPos->yWalkTo = t.getNextInteger();
|
|
|
|
charPos->flagNum = t.getNextInteger();
|
|
|
|
charPos->flagValue = t.getNextInteger();
|
|
|
|
charPos->direction = t.getNextInteger();
|
|
|
|
charPos->name = t.getNextInteger();
|
|
|
|
charPos->description = t.getNextInteger();
|
|
|
|
}
|
2008-11-23 03:42:01 +00:00
|
|
|
int quitLoop = 0;
|
|
|
|
size_t count = 0;
|
|
|
|
while (quitLoop == 0) {
|
|
|
|
t.findNextToken(kDataTokenDw);
|
|
|
|
int num = 0;
|
|
|
|
while (num != 99) {
|
|
|
|
num = t.getNextInteger();
|
|
|
|
assert(count < ARRAYSIZE(_characterAnimationsTable));
|
|
|
|
_characterAnimationsTable[count] = num;
|
|
|
|
if (num < 0) {
|
|
|
|
quitLoop = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++count;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-23 03:42:01 +00:00
|
|
|
quitLoop = 0;
|
|
|
|
count = 0;
|
|
|
|
while (quitLoop == 0) {
|
|
|
|
t.findNextToken(kDataTokenDw);
|
|
|
|
int num = 0;
|
|
|
|
while (num < 98) {
|
|
|
|
num = t.getNextInteger();
|
|
|
|
assert(count < ARRAYSIZE(_characterStateTable));
|
|
|
|
_characterStateTable[count] = num;
|
|
|
|
if (num == 98) {
|
|
|
|
--count;
|
|
|
|
}
|
|
|
|
if (num < 0) {
|
|
|
|
quitLoop = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
++count;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadSprA02_01() {
|
2008-11-16 20:51:10 +00:00
|
|
|
unloadSprA02_01();
|
2008-11-10 20:38:54 +00:00
|
|
|
const int count = _sprA02LookupTable[_locationNum];
|
|
|
|
for (int i = 1; i < count + 1; ++i) {
|
2009-01-16 21:19:30 +00:00
|
|
|
char filename[40];
|
|
|
|
sprintf(filename, "sprites/a%02d_%02d.spr", _locationNum, i);
|
|
|
|
_sprA02Table[i] = loadFile(filename, 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
_sprA02Table[0] = _sprA02Table[1];
|
|
|
|
}
|
|
|
|
|
2008-11-16 20:51:10 +00:00
|
|
|
void TuckerEngine::unloadSprA02_01() {
|
|
|
|
for (int i = 1; i < kSprA02TableSize; ++i) {
|
|
|
|
free(_sprA02Table[i]);
|
|
|
|
_sprA02Table[i] = 0;
|
|
|
|
}
|
2008-11-23 03:42:01 +00:00
|
|
|
_sprA02Table[0] = 0;
|
2008-11-16 20:51:10 +00:00
|
|
|
}
|
|
|
|
|
2008-11-10 20:38:54 +00:00
|
|
|
void TuckerEngine::loadSprC02_01() {
|
2008-11-23 03:42:01 +00:00
|
|
|
unloadSprC02_01();
|
2008-11-10 20:38:54 +00:00
|
|
|
const int count = _sprC02LookupTable[_locationNum];
|
|
|
|
for (int i = 1; i < count + 1; ++i) {
|
2009-01-16 21:19:30 +00:00
|
|
|
char filename[40];
|
|
|
|
sprintf(filename, "sprites/c%02d_%02d.spr", _locationNum, i);
|
|
|
|
_sprC02Table[i] = loadFile(filename, 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
_sprC02Table[0] = _sprC02Table[1];
|
|
|
|
_spritesCount = _sprC02LookupTable2[_locationNum];
|
|
|
|
for (int i = 0; i < kMaxCharacters; ++i) {
|
|
|
|
memset(&_spritesTable[i], 0, sizeof(Sprite));
|
|
|
|
_spritesTable[i].state = -1;
|
|
|
|
_spritesTable[i].stateIndex = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-16 20:51:10 +00:00
|
|
|
void TuckerEngine::unloadSprC02_01() {
|
|
|
|
for (int i = 1; i < kSprC02TableSize; ++i) {
|
|
|
|
free(_sprC02Table[i]);
|
|
|
|
_sprC02Table[i] = 0;
|
|
|
|
}
|
2008-11-23 03:42:01 +00:00
|
|
|
_sprC02Table[0] = 0;
|
2008-11-16 20:51:10 +00:00
|
|
|
}
|
|
|
|
|
2008-11-10 20:38:54 +00:00
|
|
|
void TuckerEngine::loadFx() {
|
2009-01-16 21:08:55 +00:00
|
|
|
loadFile("fx.c", _loadTempBuf);
|
2008-11-10 20:38:54 +00:00
|
|
|
DataTokenizer t(_loadTempBuf, _fileLoadSize);
|
|
|
|
t.findIndex(_locationNum);
|
|
|
|
t.findNextToken(kDataTokenDw);
|
|
|
|
_locationSoundsCount = t.getNextInteger();
|
|
|
|
_currentFxSet = 0;
|
|
|
|
for (int i = 0; i < _locationSoundsCount; ++i) {
|
2008-11-15 02:32:05 +00:00
|
|
|
LocationSound *s = &_locationSoundsTable[i];
|
|
|
|
s->offset = 0;
|
|
|
|
s->num = t.getNextInteger();
|
|
|
|
s->volume = t.getNextInteger();
|
|
|
|
s->type = t.getNextInteger();
|
|
|
|
switch (s->type) {
|
|
|
|
case 5:
|
2008-11-10 20:38:54 +00:00
|
|
|
_currentFxSet = 1;
|
|
|
|
_currentFxIndex = i;
|
2008-11-15 02:32:05 +00:00
|
|
|
_currentFxVolume = s->volume;
|
2008-11-10 20:38:54 +00:00
|
|
|
_currentFxDist = t.getNextInteger();
|
|
|
|
_currentFxScale = t.getNextInteger();
|
2008-11-15 02:32:05 +00:00
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
case 7:
|
|
|
|
case 8:
|
|
|
|
s->startFxSpriteState = t.getNextInteger();
|
|
|
|
s->startFxSpriteNum = t.getNextInteger();
|
|
|
|
s->updateType = t.getNextInteger();
|
|
|
|
if (s->type == 7) {
|
|
|
|
s->flagNum = t.getNextInteger();
|
|
|
|
s->flagValueStartFx = t.getNextInteger();
|
|
|
|
s->stopFxSpriteState = t.getNextInteger();
|
|
|
|
s->stopFxSpriteNum = t.getNextInteger();
|
|
|
|
s->flagValueStopFx = t.getNextInteger();
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2008-11-15 02:32:05 +00:00
|
|
|
break;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2008-11-15 02:32:05 +00:00
|
|
|
if (s->type == 8) {
|
|
|
|
s->type = 6;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
t.findNextToken(kDataTokenDw);
|
|
|
|
int count = t.getNextInteger();
|
|
|
|
_locationMusicsCount = 0;
|
|
|
|
for (int i = 0; i < count; ++i) {
|
|
|
|
int flagNum = t.getNextInteger();
|
|
|
|
int flagValue = t.getNextInteger();
|
|
|
|
if (flagValue == _flagsTable[flagNum]) {
|
2008-11-15 02:32:05 +00:00
|
|
|
LocationMusic *m = &_locationMusicsTable[_locationMusicsCount++];
|
|
|
|
m->offset = 0;
|
|
|
|
m->num = t.getNextInteger();
|
|
|
|
m->volume = t.getNextInteger();
|
|
|
|
m->flag = t.getNextInteger();
|
2008-11-10 20:38:54 +00:00
|
|
|
} else {
|
|
|
|
for (int j = 0; j < 3; ++j) {
|
|
|
|
t.getNextInteger();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadSound(Audio::Mixer::SoundType type, int num, int volume, bool loop, Audio::SoundHandle *handle) {
|
|
|
|
Audio::AudioStream *stream = 0;
|
2009-08-25 21:28:29 +00:00
|
|
|
switch (type) {
|
|
|
|
case Audio::Mixer::kSFXSoundType:
|
|
|
|
stream = _compressedSound.load(kSoundTypeFx, num, loop);
|
|
|
|
break;
|
|
|
|
case Audio::Mixer::kMusicSoundType:
|
|
|
|
stream = _compressedSound.load(kSoundTypeMusic, num, loop);
|
|
|
|
break;
|
|
|
|
case Audio::Mixer::kSpeechSoundType:
|
|
|
|
stream = _compressedSound.load(kSoundTypeSpeech, num, loop);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!stream) {
|
2008-11-10 20:38:54 +00:00
|
|
|
const char *fmt = 0;
|
|
|
|
switch (type) {
|
|
|
|
case Audio::Mixer::kSFXSoundType:
|
|
|
|
fmt = "fx/fx%d.wav";
|
|
|
|
break;
|
|
|
|
case Audio::Mixer::kMusicSoundType:
|
|
|
|
fmt = "music/mus%d.wav";
|
|
|
|
break;
|
|
|
|
case Audio::Mixer::kSpeechSoundType:
|
|
|
|
fmt = "speech/sam%04d.wav";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
char fileName[64];
|
|
|
|
snprintf(fileName, sizeof(fileName), fmt, num);
|
|
|
|
Common::File f;
|
|
|
|
if (f.open(fileName)) {
|
|
|
|
int size, rate;
|
|
|
|
uint8 flags = 0;
|
|
|
|
if (Audio::loadWAVFromStream(f, size, rate, flags)) {
|
|
|
|
uint8 *data = (uint8 *)malloc(size);
|
|
|
|
if (data) {
|
|
|
|
f.read(data, size);
|
|
|
|
flags |= Audio::Mixer::FLAG_AUTOFREE;
|
|
|
|
if (loop) {
|
|
|
|
flags |= Audio::Mixer::FLAG_LOOP;
|
|
|
|
}
|
|
|
|
stream = Audio::makeLinearInputStream(data, size, rate, flags, 0, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (stream) {
|
2008-11-16 20:51:10 +00:00
|
|
|
_mixer->stopHandle(*handle);
|
2008-11-28 23:56:25 +00:00
|
|
|
_mixer->playInputStream(type, handle, stream, -1, scaleMixerVolume(volume, kMaxSoundVolume));
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TuckerEngine::loadActionsTable() {
|
|
|
|
int table = 0;
|
|
|
|
do {
|
|
|
|
if (!_csDataLoaded) {
|
|
|
|
DataTokenizer t(_csDataBuf, _csDataSize);
|
|
|
|
bool found = t.findIndex(_locationNum);
|
|
|
|
assert(found);
|
|
|
|
for (int i = 0; i < _nextAction; ++i) {
|
|
|
|
found = t.findNextToken(kDataTokenDw);
|
|
|
|
assert(found);
|
|
|
|
}
|
2009-02-21 11:29:56 +00:00
|
|
|
_forceRedrawPanelItems = true;
|
2008-11-10 20:38:54 +00:00
|
|
|
_panelState = 1;
|
|
|
|
setCursorType(2);
|
|
|
|
_tableInstructionsPtr = _csDataBuf + t._pos + 1;
|
|
|
|
_csDataLoaded = true;
|
2009-02-21 11:29:56 +00:00
|
|
|
_csDataHandled = true;
|
2008-11-23 03:42:01 +00:00
|
|
|
debug(2, "loadActionsTable() _nextAction %d", _nextAction);
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
2009-05-17 13:25:08 +00:00
|
|
|
if (_stopActionOnSpeechFlag && _charSpeechSoundCounter > 0) {
|
2008-11-10 20:38:54 +00:00
|
|
|
break;
|
|
|
|
}
|
2009-05-17 13:25:08 +00:00
|
|
|
_stopActionOnSpeechFlag = false;
|
|
|
|
if (_stopActionOnPanelLock) {
|
2008-11-10 20:38:54 +00:00
|
|
|
if (_panelLockedFlag) {
|
|
|
|
break;
|
|
|
|
}
|
2009-05-17 13:25:08 +00:00
|
|
|
_stopActionOnPanelLock = false;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
if (_stopActionCounter > 0) {
|
|
|
|
--_stopActionCounter;
|
|
|
|
break;
|
|
|
|
}
|
2009-02-21 11:29:56 +00:00
|
|
|
if (_stopActionOnSoundFlag) {
|
2008-11-10 20:38:54 +00:00
|
|
|
if (isSoundPlaying(_soundInstructionIndex)) {
|
|
|
|
break;
|
|
|
|
}
|
2009-02-21 11:29:56 +00:00
|
|
|
_stopActionOnSoundFlag = false;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
if (_csDataTableCount != 0) {
|
|
|
|
if (_csDataTableCount == 99) {
|
|
|
|
if (_backgroundSpriteCurrentAnimation > -1) {
|
|
|
|
if (_backgroundSpriteCurrentFrame != _backgroundSpriteLastFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_spriteAnimationFramesTable[_spriteAnimationFrameIndex] != 999) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (_spritesTable[_csDataTableCount - 1].firstFrame - 1 != _spritesTable[_csDataTableCount - 1].animationFrame) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2009-05-17 13:25:08 +00:00
|
|
|
_csDataTableCount = 0;
|
2008-11-10 20:38:54 +00:00
|
|
|
}
|
|
|
|
if (_conversationOptionsCount != 0) {
|
2008-11-16 20:51:10 +00:00
|
|
|
if (_leftMouseButtonPressed && _nextTableToLoadIndex != -1) {
|
2008-11-10 20:38:54 +00:00
|
|
|
_nextAction = _nextTableToLoadTable[_nextTableToLoadIndex];
|
|
|
|
_csDataLoaded = false;
|
|
|
|
_conversationOptionsCount = 0;
|
|
|
|
setCursorType(2);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2009-05-14 23:09:04 +00:00
|
|
|
do {
|
|
|
|
table = executeTableInstruction();
|
|
|
|
} while (table == 0);
|
2008-11-10 20:38:54 +00:00
|
|
|
} while (table == 3);
|
|
|
|
if (table == 2) {
|
|
|
|
_nextAction = 0;
|
|
|
|
_csDataLoaded = false;
|
2009-02-21 11:29:56 +00:00
|
|
|
_forceRedrawPanelItems = true;
|
2008-11-10 20:38:54 +00:00
|
|
|
_panelState = 0;
|
|
|
|
setCursorType(0);
|
2009-02-21 11:29:56 +00:00
|
|
|
_csDataHandled = false;
|
2009-10-11 09:25:31 +00:00
|
|
|
_actionVerbLocked = 0;
|
2008-11-10 20:38:54 +00:00
|
|
|
_mouseClick = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Tucker
|