2016-02-26 22:32:06 +00:00
|
|
|
/* 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 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2016-03-05 21:10:54 +00:00
|
|
|
#include "common/system.h"
|
2016-02-26 22:32:06 +00:00
|
|
|
#include "common/debug.h"
|
|
|
|
#include "common/error.h"
|
|
|
|
#include "common/file.h"
|
|
|
|
#include "common/stream.h"
|
2016-03-14 09:40:51 +00:00
|
|
|
#include "common/ptr.h"
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2016-08-29 19:30:23 +00:00
|
|
|
#include "adl/adl.h"
|
|
|
|
#include "adl/graphics.h"
|
2018-07-28 12:39:12 +00:00
|
|
|
#include "adl/display_a2.h"
|
2016-02-26 22:32:06 +00:00
|
|
|
|
|
|
|
namespace Adl {
|
|
|
|
|
2016-08-29 19:30:23 +00:00
|
|
|
#define IDS_HR1_EXE_0 "AUTO LOAD OBJ"
|
|
|
|
#define IDS_HR1_EXE_1 "ADVENTURE"
|
|
|
|
#define IDS_HR1_MESSAGES "MESSAGES"
|
|
|
|
|
|
|
|
#define IDI_HR1_NUM_ROOMS 41
|
|
|
|
#define IDI_HR1_NUM_PICS 97
|
|
|
|
#define IDI_HR1_NUM_VARS 20
|
|
|
|
#define IDI_HR1_NUM_ITEM_OFFSETS 21
|
|
|
|
#define IDI_HR1_NUM_MESSAGES 168
|
|
|
|
|
|
|
|
// Messages used outside of scripts
|
|
|
|
#define IDI_HR1_MSG_CANT_GO_THERE 137
|
|
|
|
#define IDI_HR1_MSG_DONT_UNDERSTAND 37
|
|
|
|
#define IDI_HR1_MSG_ITEM_DOESNT_MOVE 151
|
|
|
|
#define IDI_HR1_MSG_ITEM_NOT_HERE 152
|
|
|
|
#define IDI_HR1_MSG_THANKS_FOR_PLAYING 140
|
|
|
|
#define IDI_HR1_MSG_DONT_HAVE_IT 127
|
|
|
|
#define IDI_HR1_MSG_GETTING_DARK 7
|
|
|
|
|
|
|
|
#define IDI_HR1_OFS_STR_ENTER_COMMAND 0x5bbc
|
|
|
|
#define IDI_HR1_OFS_STR_VERB_ERROR 0x5b4f
|
|
|
|
#define IDI_HR1_OFS_STR_NOUN_ERROR 0x5b8e
|
|
|
|
#define IDI_HR1_OFS_STR_PLAY_AGAIN 0x5f1e
|
|
|
|
#define IDI_HR1_OFS_STR_CANT_GO_THERE 0x6c0a
|
|
|
|
#define IDI_HR1_OFS_STR_DONT_HAVE_IT 0x6c31
|
|
|
|
#define IDI_HR1_OFS_STR_DONT_UNDERSTAND 0x6c51
|
|
|
|
#define IDI_HR1_OFS_STR_GETTING_DARK 0x6c7c
|
|
|
|
#define IDI_HR1_OFS_STR_PRESS_RETURN 0x5f68
|
|
|
|
#define IDI_HR1_OFS_STR_LINE_FEEDS 0x59d4
|
|
|
|
|
|
|
|
#define IDI_HR1_OFS_PD_TEXT_0 0x005d
|
|
|
|
#define IDI_HR1_OFS_PD_TEXT_1 0x012b
|
|
|
|
#define IDI_HR1_OFS_PD_TEXT_2 0x016d
|
|
|
|
#define IDI_HR1_OFS_PD_TEXT_3 0x0259
|
|
|
|
|
|
|
|
#define IDI_HR1_OFS_INTRO_TEXT 0x0066
|
|
|
|
#define IDI_HR1_OFS_GAME_OR_HELP 0x000f
|
|
|
|
|
|
|
|
#define IDI_HR1_OFS_LOGO_0 0x1003
|
|
|
|
|
|
|
|
#define IDI_HR1_OFS_ITEMS 0x0100
|
|
|
|
#define IDI_HR1_OFS_ROOMS 0x050a
|
|
|
|
#define IDI_HR1_OFS_PICS 0x4b03
|
|
|
|
#define IDI_HR1_OFS_CMDS_0 0x3c00
|
|
|
|
#define IDI_HR1_OFS_CMDS_1 0x3d00
|
|
|
|
#define IDI_HR1_OFS_MSGS 0x4d00
|
|
|
|
|
|
|
|
#define IDI_HR1_OFS_ITEM_OFFSETS 0x68ff
|
2017-02-27 09:17:21 +00:00
|
|
|
#define IDI_HR1_OFS_SHAPES 0x4f00
|
2016-08-29 19:30:23 +00:00
|
|
|
|
|
|
|
#define IDI_HR1_OFS_VERBS 0x3800
|
|
|
|
#define IDI_HR1_OFS_NOUNS 0x0f00
|
|
|
|
|
|
|
|
class HiRes1Engine : public AdlEngine {
|
|
|
|
public:
|
|
|
|
HiRes1Engine(OSystem *syst, const AdlGameDescription *gd) :
|
|
|
|
AdlEngine(syst, gd),
|
|
|
|
_files(nullptr),
|
|
|
|
_messageDelay(true) { }
|
|
|
|
~HiRes1Engine() { delete _files; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// AdlEngine
|
2016-12-11 12:35:15 +00:00
|
|
|
void runIntro();
|
2016-08-29 19:30:23 +00:00
|
|
|
void init();
|
|
|
|
void initGameState();
|
|
|
|
void restartGame();
|
|
|
|
void printString(const Common::String &str);
|
|
|
|
Common::String loadMessage(uint idx) const;
|
|
|
|
void printMessage(uint idx);
|
|
|
|
void drawItems();
|
|
|
|
void drawItem(Item &item, const Common::Point &pos);
|
|
|
|
void loadRoom(byte roomNr);
|
|
|
|
void showRoom();
|
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
void showInstructions(Common::SeekableReadStream &stream, const uint pages[], bool goHome);
|
2016-08-29 19:30:23 +00:00
|
|
|
void wordWrap(Common::String &str) const;
|
|
|
|
|
|
|
|
Files *_files;
|
|
|
|
Common::File _exe;
|
|
|
|
Common::Array<DataBlockPtr> _corners;
|
|
|
|
Common::Array<byte> _roomDesc;
|
|
|
|
bool _messageDelay;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
Common::String cantGoThere;
|
|
|
|
Common::String dontHaveIt;
|
|
|
|
Common::String dontUnderstand;
|
|
|
|
Common::String gettingDark;
|
|
|
|
} _gameStrings;
|
|
|
|
};
|
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
void HiRes1Engine::showInstructions(Common::SeekableReadStream &stream, const uint pages[], bool goHome) {
|
2018-07-28 12:39:12 +00:00
|
|
|
_display->setMode(Display::kModeText);
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
uint page = 0;
|
|
|
|
while (pages[page] != 0) {
|
|
|
|
if (goHome)
|
|
|
|
_display->home();
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
uint count = pages[page++];
|
|
|
|
for (uint i = 0; i < count; ++i) {
|
|
|
|
_display->printString(readString(stream));
|
|
|
|
stream.seek(3, SEEK_CUR);
|
|
|
|
}
|
|
|
|
|
|
|
|
inputString();
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-03 10:42:03 +00:00
|
|
|
if (shouldQuit())
|
|
|
|
return;
|
2018-02-04 15:11:59 +00:00
|
|
|
|
|
|
|
stream.seek((goHome ? 6 : 3), SEEK_CUR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HiRes1Engine::runIntro() {
|
|
|
|
StreamPtr stream(_files->createReadStream(IDS_HR1_EXE_0));
|
|
|
|
|
|
|
|
// Early version have no bitmap in 'AUTO LOAD OBJ'
|
|
|
|
if (getGameVersion() >= GAME_VER_HR1_COARSE) {
|
|
|
|
stream->seek(IDI_HR1_OFS_LOGO_0);
|
2018-07-28 12:39:12 +00:00
|
|
|
_display->setMode(Display::kModeGraphics);
|
|
|
|
static_cast<Display_A2 *>(_display)->loadFrameBuffer(*stream);
|
2019-07-22 06:54:08 +00:00
|
|
|
_display->renderGraphics();
|
2018-02-04 15:11:59 +00:00
|
|
|
|
|
|
|
if (getGameVersion() == GAME_VER_HR1_PD) {
|
|
|
|
// Only the PD version shows a title screen during the load
|
|
|
|
delay(4000);
|
|
|
|
|
|
|
|
if (shouldQuit())
|
|
|
|
return;
|
|
|
|
}
|
2018-02-03 10:42:03 +00:00
|
|
|
}
|
2016-02-26 22:32:06 +00:00
|
|
|
|
|
|
|
Common::String str;
|
|
|
|
|
2018-02-03 10:42:03 +00:00
|
|
|
// Show the PD disclaimer for the PD release
|
|
|
|
if (getGameVersion() == GAME_VER_HR1_PD) {
|
|
|
|
// The PD release on the Roberta Williams Anthology disc has a PDE
|
|
|
|
// splash screen. The original HELLO file has been renamed to
|
|
|
|
// MYSTERY.HELLO. It's unclear whether or not this splash screen
|
|
|
|
// was present in the original PD release back in 1987.
|
|
|
|
StreamPtr basic(_files->createReadStream("MYSTERY.HELLO"));
|
|
|
|
|
2018-07-28 12:39:12 +00:00
|
|
|
_display->setMode(Display::kModeText);
|
2018-02-03 10:42:03 +00:00
|
|
|
_display->home();
|
|
|
|
|
|
|
|
str = readStringAt(*basic, IDI_HR1_OFS_PD_TEXT_0, '"');
|
|
|
|
_display->printAsciiString(str + '\r');
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-03 10:42:03 +00:00
|
|
|
str = readStringAt(*basic, IDI_HR1_OFS_PD_TEXT_1, '"');
|
|
|
|
_display->printAsciiString(str + "\r\r");
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-03 10:42:03 +00:00
|
|
|
str = readStringAt(*basic, IDI_HR1_OFS_PD_TEXT_2, '"');
|
|
|
|
_display->printAsciiString(str + "\r\r");
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-03 10:42:03 +00:00
|
|
|
str = readStringAt(*basic, IDI_HR1_OFS_PD_TEXT_3, '"');
|
|
|
|
_display->printAsciiString(str + '\r');
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-03 10:42:03 +00:00
|
|
|
inputKey();
|
2018-02-04 15:11:59 +00:00
|
|
|
if (shouldQuit())
|
2018-02-03 10:42:03 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-07-28 12:39:12 +00:00
|
|
|
_display->setMode(Display::kModeMixed);
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2016-03-24 08:51:51 +00:00
|
|
|
str = readStringAt(*stream, IDI_HR1_OFS_GAME_OR_HELP);
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
if (getGameVersion() >= GAME_VER_HR1_COARSE) {
|
|
|
|
bool instructions = false;
|
2016-02-29 15:50:24 +00:00
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
while (1) {
|
|
|
|
_display->printString(str);
|
|
|
|
Common::String s = inputString();
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
if (shouldQuit())
|
|
|
|
break;
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
if (s.empty())
|
|
|
|
continue;
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2018-08-02 08:56:49 +00:00
|
|
|
if (s[0] == _display->asciiToNative('I')) {
|
2018-02-04 15:11:59 +00:00
|
|
|
instructions = true;
|
|
|
|
break;
|
2018-08-02 08:56:49 +00:00
|
|
|
} else if (s[0] == _display->asciiToNative('G')) {
|
2018-02-04 15:11:59 +00:00
|
|
|
break;
|
2016-03-06 21:50:17 +00:00
|
|
|
}
|
2018-02-04 15:11:59 +00:00
|
|
|
}
|
2016-03-06 21:50:17 +00:00
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
if (instructions) {
|
|
|
|
// This version shows the last page during the loading of the game
|
|
|
|
// We wait for a key instead (even though there's no prompt for that).
|
|
|
|
const uint pages[] = { 6, 6, 4, 5, 8, 7, 0 };
|
|
|
|
stream->seek(IDI_HR1_OFS_INTRO_TEXT);
|
|
|
|
showInstructions(*stream, pages, true);
|
|
|
|
_display->printAsciiString("\r");
|
2016-02-29 15:50:24 +00:00
|
|
|
}
|
2018-02-04 15:11:59 +00:00
|
|
|
} else {
|
|
|
|
const uint pages[] = { 6, 6, 8, 6, 0 };
|
|
|
|
stream->seek(6);
|
|
|
|
showInstructions(*stream, pages, false);
|
2016-02-26 22:32:06 +00:00
|
|
|
}
|
2016-02-29 15:50:24 +00:00
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
stream.reset(_files->createReadStream(IDS_HR1_EXE_1));
|
|
|
|
stream->seek(0x1800);
|
2018-07-28 12:39:12 +00:00
|
|
|
static_cast<Display_A2 *>(_display)->loadFrameBuffer(*stream);
|
2019-07-22 06:54:08 +00:00
|
|
|
_display->renderGraphics();
|
2016-02-29 15:50:24 +00:00
|
|
|
|
2018-07-28 12:39:12 +00:00
|
|
|
_display->setMode(Display::kModeMixed);
|
2016-02-29 15:50:24 +00:00
|
|
|
|
2018-02-04 15:11:59 +00:00
|
|
|
if (getGameVersion() == GAME_VER_HR1_SIMI) {
|
|
|
|
// The original waits for the key after initializing the state.
|
|
|
|
// This causes it to also wait for a key on a blank screen when
|
|
|
|
// a game is restarted. We only wait for a key here during the
|
|
|
|
// intro.
|
|
|
|
|
|
|
|
// This does mean we need to push out some extra line feeds to clear the screen
|
|
|
|
_display->printString(_strings.lineFeeds);
|
|
|
|
inputKey();
|
|
|
|
if (shouldQuit())
|
|
|
|
return;
|
|
|
|
}
|
2016-02-26 22:32:06 +00:00
|
|
|
}
|
|
|
|
|
2016-03-14 09:04:51 +00:00
|
|
|
void HiRes1Engine::init() {
|
2018-02-03 10:36:35 +00:00
|
|
|
if (Common::File::exists("ADVENTURE")) {
|
2016-03-26 00:01:10 +00:00
|
|
|
_files = new Files_Plain();
|
2018-02-03 10:36:35 +00:00
|
|
|
} else {
|
2018-02-03 10:42:03 +00:00
|
|
|
Files_AppleDOS *files = new Files_AppleDOS();
|
|
|
|
// The 2nd release obfuscates the VTOC (same may be true for the 1st release)
|
|
|
|
if (!files->open(getDiskImageName(0), (getGameVersion() == GAME_VER_HR1_COARSE ? 16 : 17)))
|
2018-02-03 10:36:35 +00:00
|
|
|
error("Failed to open '%s'", getDiskImageName(0).c_str());
|
|
|
|
_files = files;
|
|
|
|
}
|
2016-03-24 21:50:42 +00:00
|
|
|
|
2018-07-28 12:39:12 +00:00
|
|
|
_graphics = new GraphicsMan_v1<Display_A2>(*static_cast<Display_A2 *>(_display));
|
2018-02-03 10:42:03 +00:00
|
|
|
_display->moveCursorTo(Common::Point(0, 3));
|
2016-03-14 09:04:51 +00:00
|
|
|
|
2016-04-09 15:00:49 +00:00
|
|
|
StreamPtr stream(_files->createReadStream(IDS_HR1_EXE_1));
|
2016-02-28 20:01:01 +00:00
|
|
|
|
2016-03-07 14:19:26 +00:00
|
|
|
// Some messages have overrides inside the executable
|
2016-04-09 15:00:49 +00:00
|
|
|
_gameStrings.cantGoThere = readStringAt(*stream, IDI_HR1_OFS_STR_CANT_GO_THERE);
|
|
|
|
_gameStrings.dontHaveIt = readStringAt(*stream, IDI_HR1_OFS_STR_DONT_HAVE_IT);
|
|
|
|
_gameStrings.dontUnderstand = readStringAt(*stream, IDI_HR1_OFS_STR_DONT_UNDERSTAND);
|
|
|
|
_gameStrings.gettingDark = readStringAt(*stream, IDI_HR1_OFS_STR_GETTING_DARK);
|
2016-03-07 14:19:26 +00:00
|
|
|
|
|
|
|
// Load other strings from executable
|
2016-03-24 08:51:51 +00:00
|
|
|
_strings.enterCommand = readStringAt(*stream, IDI_HR1_OFS_STR_ENTER_COMMAND);
|
|
|
|
_strings.verbError = readStringAt(*stream, IDI_HR1_OFS_STR_VERB_ERROR);
|
|
|
|
_strings.nounError = readStringAt(*stream, IDI_HR1_OFS_STR_NOUN_ERROR);
|
|
|
|
_strings.playAgain = readStringAt(*stream, IDI_HR1_OFS_STR_PLAY_AGAIN);
|
|
|
|
_strings.pressReturn = readStringAt(*stream, IDI_HR1_OFS_STR_PRESS_RETURN);
|
2016-04-03 11:45:31 +00:00
|
|
|
_strings.lineFeeds = readStringAt(*stream, IDI_HR1_OFS_STR_LINE_FEEDS);
|
2016-03-07 14:19:26 +00:00
|
|
|
|
|
|
|
// Set message IDs
|
|
|
|
_messageIds.cantGoThere = IDI_HR1_MSG_CANT_GO_THERE;
|
|
|
|
_messageIds.dontUnderstand = IDI_HR1_MSG_DONT_UNDERSTAND;
|
|
|
|
_messageIds.itemDoesntMove = IDI_HR1_MSG_ITEM_DOESNT_MOVE;
|
|
|
|
_messageIds.itemNotHere = IDI_HR1_MSG_ITEM_NOT_HERE;
|
|
|
|
_messageIds.thanksForPlaying = IDI_HR1_MSG_THANKS_FOR_PLAYING;
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2016-04-09 15:00:49 +00:00
|
|
|
// Load message offsets
|
|
|
|
stream->seek(IDI_HR1_OFS_MSGS);
|
|
|
|
for (uint i = 0; i < IDI_HR1_NUM_MESSAGES; ++i)
|
|
|
|
_messages.push_back(_files->getDataBlock(IDS_HR1_MESSAGES, stream->readUint16LE()));
|
|
|
|
|
2016-02-26 22:32:06 +00:00
|
|
|
// Load picture data from executable
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->seek(IDI_HR1_OFS_PICS);
|
2016-03-26 15:27:51 +00:00
|
|
|
for (uint i = 1; i <= IDI_HR1_NUM_PICS; ++i) {
|
2016-03-24 08:51:51 +00:00
|
|
|
byte block = stream->readByte();
|
|
|
|
Common::String name = Common::String::format("BLOCK%i", block);
|
|
|
|
uint16 offset = stream->readUint16LE();
|
2016-03-26 15:27:51 +00:00
|
|
|
_pictures[i] = _files->getDataBlock(name, offset);
|
2016-02-26 22:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Load commands from executable
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->seek(IDI_HR1_OFS_CMDS_1);
|
|
|
|
readCommands(*stream, _roomCommands);
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->seek(IDI_HR1_OFS_CMDS_0);
|
|
|
|
readCommands(*stream, _globalCommands);
|
2016-02-26 22:32:06 +00:00
|
|
|
|
|
|
|
// Load dropped item offsets
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->seek(IDI_HR1_OFS_ITEM_OFFSETS);
|
2016-08-28 18:29:11 +00:00
|
|
|
loadDroppedItemOffsets(*stream, IDI_HR1_NUM_ITEM_OFFSETS);
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2017-02-27 09:17:21 +00:00
|
|
|
// Load shapes
|
|
|
|
stream->seek(IDI_HR1_OFS_SHAPES);
|
2016-03-24 08:51:51 +00:00
|
|
|
uint16 cornersCount = stream->readUint16LE();
|
2016-03-14 09:04:51 +00:00
|
|
|
for (uint i = 0; i < cornersCount; ++i)
|
2017-02-27 09:17:21 +00:00
|
|
|
_corners.push_back(_files->getDataBlock(IDS_HR1_EXE_1, IDI_HR1_OFS_SHAPES + stream->readUint16LE()));
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2016-03-24 08:51:51 +00:00
|
|
|
if (stream->eos() || stream->err())
|
2016-03-06 10:58:21 +00:00
|
|
|
error("Failed to read game data from '" IDS_HR1_EXE_1 "'");
|
|
|
|
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->seek(IDI_HR1_OFS_VERBS);
|
2016-03-31 13:39:46 +00:00
|
|
|
loadWords(*stream, _verbs, _priVerbs);
|
2016-02-26 22:32:06 +00:00
|
|
|
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->seek(IDI_HR1_OFS_NOUNS);
|
2016-03-31 13:39:46 +00:00
|
|
|
loadWords(*stream, _nouns, _priNouns);
|
2016-02-26 22:32:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-10 13:20:17 +00:00
|
|
|
void HiRes1Engine::initGameState() {
|
2016-03-07 19:43:37 +00:00
|
|
|
_state.vars.resize(IDI_HR1_NUM_VARS);
|
|
|
|
|
2016-03-24 21:50:42 +00:00
|
|
|
StreamPtr stream(_files->createReadStream(IDS_HR1_EXE_1));
|
2016-03-07 19:43:37 +00:00
|
|
|
|
|
|
|
// Load room data from executable
|
2016-03-10 19:44:56 +00:00
|
|
|
_roomDesc.clear();
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->seek(IDI_HR1_OFS_ROOMS);
|
2016-03-07 19:43:37 +00:00
|
|
|
for (uint i = 0; i < IDI_HR1_NUM_ROOMS; ++i) {
|
2016-03-23 10:14:51 +00:00
|
|
|
Room room;
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->readByte();
|
|
|
|
_roomDesc.push_back(stream->readByte());
|
2016-03-07 19:43:37 +00:00
|
|
|
for (uint j = 0; j < 6; ++j)
|
2016-03-24 08:51:51 +00:00
|
|
|
room.connections[j] = stream->readByte();
|
|
|
|
room.picture = stream->readByte();
|
|
|
|
room.curPicture = stream->readByte();
|
2016-03-07 19:43:37 +00:00
|
|
|
_state.rooms.push_back(room);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load item data from executable
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->seek(IDI_HR1_OFS_ITEMS);
|
2016-03-31 21:42:03 +00:00
|
|
|
byte id;
|
|
|
|
while ((id = stream->readByte()) != 0xff) {
|
2016-12-23 22:47:25 +00:00
|
|
|
Item item;
|
|
|
|
|
2016-03-31 21:42:03 +00:00
|
|
|
item.id = id;
|
2016-03-24 08:51:51 +00:00
|
|
|
item.noun = stream->readByte();
|
|
|
|
item.room = stream->readByte();
|
|
|
|
item.picture = stream->readByte();
|
2017-02-27 09:17:21 +00:00
|
|
|
item.isShape = stream->readByte();
|
2016-03-24 08:51:51 +00:00
|
|
|
item.position.x = stream->readByte();
|
|
|
|
item.position.y = stream->readByte();
|
|
|
|
item.state = stream->readByte();
|
|
|
|
item.description = stream->readByte();
|
2016-03-07 19:43:37 +00:00
|
|
|
|
2016-03-24 08:51:51 +00:00
|
|
|
stream->readByte();
|
2016-03-07 19:43:37 +00:00
|
|
|
|
2016-03-24 08:51:51 +00:00
|
|
|
byte size = stream->readByte();
|
2016-03-07 19:43:37 +00:00
|
|
|
|
|
|
|
for (uint i = 0; i < size; ++i)
|
2016-03-24 08:51:51 +00:00
|
|
|
item.roomPictures.push_back(stream->readByte());
|
2016-03-07 19:43:37 +00:00
|
|
|
|
|
|
|
_state.items.push_back(item);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HiRes1Engine::restartGame() {
|
2016-03-10 23:24:31 +00:00
|
|
|
_display->printString(_strings.pressReturn);
|
2016-04-03 11:45:31 +00:00
|
|
|
initState();
|
|
|
|
_display->printAsciiString(_strings.lineFeeds);
|
2016-03-07 19:43:37 +00:00
|
|
|
}
|
|
|
|
|
2016-03-26 13:29:26 +00:00
|
|
|
void HiRes1Engine::printString(const Common::String &str) {
|
|
|
|
Common::String wrap = str;
|
|
|
|
wordWrap(wrap);
|
|
|
|
_display->printString(wrap);
|
|
|
|
|
|
|
|
if (_messageDelay)
|
|
|
|
delay(14 * 166018 / 1000);
|
|
|
|
}
|
|
|
|
|
2016-04-09 15:00:49 +00:00
|
|
|
Common::String HiRes1Engine::loadMessage(uint idx) const {
|
2018-08-02 08:56:49 +00:00
|
|
|
const char returnChar = _display->asciiToNative('\r');
|
2016-04-09 15:00:49 +00:00
|
|
|
StreamPtr stream(_messages[idx]->createReadStream());
|
2018-08-02 08:56:49 +00:00
|
|
|
return readString(*stream, returnChar) + returnChar;
|
2016-04-09 15:00:49 +00:00
|
|
|
}
|
2016-03-26 13:11:18 +00:00
|
|
|
|
2016-04-09 15:00:49 +00:00
|
|
|
void HiRes1Engine::printMessage(uint idx) {
|
2016-03-07 14:19:26 +00:00
|
|
|
// Messages with hardcoded overrides don't delay after printing.
|
|
|
|
// It's unclear if this is a bug or not. In some cases the result
|
|
|
|
// is that these strings will scroll past the four-line text window
|
|
|
|
// before the user gets a chance to read them.
|
|
|
|
// NOTE: later games seem to wait for a key when the text window
|
|
|
|
// overflows and don't use delays. It might be better to use
|
|
|
|
// that system for this game as well.
|
2016-02-28 12:24:41 +00:00
|
|
|
switch (idx) {
|
2016-02-28 12:43:28 +00:00
|
|
|
case IDI_HR1_MSG_CANT_GO_THERE:
|
2016-04-09 15:00:49 +00:00
|
|
|
_display->printString(_gameStrings.cantGoThere);
|
|
|
|
return;
|
2016-02-28 12:43:28 +00:00
|
|
|
case IDI_HR1_MSG_DONT_HAVE_IT:
|
2016-04-09 15:00:49 +00:00
|
|
|
_display->printString(_gameStrings.dontHaveIt);
|
|
|
|
return;
|
2016-03-02 11:59:11 +00:00
|
|
|
case IDI_HR1_MSG_DONT_UNDERSTAND:
|
2016-04-09 15:00:49 +00:00
|
|
|
_display->printString(_gameStrings.dontUnderstand);
|
|
|
|
return;
|
2016-02-28 12:43:28 +00:00
|
|
|
case IDI_HR1_MSG_GETTING_DARK:
|
2016-04-09 15:00:49 +00:00
|
|
|
_display->printString(_gameStrings.gettingDark);
|
2016-03-26 13:11:18 +00:00
|
|
|
return;
|
2016-04-09 15:00:49 +00:00
|
|
|
default:
|
|
|
|
printString(loadMessage(idx));
|
2016-02-28 12:24:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-03 17:26:34 +00:00
|
|
|
void HiRes1Engine::drawItems() {
|
|
|
|
Common::List<Item>::iterator item;
|
|
|
|
|
|
|
|
uint dropped = 0;
|
|
|
|
|
|
|
|
for (item = _state.items.begin(); item != _state.items.end(); ++item) {
|
|
|
|
// Skip items not in this room
|
|
|
|
if (item->room != _state.room)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (item->state == IDI_ITEM_DROPPED) {
|
|
|
|
// Draw dropped item if in normal view
|
|
|
|
if (getCurRoom().picture == getCurRoom().curPicture)
|
|
|
|
drawItem(*item, _itemOffsets[dropped++]);
|
|
|
|
} else {
|
|
|
|
// Draw fixed item if current view is in the pic list
|
|
|
|
Common::Array<byte>::const_iterator pic;
|
|
|
|
|
|
|
|
for (pic = item->roomPictures.begin(); pic != item->roomPictures.end(); ++pic) {
|
|
|
|
if (*pic == getCurRoom().curPicture) {
|
|
|
|
drawItem(*item, item->position);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void HiRes1Engine::drawItem(Item &item, const Common::Point &pos) {
|
2017-02-27 09:17:21 +00:00
|
|
|
if (item.isShape) {
|
2016-03-24 08:51:51 +00:00
|
|
|
StreamPtr stream(_corners[item.picture - 1]->createReadStream());
|
2017-02-27 09:17:21 +00:00
|
|
|
Common::Point p(pos);
|
|
|
|
_graphics->drawShape(*stream, p);
|
2016-03-14 09:04:51 +00:00
|
|
|
} else
|
|
|
|
drawPic(item.picture, pos);
|
|
|
|
}
|
|
|
|
|
2016-03-26 13:29:26 +00:00
|
|
|
void HiRes1Engine::loadRoom(byte roomNr) {
|
2016-04-09 11:29:34 +00:00
|
|
|
_roomData.description = loadMessage(_roomDesc[_state.room - 1]);
|
2016-03-26 13:29:26 +00:00
|
|
|
}
|
|
|
|
|
2016-03-14 14:39:19 +00:00
|
|
|
void HiRes1Engine::showRoom() {
|
2016-08-21 10:27:45 +00:00
|
|
|
_state.curPicture = getCurRoom().curPicture;
|
2017-01-30 20:54:02 +00:00
|
|
|
_graphics->clearScreen();
|
2016-04-03 17:26:34 +00:00
|
|
|
loadRoom(_state.room);
|
|
|
|
|
2016-03-10 19:44:56 +00:00
|
|
|
if (!_state.isDark) {
|
|
|
|
drawPic(getCurRoom().curPicture);
|
|
|
|
drawItems();
|
|
|
|
}
|
|
|
|
|
2019-07-22 06:54:08 +00:00
|
|
|
_display->renderGraphics();
|
2016-03-26 13:11:18 +00:00
|
|
|
_messageDelay = false;
|
2016-04-11 19:24:24 +00:00
|
|
|
printString(_roomData.description);
|
2016-03-26 13:11:18 +00:00
|
|
|
_messageDelay = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void HiRes1Engine::wordWrap(Common::String &str) const {
|
|
|
|
uint end = 39;
|
|
|
|
|
2018-08-02 08:56:49 +00:00
|
|
|
const char spaceChar = _display->asciiToNative(' ');
|
|
|
|
const char returnChar = _display->asciiToNative('\r');
|
|
|
|
|
2016-03-26 13:11:18 +00:00
|
|
|
while (1) {
|
|
|
|
if (str.size() <= end)
|
|
|
|
return;
|
|
|
|
|
2018-08-02 08:56:49 +00:00
|
|
|
while (str[end] != spaceChar)
|
2016-03-26 13:11:18 +00:00
|
|
|
--end;
|
|
|
|
|
2018-08-02 08:56:49 +00:00
|
|
|
str.setChar(returnChar, end);
|
2016-03-26 13:11:18 +00:00
|
|
|
end += 40;
|
|
|
|
}
|
2016-03-10 19:44:56 +00:00
|
|
|
}
|
|
|
|
|
2016-03-06 20:59:55 +00:00
|
|
|
Engine *HiRes1Engine_create(OSystem *syst, const AdlGameDescription *gd) {
|
2016-02-27 14:03:24 +00:00
|
|
|
return new HiRes1Engine(syst, gd);
|
2016-02-26 22:32:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // End of namespace Adl
|