2004-01-06 13:44:17 +00:00
|
|
|
/* Copyright (C) 1994-2004 Revolution Software Ltd
|
2003-07-28 01:44:38 +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
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*
|
|
|
|
* $Header$
|
|
|
|
*/
|
|
|
|
|
2003-11-16 14:18:29 +00:00
|
|
|
#include "common/stdafx.h"
|
2003-10-28 19:51:30 +00:00
|
|
|
#include "sword2/sword2.h"
|
2004-02-05 14:19:07 +00:00
|
|
|
#include "sword2/resman.h"
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-10-04 00:52:27 +00:00
|
|
|
namespace Sword2 {
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the first palette entry, given the pointer to the start
|
|
|
|
* of the screen file.
|
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *Sword2Engine::fetchPalette(byte *screenFile) {
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *palette = (byte *) mscreenHeader + mscreenHeader->palette;
|
2003-09-19 13:55:19 +00:00
|
|
|
|
|
|
|
// Always set colour 0 to black, because while most background screen
|
|
|
|
// palettes have a bright colour 0 it should come out as black in the
|
|
|
|
// game.
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 13:55:19 +00:00
|
|
|
palette[0] = 0;
|
|
|
|
palette[1] = 0;
|
|
|
|
palette[2] = 0;
|
2003-07-28 01:44:38 +00:00
|
|
|
palette[3] = 0;
|
|
|
|
|
|
|
|
return palette;
|
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the start of the palette match table, given the pointer
|
|
|
|
* to the start of the screen file.
|
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *Sword2Engine::fetchPaletteMatchTable(byte *screenFile) {
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
return (byte *) mscreenHeader + mscreenHeader->paletteTable;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the screen header, given the pointer to the start of
|
|
|
|
* the screen file.
|
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
ScreenHeader *Sword2Engine::fetchScreenHeader(byte *screenFile) {
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
|
2004-04-23 07:02:11 +00:00
|
|
|
ScreenHeader *screenHeader = (ScreenHeader *) ((byte *) mscreenHeader + mscreenHeader->screen);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-07 03:18:27 +00:00
|
|
|
return screenHeader;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the requested layer header, given the pointer to the
|
|
|
|
* start of the screen file. Drops out if the requested layer number exceeds
|
|
|
|
* the number of layers on this screen.
|
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
LayerHeader *Sword2Engine::fetchLayerHeader(byte *screenFile, uint16 layerNo) {
|
2003-07-30 19:25:31 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-12-28 15:08:12 +00:00
|
|
|
ScreenHeader *screenHead = fetchScreenHeader(screenFile);
|
2003-09-07 03:18:27 +00:00
|
|
|
|
2003-09-19 13:55:19 +00:00
|
|
|
if (layerNo > screenHead->noLayers - 1)
|
2003-11-03 07:47:42 +00:00
|
|
|
error("fetchLayerHeader(%d) invalid layer number!", layerNo);
|
2003-07-28 01:44:38 +00:00
|
|
|
#endif
|
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
LayerHeader *layerHeader = (LayerHeader *) ((byte *) mscreenHeader + mscreenHeader->layers + (layerNo * sizeof(LayerHeader)));
|
2003-09-07 03:18:27 +00:00
|
|
|
|
|
|
|
return layerHeader;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the start of the shading mask, given the pointer to the
|
|
|
|
* start of the screen file.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *Sword2Engine::fetchShadingMask(byte *screenFile) {
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
return (byte *) mscreenHeader + mscreenHeader->maskOffset;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the anim header, given the pointer to the start of the
|
|
|
|
* anim file.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
AnimHeader *Sword2Engine::fetchAnimHeader(byte *animFile) {
|
2003-12-28 15:08:12 +00:00
|
|
|
return (AnimHeader *) (animFile + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the requested frame number's cdtEntry, given the
|
|
|
|
* pointer to the start of the anim file. Drops out if the requested frame
|
|
|
|
* number exceeds the number of frames in this anim.
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
CdtEntry *Sword2Engine::fetchCdtEntry(byte *animFile, uint16 frameNo) {
|
2003-12-28 15:08:12 +00:00
|
|
|
AnimHeader *animHead = fetchAnimHeader(animFile);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-07-30 19:25:31 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-09-19 13:55:19 +00:00
|
|
|
if (frameNo > animHead->noAnimFrames - 1)
|
2003-11-03 07:47:42 +00:00
|
|
|
error("fetchCdtEntry(animFile,%d) - anim only %d frames", frameNo, animHead->noAnimFrames);
|
2003-07-28 01:44:38 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
return (CdtEntry *) ((byte *) animHead + sizeof(AnimHeader) + frameNo * sizeof(CdtEntry));
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-07 03:18:27 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the requested frame number's header, given the pointer
|
|
|
|
* to the start of the anim file. Drops out if the requested frame number
|
|
|
|
* exceeds the number of frames in this anim
|
|
|
|
*/
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
FrameHeader *Sword2Engine::fetchFrameHeader(byte *animFile, uint16 frameNo) {
|
2003-07-28 01:44:38 +00:00
|
|
|
// required address = (address of the start of the anim header) + frameOffset
|
2003-12-28 15:08:12 +00:00
|
|
|
return (FrameHeader *) (animFile + sizeof(StandardHeader) + fetchCdtEntry(animFile, frameNo)->frameOffset);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
/**
|
|
|
|
* Returns a pointer to the requested parallax layer data.
|
|
|
|
*/
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
Parallax *Sword2Engine::fetchBackgroundParallaxLayer(byte *screenFile, int layer) {
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-07-30 19:25:31 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-09-12 18:52:53 +00:00
|
|
|
if (mscreenHeader->bg_parallax[layer] == 0)
|
2003-11-03 07:47:42 +00:00
|
|
|
error("fetchBackgroundParallaxLayer(%d) - No parallax layer exists", layer);
|
2003-07-28 01:44:38 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
return (Parallax *) ((byte *) mscreenHeader + mscreenHeader->bg_parallax[layer]);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
Parallax *Sword2Engine::fetchBackgroundLayer(byte *screenFile) {
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-07-30 19:25:31 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-09-12 18:52:53 +00:00
|
|
|
if (mscreenHeader->screen == 0)
|
2003-11-03 07:47:42 +00:00
|
|
|
error("fetchBackgroundLayer (%d) - No background layer exists");
|
2003-07-28 01:44:38 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
return (Parallax *) ((byte *) mscreenHeader + mscreenHeader->screen + sizeof(ScreenHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
Parallax *Sword2Engine::fetchForegroundParallaxLayer(byte *screenFile, int layer) {
|
2003-12-28 15:08:12 +00:00
|
|
|
MultiScreenHeader *mscreenHeader = (MultiScreenHeader *) (screenFile + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-07-30 19:25:31 +00:00
|
|
|
#ifdef _SWORD2_DEBUG
|
2003-09-12 18:52:53 +00:00
|
|
|
if (mscreenHeader->fg_parallax[layer] == 0)
|
2003-11-03 07:47:42 +00:00
|
|
|
error("fetchForegroundParallaxLayer(%d) - No parallax layer exists", layer);
|
2003-07-28 01:44:38 +00:00
|
|
|
#endif
|
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
return (Parallax *) ((byte *) mscreenHeader + mscreenHeader->fg_parallax[layer]);
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
static byte errorLine[128];
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
byte *Sword2Engine::fetchTextLine(byte *file, uint32 text_line) {
|
2003-12-28 15:08:12 +00:00
|
|
|
StandardHeader *fileHeader;
|
2003-09-19 13:55:19 +00:00
|
|
|
uint32 *point;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-28 15:08:12 +00:00
|
|
|
TextHeader *text_header = (TextHeader *) (file + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-26 10:07:18 +00:00
|
|
|
if (text_line >= text_header->noOfLines) {
|
2003-12-28 15:08:12 +00:00
|
|
|
fileHeader = (StandardHeader *) file;
|
2003-10-05 15:28:15 +00:00
|
|
|
sprintf((char *) errorLine, "xxMissing line %d of %s (only 0..%d)", text_line, fileHeader->name, text_header->noOfLines - 1);
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-09-19 13:55:19 +00:00
|
|
|
|
|
|
|
// first 2 chars are NULL so that actor-number comes out as '0'
|
|
|
|
errorLine[0] = 0;
|
|
|
|
errorLine[1] = 0;
|
|
|
|
return errorLine;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
|
|
|
|
2003-11-03 07:47:42 +00:00
|
|
|
// point to the lookup table
|
2003-10-05 15:28:15 +00:00
|
|
|
point = (uint32 *) text_header + 1;
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
return (byte *) (file + READ_LE_UINT32(point + text_line));
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
|
|
|
|
2003-10-18 08:11:50 +00:00
|
|
|
// Used for testing text & speech (see fnISpeak in speech.cpp)
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-23 07:02:11 +00:00
|
|
|
bool Sword2Engine::checkTextLine(byte *file, uint32 text_line) {
|
2003-12-28 15:08:12 +00:00
|
|
|
TextHeader *text_header = (TextHeader *) (file + sizeof(StandardHeader));
|
2003-07-28 01:44:38 +00:00
|
|
|
|
2003-12-11 13:08:36 +00:00
|
|
|
return text_line < text_header->noOfLines;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-24 12:29:35 +00:00
|
|
|
byte *Sword2Engine::fetchObjectName(int32 resourceId, byte *buf) {
|
|
|
|
StandardHeader *header = (StandardHeader *) _resman->openResource(resourceId);
|
2003-09-19 13:55:19 +00:00
|
|
|
|
2004-04-24 12:29:35 +00:00
|
|
|
memcpy(buf, header->name, NAME_LEN);
|
|
|
|
_resman->closeResource(resourceId);
|
|
|
|
return buf;
|
2003-07-28 01:44:38 +00:00
|
|
|
}
|
2003-10-04 00:52:27 +00:00
|
|
|
|
|
|
|
} // End of namespace Sword2
|