scummvm/engines/adl/adl.h

388 lines
9.7 KiB
C
Raw Normal View History

2016-02-26 23:32:06 +01: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.
*
*/
#ifndef ADL_ADL_H
#define ADL_ADL_H
#include "common/debug-channels.h"
2016-03-07 20:43:37 +01:00
#include "common/array.h"
2016-02-27 13:54:47 +01:00
#include "common/rect.h"
2016-03-07 20:43:37 +01:00
#include "common/str.h"
2016-03-15 20:06:03 +01:00
#include "common/hashmap.h"
#include "common/hash-str.h"
2016-03-18 00:30:51 +01:00
#include "common/func.h"
#include "common/scummsys.h"
2016-02-27 13:54:47 +01:00
2016-02-26 23:32:06 +01:00
#include "engines/engine.h"
2016-02-27 13:54:47 +01:00
2016-03-15 20:06:03 +01:00
#include "audio/mixer.h"
#include "audio/softsynth/pcspk.h"
2016-03-26 23:26:22 +01:00
#include "adl/console.h"
2016-03-23 11:14:51 +01:00
#include "adl/disk.h"
2016-02-26 23:32:06 +01:00
namespace Common {
class ReadStream;
class SeekableReadStream;
2016-03-15 20:06:03 +01:00
class File;
struct Event;
2016-02-26 23:32:06 +01:00
}
namespace Adl {
2016-03-07 20:43:37 +01:00
2016-03-26 23:26:22 +01:00
class Console;
2016-02-26 23:32:06 +01:00
class Display;
class GraphicsMan;
2016-03-15 20:06:03 +01:00
class Speaker;
2016-02-26 23:32:06 +01:00
struct AdlGameDescription;
2016-03-18 00:30:51 +01:00
struct ScriptEnv;
enum kDebugChannels {
kDebugChannelScript = 1 << 0
};
2016-03-18 11:52:19 +01:00
// Save and restore opcodes
2016-02-28 15:56:17 +01:00
#define IDO_ACT_SAVE 0x0f
#define IDO_ACT_LOAD 0x10
#define IDI_CUR_ROOM 0xfc
#define IDI_VOID_ROOM 0xfd
2016-03-19 14:20:48 +01:00
#define IDI_ANY 0xfe
2016-03-18 12:18:22 +01:00
2016-03-06 19:34:14 +01:00
#define IDI_WORD_SIZE 8
2016-03-18 00:50:30 +01:00
enum Direction {
IDI_DIR_NORTH,
IDI_DIR_SOUTH,
IDI_DIR_EAST,
IDI_DIR_WEST,
IDI_DIR_UP,
IDI_DIR_DOWN,
IDI_DIR_TOTAL
};
2016-02-27 13:35:49 +01:00
struct Room {
2016-03-23 11:14:51 +01:00
Room() :
description(0),
picture(0),
curPicture(0) {
memset(connections, 0, sizeof(connections));
}
2016-02-27 13:35:49 +01:00
byte description;
2016-03-18 00:50:30 +01:00
byte connections[IDI_DIR_TOTAL];
2016-03-23 11:14:51 +01:00
DataBlockPtr data;
2016-02-27 13:35:49 +01:00
byte picture;
2016-02-28 15:18:00 +01:00
byte curPicture;
bool isFirstTime;
2016-02-27 13:35:49 +01:00
};
2016-03-26 16:27:51 +01:00
typedef Common::HashMap<byte, DataBlockPtr> PictureMap;
2016-02-27 13:35:49 +01:00
2016-03-18 00:30:51 +01:00
typedef Common::Array<byte> Script;
2016-02-27 13:35:49 +01:00
struct Command {
byte room;
byte verb, noun;
byte numCond, numAct;
2016-03-18 00:30:51 +01:00
Script script;
};
class ScriptEnv {
public:
2016-03-18 12:18:22 +01:00
ScriptEnv(const Command &cmd, byte room, byte verb, byte noun) :
_cmd(cmd), _room(room), _verb(verb), _noun(noun), _ip(0) { }
2016-03-18 00:30:51 +01:00
2016-03-18 12:18:22 +01:00
byte op() const { return _cmd.script[_ip]; }
// We keep this 1-based for easier comparison with the original engine
2016-03-18 12:18:22 +01:00
byte arg(uint i) const { return _cmd.script[_ip + i]; }
void skip(uint i) { _ip += i; }
bool isMatch() const {
2016-03-19 14:20:48 +01:00
return (_cmd.room == IDI_ANY || _cmd.room == _room) &&
(_cmd.verb == IDI_ANY || _cmd.verb == _verb) &&
(_cmd.noun == IDI_ANY || _cmd.noun == _noun);
2016-03-18 12:18:22 +01:00
}
byte getCondCount() const { return _cmd.numCond; }
byte getActCount() const { return _cmd.numAct; }
byte getNoun() const { return _noun; }
const Command &getCommand() const { return _cmd; }
2016-03-18 12:18:22 +01:00
private:
const Command &_cmd;
const byte _room, _verb, _noun;
byte _ip;
2016-02-27 13:35:49 +01:00
};
2016-02-28 14:24:04 +01:00
enum {
IDI_ITEM_NOT_MOVED,
IDI_ITEM_DROPPED,
2016-02-28 14:24:04 +01:00
IDI_ITEM_DOESNT_MOVE
};
2016-02-27 13:35:49 +01:00
struct Item {
byte id;
2016-02-28 14:24:04 +01:00
byte noun;
byte room;
byte picture;
2016-02-28 17:21:09 +01:00
bool isLineArt;
2016-02-28 14:24:04 +01:00
Common::Point position;
int state;
byte description;
Common::Array<byte> roomPictures;
2016-02-27 13:35:49 +01:00
};
2016-03-20 07:56:53 +01:00
struct Time {
byte hours, minutes;
Time() : hours(12), minutes(0) { }
};
struct State {
Common::Array<Room> rooms;
Common::List<Item> items;
Common::Array<byte> vars;
byte room;
uint16 moves;
bool isDark;
2016-03-20 07:56:53 +01:00
Time time;
2016-03-18 23:41:42 +01:00
State() : room(1), moves(1), isDark(false) { }
};
2016-02-27 13:35:49 +01:00
typedef Common::List<Command> Commands;
2016-03-06 16:43:30 +01:00
typedef Common::HashMap<Common::String, uint> WordMap;
2016-02-26 23:32:06 +01:00
struct RoomData {
Common::String description;
2016-03-26 16:27:51 +01:00
PictureMap pictures;
Commands commands;
};
// Opcode debugging macros
#define OP_DEBUG_0(F) do { \
if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F)) \
return 0; \
} while (0)
#define OP_DEBUG_1(F, P1) do { \
if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1)) \
return 1; \
} while (0)
#define OP_DEBUG_2(F, P1, P2) do { \
if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1, P2)) \
return 2; \
} while (0)
#define OP_DEBUG_3(F, P1, P2, P3) do { \
if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1, P2, P3)) \
return 3; \
} while (0)
#define OP_DEBUG_4(F, P1, P2, P3, P4) do { \
if (DebugMan.isDebugChannelEnabled(kDebugChannelScript) && op_debug(F, P1, P2, P3, P4)) \
return 4; \
} while (0)
2016-02-26 23:32:06 +01:00
class AdlEngine : public Engine {
friend class Console;
2016-02-26 23:32:06 +01:00
public:
virtual ~AdlEngine();
2016-03-26 23:26:22 +01:00
bool pollEvent(Common::Event &event) const;
2016-03-15 20:06:03 +01:00
2016-02-26 23:32:06 +01:00
protected:
2016-03-06 16:43:30 +01:00
AdlEngine(OSystem *syst, const AdlGameDescription *gd);
2016-03-01 15:47:34 +01:00
// Engine
Common::Error loadGameState(int slot);
Common::Error saveGameState(int slot, const Common::String &desc);
2016-03-06 16:43:30 +01:00
Common::String readString(Common::ReadStream &stream, byte until = 0) const;
2016-03-07 15:19:26 +01:00
Common::String readStringAt(Common::SeekableReadStream &stream, uint offset, byte until = 0) const;
2016-03-14 10:40:51 +01:00
void openFile(Common::File &file, const Common::String &name) const;
2016-03-06 22:50:17 +01:00
2016-03-26 14:29:26 +01:00
virtual void printString(const Common::String &str) = 0;
virtual void printMessage(uint idx);
2016-03-06 16:43:30 +01:00
void delay(uint32 ms) const;
2016-03-06 22:50:17 +01:00
Common::String inputString(byte prompt = 0) const;
2016-03-14 15:39:19 +01:00
byte inputKey(bool showCursor = true) const;
2016-03-06 22:50:17 +01:00
void loadWords(Common::ReadStream &stream, WordMap &map, Common::StringArray &pri) const;
2016-03-06 22:50:17 +01:00
void readCommands(Common::ReadStream &stream, Commands &commands);
void checkInput(byte verb, byte noun);
2016-04-01 11:03:22 +02:00
virtual bool isInputValid(byte verb, byte noun, bool &is_any);
virtual bool isInputValid(const Commands &commands, byte verb, byte noun, bool &is_any);
2016-02-27 13:54:47 +01:00
2016-03-18 00:30:51 +01:00
virtual void setupOpcodeTables();
2016-03-19 14:18:01 +01:00
virtual bool matchesCurrentPic(byte pic) const;
virtual byte roomArg(byte room) const;
2016-03-20 07:56:53 +01:00
virtual void advanceClock() { }
2016-03-18 00:30:51 +01:00
// Opcodes
2016-03-18 11:22:01 +01:00
int o1_isItemInRoom(ScriptEnv &e);
2016-03-18 23:41:42 +01:00
int o1_isMovesGT(ScriptEnv &e);
2016-03-18 23:50:24 +01:00
int o1_isVarEQ(ScriptEnv &e);
int o1_isCurPicEQ(ScriptEnv &e);
int o1_isItemPicEQ(ScriptEnv &e);
2016-03-18 11:22:01 +01:00
int o1_varAdd(ScriptEnv &e);
int o1_varSub(ScriptEnv &e);
int o1_varSet(ScriptEnv &e);
int o1_listInv(ScriptEnv &e);
int o1_moveItem(ScriptEnv &e);
int o1_setRoom(ScriptEnv &e);
int o1_setCurPic(ScriptEnv &e);
int o1_setPic(ScriptEnv &e);
int o1_printMsg(ScriptEnv &e);
int o1_setLight(ScriptEnv &e);
int o1_setDark(ScriptEnv &e);
int o1_save(ScriptEnv &e);
int o1_restore(ScriptEnv &e);
int o1_restart(ScriptEnv &e);
int o1_quit(ScriptEnv &e);
int o1_placeItem(ScriptEnv &e);
int o1_setItemPic(ScriptEnv &e);
int o1_resetPic(ScriptEnv &e);
2016-03-18 00:50:30 +01:00
template <Direction D>
2016-03-18 11:22:01 +01:00
int o1_goDirection(ScriptEnv &e);
int o1_takeItem(ScriptEnv &e);
int o1_dropItem(ScriptEnv &e);
int o1_setRoomPic(ScriptEnv &e);
2016-03-18 00:30:51 +01:00
2016-03-10 20:44:56 +01:00
// Graphics
void clearScreen() const;
2016-03-26 22:48:04 +01:00
void drawPic(byte pic, Common::Point pos = Common::Point()) const;
2016-03-10 20:44:56 +01:00
void drawItems() const;
2016-03-15 20:06:03 +01:00
// Sound
void bell(uint count = 1) const;
2016-03-10 20:44:56 +01:00
// Game state functions
const Room &getRoom(uint i) const;
Room &getRoom(uint i);
const Room &getCurRoom() const;
Room &getCurRoom();
const Item &getItem(uint i) const;
Item &getItem(uint i);
byte getVar(uint i) const;
void setVar(uint i, byte value);
void takeItem(byte noun);
void dropItem(byte noun);
2016-03-18 12:18:22 +01:00
bool matchCommand(ScriptEnv &env) const;
2016-03-18 00:30:51 +01:00
void doActions(ScriptEnv &env);
2016-03-10 20:44:56 +01:00
bool doOneCommand(const Commands &commands, byte verb, byte noun);
void doAllCommands(const Commands &commands, byte verb, byte noun);
// Debug functions
static Common::String toAscii(const Common::String &str);
Common::String itemStr(uint i) const;
Common::String roomStr(uint i) const;
Common::String itemRoomStr(uint i) const;
Common::String verbStr(uint i) const;
Common::String nounStr(uint i) const;
Common::String msgStr(uint i) const;
Common::String dirStr(Direction dir) const;
bool op_debug(const char *fmt, ...) const;
Common::DumpFile *_dumpFile;
2016-02-26 23:32:06 +01:00
Display *_display;
GraphicsMan *_graphics;
2016-03-15 20:06:03 +01:00
Speaker *_speaker;
2016-02-26 23:32:06 +01:00
2016-03-18 00:30:51 +01:00
// Opcodes
2016-03-18 11:22:01 +01:00
typedef Common::Functor1<ScriptEnv &, int> Opcode;
2016-03-18 00:30:51 +01:00
Common::Array<const Opcode *> _condOpcodes, _actOpcodes;
2016-03-06 19:34:14 +01:00
// Message strings in data file
Common::Array<Common::String> _messages;
2016-03-06 19:34:14 +01:00
// Picture data
2016-03-26 16:27:51 +01:00
PictureMap _pictures;
2016-03-06 19:34:14 +01:00
// Dropped item screen offsets
2016-02-27 13:54:47 +01:00
Common::Array<Common::Point> _itemOffsets;
2016-03-06 19:34:14 +01:00
// <room, verb, noun, script> lists
2016-02-27 13:54:47 +01:00
Commands _roomCommands;
Commands _globalCommands;
// Data related to the current room
RoomData _roomData;
2016-02-27 13:54:47 +01:00
2016-03-06 19:34:14 +01:00
WordMap _verbs;
WordMap _nouns;
Common::StringArray _priVerbs;
Common::StringArray _priNouns;
2016-03-06 19:34:14 +01:00
2016-03-07 15:19:26 +01:00
struct {
Common::String enterCommand;
Common::String verbError;
Common::String nounError;
Common::String playAgain;
2016-03-11 00:24:31 +01:00
Common::String pressReturn;
2016-04-03 13:45:31 +02:00
Common::String lineFeeds;
2016-03-07 15:19:26 +01:00
} _strings;
struct {
uint cantGoThere;
uint dontUnderstand;
uint itemDoesntMove;
uint itemNotHere;
uint thanksForPlaying;
} _messageIds;
2016-02-27 13:54:47 +01:00
// Game state
State _state;
bool _isRestarting, _isRestoring;
private:
2016-03-06 22:50:17 +01:00
virtual void runIntro() const { }
virtual void init() = 0;
2016-03-06 16:43:30 +01:00
virtual void initState() = 0;
virtual void drawItem(const Item &item, const Common::Point &pos) const = 0;
2016-03-26 14:29:26 +01:00
virtual void loadRoom(byte roomNr) = 0;
2016-03-14 15:39:19 +01:00
virtual void showRoom() = 0;
2016-03-06 16:43:30 +01:00
// Engine
Common::Error run();
bool hasFeature(EngineFeature f) const;
bool canLoadGameStateCurrently();
bool canSaveGameStateCurrently();
2016-03-06 16:43:30 +01:00
// Text input
byte convertKey(uint16 ascii) const;
Common::String getLine() const;
Common::String getWord(const Common::String &line, uint &index) const;
void getInput(uint &verb, uint &noun);
2016-03-26 23:26:22 +01:00
Console *_console;
GUI::Debugger *getDebugger() { return _console; }
2016-03-06 16:43:30 +01:00
const AdlGameDescription *_gameDescription;
byte _saveVerb, _saveNoun, _restoreVerb, _restoreNoun;
bool _canSaveNow, _canRestoreNow;
2016-02-26 23:32:06 +01:00
};
} // End of namespace Adl
#endif