scummvm/engines/adl/adl.h

295 lines
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
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"
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-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-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;
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
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 {
byte description;
2016-03-18 00:50:30 +01:00
byte connections[IDI_DIR_TOTAL];
2016-03-10 20:47:30 +01:00
byte track;
byte sector;
byte offset;
2016-02-27 13:35:49 +01:00
byte picture;
2016-02-28 15:18:00 +01:00
byte curPicture;
2016-02-27 13:35:49 +01:00
};
struct Picture {
byte block;
uint16 offset;
};
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 00:30:51 +01:00
ScriptEnv(const Command &cmd_, byte verb_, byte noun_) :
cmd(cmd_), verb(verb_), noun(noun_), ip(0) { }
byte op() const { return cmd.script[ip]; }
// We keep this 1-based for easier comparison with the original engine
byte arg(uint i) const { return cmd.script[ip + i]; }
2016-03-18 00:30:51 +01:00
const Command &cmd;
byte 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_MOVED,
IDI_ITEM_DOESNT_MOVE
};
#define IDI_NONE 0xfe
2016-02-27 13:35:49 +01:00
struct Item {
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
};
struct State {
Common::Array<Room> rooms;
Common::Array<Item> items;
Common::Array<byte> vars;
byte room;
uint16 moves;
bool isDark;
State() : room(1), moves(0), 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
class AdlEngine : public Engine {
public:
virtual ~AdlEngine();
2016-03-15 20:06:03 +01:00
static bool pollEvent(Common::Event &event);
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
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-15 22:34:00 +01:00
virtual void printMessage(uint idx, bool wait = true);
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
2016-03-06 19:34:14 +01:00
void loadWords(Common::ReadStream &stream, WordMap &map) const;
2016-03-06 22:50:17 +01:00
void readCommands(Common::ReadStream &stream, Commands &commands);
2016-03-16 11:04:34 +01:00
virtual void checkInput(byte verb, byte noun);
2016-02-27 13:54:47 +01:00
2016-03-18 00:30:51 +01:00
virtual void setupOpcodeTables();
// Opcodes
2016-03-18 11:22:01 +01:00
int o1_isItemInRoom(ScriptEnv &e);
int o1_isMovesGrEq(ScriptEnv &e);
int o1_isVarEq(ScriptEnv &e);
int o1_isCurPicEq(ScriptEnv &e);
int o1_isItemPicEq(ScriptEnv &e);
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;
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 00:30:51 +01:00
bool matchCommand(ScriptEnv &env, uint *actions = nullptr) const;
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);
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-02-27 13:54:47 +01:00
Common::Array<Picture> _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;
2016-03-06 19:34:14 +01:00
WordMap _verbs;
WordMap _nouns;
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-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;
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 restartGame() = 0;
virtual void drawItem(const Item &item, const Common::Point &pos) const = 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;
Common::Error loadGameState(int slot);
bool canLoadGameStateCurrently();
2016-03-06 16:43:30 +01:00
Common::Error saveGameState(int slot, const Common::String &desc);
bool canSaveGameStateCurrently();
2016-03-06 16:43:30 +01:00
// Text output
void wordWrap(Common::String &str) const;
// 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);
const AdlGameDescription *_gameDescription;
bool _isRestarting, _isRestoring;
byte _saveVerb, _saveNoun, _restoreVerb, _restoreNoun;
bool _canSaveNow, _canRestoreNow;
2016-02-26 23:32:06 +01:00
};
AdlEngine *HiRes1Engine__create(OSystem *syst, const AdlGameDescription *gd);
2016-02-26 23:32:06 +01:00
} // End of namespace Adl
#endif