Skip to content

Commit

Permalink
ADL: Improve error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
waltervn committed Mar 9, 2016
1 parent f62c56e commit af42795
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 22 deletions.
5 changes: 4 additions & 1 deletion engines/adl/adl.cpp
Expand Up @@ -94,7 +94,10 @@ Common::String AdlEngine::readString(Common::ReadStream &stream, byte until) {
while (1) {
byte b = stream.readByte();

if (stream.eos() || stream.err() || b == until)
if (stream.eos() || stream.err())
error("Error reading string");

if (b == until)
break;

str += b;
Expand Down
3 changes: 3 additions & 0 deletions engines/adl/display.cpp
Expand Up @@ -213,6 +213,9 @@ void Display::loadFrameBuffer(Common::ReadStream &stream) {
}
dst -= DISPLAY_PITCH * 63;
}

if (stream.eos() || stream.err())
error("Failed to read frame buffer");
}

void Display::putPixel(const Common::Point &p, byte color) {
Expand Down
47 changes: 29 additions & 18 deletions engines/adl/hires1.cpp
Expand Up @@ -31,10 +31,16 @@

namespace Adl {

#define IDI_HR1_NUM_ROOMS 41
#define IDI_HR1_NUM_PICS 98
#define IDI_HR1_NUM_VARS 20
#define IDI_HR1_NUM_ITEM_OFFSETS 21
#define IDS_HR1_EXE_0 "AUTO LOAD OBJ"
#define IDS_HR1_EXE_1 "ADVENTURE"
#define IDS_HR1_LOADER "MYSTERY.HELLO"
#define IDS_HR1_MESSAGES "MESSAGES"

#define IDI_HR1_NUM_ROOMS 41
#define IDI_HR1_NUM_PICS 98
#define IDI_HR1_NUM_VARS 20
#define IDI_HR1_NUM_ITEM_OFFSETS 21
#define IDI_HR1_NUM_MESSAGES 167

// Messages used outside of scripts
#define IDI_HR1_MSG_CANT_GO_THERE 137
Expand Down Expand Up @@ -99,8 +105,8 @@ HiRes1Engine::HiRes1Engine(OSystem *syst, const AdlGameDescription *gd) :
void HiRes1Engine::runIntro() {
Common::File file;

if (!file.open("AUTO LOAD OBJ"))
error("Failed to open file");
if (!file.open(IDS_HR1_EXE_0))
error("Failed to open file '" IDS_HR1_EXE_0 "'");

file.seek(IDI_HR1_OFS_LOGO_0);
_display->setMode(DISPLAY_MODE_HIRES);
Expand All @@ -114,8 +120,8 @@ void HiRes1Engine::runIntro() {
_display->setMode(DISPLAY_MODE_TEXT);

Common::File basic;
if (!basic.open("MYSTERY.HELLO"))
error("Failed to open file");
if (!basic.open(IDS_HR1_LOADER))
error("Failed to open file '" IDS_HR1_LOADER "'");

Common::String str;

Expand Down Expand Up @@ -189,8 +195,8 @@ void HiRes1Engine::runIntro() {

_display->setMode(DISPLAY_MODE_MIXED);

if (!file.open("ADVENTURE"))
error("Failed to open file");
if (!file.open(IDS_HR1_EXE_1))
error("Failed to open file '" IDS_HR1_EXE_1 "'");

// Title screen shown during loading
file.seek(IDI_HR1_OFS_LOGO_1);
Expand Down Expand Up @@ -241,7 +247,7 @@ void HiRes1Engine::drawPic(byte pic, Common::Point pos) {
Common::String name = Common::String::format("BLOCK%i", _pictures[pic].block);

if (!f.open(name))
error("Failed to open file");
error("Failed to open file '%s'", name.c_str());

f.seek(_pictures[pic].offset);
drawPic(f, pos);
Expand All @@ -257,8 +263,8 @@ void HiRes1Engine::initState() {
_state.vars.clear();
_state.vars.resize(IDI_HR1_NUM_VARS);

if (!f.open("ADVENTURE"))
error("Failed to open file");
if (!f.open(IDS_HR1_EXE_1))
error("Failed to open file '" IDS_HR1_EXE_1 "'");

// Load room data from executable
_state.rooms.clear();
Expand Down Expand Up @@ -311,16 +317,16 @@ void HiRes1Engine::runGame() {

Common::File f;

if (!f.open("MESSAGES"))
error("Failed to open file");
if (!f.open(IDS_HR1_MESSAGES))
error("Failed to open file '" IDS_HR1_MESSAGES "'");

while (!f.eos() && !f.err())
for (uint i = 0; i < IDI_HR1_NUM_MESSAGES; ++i)
_messages.push_back(readString(f, APPLECHAR('\r')) + APPLECHAR('\r'));

f.close();

if (!f.open("ADVENTURE"))
error("Failed to open file");
if (!f.open(IDS_HR1_EXE_1))
error("Failed to open file '" IDS_HR1_EXE_1 "'");

// Load strings from executable
_strings.resize(IDI_HR1_STR_TOTAL);
Expand Down Expand Up @@ -371,6 +377,9 @@ void HiRes1Engine::runGame() {
_lineArt.push_back(lineArt);
}

if (f.eos() || f.err())
error("Failed to read game data from '" IDS_HR1_EXE_1 "'");

f.seek(IDI_HR1_OFS_VERBS);
loadVerbs(f);

Expand Down Expand Up @@ -465,6 +474,8 @@ uint HiRes1Engine::getEngineMessage(EngineMessage msg) {
}

void HiRes1Engine::drawLine(const Common::Point &p1, const Common::Point &p2, byte color) {
// This draws a four-connected line

int16 deltaX = p2.x - p1.x;
int8 xStep = 1;

Expand Down
5 changes: 2 additions & 3 deletions engines/adl/hires1.h
Expand Up @@ -27,6 +27,7 @@

namespace Common {
class ReadStream;
class Point;
}

namespace Adl {
Expand All @@ -35,16 +36,14 @@ class HiRes1Engine : public AdlEngine {
public:
HiRes1Engine(OSystem *syst, const AdlGameDescription *gd);

protected:
void runGame();

private:
void restartGame();
void printMessage(uint idx, bool wait = true);
uint getEngineMessage(EngineMessage msg);

void initState();
void runIntro();
void runGame();
void drawPic(Common::ReadStream &stream, const Common::Point &pos);
void drawItems();
void drawLine(const Common::Point &p1, const Common::Point &p2, byte color);
Expand Down

0 comments on commit af42795

Please sign in to comment.