Initial commit

This commit is contained in:
2026-02-02 04:50:13 +01:00
commit 5b11698731
22592 changed files with 7677434 additions and 0 deletions

View File

@@ -0,0 +1,143 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/castle/castle.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
byte kAmigaCastlePalette[16][3] = {
{0x00, 0x00, 0x00},
{0x44, 0x44, 0x44},
{0x66, 0x66, 0x66},
{0x88, 0x88, 0x88},
{0xaa, 0xaa, 0xaa},
{0xcc, 0xcc, 0xcc},
{0x00, 0x00, 0x88},
{0x66, 0xaa, 0x00},
{0x88, 0xcc, 0x00},
{0xcc, 0xee, 0x00},
{0xee, 0xee, 0x66},
{0x44, 0x88, 0x00},
{0xee, 0xaa, 0x00},
{0xcc, 0x44, 0x00},
{0x88, 0x44, 0x00},
{0xee, 0xee, 0xee},
};
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanesVertical(Common::SeekableReadStream *file, int widthInBytes, int height) {
Graphics::ManagedSurface *surface;
surface = new Graphics::ManagedSurface();
surface->create(widthInBytes * 8 / 4, height, Graphics::PixelFormat::createFormatCLUT8());
surface->fillRect(Common::Rect(0, 0, widthInBytes * 8 / 4, height), 0);
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 0);
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 1);
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 2);
loadFrameFromPlanesInternalVertical(file, surface, widthInBytes / 4, height, 3);
return surface;
}
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanesInternalVertical(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, int plane) {
byte *colors = (byte *)malloc(sizeof(byte) * height * width);
file->read(colors, height * width);
for (int i = 0; i < height * width; i++) {
byte color = colors[i];
for (int n = 0; n < 8; n++) {
int y = i / width;
int x = (i % width) * 8 + (7 - n);
int bit = ((color >> n) & 0x01) << plane;
int sample = surface->getPixel(x, y) | bit;
assert(sample < 16);
surface->setPixel(x, y, sample);
}
}
free(colors);
return surface;
}
void CastleEngine::loadAssetsAmigaDemo() {
Common::File file;
file.open("x");
if (!file.isOpen())
error("Failed to open 'x' file");
_viewArea = Common::Rect(40, 29, 280, 154);
loadMessagesVariableSize(&file, 0x8bb2, 178);
loadRiddles(&file, 0x96c8 - 2 - 19 * 2, 19);
file.seek(0x11eec);
Common::Array<Graphics::ManagedSurface *> chars;
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *img = loadFrameFromPlanes(&file, 8, 8);
//Graphics::ManagedSurface *imgRiddle = new Graphics::ManagedSurface();
//imgRiddle->copyFrom(*img);
chars.push_back(img);
chars[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)kAmigaCastlePalette, 16);
//charsRiddle.push_back(imgRiddle);
//charsRiddle[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGARiddleFontPalette, 16);
}
// 0x1356c
_font = Font(chars);
_font.setCharWidth(9);
load8bitBinary(&file, 0x162a6, 16);
for (int i = 0; i < 3; i++) {
debugC(1, kFreescapeDebugParser, "Continue to parse area index %d at offset %x", _areaMap.size() + i + 1, (int)file.pos());
Area *newArea = load8bitArea(&file, 16);
if (newArea) {
if (!_areaMap.contains(newArea->getAreaID()))
_areaMap[newArea->getAreaID()] = newArea;
else
error("Repeated area ID: %d", newArea->getAreaID());
} else {
error("Invalid area %d?", i);
}
}
loadPalettes(&file, 0x151a6);
file.seek(0x2be96); // Area 255
_areaMap[255] = load8bitArea(&file, 16);
file.seek(0x2cf28 + 0x28 - 0x2 + 0x28);
_border = loadFrameFromPlanesVertical(&file, 160, 200);
_border->convertToInPlace(_gfx->_texturePixelFormat, (byte *)kAmigaCastlePalette, 16);
file.close();
_areaMap[2]->_groundColor = 1;
for (auto &it : _areaMap)
it._value->addStructure(_areaMap[255]);
}
void CastleEngine::drawAmigaAtariSTUI(Graphics::Surface *surface) {
drawStringInSurface(_currentArea->_name, 97, 182, 0, 0, surface);
}
} // End of namespace Freescape

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,164 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
namespace Freescape {
struct RiddleText {
int8 _dx;
int8 _dy;
Common::String _text;
RiddleText(int8 dx, int8 dy, const Common::String &text) : _dx(dx), _dy(dy), _text(text) {}
};
struct Riddle {
Common::Point _origin;
Common::Array<RiddleText> _lines;
};
class CastleEngine : public FreescapeEngine {
public:
CastleEngine(OSystem *syst, const ADGameDescription *gd);
~CastleEngine();
// Only in DOS
Graphics::ManagedSurface *_option;
Graphics::ManagedSurface *_menuButtons;
Graphics::ManagedSurface *_menuCrawlIndicator;
Graphics::ManagedSurface *_menuWalkIndicator;
Graphics::ManagedSurface *_menuRunIndicator;
Graphics::ManagedSurface *_menuFxOnIndicator;
Graphics::ManagedSurface *_menuFxOffIndicator;
Graphics::ManagedSurface *_menu;
void beforeStarting() override;
void initKeymaps(Common::Keymap *engineKeyMap, Common::Keymap *infoScreenKeyMap, const char *target) override;
void initGameState() override;
void endGame() override;
void drawInfoMenu() override;
void loadAssets() override;
void loadAssetsDOSFullGame() override;
void loadAssetsDOSDemo() override;
void loadAssetsAmigaDemo() override;
void loadAssetsZXFullGame() override;
void loadAssetsCPCFullGame() override;
void borderScreen() override;
void selectCharacterScreen();
void drawOption();
void initZX();
void initDOS();
void initCPC();
void drawDOSUI(Graphics::Surface *surface) override;
void drawZXUI(Graphics::Surface *surface) override;
void drawCPCUI(Graphics::Surface *surface) override;
void drawAmigaAtariSTUI(Graphics::Surface *surface) override;
void drawEnergyMeter(Graphics::Surface *surface, Common::Point origin);
void drawLiftingGate(Graphics::Surface *surface);
void drawDroppingGate(Graphics::Surface *surface);
void pressedKey(const int keycode) override;
void checkSensors() override;
void updateTimeVariables() override;
void drawBackground() override;
bool checkIfGameEnded() override;
void drawSensorShoot(Sensor *sensor) override;
void executePrint(FCLInstruction &instruction) override;
void executeDestroy(FCLInstruction &instruction) override;
void executeRedraw(FCLInstruction &instruction) override;
void gotoArea(uint16 areaID, int entranceID) override;
Common::Error saveGameStreamExtended(Common::WriteStream *stream, bool isAutosave = false) override;
Common::Error loadGameStreamExtended(Common::SeekableReadStream *stream) override;
Common::Array<Riddle> _riddleList;
Common::BitArray _fontPlane1;
Common::BitArray _fontPlane2;
Common::BitArray _fontPlane3;
void drawRiddleStringInSurface(const Common::String &str, int x, int y, uint32 fontColor, uint32 backColor, Graphics::Surface *surface);
Graphics::ManagedSurface *loadFrameWithHeaderDOS(Common::SeekableReadStream *file);
Common::Array <Graphics::ManagedSurface *>loadFramesWithHeaderDOS(Common::SeekableReadStream *file, int numFrames);
Common::Array<Graphics::ManagedSurface *> loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back);
Graphics::ManagedSurface *loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back);
Graphics::ManagedSurface *loadFrame(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, uint32 back);
Graphics::ManagedSurface *loadFrameFromPlanes(Common::SeekableReadStream *file, int widthInBytes, int height);
Graphics::ManagedSurface *loadFrameFromPlanesInternal(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height);
Graphics::ManagedSurface *loadFrameFromPlanesVertical(Common::SeekableReadStream *file, int widthInBytes, int height);
Graphics::ManagedSurface *loadFrameFromPlanesInternalVertical(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, int plane);
Common::Array<Graphics::ManagedSurface *>_keysBorderFrames;
Common::Array<Graphics::ManagedSurface *>_keysMenuFrames;
Graphics::ManagedSurface *_spiritsMeterIndicatorBackgroundFrame;
Graphics::ManagedSurface *_spiritsMeterIndicatorFrame;
Graphics::ManagedSurface *_spiritsMeterIndicatorSideFrame;
Graphics::ManagedSurface *_strenghtBackgroundFrame;
Graphics::ManagedSurface *_strenghtBarFrame;
Common::Array<Graphics::ManagedSurface *> _strenghtWeightsFrames;
Common::Array<Graphics::ManagedSurface *> _flagFrames;
Common::Array<Graphics::ManagedSurface *> _thunderFrames;
Graphics::ManagedSurface *_riddleTopFrame;
Graphics::ManagedSurface *_riddleBackgroundFrame;
Graphics::ManagedSurface *_riddleBottomFrame;
Graphics::ManagedSurface *_endGameThroneFrame;
Graphics::ManagedSurface *_endGameBackgroundFrame;
Graphics::ManagedSurface *_gameOverBackgroundFrame;
Common::Array<int> _keysCollected;
bool _useRockTravel;
int _spiritsMeter;
int _spiritsMeterPosition;
int _spiritsMeterMax;
int _spiritsToKill;
int _lastTenSeconds;
int _soundIndexStartFalling;
private:
Common::SeekableReadStream *decryptFile(const Common::Path &filename);
void loadRiddles(Common::SeekableReadStream *file, int offset, int number);
void loadDOSFonts(Common::SeekableReadStream *file, int pos);
void drawFullscreenRiddleAndWait(uint16 riddle);
void drawFullscreenEndGameAndWait();
void drawFullscreenGameOverAndWait();
void drawRiddle(uint16 riddle, uint32 front, uint32 back, Graphics::Surface *surface);
void tryToCollectKey();
void addGhosts();
bool ghostInArea();
void updateThunder();
Audio::SoundHandle _soundFxGhostHandle;
Texture *_optionTexture;
Font _fontRiddle;
int _droppingGateStartTicks;
int _thunderTicks;
int _thunderFrameDuration;
Math::Vector3d _thunderOffset;
Common::Array<Texture *>_thunderTextures;
};
}

View File

@@ -0,0 +1,345 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/castle/castle.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void CastleEngine::initCPC() {
_viewArea = Common::Rect(40, 33 - 2, 280, 152);
_soundIndexShoot = 5;
_soundIndexCollide = -1;
_soundIndexFallen = -1;
_soundIndexStepUp = -1;
_soundIndexStepDown = -1;
_soundIndexMenu = -1;
_soundIndexStart = 6;
_soundIndexAreaChange = 7;
}
byte kCPCPaletteCastleTitleData[4][3] = {
{0x00, 0x00, 0x00},
{0x00, 0x00, 0xff},
{0xff, 0xff, 0x00},
{0xff, 0x00, 0x00},
};
byte kCPCPaletteCastleBorderData[4][3] = {
{0x00, 0x00, 0x00},
{0x80, 0x80, 0x80},
{0x00, 0x80, 0x00},
{0xff, 0xff, 0xff},
};
// Data for the mountains background. This is not included in the original game for some reason
// but all the other releases have it. This is coming from the ZX Spectrum version.
byte mountainsData[288] {
0x06, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0b,
0x00, 0x00, 0x38, 0x01, 0xa0, 0x00, 0x00, 0x00,
0x00, 0x1e, 0x30, 0x00, 0x00, 0x00, 0x00, 0x17,
0x80, 0x00, 0x7c, 0x03, 0xd0, 0x00, 0x00, 0x01,
0x00, 0x3f, 0x5c, 0x80, 0x0, 0x18, 0x0, 0x23,
0xc0, 0x00, 0xfe, 0x0d, 0xfe, 0x6, 0x00, 0x02,
0x80, 0x7e, 0xbe, 0xc0, 0x0, 0x3c, 0x0, 0x47,
0xe0, 0x1, 0x57, 0x56, 0xff, 0xf, 0x80, 0x5,
0x40, 0xf5, 0xfb, 0x40, 0x0, 0x76, 0x0, 0x93,
0xd0, 0xa, 0xab, 0xab, 0xff, 0xaf, 0xc3, 0x2a,
0xa1, 0xeb, 0xfe, 0xa8, 0x0, 0xde, 0x0, 0x21,
0xa8, 0x75, 0x55, 0x41, 0xff, 0xd6, 0xef, 0xd5,
0x53, 0x57, 0xfc, 0x14, 0x1, 0xb7, 0x7, 0x42,
0xd5, 0xea, 0xaa, 0x92, 0xfb, 0xeb, 0xab, 0xea,
0xaa, 0xae, 0xfa, 0x4a, 0x82, 0xea, 0xbe, 0x97,
0xab, 0xd5, 0x55, 0x25, 0xdd, 0x75, 0x45, 0xf5,
0x55, 0x7d, 0xdd, 0x25, 0x55, 0xd5, 0x54, 0x2f,
0xf7, 0xaa, 0xaa, 0x53, 0xea, 0xa8, 0x13, 0xfa,
0xaa, 0xea, 0xbe, 0x42, 0xab, 0xaa, 0xa9, 0x5f,
0xdd, 0xd5, 0x55, 0x7, 0x55, 0x2, 0x45, 0xfd,
0x51, 0x55, 0x57, 0x15, 0x57, 0xd5, 0x52, 0xaf,
0xee, 0xfa, 0xaa, 0x2b, 0xaa, 0x80, 0x8b, 0xfe,
0xaa, 0xaa, 0xae, 0xaa, 0xbe, 0xaa, 0xa4, 0x5a,
0xb5, 0x5d, 0x5c, 0x56, 0xd5, 0x29, 0x1f, 0xff,
0x55, 0x55, 0x5b, 0x55, 0x7d, 0x55, 0x9, 0xb5,
0x5a, 0xaf, 0xba, 0xad, 0xaa, 0x92, 0x3e, 0xbf,
0xea, 0xaa, 0xaf, 0xab, 0xea, 0xaa, 0x2, 0x5a,
0xf5, 0x55, 0xfd, 0x57, 0x55, 0x5, 0x5f, 0x57,
0xfd, 0x55, 0x55, 0x57, 0x55, 0x50, 0x15, 0xaf,
0xba, 0xaa, 0xfe, 0xae, 0xfa, 0xaa, 0xbe, 0xaa,
0xbf, 0xaa, 0xaa, 0xaa, 0xaa, 0x82, 0xaa, 0x55,
0x55, 0x55, 0x5f, 0xd5, 0xfd, 0x55, 0x55, 0x55,
0x5f, 0xfd, 0x55, 0x55, 0x55, 0x55, 0x55, 0xea,
0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
0xaa, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
};
extern Graphics::ManagedSurface *readCPCImage(Common::SeekableReadStream *file, bool mode0);
void CastleEngine::loadAssetsCPCFullGame() {
Common::File file;
uint8 r, g, b;
Common::Array<Graphics::ManagedSurface *> chars;
file.open("CMLOAD.BIN");
if (!file.isOpen())
error("Failed to open CMLOAD.BIN");
_title = readCPCImage(&file, true);
_title->setPalette((byte*)&kCPCPaletteCastleTitleData, 0, 4);
file.close();
file.open("CMSCR.BIN");
if (!file.isOpen())
error("Failed to open CMSCR.BIN");
_border = readCPCImage(&file, true);
_border->setPalette((byte*)&kCPCPaletteCastleBorderData, 0, 4);
file.close();
file.open("CM.BIN");
if (!file.isOpen())
error("Failed to open TECODE.BIN/TE2.BI2");
loadMessagesVariableSize(&file, 0x16c6, 71);
switch (_language) {
/*case Common::ES_ESP:
loadRiddles(&file, 0x1470 - 4 - 2 - 9 * 2, 9);
loadMessagesVariableSize(&file, 0xf3d, 71);
load8bitBinary(&file, 0x6aab - 2, 16);
loadSpeakerFxZX(&file, 0xca0, 0xcdc);
file.seek(0x1218 + 16);
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
}
_font = Font(chars);
_font.setCharWidth(9);
_fontLoaded = true;
break;*/
case Common::EN_ANY:
loadRiddles(&file, 0x1b75 - 2 - 9 * 2, 9);
load8bitBinary(&file, 0x791a, 16);
file.seek(0x2724);
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
}
_font = Font(chars);
_font.setCharWidth(9);
_fontLoaded = true;
break;
default:
error("Language not supported");
break;
}
loadColorPalette();
int backgroundWidth = 16;
int backgroundHeight = 18;
Graphics::ManagedSurface *background = new Graphics::ManagedSurface();
background->create(backgroundWidth * 8, backgroundHeight, _gfx->_texturePixelFormat);
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
Common::MemoryReadStream mountainsStream(mountainsData, sizeof(mountainsData));
_gfx->readFromPalette(11, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_background = loadFrame(&mountainsStream, background, backgroundWidth, backgroundHeight, front);
/*_gfx->readFromPalette(2, r, g, b);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(7, r, g, b);
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_keysBorderFrames.push_back(loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xe06 : 0xdf7, red, white));
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
_spiritsMeterIndicatorFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xe5e : 0xe4f, green, white);
_gfx->readFromPalette(4, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int backgroundWidth = 16;
int backgroundHeight = 18;
Graphics::ManagedSurface *background = new Graphics::ManagedSurface();
background->create(backgroundWidth * 8, backgroundHeight, _gfx->_texturePixelFormat);
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
file.seek(_language == Common::ES_ESP ? 0xfd3 : 0xfc4);
_background = loadFrame(&file, background, backgroundWidth, backgroundHeight, front);
_gfx->readFromPalette(6, r, g, b);
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0, 0);
_strenghtBackgroundFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xee6 : 0xed7, yellow, black);
_strenghtBarFrame = loadFrameWithHeader(&file, _language == Common::ES_ESP ? 0xf72 : 0xf63, yellow, black);
Graphics::ManagedSurface *bar = new Graphics::ManagedSurface();
bar->create(_strenghtBarFrame->w - 4, _strenghtBarFrame->h, _gfx->_texturePixelFormat);
_strenghtBarFrame->copyRectToSurface(*bar, 4, 0, Common::Rect(4, 0, _strenghtBarFrame->w - 4, _strenghtBarFrame->h));
_strenghtBarFrame->free();
delete _strenghtBarFrame;
_strenghtBarFrame = bar;
_strenghtWeightsFrames = loadFramesWithHeader(&file, _language == Common::ES_ESP ? 0xf92 : 0xf83, 4, yellow, black);
_flagFrames = loadFramesWithHeader(&file, (_language == Common::ES_ESP ? 0x10e4 + 15 : 0x10e4), 4, green, black);
int thunderWidth = 4;
int thunderHeight = 43;
_thunderFrame = new Graphics::ManagedSurface();
_thunderFrame->create(thunderWidth * 8, thunderHeight, _gfx->_texturePixelFormat);
_thunderFrame->fillRect(Common::Rect(0, 0, thunderWidth * 8, thunderHeight), 0);
_thunderFrame = loadFrame(&file, _thunderFrame, thunderWidth, thunderHeight, front);
Graphics::Surface *tmp;
tmp = loadBundledImage("castle_riddle_top_frame");
_riddleTopFrame = new Graphics::ManagedSurface;
_riddleTopFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleTopFrame->convertToInPlace(_gfx->_texturePixelFormat);
tmp = loadBundledImage("castle_riddle_background_frame");
_riddleBackgroundFrame = new Graphics::ManagedSurface();
_riddleBackgroundFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
tmp = loadBundledImage("castle_riddle_bottom_frame");
_riddleBottomFrame = new Graphics::ManagedSurface();
_riddleBottomFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleBottomFrame->convertToInPlace(_gfx->_texturePixelFormat);*/
for (auto &it : _areaMap) {
it._value->addStructure(_areaMap[255]);
it._value->addObjectFromArea(164, _areaMap[255]);
it._value->addObjectFromArea(174, _areaMap[255]);
it._value->addObjectFromArea(175, _areaMap[255]);
for (int16 id = 136; id < 140; id++) {
it._value->addObjectFromArea(id, _areaMap[255]);
}
it._value->addObjectFromArea(195, _areaMap[255]);
for (int16 id = 214; id < 228; id++) {
it._value->addObjectFromArea(id, _areaMap[255]);
}
}
// Discard some global conditions
// It is unclear why they hide/unhide objects that formed the spirits
for (int i = 0; i < 3; i++) {
debugC(kFreescapeDebugParser, "Discarding condition %s", _conditionSources[0].c_str());
_conditions.remove_at(0);
_conditionSources.remove_at(0);
}
}
void CastleEngine::drawCPCUI(Graphics::Surface *surface) {
uint32 color = _gfx->_paperColor;
//uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = 1;
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Rect backRect(97, 181, 232, 190);
surface->fillRect(backRect, back);
Common::String message;
int deadline = -1;
getLatestMessages(message, deadline);
if (deadline > 0 && deadline <= _countdown) {
drawStringInSurface(message, 97, 182, front, back, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_gameStateControl == kFreescapeGameStatePlaying) {
drawStringInSurface(_currentArea->_name, 97, 182, front, back, surface);
}
}
/*uint32 color = 5;
uint8 r, g, b;
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = 0;
_gfx->readFromPalette(color, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Rect backRect(123, 179, 242 + 5, 188);
surface->fillRect(backRect, black);
Common::String message;
int deadline = -1;
getLatestMessages(message, deadline);
if (deadline > 0 && deadline <= _countdown) {
//debug("deadline: %d countdown: %d", deadline, _countdown);
drawStringInSurface(message, 120, 179, front, black, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_gameStateControl == kFreescapeGameStatePlaying) {
drawStringInSurface(_currentArea->_name, 120, 179, front, black, surface);
}
}
for (int k = 0; k < int(_keysCollected.size()); k++) {
surface->copyRectToSurface((const Graphics::Surface)*_keysBorderFrames[0], 99 - k * 4, 177, Common::Rect(0, 0, 6, 11));
}
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
surface->fillRect(Common::Rect(152, 156, 216, 164), green);
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 140 + _spiritsMeterPosition, 156, Common::Rect(0, 0, 15, 8));
drawEnergyMeter(surface, Common::Point(63, 154));
int ticks = g_system->getMillis() / 20;
int flagFrameIndex = (ticks / 10) % 4;
surface->copyRectToSurface(*_flagFrames[flagFrameIndex], 264, 9, Common::Rect(0, 0, _flagFrames[flagFrameIndex]->w, _flagFrames[flagFrameIndex]->h));*/
}
} // End of namespace Freescape

View File

@@ -0,0 +1,476 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "common/memstream.h"
#include "freescape/freescape.h"
#include "freescape/games/castle/castle.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
Common::SeekableReadStream *CastleEngine::decryptFile(const Common::Path &filename) {
Common::File file;
file.open(filename);
if (!file.isOpen())
error("Failed to open %s", filename.toString().c_str());
int size = file.size();
byte *encryptedBuffer = (byte *)malloc(size);
file.read(encryptedBuffer, size);
file.close();
int seed = 24;
for (int i = 0; i < size; i++) {
if (i > 1)
encryptedBuffer[i] ^= seed;
seed = (seed + 1) & 0xff;
}
return (new Common::MemoryReadStream(encryptedBuffer, size));
}
extern byte kEGADefaultPalette[16][3];
extern Common::MemoryReadStream *unpackEXE(Common::File &ms);
byte kEGARiddleFontPalette[16][3] = {
{0x00, 0x00, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00},
{0xaa, 0x55, 0x00}
};
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanes(Common::SeekableReadStream *file, int widthInBytes, int height) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(widthInBytes * 8 / 4, height, Graphics::PixelFormat::createFormatCLUT8());
surface->fillRect(Common::Rect(0, 0, widthInBytes * 8 / 4, height), 0);
loadFrameFromPlanesInternal(file, surface, widthInBytes, height);
return surface;
}
Graphics::ManagedSurface *CastleEngine::loadFrameFromPlanesInternal(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height) {
byte *colors = (byte *)malloc(sizeof(byte) * height * width);
file->read(colors, height * width);
for (int p = 0; p < 4; p++) {
for (int i = 0; i < height * width; i++) {
byte color = colors[i];
for (int n = 0; n < 8; n++) {
int y = i / width;
int x = (i % width) * 8 + (7 - n);
// Check that we are in the right plane
if (x < width * (8 / 4) * p || x >= width * (8 / 4) * (p + 1))
continue;
int bit = ((color >> n) & 0x01) << p;
int sample = surface->getPixel(x % (width * 8 / 4), y) | bit;
assert(sample < 16);
surface->setPixel(x % (width * 8 / 4), y, sample);
}
}
}
return surface;
}
Common::Array <Graphics::ManagedSurface *>CastleEngine::loadFramesWithHeaderDOS(Common::SeekableReadStream *file, int numFrames) {
uint8 header1 = file->readByte();
uint8 header2 = file->readByte();
int height = file->readByte();
uint8 mask = file->readByte();
int size = file->readUint16LE();
assert(size % height == 0);
int widthBytes = (size / height);
Common::Array<Graphics::ManagedSurface *> frames;
for (int i = 0; i < numFrames; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(file, widthBytes, height);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
frames.push_back(frame);
}
debug("header: %x %x, height: %d, mask: %x, widthBytes: %d, size: %d", header1, header2, height, mask, widthBytes, size);
return frames;
}
Graphics::ManagedSurface *CastleEngine::loadFrameWithHeaderDOS(Common::SeekableReadStream *file) {
uint8 header1 = file->readByte();
uint8 header2 = file->readByte();
int height = file->readByte();
uint8 mask = file->readByte();
int size = file->readUint16LE();
assert(size % height == 0);
int widthBytes = (size / height);
Graphics::ManagedSurface *frame = loadFrameFromPlanes(file, widthBytes, height);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
debug("header: %x %x, height: %d, mask: %x, widthBytes: %d, size: %d", header1, header2, height, mask, widthBytes, size);
debug("pos: %x", (int32)file->pos());
return frame;
}
void CastleEngine::initDOS() {
_viewArea = Common::Rect(40, 33 - 2, 280, 152);
}
void CastleEngine::loadAssetsDOSFullGame() {
Common::File file;
Common::SeekableReadStream *stream = nullptr;
if (_renderMode == Common::kRenderEGA) {
file.open("CME.EXE");
stream = unpackEXE(file);
if (stream) {
loadSpeakerFxDOS(stream, 0x636d + 0x200, 0x63ed + 0x200, 30);
stream->seek(0x197c0);
_endGameBackgroundFrame = loadFrameFromPlanes(stream, 112, 108);
_endGameBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_background = loadFrameFromPlanes(stream, 504, 18);
_background->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
debug("%x", (int32)stream->pos());
// Eye widget is next to 0x1f058
stream->seek(0x1f4e3);
for (int i = 0; i < 6; i++)
debug("i: %d -> %x", i, stream->readByte());
debug("%x", (int32)stream->pos());
debug("extra: %x", stream->readByte());
for (int i = 0; i < 10; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_keysBorderFrames.push_back(frame);
}
for (int i = 0; i < 10; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_keysMenuFrames.push_back(frame);
}
//for (int i = 0; i < 6; i++)
// debug("i: %d -> %x", i, stream->readByte());
//loadFrameWithHeaderDOS(stream);
//debug("%lx", stream->pos());
//assert(0);
stream->seek(0x20262);
_strenghtBackgroundFrame = loadFrameWithHeaderDOS(stream);
_strenghtBarFrame = loadFrameWithHeaderDOS(stream);
_strenghtWeightsFrames = loadFramesWithHeaderDOS(stream, 4);
_spiritsMeterIndicatorBackgroundFrame = loadFrameWithHeaderDOS(stream);
_spiritsMeterIndicatorFrame = loadFrameWithHeaderDOS(stream);
_spiritsMeterIndicatorSideFrame = loadFrameWithHeaderDOS(stream); // side
loadFrameWithHeaderDOS(stream); // ???
/*for (int i = 0; i < 6; i++)
debug("i: %d -> %x", i, stream->readByte());
debug("%lx", stream->pos());*/
//assert(0);
stream->seek(0x221ae);
// No header?
_menu = loadFrameFromPlanes(stream, 112, 115);
_menu->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
Common::Array <Graphics::ManagedSurface *> menuFrames = loadFramesWithHeaderDOS(stream, 5);
_menuCrawlIndicator = menuFrames[0];
_menuWalkIndicator = menuFrames[1];
_menuRunIndicator = menuFrames[2];
_menuFxOffIndicator = menuFrames[3];
_menuFxOnIndicator = menuFrames[4];
_flagFrames = loadFramesWithHeaderDOS(stream, 4);
_riddleTopFrame = loadFrameWithHeaderDOS(stream);
_riddleBackgroundFrame = loadFrameWithHeaderDOS(stream);
_riddleBottomFrame = loadFrameWithHeaderDOS(stream);
_endGameThroneFrame = loadFrameWithHeaderDOS(stream);
// No header
Graphics::ManagedSurface *thunderFrame = loadFrameFromPlanes(stream, 32, 128);
thunderFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_thunderFrames.push_back(thunderFrame);
stream->seek(0x29696);
Common::Array<Graphics::ManagedSurface *> chars;
Common::Array<Graphics::ManagedSurface *> charsRiddle;
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *img = loadFrameFromPlanes(stream, 8, 8);
Graphics::ManagedSurface *imgRiddle = new Graphics::ManagedSurface();
imgRiddle->copyFrom(*img);
chars.push_back(img);
chars[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
charsRiddle.push_back(imgRiddle);
charsRiddle[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGARiddleFontPalette, 16);
}
_font = Font(chars);
_font.setCharWidth(9);
_fontRiddle = Font(charsRiddle);
_fontRiddle.setCharWidth(9);
_fontLoaded = true;
}
delete stream;
file.close();
file.open("CMLE.DAT");
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
file.open("CMOE.DAT");
_option = load8bitBinImage(&file, 0x0);
_option->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
file.open("CME.DAT");
_border = load8bitBinImage(&file, 0x0);
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
switch (_language) {
case Common::ES_ESP:
stream = decryptFile("CMLS");
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
// Fixes for incorrect or wrong translations
Common::replace(_riddleList[16]._lines[5]._text, "IN", "EN");
break;
case Common::FR_FRA:
stream = decryptFile("CMLF");
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
break;
case Common::DE_DEU:
stream = decryptFile("CMLG");
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
break;
case Common::EN_ANY:
stream = decryptFile("CMLE");
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
break;
default:
error("Invalid or unsupported language: %x", _language);
}
loadMessagesVariableSize(stream, 0x11, 164);
delete stream;
stream = decryptFile("CMEDF");
load8bitBinary(stream, 0, 16);
delete stream;
} else
error("Not implemented yet");
// CPC
// file = gameDir.createReadStreamForMember("cm.bin");
// if (file == nullptr)
// error("Failed to open cm.bin");
// load8bitBinary(file, 0x791a, 16);
}
void CastleEngine::loadAssetsDOSDemo() {
Common::File file;
Common::SeekableReadStream *stream = nullptr;
if (_renderMode == Common::kRenderEGA) {
file.open("CMDE.EXE");
stream = unpackEXE(file);
if (stream) {
loadSpeakerFxDOS(stream, 0x636d + 0x200, 0x63ed + 0x200, 30);
stream->seek(0x197c0 - 0x2a0);
_endGameBackgroundFrame = loadFrameFromPlanes(stream, 112, 108);
_endGameBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_background = loadFrameFromPlanes(stream, 504, 18);
_background->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
stream->seek(0x1f4e3 - 0x2a0);
for (int i = 0; i < 6; i++)
debug("i: %d -> %x", i, stream->readByte());
debug("%x", (int32)stream->pos());
debug("extra: %x", stream->readByte());
for (int i = 0; i < 9; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_keysBorderFrames.push_back(frame);
}
for (int i = 0; i < 11; i++) {
Graphics::ManagedSurface *frame = loadFrameFromPlanes(stream, 8, 14);
frame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_keysMenuFrames.push_back(frame);
}
stream->seek(0x20262 - 0x2a0);
_strenghtBackgroundFrame = loadFrameWithHeaderDOS(stream);
_strenghtBarFrame = loadFrameWithHeaderDOS(stream);
_strenghtWeightsFrames = loadFramesWithHeaderDOS(stream, 4);
_spiritsMeterIndicatorBackgroundFrame = loadFrameWithHeaderDOS(stream);
_spiritsMeterIndicatorFrame = loadFrameWithHeaderDOS(stream);
_spiritsMeterIndicatorSideFrame = loadFrameWithHeaderDOS(stream); // side
loadFrameWithHeaderDOS(stream); // ???
stream->seek(0x221ae - 0x2a0);
// No header?
_menu = loadFrameFromPlanes(stream, 112, 115);
_menu->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
Common::Array <Graphics::ManagedSurface *> menuFrames = loadFramesWithHeaderDOS(stream, 5);
_menuCrawlIndicator = menuFrames[0];
_menuWalkIndicator = menuFrames[1];
_menuRunIndicator = menuFrames[2];
_menuFxOffIndicator = menuFrames[3];
_menuFxOnIndicator = menuFrames[4];
_flagFrames = loadFramesWithHeaderDOS(stream, 4);
_riddleTopFrame = loadFrameWithHeaderDOS(stream);
_riddleBackgroundFrame = loadFrameWithHeaderDOS(stream);
_riddleBottomFrame = loadFrameWithHeaderDOS(stream);
_endGameThroneFrame = loadFrameWithHeaderDOS(stream);
// No header
Graphics::ManagedSurface *thunderFrame = loadFrameFromPlanes(stream, 32, 128);
thunderFrame->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
_thunderFrames.push_back(thunderFrame);
stream->seek(0x293f6); // TODO: check this
Common::Array<Graphics::ManagedSurface *> chars;
Common::Array<Graphics::ManagedSurface *> charsRiddle;
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *img = loadFrameFromPlanes(stream, 8, 8);
Graphics::ManagedSurface *imgRiddle = new Graphics::ManagedSurface();
imgRiddle->copyFrom(*img);
chars.push_back(img);
chars[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGADefaultPalette, 16);
charsRiddle.push_back(imgRiddle);
charsRiddle[i]->convertToInPlace(_gfx->_texturePixelFormat, (byte *)&kEGARiddleFontPalette, 16);
}
_font = Font(chars);
_font.setCharWidth(9);
_fontRiddle = Font(charsRiddle);
_fontRiddle.setCharWidth(9);
_fontLoaded = true;
}
delete stream;
file.close();
file.open("CMLE.DAT");
_title = load8bitBinImage(&file, 0x0);
_title->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
file.open("CMOE.DAT");
_option = load8bitBinImage(&file, 0x0);
_option->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
file.open("CME.DAT");
_border = load8bitBinImage(&file, 0x0);
_border->setPalette((byte *)&kEGADefaultPalette, 0, 16);
file.close();
stream = decryptFile("CMLD"); // Only english
loadMessagesVariableSize(stream, 0x11, 164);
loadRiddles(stream, 0xaae - 2 - 22 * 2, 22);
delete stream;
stream = decryptFile("CDEDF");
load8bitBinary(stream, 0, 16);
delete stream;
} else
error("Not implemented yet");
}
void CastleEngine::drawDOSUI(Graphics::Surface *surface) {
uint32 color = 10;
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00);
uint8 r, g, b;
drawLiftingGate(surface);
drawDroppingGate(surface);
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = 0;
_gfx->readFromPalette(color, r, g, b);
uint32 back = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Rect backRect(97, 181, 232, 190);
surface->fillRect(backRect, back);
Common::String message;
int deadline = -1;
getLatestMessages(message, deadline);
if (deadline > 0 && deadline <= _countdown) {
drawStringInSurface(message, 97, 182, front, back, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_gameStateControl != kFreescapeGameStateEnd) {
if (ghostInArea())
drawStringInSurface(_messagesList[116], 97, 182, front, back, surface);
else
drawStringInSurface(_currentArea->_name, 97, 182, front, back, surface);
}
}
for (int k = 0; k < int(_keysCollected.size()); k++) {
surface->copyRectToSurfaceWithKey((const Graphics::Surface)*_keysBorderFrames[k], 76 - k * 3, 179, Common::Rect(0, 0, 6, 14), black);
}
drawEnergyMeter(surface, Common::Point(38, 158));
int flagFrameIndex = (_ticks / 10) % 4;
surface->copyRectToSurface(*_flagFrames[flagFrameIndex], 285, 5, Common::Rect(0, 0, _flagFrames[flagFrameIndex]->w, _flagFrames[flagFrameIndex]->h));
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorBackgroundFrame, 136, 162, Common::Rect(0, 0, _spiritsMeterIndicatorBackgroundFrame->w, _spiritsMeterIndicatorBackgroundFrame->h));
surface->copyRectToSurfaceWithKey((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 125 + 6 + _spiritsMeterPosition, 161, Common::Rect(0, 0, _spiritsMeterIndicatorFrame->w, _spiritsMeterIndicatorFrame->h), black);
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorSideFrame, 122 + 5 + 1, 157 + 5 - 1, Common::Rect(0, 0, _spiritsMeterIndicatorSideFrame->w / 2, _spiritsMeterIndicatorSideFrame->h));
//surface->copyRectToSurface(*_spiritsMeterIndicatorFrame, 100, 50, Common::Rect(0, 0, _spiritsMeterIndicatorFrame->w, _spiritsMeterIndicatorFrame->h));
}
} // End of namespace Freescape

View File

@@ -0,0 +1,286 @@
/* 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 3 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, see <http://www.gnu.org/licenses/>.
*
*/
#include "common/file.h"
#include "freescape/freescape.h"
#include "freescape/games/castle/castle.h"
#include "freescape/language/8bitDetokeniser.h"
namespace Freescape {
void CastleEngine::initZX() {
_viewArea = Common::Rect(64, 36, 256, 148);
_soundIndexShoot = 5;
_soundIndexCollide = 3;
_soundIndexStartFalling = -1;
_soundIndexFallen = 1;
_soundIndexFall = 6;
_soundIndexStepUp = 12;
_soundIndexStepDown = 12;
_soundIndexMenu = 3;
_soundIndexStart = 7;
_soundIndexAreaChange = 7;
}
Graphics::ManagedSurface *CastleEngine::loadFrameWithHeader(Common::SeekableReadStream *file, int pos, uint32 front, uint32 back) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
file->seek(pos);
int16 width = file->readByte();
int16 height = file->readByte();
debugC(kFreescapeDebugParser, "Frame size: %d x %d", width, height);
surface->create(width * 8, height, _gfx->_texturePixelFormat);
/*byte mask =*/ file->readByte();
surface->fillRect(Common::Rect(0, 0, width * 8, height), back);
/*int frameSize =*/ file->readUint16LE();
return loadFrame(file, surface, width, height, front);
}
Common::Array<Graphics::ManagedSurface *> CastleEngine::loadFramesWithHeader(Common::SeekableReadStream *file, int pos, int numFrames, uint32 front, uint32 back) {
Graphics::ManagedSurface *surface = nullptr;
file->seek(pos);
int16 width = file->readByte();
int16 height = file->readByte();
/*byte mask =*/ file->readByte();
/*int frameSize =*/ file->readUint16LE();
Common::Array<Graphics::ManagedSurface *> frames;
for (int i = 0; i < numFrames; i++) {
surface = new Graphics::ManagedSurface();
surface->create(width * 8, height, _gfx->_texturePixelFormat);
surface->fillRect(Common::Rect(0, 0, width * 8, height), back);
frames.push_back(loadFrame(file, surface, width, height, front));
}
return frames;
}
Graphics::ManagedSurface *CastleEngine::loadFrame(Common::SeekableReadStream *file, Graphics::ManagedSurface *surface, int width, int height, uint32 front) {
for (int i = 0; i < width * height; i++) {
byte color = file->readByte();
for (int n = 0; n < 8; n++) {
int y = i / width;
int x = (i % width) * 8 + (7 - n);
if ((color & (1 << n)))
surface->setPixel(x, y, front);
}
}
return surface;
}
void CastleEngine::loadAssetsZXFullGame() {
Common::File file;
uint8 r, g, b;
Common::Array<Graphics::ManagedSurface *> chars;
file.open("castlemaster.zx.title");
if (file.isOpen()) {
_title = loadAndConvertScrImage(&file);
} else
error("Unable to find castlemaster.zx.title");
file.close();
file.open("castlemaster.zx.border");
if (file.isOpen()) {
_border = loadAndConvertScrImage(&file);
} else
error("Unable to find castlemaster.zx.border");
file.close();
file.open("castlemaster.zx.data");
if (!file.isOpen())
error("Failed to open castlemaster.zx.data");
loadMessagesVariableSize(&file, 0x4bd, 71);
switch (_language) {
case Common::ES_ESP:
loadRiddles(&file, 0x1458, 9);
load8bitBinary(&file, 0x6aa9, 16);
loadSpeakerFxZX(&file, 0xca0, 0xcdc);
file.seek(0x1228);
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
}
_font = Font(chars);
_font.setCharWidth(9);
_fontLoaded = true;
break;
case Common::EN_ANY:
if (_variant & GF_ZX_RETAIL) {
loadRiddles(&file, 0x1448, 9);
load8bitBinary(&file, 0x6a3b, 16);
loadSpeakerFxZX(&file, 0xc91, 0xccd);
file.seek(0x1219);
} else if (_variant & GF_ZX_DISC) {
loadRiddles(&file, 0x1457, 9);
load8bitBinary(&file, 0x6a9b, 16);
loadSpeakerFxZX(&file, 0xca0, 0xcdc);
file.seek(0x1228);
} else {
error("Unknown Castle Master ZX variant");
}
for (int i = 0; i < 90; i++) {
Graphics::ManagedSurface *surface = new Graphics::ManagedSurface();
surface->create(8, 8, Graphics::PixelFormat::createFormatCLUT8());
chars.push_back(loadFrame(&file, surface, 1, 8, 1));
}
_font = Font(chars);
_font.setCharWidth(9);
_fontLoaded = true;
break;
default:
error("Language not supported");
break;
}
loadColorPalette();
_gfx->readFromPalette(2, r, g, b);
uint32 red = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_gfx->readFromPalette(7, r, g, b);
uint32 white = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
_keysBorderFrames.push_back(loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xe06 : 0xdf7, red, white));
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
_spiritsMeterIndicatorFrame = loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xe5e : 0xe4f, green, white);
_gfx->readFromPalette(4, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
int backgroundWidth = 16;
int backgroundHeight = 18;
Graphics::ManagedSurface *background = new Graphics::ManagedSurface();
background->create(backgroundWidth * 8, backgroundHeight, _gfx->_texturePixelFormat);
background->fillRect(Common::Rect(0, 0, backgroundWidth * 8, backgroundHeight), 0);
file.seek(_variant & GF_ZX_DISC ? 0xfd3 : 0xfc4);
_background = loadFrame(&file, background, backgroundWidth, backgroundHeight, front);
_gfx->readFromPalette(6, r, g, b);
uint32 yellow = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0, 0);
_strenghtBackgroundFrame = loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xee6 : 0xed7, yellow, black);
_strenghtBarFrame = loadFrameWithHeader(&file, _variant & GF_ZX_DISC ? 0xf72 : 0xf63, yellow, black);
_strenghtWeightsFrames = loadFramesWithHeader(&file, _variant & GF_ZX_DISC ? 0xf92 : 0xf83, 4, yellow, black);
_flagFrames = loadFramesWithHeader(&file, (_variant & GF_ZX_DISC ? 0x10e4 + 15 : 0x10e4), 4, green, black);
file.skip(24);
int thunderWidth = 4;
int thunderHeight = 44;
Graphics::ManagedSurface *thunderFrame = new Graphics::ManagedSurface();
thunderFrame->create(thunderWidth * 8, thunderHeight, _gfx->_texturePixelFormat);
thunderFrame->fillRect(Common::Rect(0, 0, thunderWidth * 8, thunderHeight), 0);
thunderFrame = loadFrame(&file, thunderFrame, thunderWidth, thunderHeight, front);
_thunderFrames.push_back(new Graphics::ManagedSurface);
_thunderFrames.push_back(new Graphics::ManagedSurface);
_thunderFrames[0]->create(thunderWidth * 8 / 2, thunderHeight, _gfx->_texturePixelFormat);
_thunderFrames[1]->create(thunderWidth * 8 / 2, thunderHeight, _gfx->_texturePixelFormat);
_thunderFrames[0]->copyRectToSurface(*thunderFrame, 0, 0, Common::Rect(0, 0, thunderWidth * 8 / 2, thunderHeight));
_thunderFrames[1]->copyRectToSurface(*thunderFrame, 0, 0, Common::Rect(thunderWidth * 8 / 2, 0, thunderWidth * 8, thunderHeight));
Graphics::Surface *tmp;
tmp = loadBundledImage("castle_riddle_top_frame");
_riddleTopFrame = new Graphics::ManagedSurface;
_riddleTopFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleTopFrame->convertToInPlace(_gfx->_texturePixelFormat);
tmp = loadBundledImage("castle_riddle_background_frame");
_riddleBackgroundFrame = new Graphics::ManagedSurface();
_riddleBackgroundFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleBackgroundFrame->convertToInPlace(_gfx->_texturePixelFormat);
tmp = loadBundledImage("castle_riddle_bottom_frame");
_riddleBottomFrame = new Graphics::ManagedSurface();
_riddleBottomFrame->copyFrom(*tmp);
tmp->free();
delete tmp;
_riddleBottomFrame->convertToInPlace(_gfx->_texturePixelFormat);
}
void CastleEngine::drawZXUI(Graphics::Surface *surface) {
uint32 color = 5;
uint8 r, g, b;
drawLiftingGate(surface);
drawDroppingGate(surface);
_gfx->readFromPalette(color, r, g, b);
uint32 front = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
color = 0;
_gfx->readFromPalette(color, r, g, b);
uint32 black = _gfx->_texturePixelFormat.ARGBToColor(0xFF, r, g, b);
Common::Rect backRect(123, 179, 242 + 5, 188);
surface->fillRect(backRect, black);
Common::String message;
int deadline = -1;
getLatestMessages(message, deadline);
if (deadline > 0 && deadline <= _countdown) {
//debug("deadline: %d countdown: %d", deadline, _countdown);
drawStringInSurface(message, 120, 179, front, black, surface);
_temporaryMessages.push_back(message);
_temporaryMessageDeadlines.push_back(deadline);
} else {
if (_gameStateControl != kFreescapeGameStateEnd) {
if (getGameBit(31)) { // The final cutscene is playing but it is not ended yet
drawStringInSurface(_messagesList[5], 120, 179, front, black, surface); // "You did it!"
} else
drawStringInSurface(_currentArea->_name, 120, 179, front, black, surface);
}
}
for (int k = 0; k < int(_keysCollected.size()); k++) {
surface->copyRectToSurface((const Graphics::Surface)*_keysBorderFrames[0], 99 - k * 4, 177, Common::Rect(0, 0, 6, 11));
}
uint32 green = _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0, 0xff, 0);
surface->fillRect(Common::Rect(152, 156, 216, 164), green);
surface->copyRectToSurface((const Graphics::Surface)*_spiritsMeterIndicatorFrame, 140 + _spiritsMeterPosition, 156, Common::Rect(0, 0, 15, 8));
surface->fillRect(Common::Rect(64, 155, 64 + 72, 155 + 15), _gfx->_texturePixelFormat.ARGBToColor(0xFF, 0x00, 0x00, 0x00));
drawEnergyMeter(surface, Common::Point(64, 155));
int ticks = g_system->getMillis() / 20;
int flagFrameIndex = (ticks / 10) % 4;
surface->copyRectToSurface(*_flagFrames[flagFrameIndex], 264, 9, Common::Rect(0, 0, _flagFrames[flagFrameIndex]->w, _flagFrames[flagFrameIndex]->h));
}
} // End of namespace Freescape