Commit 1174dd9f authored by alistert's avatar alistert

Tidied cutscene code. Fixed text positioning and broken characters.

parent 2334cb55
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
* Part of the OpenJazz project * Part of the OpenJazz project
* *
* *
* Copyright (c) 2005-2009 Alister Thomson * Copyright (c) 2005-2010 Alister Thomson
* *
* OpenJazz is distributed under the terms of * OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0 * the GNU General Public License, version 2.0
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include "io/sound.h" #include "io/sound.h"
#include "level/level.h" #include "level/level.h"
#include "player/player.h" #include "player/player.h"
#include "scene.h" #include "scene/scene.h"
Game::Game () { Game::Game () {
......
...@@ -321,10 +321,8 @@ void File::loadPalette (SDL_Color *palette) { ...@@ -321,10 +321,8 @@ void File::loadPalette (SDL_Color *palette) {
// Palette entries are 6-bit // Palette entries are 6-bit
// Shift them upwards to 8-bit, and fill in the lower 2 bits // Shift them upwards to 8-bit, and fill in the lower 2 bits
palette[count].r = (buffer[count * 3] << 2) + (buffer[count * 3] >> 4); palette[count].r = (buffer[count * 3] << 2) + (buffer[count * 3] >> 4);
palette[count].g = (buffer[(count * 3) + 1] << 2) + palette[count].g = (buffer[(count * 3) + 1] << 2) + (buffer[(count * 3) + 1] >> 4);
(buffer[(count * 3) + 1] >> 4); palette[count].b = (buffer[(count * 3) + 2] << 2) + (buffer[(count * 3) + 2] >> 4);
palette[count].b = (buffer[(count * 3) + 2] << 2) +
(buffer[(count * 3) + 2] >> 4);
} }
......
...@@ -313,7 +313,6 @@ Font::~Font () { ...@@ -313,7 +313,6 @@ Font::~Font () {
} }
int Font::showString (const char * s, int x, int y) { int Font::showString (const char * s, int x, int y) {
SDL_Rect src, dst; SDL_Rect src, dst;
...@@ -340,8 +339,6 @@ int Font::showString (const char * s, int x, int y) { ...@@ -340,8 +339,6 @@ int Font::showString (const char * s, int x, int y) {
// Determine the character's position on the screen // Determine the character's position on the screen
src.w = w[(int)(map[(int)(s[count])])]; src.w = w[(int)(map[(int)(s[count])])];
if(s[count] == 32) src.w >>= 1;
dst.y = yOffset; dst.y = yOffset;
dst.x = xOffset; dst.x = xOffset;
...@@ -352,7 +349,8 @@ int Font::showString (const char * s, int x, int y) { ...@@ -352,7 +349,8 @@ int Font::showString (const char * s, int x, int y) {
// Draw the character to the screen // Draw the character to the screen
SDL_BlitSurface(surface, &src, canvas, &dst); SDL_BlitSurface(surface, &src, canvas, &dst);
xOffset += src.w-1; xOffset += src.w;
} }
} }
...@@ -362,7 +360,45 @@ int Font::showString (const char * s, int x, int y) { ...@@ -362,7 +360,45 @@ int Font::showString (const char * s, int x, int y) {
} }
int Font::showSceneString (const char * s, int x, int y) {
SDL_Rect src, dst;
unsigned int count;
int xOffset;
// Determine the characters' dimensions
src.x = 0;
src.h = h;
// Determine the position at which to draw the first character
xOffset = x;
// Go through each character of the string
for (count = 0; s[count]; count++) {
// Determine the character's position on the screen
src.w = w[(int)(s[count])];
if (s[count] == 0x7F) src.w -= 3;
dst.y = y;
dst.x = xOffset;
// Determine the character's position in the font
if (s[count] >= 0) src.y = s[count] * h;
else src.y = 0;
// Draw the character to the screen
SDL_BlitSurface(surface, &src, canvas, &dst);
xOffset += src.w - 1;
}
return xOffset;
}
void Font::showNumber (int n, int x, int y) { void Font::showNumber (int n, int x, int y) {
SDL_Rect src, dst; SDL_Rect src, dst;
...@@ -471,29 +507,38 @@ int Font::getHeight () { ...@@ -471,29 +507,38 @@ int Font::getHeight () {
} }
int Font::getStringWidth (const char *string) { int Font::getStringWidth (const char *string) {
int count;
int stringWidth = 0;
// Go through each character of the string
for (count = 0; string[count]; count++) {
// Only get the width of the first line
if (string[count] == '\n') return stringWidth;
stringWidth += w[(int)(string[count])];
}
return stringWidth;
}
int Font::getSceneStringWidth (const char *string) {
int count; int count;
int stringWidth = 0; int width, stringWidth = 0;
// Go through each character of the string // Go through each character of the string
for (count = 0; string[count]; count++) { for (count = 0; string[count]; count++) {
if (string[count] == '\n') { width = w[(int)(string[count])];
if (string[count] == 0x7F) width -= 3;
} else {
int width = w[(int)(map[(int)(string[count])])];
if (string[count] == ' ') { stringWidth += width - 1;
width = width >> 1;
}
stringWidth += width - 1;
}
} }
......
...@@ -42,17 +42,18 @@ class Font { ...@@ -42,17 +42,18 @@ class Font {
char map[128]; // Maps ASCII values to letter positions char map[128]; // Maps ASCII values to letter positions
public: public:
Font (const char *fileName); Font (const char *fileName);
Font (File *file, bool big); Font (File *file, bool big);
~Font (); ~Font ();
int showString (const char *s, int x, int y); int showString (const char *s, int x, int y);
void showNumber (int n, int x, int y); int showSceneString (const char *s, int x, int y);
void mapPalette (int start, int length, int newStart, void showNumber (int n, int x, int y);
int newLength); void mapPalette (int start, int length, int newStart, int newLength);
void restorePalette (); void restorePalette ();
int getHeight (); int getHeight ();
int getStringWidth (const char *string); int getStringWidth (const char *string);
int getSceneStringWidth (const char *string);
}; };
// Variables // Variables
......
/* /*
* *
* guardians.cpp * bridge.cpp
* *
* 2nd March 2010: Created bridge.cpp from parts of event.cpp and eventframe.cpp * 2nd March 2010: Created bridge.cpp from parts of event.cpp and eventframe.cpp
* *
......
...@@ -49,7 +49,7 @@ ...@@ -49,7 +49,7 @@
#include "io/sound.h" #include "io/sound.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "player/player.h" #include "player/player.h"
#include "scene.h" #include "scene/scene.h"
#include <string.h> #include <string.h>
......
...@@ -43,7 +43,7 @@ ...@@ -43,7 +43,7 @@
#include "level/level.h" #include "level/level.h"
#include "menu/menu.h" #include "menu/menu.h"
#include "player/player.h" #include "player/player.h"
#include "scene.h" #include "scene/scene.h"
#include <string.h> #include <string.h>
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
#include "io/sound.h" #include "io/sound.h"
#include "level/level.h" #include "level/level.h"
#include "player/player.h" #include "player/player.h"
#include "scene.h" #include "scene/scene.h"
int Menu::main () { int Menu::main () {
......
/*
*
* scene.cpp
*
* 23rd August 2005: Created scene.c
* 3rd February 2009: Created scene.h from parts of scene.c
* 3rd February 2009: Renamed scene.c to scene.cpp
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*
* Deals with the loading, displaying and freeing of the cutscenes.
*
*/
#include "scene.h"
#include "io/controls.h"
#include "io/file.h"
#include "io/gfx/video.h"
#include "io/gfx/font.h"
#include "io/sound.h"
#include "io/gfx/paletteeffects.h"
#include <string.h>
/**
* This is the 0sc format
* Offset, Size (hex), type
* 0, 0x13, "Digital Dimensions\1a" header
* 0x13, 0x04, Offset to datablock
* 0x17, 0x02, Number of script items
* 0x19, 0x4* Number of script items, Offset to Scripts
*
* ----, 0x02 Number of data items
* * 0x19, 0x4* Number of script items, Offset to datablocks
*
*/
// These are the known script types
enum
{
ESceneMusic = 0x2A,
ESceneFadeType = 0x3F,
ESceneTextBlock = 0x40,
ESceneTextColour = 0x41,
ESceneFontFun = 0x45,
ESceneFontIndex = 0x46,
ESceneTextPosition = 0x47,
ESceneTextAlign = 0x4A,
ESceneTextAlign2 = 0x4B,
ESceneBackground =0x4c,
ESceneBreaker = 0x50,
ESceneSomethingElse = 0x51,
ESceneTextRect = 0x57,
ESceneFontDefine = 0x58,
ESceneTime = 0x5d,
ESceneTextLine = 0x5e,
ESceneTextVAdjust = 0x5f,
ESceneAnimationIndex = 0xA7,
ESceneAnimationSetting = 0xA6,
ESceneTextSetting = 0xb1,
ESceneTextSomething = 0xd9,
ESceneTextShadow = 0xdb
};
ImageInfo::ImageInfo() {
image = NULL;
}
ImageInfo::~ImageInfo() {
if(image != NULL) {
SDL_FreeSurface(image);
image = NULL;
}
}
ScriptText::ScriptText() {
x = -1;
y = -1;
textRect.x = -1;
textRect.y = -1;
extraLineHeight = -1;
text = NULL;
}
ScriptText::~ScriptText() {
if (text) delete[] text;
}
ScriptPage::ScriptPage() {
pageTime = 0;
noScriptTexts = 0;
backgrounds = 0;
musicfile = NULL;
paletteIndex = 0;
}
ScriptPage::~ScriptPage() {
if (musicfile) delete[] musicfile;
}
void Scene::ParseAni(File* f, int dataIndex) {
unsigned short int aniType = f->loadShort();// should be 0x02
LOG("ParseAni DataLen", aniType);
unsigned short int aniOffset = f->loadShort();// unknown, number of frames?
LOG("ParseAni Frames?", aniOffset);
unsigned short int type = 0;//
int loop;
while(type != 0x4C50) {
type = f->loadShort();
if(type == 0x4C53) { // SL
/*unsigned short int offset =*/ f->loadShort();
unsigned char noSounds = f->loadChar();
for(loop = 0;loop<noSounds;loop++) {
char* soundName = f->loadString();
LOG("Soundname ", soundName);
delete[] soundName;
}
}
else if(type == 0x4C50) {// PL
int pos = f->tell();
int nextPos = f->tell();
LOG("PL Read position", pos);
unsigned short int len = f->loadShort();
unsigned char* buffer = f->loadBlock(len);
for (int count = 0; count < 256; count++) {
// Palette entries are 6-bit
// Shift them upwards to 8-bit, and fill in the lower 2 bits
paletteInfos[paletteIndex].palette[count].r = (buffer[count * 3] << 2) + (buffer[count * 3] >> 4);
paletteInfos[paletteIndex].palette[count].g = (buffer[(count * 3) + 1] << 2) +
(buffer[(count * 3) + 1] >> 4);
paletteInfos[paletteIndex].palette[count].b = (buffer[(count * 3) + 2] << 2) +
(buffer[(count * 3) + 2] >> 4);
}
delete[] buffer;
paletteInfos[paletteIndex].dataIndex = dataIndex;
paletteIndex++;
unsigned short int value = 0x4646;
int items = 0;
int validValue = true;
pos = f->tell();
LOG("PL Read position start", pos);
while(validValue)
{
value = f->loadShort();
LOG("PL Read block start tag", value);
unsigned short int size= f->loadShort();
LOG("PL Anim block size", size);
nextPos = f->tell();
// next pos is intial position + size and four bytes header
nextPos+=(size);
switch(value)
{
case 0x455F:
validValue = false;
break;
case 0x3131:
{
// Skip back size header, this is read by the surface reader
f->seek(-2, false);
SDL_Surface* image = f->loadSurface(320, 200, true);
SDL_Rect dst;
dst.x = 0;
dst.y = 0;
SDL_BlitSurface(image, NULL, canvas, &dst);
SDL_SetPalette(screen, SDL_PHYSPAL, paletteInfos[paletteIndex-1].palette, 0, 256);
currentPalette = paletteInfos[paletteIndex-1].palette;
}break;
case 0x4c31:
{
int longvalue = f->loadInt();
LOG("PL Anim block value", longvalue);
// Skip back size header, this is read by the surface reader
//f->seek(-2, false);
while(size) {
size--;
unsigned char header = f->loadChar();
LOG("PL 4c31 block header", header);
switch(header)
{
case 0x7F:
{
unsigned short fillWidth = f->loadShort();
unsigned char fillColor = f->loadChar();
LOG("PL Fillblock width", fillWidth);
LOG("PL Fillblock with color", fillColor);
size-=3;
}break;
case 0xff:
{
unsigned char x= f->loadChar();
unsigned char y= f->loadChar();
LOG("PL block x", x);
LOG("PL block y", y);
size-=2;
}break;
default:
{
LOG("PL Unknown type", header);
}break;
}
}
}break;
case 0x4646:
{
while(size) {
unsigned char header = f->loadChar();
LOG("PL 4646 block header", header);
switch(header)
{
case 0x7F:
{
unsigned short fillWidth = f->loadShort();
unsigned char fillColor = f->loadChar();
LOG("PL Fillblock width", fillWidth);
LOG("PL Fillblock with color", fillColor);
size-=3;
}break;
case 0xff:
{
unsigned char x= f->loadChar();
unsigned char y= f->loadChar();
LOG("PL block x", x);
LOG("PL block y", y);
size-=2;
}break;
default:
{
LOG("PL Unknown type", header);
}break;
}
size--;
}
}break;
case 0x4e52:
case 0x4252:
case 0x4352:
case 0x4c52:
case 0x4e41:
case 0x584d:
case 0x5252:
break;
case 0x5b5d:
{
unsigned char header = f->loadChar();
LOG("PL 5b5d block header", header);
unsigned short int value = f->loadShort();
LOG("PL 5b5d block value", value);
}
break;
case 0x5453:
{
unsigned char soundIndex = f->loadChar();
unsigned char soundNote = f->loadChar();
unsigned char soundOffset = f->loadChar();
LOG("PL Audio tag with index", soundIndex);
LOG("PL Audio tag play at ", soundNote);
LOG("PL Audio tag play offset ", soundOffset);
}
break;
case 0:
{
int longvalue = f->loadInt();
while(longvalue == 0) {
longvalue = f->loadInt();
nextPos+=4;
}
f->seek(-4, false);
value = longvalue;
}
break;
default:
LOG("PL Read Unknown type", value);
validValue = false;
break;
}
pos = f->tell();
LOG("PL Read position after block should be", nextPos);
f->seek(nextPos, true);
if(validValue) {
items++;
}
}
LOG("PL Parsed through number of items skipping 0 items", items);
pos = f->tell();
LOG("PL Read position after parsing anim blocks", pos);
}
}
}
void Scene::ParseData(File *f) {
int loop;
for(loop = 0;loop < dataItems; loop++) {
f->seek(dataOffsets[loop], true); // Seek to data start
unsigned short int dataLen = f->loadShort(); // Get get the length of the datablock
LOG("Data dataLen", dataLen);
// AN
if(dataLen == 0x4e41) {
LOG("Data Type", "ANI");
ParseAni(f, loop);
}
else {
unsigned char type = f->loadChar();
LOG("Data Type", type);
switch(type)
{
case 3:
case 4: // image
case 5:
case 6:
{
LOG("Data Type", "Image");
LOG("Data Type Image index", loop);
unsigned short int width = f->loadShort(); // get width
unsigned short int height;
if(type == 3)
height = f->loadChar(); // Get height
else
height = f->loadShort(); // Get height
if(imageIndex<100) {
f->seek(-2, false);
imageInfos[imageIndex].image = f->loadSurface(width, height);
imageInfos[imageIndex].dataIndex = loop;
imageIndex++;
}
}break;
default:
{
LOG("Data Type", "Palette");
LOG("Data Type Palette index", loop);
f->seek(-3, false);
f->loadPalette(paletteInfos[paletteIndex].palette);
paletteInfos[paletteIndex].dataIndex = loop;
paletteIndex++;
}
break;
}
}
}
}
void Scene::ParseScripts(File *f) {
int loop;
char *string;
/*int bgIndex = 0;*/
int textAlignment = 0;
int textFont = 0;
for(loop = 0;loop < scriptItems; loop++)
{
LOG("\nParse Script", loop);
int textPosX = -1;
int textPosY = -1;
int extraheight = -1;
SDL_Rect textRect;
bool textRectValid = false;
f->seek(scriptStarts[loop], true); // Seek to data start
if(f->loadChar() == 0x50) { // Script tag
unsigned short int scriptid = f->loadShort();
LOG("Script id:", scriptid);
int palette = f->loadShort();
LOG("Script default palette", palette);
scriptPages[loop].paletteIndex = palette;
unsigned char type = 0;
bool breakloop = false;
int pos = f->tell();
while(!breakloop && pos< dataOffsets[0]) {
type = f->loadChar();
switch(type)
{
case ESceneAnimationSetting:
{
signed long int something = f->loadInt();
signed long int something2 = f->loadInt();
LOG("ESceneAnimationSetting1", something);
LOG("ESceneAnimationSetting2", something2);
}break;
case ESceneAnimationIndex:
{
unsigned char aniIndex = f->loadChar();
LOG("ESceneAnimationIndex:", aniIndex);
}break;
case ESceneFadeType:
{
unsigned char fadein = f->loadChar();
LOG("ESceneFadeType:", fadein);
}break;
case ESceneBackground:
{
unsigned short int xpos = f->loadShort();
unsigned short int ypos = f->loadShort();
unsigned short bgImageIndex = f->loadShort();
LOG("ESceneBackground: index", bgImageIndex);
LOG("ESceneBackground: xpos", xpos);
LOG("ESceneBackground: ypos", ypos);
scriptPages[loop].bgIndex[scriptPages[loop].backgrounds] = bgImageIndex;
scriptPages[loop].bgPos[scriptPages[loop].backgrounds] = xpos|(ypos<<16);
scriptPages[loop].backgrounds++;
}break;
case ESceneMusic:
{
// Music file name
string = f->loadString();
LOG("ESceneMusic: ", string);
scriptPages[loop].musicfile = createString(string);
delete[] string;
}break;
case ESceneSomethingElse:
{
unsigned char value = 0;//f->loadChar();
LOG("ESceneSomethingElse", value);
}break;
case ESceneTextRect: // String
{
unsigned short x = textRect.x = f->loadShort();
unsigned short y = textRect.y = f->loadShort();
unsigned short w = textRect.w = (f->loadShort()-x);
unsigned short h = textRect.h = (f->loadShort()-y);
textRectValid = true;
LOG("Text rectangle xpos:", x);
LOG("Text rectangle ypos:", y);
LOG("Text rectangle w:", w);
LOG("Text rectangle h:", h);
}break;
case ESceneFontDefine: // Font defnition
{
unsigned short fontid = f->loadShort();
char* fontname = f->loadString();
LOG("ESceneFontDefine", fontname);
LOG("ESceneFontDefine with id=", fontid);
if(strcmp(fontname, "FONT2") == 0)
{
scriptFonts[noScriptFonts].fontType = EFONT2Type;
}
else if(strcmp(fontname, "FONTBIG") == 0)
{
scriptFonts[noScriptFonts].fontType = EFONTBIGType;
}
else if(strcmp(fontname, "FONTTINY") == 0)
{
scriptFonts[noScriptFonts].fontType = EFONTINYType;
}
else if(strcmp(fontname, "FONTMN1") == 0)
{
scriptFonts[noScriptFonts].fontType = EFONTMN1Type;
}
else if(strcmp(fontname, "FONTMN2") == 0)
{
scriptFonts[noScriptFonts].fontType = EFONTMN2Type;
}
scriptFonts[noScriptFonts].fontId = fontid;
noScriptFonts++;
delete[] fontname;
}break;
case ESceneTextPosition:
{
unsigned short newx = f->loadShort();
unsigned short newy = f->loadShort();
LOG("TextPosition x", newx);
LOG("TextPosition y", newy);
textPosX = newx;
textPosY = newy;
}
break;
case ESceneTextColour:
{
unsigned short value = f->loadShort();
LOG("ESceneTextColour", value);
}
break;
case ESceneFontFun:
{
unsigned short len = f->loadShort();
LOG("ESceneFontFun len", len);
/*while(len)
{
unsigned char data = f->loadChar();
len--;
}*/
}break;
case ESceneFontIndex:
{
unsigned short value = f->loadShort();
LOG("ESceneFontIndex", value);
textFont = value;
}
break;
case ESceneTextVAdjust:
{
unsigned short value = f->loadShort();
LOG("ESceneTextVAdjust", value);
extraheight = value;
}
break;
case ESceneTextSetting:
{
unsigned short value = f->loadShort();
LOG("ESceneTextSetting", value);
}break;
case ESceneTextShadow:
{
unsigned short value = f->loadShort();
LOG("ESceneTextVAdjust", value);
}break;
case ESceneTextAlign:
{
unsigned char alignment = f->loadChar();
LOG("ESceneTextAlign", alignment);
textAlignment = alignment;
}break;
case ESceneTextAlign2:
{
unsigned char a = f->loadChar();
unsigned short b = f->loadShort();
LOG("ESceneTextAlign2 a", a);
LOG("ESceneTextAlign2 b", b);
}break;
case ESceneTextSomething:
{
unsigned char a = f->loadChar();
unsigned short b = f->loadShort();
LOG("ESceneTextSomething a", a);
LOG("ESceneTextSomething b", b);
}break;
case ESceneTextLine:
case ESceneTextBlock:
{
unsigned char datalen = f->loadChar();
unsigned char* block = f->loadBlock(datalen);
unsigned char pos = 0;
unsigned char orgdatalen = datalen;
char pagebuf[3];
LOG("Text len=", datalen);
// Convert to ascii
while(datalen>0) {
if(block[pos] == 0x8b) {
sprintf(pagebuf, "%2d", loop+1);
memcpy(&block[pos-1], pagebuf,2);
}
else if(block[pos] == 0x8a) {
sprintf(pagebuf, "%2d", scriptItems);
memcpy(&block[pos-1], pagebuf,2);
}
else if(block[pos] == 'C') {
block[pos]=' ';
}
else if(block[pos]>='a'-70 && block[pos]<='z'-70) {
block[pos]+=70;
}
else if(block[pos]>='A'-64 && block[pos]<='Z'-64) {
block[pos]+=64;
}
else if(block[pos]>='0'+5 && block[pos]<='9'+5) {
block[pos]-=5;
}
else if(block[pos] == 0x7f) {
block[pos]=' ';
}
else if(block[pos] == 0x73) {
block[pos]='\'';
}
else if(block[pos] == 'r') {
block[pos]=':';
}
else if(block[pos] == 'o') {
block[pos]='(';
}
else if(block[pos] == 'p') {
block[pos]=')';
}
else if(block[pos] == 0x6b) {
block[pos]='!';
}
else if(block[pos] == 0x68) {
block[pos]='-';
}
else if(block[pos] == 0x67) {
block[pos]='?';
}
else if(block[pos] == 0x66) {
block[pos]='.';
}
else if(block[pos] == 0x65) {
block[pos]=',';
}
else if(block[pos] == '?') {
block[pos]='$';
}
else if(block[pos] == 't') {
block[pos]='\'';
}
pos++;
datalen--;
}
if(orgdatalen > 0) {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text = new char[orgdatalen + 1];
memcpy(scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text, block, orgdatalen);
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text[orgdatalen] = 0;
LOG("Text data",(char*) scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text);
}
else {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text = new char[1];
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text[0] = 0;
LOG("Text data", "Empty line");
}
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].alignment = textAlignment;
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].fontId = textFont;
if(textPosX != -1) {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].x = textPosX;
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].y = textPosY;
textPosX = -1;
textPosY = -1;
}
if(textRectValid)
{
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].textRect = textRect;
textRectValid = false;
}
if(extraheight != -1)
{
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].extraLineHeight = extraheight;
extraheight = -1;
}
scriptPages[loop].noScriptTexts++;
}break;
case ESceneTime:
{
unsigned short int sceneTime = f->loadShort();
LOG("Scene time",sceneTime&255);
scriptPages[loop].pageTime = sceneTime&255;
}
break;
case ESceneBreaker:
case 0x3e:
pos = f->tell();
LOG("Parse script end at position", pos);
LOG("Parse script end with", type);
breakloop = true;
f->loadChar();
break;
default:
{
pos = f->tell();
LOG("Parse script end at position", pos);
LOG("Parse script breaker", type);
breakloop = true;
}
break;
}
pos = f->tell();
}
}
}
}
Scene::Scene (const char * fileName) {
File *file;
int loop;
noScriptFonts = 0;
LOG("\nScene", fileName);
try {
file = new File(fileName, false);
} catch (int e) {
throw e;
}
imageIndex = 0;
paletteIndex = 0;
file->seek(0x13, true); // Skip Digital Dimensions header
signed long int dataOffset = file->loadInt(); //get offset pointer to first data block
scriptItems = file->loadShort(); // Get number of script items
scriptStarts = new signed long int[scriptItems];
scriptPages = new ScriptPage[scriptItems];
LOG("Scene: Script items", scriptItems);
for(loop = 0;loop < scriptItems; loop++) {
scriptStarts[loop] = file->loadInt();// Load offset to script
LOG("scriptStart:", scriptStarts[loop]);
}
// Seek to datastart now
file->seek(dataOffset, true); // Seek to data offsets
dataItems = file->loadShort()+1; // Get number of data items
LOG("Scene: Data items", dataItems);
dataOffsets = new signed long int[dataItems];
for(loop = 0;loop < dataItems; loop++) {
dataOffsets[loop] = file->loadInt();// Load offset to script
LOG("dataOffsets:", dataOffsets[loop]);
}
ParseData(file);
ParseScripts(file);
delete []scriptStarts;
delete []dataOffsets;
delete file;
return;
}
Scene::~Scene () {
delete []scriptPages;
}
ImageInfo* Scene::FindImage(int dataIndex) {
int loop = 0;
while(loop<imageIndex)
{
if(imageInfos[loop].dataIndex == dataIndex)
{
return &imageInfos[loop];
}
loop++;
}
return NULL;
}
int Scene::play () {
SDL_Rect dst;
unsigned int sceneIndex = 0;
ImageInfo* imageInfo;
unsigned int pageTime = scriptPages[sceneIndex].pageTime;
unsigned int lastTicks = globalTicks;
int newpage = true;
int fadein = false;
SDL_Rect textRect = {0,0,320,200};
while (true) {
if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT;
if (controls.release(C_ESCAPE)) {
return E_NONE;
}
SDL_Delay(T_FRAME);
int upOrLeft = (controls.release(C_UP) || controls.release(C_LEFT));
if((sceneIndex > 0 && upOrLeft) || controls.release(C_RIGHT) || controls.release(C_DOWN) || controls.release(C_ENTER) ||
((globalTicks-lastTicks)>=pageTime*1000 && pageTime != 256 && pageTime != 0)) {
if(upOrLeft) {
sceneIndex--;
}
else {
sceneIndex++;
}
if(sceneIndex == scriptItems) {
return E_NONE;
}
lastTicks = globalTicks;
// Get bg for this page
newpage = true;
pageTime = scriptPages[sceneIndex].pageTime;
}
if(newpage) {
//firstPE = new FadeOutPaletteEffect(250, firstPE);
textRect.x = 0;
textRect.y = 0;
textRect.w = 320;
textRect.h = 200;
PaletteInfo* paletteInfo = NULL;
for(int palette = 0;palette<paletteIndex;palette++) {
if(paletteInfos[palette].dataIndex == scriptPages[sceneIndex].paletteIndex) {
paletteInfo = &paletteInfos[palette];
break;
}
}
if(paletteInfo != NULL) {
// usePalette(paletteInfo->palette);
currentPalette = paletteInfo->palette;
fadein = true;
}
else {
restorePalette(screen);
}
newpage = 0;
}
// First draw the backgrounds associated with this page
if(scriptPages[sceneIndex].backgrounds > 0) {
for(int bg = 0;bg<scriptPages[sceneIndex].backgrounds;bg++) {
imageInfo = FindImage(scriptPages[sceneIndex].bgIndex[bg]);
if(imageInfo != NULL) {
dst.x = (scriptPages[sceneIndex].bgPos[bg] & 65535)*2+(canvasW - 320) >> 1;
dst.y = ((scriptPages[sceneIndex].bgPos[bg] & (~65535))>>16)*2+(canvasH - 200) >> 1;
SDL_BlitSurface(imageInfo->image, NULL, canvas, &dst);
}
}
} else {
clearScreen(0);
}
// Draw the texts associated with this page
int x = 0;
int y = 0;
int extraLineHeight = 0;
for (int text = 0; text < scriptPages[sceneIndex].noScriptTexts; text++) {
Font *font = NULL;
int xOffset, yOffset;
for (int index = 0; index < noScriptFonts; index++) {
if (scriptPages[sceneIndex].scriptTexts[text].fontId == scriptFonts[index].fontId) {
switch (scriptFonts[index].fontType) {
case EFONT2Type:
font = font2;
break;
case EFONTBIGType:
font = fontbig;
break;
case EFONTINYType:
font = fontiny;
break;
case EFONTMN1Type:
font = fontmn1;
break;
case EFONTMN2Type:
font = fontmn2;
break;
}
continue;
}
}
if (scriptPages[sceneIndex].scriptTexts[text].x != -1) {
x = scriptPages[sceneIndex].scriptTexts[text].x;
y = scriptPages[sceneIndex].scriptTexts[text].y;
}
if (scriptPages[sceneIndex].scriptTexts[text].textRect.x != -1) {
textRect = scriptPages[sceneIndex].scriptTexts[text].textRect;
x = 0;
y = 0;
}
if (scriptPages[sceneIndex].scriptTexts[text].extraLineHeight != -1) {
extraLineHeight = scriptPages[sceneIndex].scriptTexts[text].extraLineHeight;
}
xOffset = ((canvasW - 320) >> 1) + textRect.x;
yOffset = ((canvasH - 200) >> 1) + textRect.y + y;
switch (scriptPages[sceneIndex].scriptTexts[text].alignment) {
case 0: // left
xOffset += x;
break;
case 1: // right
xOffset += textRect.w - font->getStringWidth(scriptPages[sceneIndex].scriptTexts[text].text);
break;
case 2: // center
xOffset += (textRect.w - font->getStringWidth(scriptPages[sceneIndex].scriptTexts[text].text)) >> 1;
break;
}
// Drop shadow
font->mapPalette(0, 256, 0, 1);
font->showString(scriptPages[sceneIndex].scriptTexts[text].text, xOffset + 1, yOffset + 1);
font->restorePalette();
// Text itself
font->showString(scriptPages[sceneIndex].scriptTexts[text].text, xOffset, yOffset);
y += extraLineHeight + font->getHeight() / 2;
}
// Fade in from black
if (fadein) {
fadein = false;
firstPE = new FadeInPaletteEffect(250, firstPE);
clearScreen(0);
}
}
return E_NONE;
}
/*
*
* scene.h
*
* 3rd February 2009: Created scene.h from parts of scene.c
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2009 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef _SCENE_H
#define _SCENE_H
#include <io/file.h>
#include <SDL/SDL.h>
enum EScriptFontTypes
{
EFONT2Type,
EFONTBIGType,
EFONTINYType,
EFONTMN1Type,
EFONTMN2Type
};
class ScriptFont
{
public:
// This maps to any of the available types (already loaded)
EScriptFontTypes fontType;
// Font id given this font
int fontId;
};
class ScriptText
{
public:
ScriptText();
~ScriptText();
char* text;
int alignment;
int fontId;
int x;
int y;
SDL_Rect textRect;
int extraLineHeight;
};
// Class
class ScriptPage
{
public:
ScriptPage();
~ScriptPage();
int backgrounds;
int bgIndex[30];
unsigned int bgPos[30];
// Length of the scene in seconds, or if zero = anim complete, or 256 = user interaction
int pageTime;
ScriptText scriptTexts[100];
int noScriptTexts;
char* musicfile;
int paletteIndex;
};
class ImageInfo
{
public:
ImageInfo();
~ImageInfo();
// SDL_Surface with the image
SDL_Surface *image;
// data index of the image (not the palette) to compare with scripts
int dataIndex;
};
class PaletteInfo
{
public:
// Palette associated with the image
SDL_Color palette[256];
// data index of the image (not the palette) to compare with scripts
int dataIndex;
};
class Scene {
private:
ImageInfo imageInfos[100];
PaletteInfo paletteInfos[100];
unsigned short int scriptItems;
unsigned short int dataItems;
signed long int* scriptStarts;
signed long int* dataOffsets;
int imageIndex;
int paletteIndex;
// Scripts all information needed to render script pages, text etc
ScriptPage* scriptPages;
ImageInfo* FindImage(int dataIndex);
// DataBlock
protected:
void ParseScripts(File *f);
void ParseData(File *f);
void ParseAni(File* f, int dataIndex);
public:
Scene (const char * fileName);
~Scene ();
int play ();
ScriptFont scriptFonts[5];
int noScriptFonts;
};
#endif
/*
*
* scene.cpp
*
* 23rd August 2005: Created scene.c
* 3rd February 2009: Created scene.h from parts of scene.c
* 3rd February 2009: Renamed scene.c to scene.cpp
* 27th March 2010: Created sceneload.cpp from parts of scene.cpp
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*
* Deals with the displaying and freeing of the cutscenes.
*
*/
#include "scene/scene.h"
#include "io/controls.h"
#include "io/gfx/font.h"
#include "io/gfx/paletteeffects.h"
#include "io/gfx/video.h"
/**
* This is the 0sc format
* Offset, Size (hex), type
* 0, 0x13, "Digital Dimensions\1a" header
* 0x13, 0x04, Offset to datablock
* 0x17, 0x02, Number of script items
* 0x19, 0x4* Number of script items, Offset to Scripts
*
* ----, 0x02 Number of data items
* * 0x19, 0x4* Number of script items, Offset to datablocks
*
*/
ImageInfo::ImageInfo () {
image = NULL;
}
ImageInfo::~ImageInfo () {
if (image != NULL) SDL_FreeSurface(image);
}
ScriptText::ScriptText() {
x = -1;
y = -1;
textRect.x = -1;
textRect.y = -1;
extraLineHeight = -1;
text = NULL;
}
ScriptText::~ScriptText() {
if (text) delete[] text;
}
ScriptPage::ScriptPage() {
pageTime = 0;
noScriptTexts = 0;
backgrounds = 0;
musicfile = NULL;
paletteIndex = 0;
}
ScriptPage::~ScriptPage() {
if (musicfile) delete[] musicfile;
}
Scene::Scene (const char * fileName) {
File *file;
int loop;
noScriptFonts = 0;
LOG("\nScene", fileName);
try {
file = new File(fileName, false);
} catch (int e) {
throw e;
}
imageIndex = 0;
paletteIndex = 0;
file->seek(0x13, true); // Skip Digital Dimensions header
signed long int dataOffset = file->loadInt(); //get offset pointer to first data block
scriptItems = file->loadShort(); // Get number of script items
scriptStarts = new signed long int[scriptItems];
scriptPages = new ScriptPage[scriptItems];
LOG("Scene: Script items", scriptItems);
for (loop = 0; loop < scriptItems; loop++) {
scriptStarts[loop] = file->loadInt();// Load offset to script
LOG("scriptStart:", scriptStarts[loop]);
}
// Seek to datastart now
file->seek(dataOffset, true); // Seek to data offsets
dataItems = file->loadShort() + 1; // Get number of data items
LOG("Scene: Data items", dataItems);
dataOffsets = new signed long int[dataItems];
for (loop = 0; loop < dataItems; loop++) {
dataOffsets[loop] = file->loadInt();// Load offset to script
LOG("dataOffsets:", dataOffsets[loop]);
}
loadData(file);
loadScripts(file);
delete[] scriptStarts;
delete[] dataOffsets;
delete file;
return;
}
Scene::~Scene () {
delete[] scriptPages;
}
ImageInfo * Scene::FindImage (int dataIndex) {
int loop;
for (loop = 0; loop < imageIndex; loop++) {
if (imageInfos[loop].dataIndex == dataIndex) return imageInfos + loop;
}
return NULL;
}
int Scene::play () {
SDL_Rect dst;
unsigned int sceneIndex = 0;
ImageInfo* imageInfo;
unsigned int pageTime = scriptPages[sceneIndex].pageTime;
unsigned int lastTicks = globalTicks;
int newpage = true;
int fadein = false;
SDL_Rect textRect = {0,0,320,200};
while (true) {
if (loop(NORMAL_LOOP) == E_QUIT) return E_QUIT;
if (controls.release(C_ESCAPE)) return E_NONE;
SDL_Delay(T_FRAME);
int upOrLeft = (controls.release(C_UP) || controls.release(C_LEFT));
if ((sceneIndex > 0 && upOrLeft) ||
controls.release(C_RIGHT) || controls.release(C_DOWN) || controls.release(C_ENTER) ||
((globalTicks-lastTicks) >= pageTime * 1000 && pageTime != 256 && pageTime != 0)) {
if (upOrLeft) sceneIndex--;
else sceneIndex++;
if (sceneIndex == scriptItems) return E_NONE;
lastTicks = globalTicks;
// Get bg for this page
newpage = true;
pageTime = scriptPages[sceneIndex].pageTime;
}
if (newpage) {
//firstPE = new FadeOutPaletteEffect(250, firstPE);
textRect.x = 0;
textRect.y = 0;
textRect.w = 320;
textRect.h = 200;
PaletteInfo* paletteInfo = NULL;
for (int palette = 0; palette < paletteIndex; palette++) {
if (paletteInfos[palette].dataIndex == scriptPages[sceneIndex].paletteIndex) {
paletteInfo = &paletteInfos[palette];
break;
}
}
if (paletteInfo != NULL) {
// usePalette(paletteInfo->palette);
currentPalette = paletteInfo->palette;
fadein = true;
} else restorePalette(screen);
newpage = 0;
}
// First draw the backgrounds associated with this page
if (scriptPages[sceneIndex].backgrounds > 0) {
for (int bg = 0; bg < scriptPages[sceneIndex].backgrounds; bg++) {
imageInfo = FindImage(scriptPages[sceneIndex].bgIndex[bg]);
if (imageInfo != NULL) {
dst.x = (scriptPages[sceneIndex].bgPos[bg] & 65535)*2 + (canvasW - 320) >> 1;
dst.y = ((scriptPages[sceneIndex].bgPos[bg] & (~65535))>>16)*2 + (canvasH - 200) >> 1;
SDL_BlitSurface(imageInfo->image, NULL, canvas, &dst);
}
}
} else clearScreen(0);
// Draw the texts associated with this page
int x = 0;
int y = 0;
int extraLineHeight = 0;
for (int text = 0; text < scriptPages[sceneIndex].noScriptTexts; text++) {
Font *font = NULL;
int xOffset, yOffset;
for (int index = 0; index < noScriptFonts; index++) {
if (scriptPages[sceneIndex].scriptTexts[text].fontId == scriptFonts[index].fontId) {
font = scriptFonts[index].font;
continue;
}
}
if (scriptPages[sceneIndex].scriptTexts[text].x != -1) {
x = scriptPages[sceneIndex].scriptTexts[text].x;
y = scriptPages[sceneIndex].scriptTexts[text].y;
}
if (scriptPages[sceneIndex].scriptTexts[text].textRect.x != -1) {
textRect = scriptPages[sceneIndex].scriptTexts[text].textRect;
x = 0;
y = 0;
}
if (scriptPages[sceneIndex].scriptTexts[text].extraLineHeight != -1) {
extraLineHeight = scriptPages[sceneIndex].scriptTexts[text].extraLineHeight;
}
xOffset = ((canvasW - 320) >> 1) + textRect.x + x;
yOffset = ((canvasH - 200) >> 1) + textRect.y + y;
switch (scriptPages[sceneIndex].scriptTexts[text].alignment) {
case 0: // left
break;
case 1: // right
xOffset += textRect.w - font->getSceneStringWidth(scriptPages[sceneIndex].scriptTexts[text].text);
break;
case 2: // center
xOffset += (textRect.w - font->getSceneStringWidth(scriptPages[sceneIndex].scriptTexts[text].text)) >> 1;
break;
}
// Drop shadow
font->mapPalette(0, 256, 0, 1);
font->showSceneString(scriptPages[sceneIndex].scriptTexts[text].text, xOffset + 1, yOffset + 1);
font->restorePalette();
// Text itself
font->showSceneString(scriptPages[sceneIndex].scriptTexts[text].text, xOffset, yOffset);
y += extraLineHeight + font->getHeight() / 2;
}
// Fade in from black
if (fadein) {
fadein = false;
firstPE = new FadeInPaletteEffect(250, firstPE);
clearScreen(0);
}
}
return E_NONE;
}
/*
*
* scene.h
*
* 3rd February 2009: Created scene.h from parts of scene.c
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef _SCENE_H
#define _SCENE_H
#include <io/file.h>
#include <SDL/SDL.h>
// Enums
// These are the known script types
enum {
ESceneMusic = 0x2A,
ESceneFadeType = 0x3F,
ESceneTextBlock = 0x40,
ESceneTextColour = 0x41,
ESceneFontFun = 0x45,
ESceneFontIndex = 0x46,
ESceneTextPosition = 0x47,
ESceneTextAlign = 0x4A,
ESceneTextAlign2 = 0x4B,
ESceneBackground = 0x4c,
ESceneBreaker = 0x50,
ESceneSomethingElse = 0x51,
ESceneTextRect = 0x57,
ESceneFontDefine = 0x58,
ESceneTime = 0x5d,
ESceneTextLine = 0x5e,
ESceneTextVAdjust = 0x5f,
ESceneAnimationIndex = 0xA7,
ESceneAnimationSetting = 0xA6,
ESceneTextSetting = 0xb1,
ESceneTextSomething = 0xd9,
ESceneTextShadow = 0xdb
};
// Classes
class Font;
class ScriptFont {
public:
// This points to any of the available types (already loaded)
Font *font;
// Font id given this font
int fontId;
};
class ScriptText {
public:
char *text;
int alignment;
int fontId;
int x;
int y;
SDL_Rect textRect;
int extraLineHeight;
ScriptText ();
~ScriptText ();
};
class ScriptPage {
public:
int backgrounds;
int bgIndex[30];
unsigned int bgPos[30];
// Length of the scene in seconds, or if zero = anim complete, or 256 = user interaction
int pageTime;
ScriptText scriptTexts[100];
int noScriptTexts;
char *musicfile;
int paletteIndex;
ScriptPage();
~ScriptPage();
};
class ImageInfo {
public:
// SDL_Surface with the image
SDL_Surface *image;
// data index of the image (not the palette) to compare with scripts
int dataIndex;
ImageInfo ();
~ImageInfo ();
};
class PaletteInfo {
public:
// Palette associated with the image
SDL_Color palette[256];
// data index of the image (not the palette) to compare with scripts
int dataIndex;
};
class Scene {
private:
ImageInfo imageInfos[100];
PaletteInfo paletteInfos[100];
unsigned short int scriptItems;
unsigned short int dataItems;
signed long int *scriptStarts;
signed long int *dataOffsets;
int imageIndex;
int paletteIndex;
// Scripts all information needed to render script pages, text etc
ScriptPage *scriptPages;
void loadScripts (File *f);
void loadData (File *f);
void loadAni (File* f, int dataIndex);
ImageInfo * FindImage (int dataIndex);
public:
ScriptFont scriptFonts[5];
int noScriptFonts;
Scene (const char * fileName);
~Scene ();
int play ();
};
#endif
/*
*
* sceneload.cpp
*
* 27th March 2010: Created sceneload.cpp from parts of scene.cpp
*
* Part of the OpenJazz project
*
*
* Copyright (c) 2005-2010 Alister Thomson
*
* OpenJazz is distributed under the terms of
* the GNU General Public License, version 2.0
*
* 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 St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
/*
* Deals with the loading of cutscene data.
*
*/
#include "scene/scene.h"
#include "io/file.h"
#include "io/gfx/font.h"
#include "io/gfx/video.h"
#include <string.h>
void Scene::loadAni (File *f, int dataIndex) {
unsigned short int aniType = f->loadShort();// should be 0x02
LOG("ParseAni DataLen", aniType);
unsigned short int aniOffset = f->loadShort();// unknown, number of frames?
LOG("ParseAni Frames?", aniOffset);
unsigned short int type = 0;//
int loop;
while (type != 0x4C50) {
type = f->loadShort();
if (type == 0x4C53) { // SL
/*unsigned short int offset =*/ f->loadShort();
unsigned char noSounds = f->loadChar();
for(loop = 0;loop<noSounds;loop++) {
char* soundName = f->loadString();
LOG("Soundname ", soundName);
delete[] soundName;
}
} else if (type == 0x4C50) {// PL
int pos = f->tell();
int nextPos = f->tell();
LOG("PL Read position", pos);
unsigned short int len = f->loadShort();
unsigned char* buffer = f->loadBlock(len);
for (int count = 0; count < 256; count++) {
// Palette entries are 6-bit
// Shift them upwards to 8-bit, and fill in the lower 2 bits
paletteInfos[paletteIndex].palette[count].r =
(buffer[count * 3] << 2) + (buffer[count * 3] >> 4);
paletteInfos[paletteIndex].palette[count].g =
(buffer[(count * 3) + 1] << 2) + (buffer[(count * 3) + 1] >> 4);
paletteInfos[paletteIndex].palette[count].b =
(buffer[(count * 3) + 2] << 2) + (buffer[(count * 3) + 2] >> 4);
}
delete[] buffer;
paletteInfos[paletteIndex].dataIndex = dataIndex;
paletteIndex++;
unsigned short int value = 0x4646;
int items = 0;
int validValue = true;
pos = f->tell();
LOG("PL Read position start", pos);
while (validValue) {
value = f->loadShort();
LOG("PL Read block start tag", value);
unsigned short int size= f->loadShort();
LOG("PL Anim block size", size);
nextPos = f->tell();
// next pos is intial position + size and four bytes header
nextPos+=(size);
switch (value) {
case 0x455F:
validValue = false;
break;
case 0x3131:
{
// Skip back size header, this is read by the surface reader
f->seek(-2, false);
SDL_Surface *image = f->loadSurface(320, 200, true);
SDL_BlitSurface(image, NULL, canvas, NULL);
SDL_FreeSurface(image);
SDL_SetPalette(screen, SDL_PHYSPAL, paletteInfos[paletteIndex-1].palette, 0, 256);
currentPalette = paletteInfos[paletteIndex-1].palette;
}
break;
case 0x4c31:
{
int longvalue = f->loadInt();
LOG("PL Anim block value", longvalue);
// Skip back size header, this is read by the surface reader
//f->seek(-2, false);
while (size) {
size--;
unsigned char header = f->loadChar();
LOG("PL 4c31 block header", header);
switch (header) {
case 0x7F:
{
unsigned short fillWidth = f->loadShort();
unsigned char fillColor = f->loadChar();
LOG("PL Fillblock width", fillWidth);
LOG("PL Fillblock with color", fillColor);
size -= 3;
}
break;
case 0xff:
{
unsigned char x = f->loadChar();
unsigned char y = f->loadChar();
LOG("PL block x", x);
LOG("PL block y", y);
size -= 2;
}
break;
default:
LOG("PL Unknown type", header);
break;
}
}
}
break;
case 0x4646:
while (size) {
unsigned char header = f->loadChar();
LOG("PL 4646 block header", header);
switch (header) {
case 0x7F:
{
unsigned short fillWidth = f->loadShort();
unsigned char fillColor = f->loadChar();
LOG("PL Fillblock width", fillWidth);
LOG("PL Fillblock with color", fillColor);
size -= 3;
}
break;
case 0xff:
{
unsigned char x = f->loadChar();
unsigned char y = f->loadChar();
LOG("PL block x", x);
LOG("PL block y", y);
size -= 2;
}
break;
default:
LOG("PL Unknown type", header);
break;
}
size--;
}
break;
case 0x4e52:
case 0x4252:
case 0x4352:
case 0x4c52:
case 0x4e41:
case 0x584d:
case 0x5252:
break;
case 0x5b5d:
{
unsigned char header = f->loadChar();
LOG("PL 5b5d block header", header);
unsigned short int value = f->loadShort();
LOG("PL 5b5d block value", value);
}
break;
case 0x5453:
{
unsigned char soundIndex = f->loadChar();
unsigned char soundNote = f->loadChar();
unsigned char soundOffset = f->loadChar();
LOG("PL Audio tag with index", soundIndex);
LOG("PL Audio tag play at ", soundNote);
LOG("PL Audio tag play offset ", soundOffset);
}
break;
case 0:
{
int longvalue = f->loadInt();
while (longvalue == 0) {
longvalue = f->loadInt();
nextPos += 4;
}
f->seek(-4, false);
value = longvalue;
}
break;
default:
LOG("PL Read Unknown type", value);
validValue = false;
break;
}
pos = f->tell();
LOG("PL Read position after block should be", nextPos);
f->seek(nextPos, true);
if(validValue) items++;
}
LOG("PL Parsed through number of items skipping 0 items", items);
pos = f->tell();
LOG("PL Read position after parsing anim blocks", pos);
}
}
}
void Scene::loadData (File *f) {
int loop;
for(loop = 0; loop < dataItems; loop++) {
f->seek(dataOffsets[loop], true); // Seek to data start
unsigned short int dataLen = f->loadShort(); // Get get the length of the datablock
LOG("Data dataLen", dataLen);
// AN
if (dataLen == 0x4e41) {
LOG("Data Type", "ANI");
loadAni(f, loop);
} else {
unsigned char type = f->loadChar();
LOG("Data Type", type);
switch (type) {
case 3:
case 4: // image
case 5:
case 6:
{
LOG("Data Type", "Image");
LOG("Data Type Image index", loop);
unsigned short int width = f->loadShort(); // get width
unsigned short int height;
if (type == 3) height = f->loadChar(); // Get height
else height = f->loadShort(); // Get height
if (imageIndex<100) {
f->seek(-2, false);
imageInfos[imageIndex].image = f->loadSurface(width, height);
imageInfos[imageIndex].dataIndex = loop;
imageIndex++;
}
}
break;
default:
{
LOG("Data Type", "Palette");
LOG("Data Type Palette index", loop);
f->seek(-3, false);
f->loadPalette(paletteInfos[paletteIndex].palette);
paletteInfos[paletteIndex].dataIndex = loop;
paletteIndex++;
}
break;
}
}
}
}
void Scene::loadScripts (File *f) {
int loop;
char *string;
/*int bgIndex = 0;*/
int textAlignment = 0;
int textFont = 0;
for(loop = 0; loop < scriptItems; loop++) {
LOG("\nParse Script", loop);
int textPosX = -1;
int textPosY = -1;
int extraheight = -1;
SDL_Rect textRect;
bool textRectValid = false;
f->seek(scriptStarts[loop], true); // Seek to data start
if (f->loadChar() == 0x50) { // Script tag
unsigned short int scriptid = f->loadShort();
LOG("Script id:", scriptid);
int palette = f->loadShort();
LOG("Script default palette", palette);
scriptPages[loop].paletteIndex = palette;
unsigned char type = 0;
bool breakloop = false;
int pos = f->tell();
while(!breakloop && pos < dataOffsets[0]) {
type = f->loadChar();
switch(type) {
case ESceneAnimationSetting:
{
signed long int something = f->loadInt();
signed long int something2 = f->loadInt();
LOG("ESceneAnimationSetting1", something);
LOG("ESceneAnimationSetting2", something2);
}
break;
case ESceneAnimationIndex:
{
unsigned char aniIndex = f->loadChar();
LOG("ESceneAnimationIndex:", aniIndex);
}
break;
case ESceneFadeType:
{
unsigned char fadein = f->loadChar();
LOG("ESceneFadeType:", fadein);
}
break;
case ESceneBackground:
{
unsigned short int xpos = f->loadShort();
unsigned short int ypos = f->loadShort();
unsigned short bgImageIndex = f->loadShort();
LOG("ESceneBackground: index", bgImageIndex);
LOG("ESceneBackground: xpos", xpos);
LOG("ESceneBackground: ypos", ypos);
scriptPages[loop].bgIndex[scriptPages[loop].backgrounds] = bgImageIndex;
scriptPages[loop].bgPos[scriptPages[loop].backgrounds] = xpos|(ypos<<16);
scriptPages[loop].backgrounds++;
}
break;
case ESceneMusic:
{
// Music file name
string = f->loadString();
LOG("ESceneMusic: ", string);
scriptPages[loop].musicfile = createString(string);
delete[] string;
}
break;
case ESceneSomethingElse:
{
unsigned char value = 0;//f->loadChar();
LOG("ESceneSomethingElse", value);
}
break;
case ESceneTextRect: // String
{
unsigned short x = textRect.x = f->loadShort();
unsigned short y = textRect.y = f->loadShort();
unsigned short w = textRect.w = f->loadShort() - x;
unsigned short h = textRect.h = f->loadShort() - y;
textRectValid = true;
LOG("Text rectangle xpos:", x);
LOG("Text rectangle ypos:", y);
LOG("Text rectangle w:", w);
LOG("Text rectangle h:", h);
}
break;
case ESceneFontDefine: // Font defnition
{
unsigned short fontid = f->loadShort();
char* fontname = f->loadString();
LOG("ESceneFontDefine", fontname);
LOG("ESceneFontDefine with id=", fontid);
if (strcmp(fontname, "FONT2") == 0)
scriptFonts[noScriptFonts].font = font2;
else if (strcmp(fontname, "FONTBIG") == 0)
scriptFonts[noScriptFonts].font = fontbig;
else if (strcmp(fontname, "FONTTINY") == 0)
scriptFonts[noScriptFonts].font = fontiny;
else if (strcmp(fontname, "FONTMN1") == 0)
scriptFonts[noScriptFonts].font = fontmn1;
else if (strcmp(fontname, "FONTMN2") == 0)
scriptFonts[noScriptFonts].font = fontmn2;
else scriptFonts[noScriptFonts].font = font2;
scriptFonts[noScriptFonts].fontId = fontid;
noScriptFonts++;
delete[] fontname;
}
break;
case ESceneTextPosition:
{
unsigned short newx = f->loadShort();
unsigned short newy = f->loadShort();
LOG("TextPosition x", newx);
LOG("TextPosition y", newy);
textPosX = newx;
textPosY = newy;
}
break;
case ESceneTextColour:
{
unsigned short value = f->loadShort();
LOG("ESceneTextColour", value);
}
break;
case ESceneFontFun:
{
unsigned short len = f->loadShort();
LOG("ESceneFontFun len", len);
/*while (len) {
unsigned char data = f->loadChar();
len--;
}*/
}
break;
case ESceneFontIndex:
{
unsigned short value = f->loadShort();
LOG("ESceneFontIndex", value);
textFont = value;
}
break;
case ESceneTextVAdjust:
{
unsigned short value = f->loadShort();
LOG("ESceneTextVAdjust", value);
extraheight = value;
}
break;
case ESceneTextSetting:
{
unsigned short value = f->loadShort();
LOG("ESceneTextSetting", value);
}
break;
case ESceneTextShadow:
{
unsigned short value = f->loadShort();
LOG("ESceneTextVAdjust", value);
}
break;
case ESceneTextAlign:
{
unsigned char alignment = f->loadChar();
LOG("ESceneTextAlign", alignment);
textAlignment = alignment;
}
break;
case ESceneTextAlign2:
{
unsigned char a = f->loadChar();
unsigned short b = f->loadShort();
LOG("ESceneTextAlign2 a", a);
LOG("ESceneTextAlign2 b", b);
}
break;
case ESceneTextSomething:
{
unsigned char a = f->loadChar();
unsigned short b = f->loadShort();
LOG("ESceneTextSomething a", a);
LOG("ESceneTextSomething b", b);
}
break;
case ESceneTextLine:
case ESceneTextBlock:
{
unsigned char datalen = f->loadChar();
LOG("Text len=", datalen);
if (datalen > 0) {
f->seek(-1, false);
char *block = f->loadString();
// Convert number placeholders
for (int pos = 1; pos < datalen; pos++) {
if (block[pos] == -117) {
if (loop >= 9)
block[pos - 1] = ((loop + 1) / 10) + 53;
block[pos] = ((loop + 1) % 10) + 53;
} else if (block[pos] == -118) {
if (scriptItems >= 10)
block[pos - 1] = (scriptItems / 10) + 53;
block[pos] = (scriptItems % 10) + 53;
}
}
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text = block;
LOG("Text data",(char*) scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text);
} else {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text = new char[1];
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].text[0] = 0;
LOG("Text data", "Empty line");
}
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].alignment = textAlignment;
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].fontId = textFont;
if(textPosX != -1) {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].x = textPosX;
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].y = textPosY;
textPosX = -1;
textPosY = -1;
}
if(textRectValid) {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].textRect = textRect;
textRectValid = false;
}
if(extraheight != -1) {
scriptPages[loop].scriptTexts[scriptPages[loop].noScriptTexts].extraLineHeight = extraheight;
extraheight = -1;
}
scriptPages[loop].noScriptTexts++;
}
break;
case ESceneTime:
{
unsigned short int sceneTime = f->loadShort();
LOG("Scene time",sceneTime&255);
scriptPages[loop].pageTime = sceneTime&255;
}
break;
case ESceneBreaker:
case 0x3e:
pos = f->tell();
LOG("Parse script end at position", pos);
LOG("Parse script end with", type);
breakloop = true;
f->loadChar();
break;
default:
pos = f->tell();
LOG("Parse script end at position", pos);
LOG("Parse script breaker", type);
breakloop = true;
break;
}
pos = f->tell();
}
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment