Skip to content

Commit

Permalink
ADL: Set room description in hires1
Browse files Browse the repository at this point in the history
  • Loading branch information
waltervn committed Jun 6, 2016
1 parent c982492 commit 41e8227
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 38 deletions.
6 changes: 6 additions & 0 deletions engines/adl/adl.cpp
Expand Up @@ -110,6 +110,10 @@ void AdlEngine::openFile(Common::File &file, const Common::String &name) const {
error("Error opening '%s'", name.c_str());
}

void AdlEngine::printMessage(uint idx) {
printString(_messages[idx - 1]);
}

void AdlEngine::delay(uint32 ms) const {
uint32 start = g_system->getMillis();

Expand Down Expand Up @@ -513,6 +517,8 @@ Common::Error AdlEngine::run() {
// (Also see comment below.)
if (!_isRestoring) {
clearScreen();
// FIXME: Should only be called when room changes
loadRoom(_state.room);
showRoom();

_canSaveNow = _canRestoreNow = true;
Expand Down
4 changes: 3 additions & 1 deletion engines/adl/adl.h
Expand Up @@ -192,7 +192,8 @@ class AdlEngine : public Engine {
Common::String readStringAt(Common::SeekableReadStream &stream, uint offset, byte until = 0) const;
void openFile(Common::File &file, const Common::String &name) const;

virtual void printMessage(uint idx) = 0;
virtual void printString(const Common::String &str) = 0;
virtual void printMessage(uint idx);
void delay(uint32 ms) const;

Common::String inputString(byte prompt = 0) const;
Expand Down Expand Up @@ -310,6 +311,7 @@ class AdlEngine : public Engine {
virtual void initState() = 0;
virtual void restartGame() = 0;
virtual void drawItem(const Item &item, const Common::Point &pos) const = 0;
virtual void loadRoom(byte roomNr) = 0;
virtual void showRoom() = 0;

// Engine
Expand Down
2 changes: 1 addition & 1 deletion engines/adl/adl_v2.h
Expand Up @@ -49,9 +49,9 @@ class AdlEngine_v2 : public AdlEngine {
bool matchesCurrentPic(byte pic) const;
byte roomArg(byte room) const;
void advanceClock();
void printString(const Common::String &str);

void checkTextOverflow(char c);
void printString(const Common::String &str);

int o2_isFirstTime(ScriptEnv &e);
int o2_isRandomGT(ScriptEnv &e);
Expand Down
23 changes: 17 additions & 6 deletions engines/adl/hires1.cpp
Expand Up @@ -268,10 +268,17 @@ void HiRes1Engine::drawPic(byte pic, Common::Point pos) const {
_graphics->drawPic(*_pictures[pic].data->createReadStream(), pos, 0x7f);
}

void HiRes1Engine::printString(const Common::String &str) {
Common::String wrap = str;
wordWrap(wrap);
_display->printString(wrap);

if (_messageDelay)
delay(14 * 166018 / 1000);
}

void HiRes1Engine::printMessage(uint idx) {
Common::String msg = _messages[idx - 1];
wordWrap(msg);
_display->printString(msg);
const Common::String &msg = _messages[idx - 1];

// Messages with hardcoded overrides don't delay after printing.
// It's unclear if this is a bug or not. In some cases the result
Expand All @@ -285,11 +292,11 @@ void HiRes1Engine::printMessage(uint idx) {
case IDI_HR1_MSG_DONT_HAVE_IT:
case IDI_HR1_MSG_DONT_UNDERSTAND:
case IDI_HR1_MSG_GETTING_DARK:
_display->printString(msg);
return;
}

if (_messageDelay)
delay(14 * 166018 / 1000);
printString(msg);
}

void HiRes1Engine::drawItem(const Item &item, const Common::Point &pos) const {
Expand All @@ -300,6 +307,10 @@ void HiRes1Engine::drawItem(const Item &item, const Common::Point &pos) const {
drawPic(item.picture, pos);
}

void HiRes1Engine::loadRoom(byte roomNr) {
_roomData.description = _messages[_roomDesc[_state.room - 1] - 1];
}

void HiRes1Engine::showRoom() {
if (!_state.isDark) {
drawPic(getCurRoom().curPicture);
Expand All @@ -308,7 +319,7 @@ void HiRes1Engine::showRoom() {

_display->updateHiResScreen();
_messageDelay = false;
printMessage(_roomDesc[_state.room - 1]);
printString(_roomData.description);
_messageDelay = true;
}

Expand Down
2 changes: 2 additions & 0 deletions engines/adl/hires1.h
Expand Up @@ -104,8 +104,10 @@ class HiRes1Engine : public AdlEngine {
void initState();
void restartGame();
void drawPic(byte pic, Common::Point pos = Common::Point()) const;
void printString(const Common::String &str);
void printMessage(uint idx);
void drawItem(const Item &item, const Common::Point &pos) const;
void loadRoom(byte roomNr);
void showRoom();

void wordWrap(Common::String &str) const;
Expand Down
51 changes: 23 additions & 28 deletions engines/adl/hires2.cpp
Expand Up @@ -182,29 +182,6 @@ void HiRes2Engine::initState() {
}
}

void HiRes2Engine::loadRoom(byte roomNr) {
Room &room = getRoom(roomNr);
StreamPtr stream(room.data->createReadStream());

uint16 descOffset = stream->readUint16LE();
uint16 commandOffset = stream->readUint16LE();

// There's no picture count. The original engine always checks at most
// five pictures. We use the description offset to bound our search.
uint16 picCount = (descOffset - 4) / 5;

for (uint i = 0; i < picCount; ++i) {
Picture2 pic;
readPictureMeta(*stream, pic);
_roomData.pictures.push_back(pic);
}

_roomData.description = readStringAt(*stream, descOffset, 0xff);

stream->seek(commandOffset);
readCommands(*stream, _roomData.commands);
}

void HiRes2Engine::restartGame() {
initState();
}
Expand All @@ -230,19 +207,37 @@ void HiRes2Engine::drawItem(const Item &item, const Common::Point &pos) const {
_graphics->drawPic(*stream, pos, 0);
}

void HiRes2Engine::loadRoom(byte roomNr) {
Room &room = getRoom(roomNr);
StreamPtr stream(room.data->createReadStream());

uint16 descOffset = stream->readUint16LE();
uint16 commandOffset = stream->readUint16LE();

// There's no picture count. The original engine always checks at most
// five pictures. We use the description offset to bound our search.
uint16 picCount = (descOffset - 4) / 5;

for (uint i = 0; i < picCount; ++i) {
Picture2 pic;
readPictureMeta(*stream, pic);
_roomData.pictures.push_back(pic);
}

_roomData.description = readStringAt(*stream, descOffset, 0xff);

stream->seek(commandOffset);
readCommands(*stream, _roomData.commands);
}

void HiRes2Engine::showRoom() {
loadRoom(_state.room);
drawPic(getCurRoom().curPicture, Common::Point());
drawItems();
_display->updateHiResScreen();
printString(_roomData.description);
_linesPrinted = 0;
}

void HiRes2Engine::printMessage(uint idx) {
printString(_messages[idx - 1]);
}

Engine *HiRes2Engine_create(OSystem *syst, const AdlGameDescription *gd) {
return new HiRes2Engine(syst, gd);
}
Expand Down
3 changes: 1 addition & 2 deletions engines/adl/hires2.h
Expand Up @@ -62,10 +62,9 @@ class HiRes2Engine : public AdlEngine_v2 {
void restartGame();
void drawPic(byte pic, Common::Point pos) const;
void drawItem(const Item &item, const Common::Point &pos) const;
void loadRoom(byte roomNr);
void showRoom();
void printMessage(uint idx);

void loadRoom(byte roomNr);
DataBlockPtr readDataBlockPtr(Common::ReadStream &f) const;
void readPictureMeta(Common::ReadStream &f, Picture2 &pic) const;

Expand Down

0 comments on commit 41e8227

Please sign in to comment.