2009-12-29 23:18:24 +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.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2009-12-29 23:18:24 +00:00
|
|
|
* 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.
|
2014-02-18 02:34:22 +01:00
|
|
|
*
|
2009-12-29 23:18:24 +00:00
|
|
|
* 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 RIVEN_SCRIPTS_H
|
|
|
|
#define RIVEN_SCRIPTS_H
|
|
|
|
|
2010-03-18 15:09:24 +00:00
|
|
|
#include "common/str-array.h"
|
2010-05-04 11:56:52 +00:00
|
|
|
#include "common/ptr.h"
|
2011-04-24 11:34:27 +03:00
|
|
|
#include "common/textconsole.h"
|
2010-03-18 15:09:24 +00:00
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
#define DECLARE_OPCODE(x) void x(uint16 op, uint16 argc, uint16 *argv)
|
|
|
|
|
2016-08-03 07:19:11 +02:00
|
|
|
namespace Common {
|
|
|
|
class ReadStream;
|
|
|
|
}
|
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
namespace Mohawk {
|
2011-03-22 20:31:54 -04:00
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
// Script Types
|
|
|
|
enum {
|
|
|
|
kMouseDownScript = 0,
|
2016-08-02 19:44:02 +02:00
|
|
|
kMouseDragScript = 1,
|
2009-12-29 23:18:24 +00:00
|
|
|
kMouseUpScript = 2,
|
2016-08-02 19:44:02 +02:00
|
|
|
kMouseEnterScript = 3,
|
2009-12-29 23:18:24 +00:00
|
|
|
kMouseInsideScript = 4,
|
2016-08-02 19:44:02 +02:00
|
|
|
kMouseLeaveScript = 5,
|
2009-12-29 23:18:24 +00:00
|
|
|
|
|
|
|
kCardLoadScript = 6,
|
|
|
|
kCardLeaveScript = 7,
|
|
|
|
kCardOpenScript = 9,
|
2016-08-02 19:43:15 +02:00
|
|
|
kCardUpdateScript = 10
|
2009-12-29 23:18:24 +00:00
|
|
|
};
|
|
|
|
|
2012-03-10 13:50:27 -05:00
|
|
|
class MohawkEngine_Riven;
|
2016-08-02 18:56:55 +02:00
|
|
|
class RivenCommand;
|
2016-08-04 06:28:04 +02:00
|
|
|
class RivenScript;
|
|
|
|
|
|
|
|
typedef Common::SharedPtr<RivenScript> RivenScriptPtr;
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/**
|
|
|
|
* Scripts in Riven are a list of Commands
|
|
|
|
*
|
|
|
|
* This class should only be used through the RivenScriptPtr
|
|
|
|
* type to ensure the underlying memory is not freed when changing card.
|
|
|
|
*/
|
2009-12-29 23:18:24 +00:00
|
|
|
class RivenScript {
|
|
|
|
public:
|
2016-08-02 21:04:34 +02:00
|
|
|
RivenScript();
|
2009-12-29 23:18:24 +00:00
|
|
|
~RivenScript();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/** Append a command to the script */
|
2016-08-02 18:56:55 +02:00
|
|
|
void addCommand(RivenCommand *command);
|
|
|
|
|
2016-08-06 19:22:12 +02:00
|
|
|
/** True if the script does not contain any command */
|
|
|
|
bool empty() const;
|
|
|
|
|
2016-08-02 21:43:22 +02:00
|
|
|
/**
|
|
|
|
* Run the script
|
|
|
|
*
|
|
|
|
* Script execution must go through the ScriptManager,
|
|
|
|
* this method should not be called directly.
|
|
|
|
*/
|
|
|
|
void run();
|
2016-08-02 21:04:34 +02:00
|
|
|
|
|
|
|
/** Print script details to the standard output */
|
2016-08-06 14:36:41 +02:00
|
|
|
void dumpScript(byte tabs);
|
2016-08-02 21:04:34 +02:00
|
|
|
|
|
|
|
/** Stop the script after the current command */
|
2010-09-01 13:28:12 +00:00
|
|
|
void stopRunning() { _continueRunning = false; }
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2016-08-02 18:56:55 +02:00
|
|
|
private:
|
|
|
|
Common::Array<RivenCommand *> _commands;
|
|
|
|
bool _continueRunning;
|
|
|
|
};
|
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/**
|
|
|
|
* A script and its type
|
|
|
|
*
|
|
|
|
* The type defines when the script should be run
|
|
|
|
*/
|
2016-08-02 19:43:15 +02:00
|
|
|
struct RivenTypedScript {
|
|
|
|
uint16 type;
|
|
|
|
RivenScriptPtr script;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef Common::Array<RivenTypedScript> RivenScriptList;
|
2016-08-02 18:56:55 +02:00
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/**
|
|
|
|
* Script manager
|
|
|
|
*
|
|
|
|
* Reads scripts from raw data.
|
|
|
|
* Can run scripts immediatly, or store them for future execution.
|
|
|
|
*/
|
2016-08-02 18:56:55 +02:00
|
|
|
class RivenScriptManager {
|
|
|
|
public:
|
|
|
|
RivenScriptManager(MohawkEngine_Riven *vm);
|
|
|
|
~RivenScriptManager();
|
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/** Read a single script from a stream */
|
2016-08-02 19:43:15 +02:00
|
|
|
RivenScriptPtr readScript(Common::ReadStream *stream);
|
2016-08-02 21:04:34 +02:00
|
|
|
|
2016-08-04 06:28:04 +02:00
|
|
|
/** Create a script from the caller provided arguments containing raw data */
|
|
|
|
RivenScriptPtr createScriptFromData(uint16 commandCount, ...);
|
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/** Read a list of typed scripts from a stream */
|
2016-08-02 18:56:55 +02:00
|
|
|
RivenScriptList readScripts(Common::ReadStream *stream);
|
2016-08-02 21:43:22 +02:00
|
|
|
|
|
|
|
/** Run a script */
|
|
|
|
void runScript(const RivenScriptPtr &script, bool queue);
|
|
|
|
|
2016-08-02 18:56:55 +02:00
|
|
|
void stopAllScripts();
|
|
|
|
|
|
|
|
struct StoredMovieOpcode {
|
|
|
|
RivenScriptPtr script;
|
|
|
|
uint32 time;
|
|
|
|
uint16 id;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint16 getStoredMovieOpcodeID() { return _storedMovieOpcode.id; }
|
|
|
|
uint32 getStoredMovieOpcodeTime() { return _storedMovieOpcode.time; }
|
|
|
|
void setStoredMovieOpcode(const StoredMovieOpcode &op);
|
|
|
|
void runStoredMovieOpcode();
|
|
|
|
void clearStoredMovieOpcode();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
private:
|
2016-08-02 18:56:55 +02:00
|
|
|
MohawkEngine_Riven *_vm;
|
2016-08-02 21:43:22 +02:00
|
|
|
|
|
|
|
Common::Array<RivenScriptPtr> _queue;
|
2016-08-02 18:56:55 +02:00
|
|
|
StoredMovieOpcode _storedMovieOpcode;
|
|
|
|
|
|
|
|
RivenCommand *readCommand(Common::ReadStream *stream);
|
|
|
|
};
|
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/**
|
|
|
|
* An abstract command
|
|
|
|
*
|
|
|
|
* Commands are unit operations part of a script
|
|
|
|
*/
|
2016-08-02 18:56:55 +02:00
|
|
|
class RivenCommand {
|
|
|
|
public:
|
|
|
|
RivenCommand(MohawkEngine_Riven *vm);
|
|
|
|
virtual ~RivenCommand();
|
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/** Print details about the command to standard output */
|
2016-08-06 14:36:41 +02:00
|
|
|
virtual void dump(byte tabs) = 0;
|
2016-08-02 18:56:55 +02:00
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/** Execute the command */
|
2016-08-02 18:56:55 +02:00
|
|
|
virtual void execute() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
MohawkEngine_Riven *_vm;
|
|
|
|
};
|
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/**
|
|
|
|
* A simple Command
|
|
|
|
*
|
|
|
|
* Simple commands have a type and a list of arguments.
|
|
|
|
* The operation to be executed when running the command
|
|
|
|
* depends on the type.
|
|
|
|
*/
|
2016-08-02 18:56:55 +02:00
|
|
|
class RivenSimpleCommand : public RivenCommand {
|
|
|
|
public:
|
|
|
|
static RivenSimpleCommand *createFromStream(MohawkEngine_Riven *vm, int type, Common::ReadStream *stream);
|
|
|
|
virtual ~RivenSimpleCommand();
|
|
|
|
|
|
|
|
// RivenCommand API
|
2016-08-06 14:36:41 +02:00
|
|
|
virtual void dump(byte tabs) override;
|
2016-08-02 18:56:55 +02:00
|
|
|
virtual void execute() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Common::Array<uint16> ArgumentArray;
|
|
|
|
typedef void (RivenSimpleCommand::*OpcodeProcRiven)(uint16 op, uint16 argc, uint16 *argv);
|
2009-12-29 23:18:24 +00:00
|
|
|
struct RivenOpcode {
|
|
|
|
OpcodeProcRiven proc;
|
|
|
|
const char *desc;
|
|
|
|
};
|
2016-08-02 21:04:34 +02:00
|
|
|
|
|
|
|
RivenSimpleCommand(MohawkEngine_Riven *vm, int type, const ArgumentArray &arguments);
|
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
void setupOpcodes();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
DECLARE_OPCODE(empty) { warning ("Unknown Opcode %04x", op); }
|
|
|
|
|
2016-08-02 21:43:22 +02:00
|
|
|
// Opcodes
|
2009-12-29 23:18:24 +00:00
|
|
|
DECLARE_OPCODE(drawBitmap);
|
|
|
|
DECLARE_OPCODE(switchCard);
|
|
|
|
DECLARE_OPCODE(playScriptSLST);
|
|
|
|
DECLARE_OPCODE(playSound);
|
|
|
|
DECLARE_OPCODE(setVariable);
|
|
|
|
DECLARE_OPCODE(mohawkSwitch);
|
|
|
|
DECLARE_OPCODE(enableHotspot);
|
|
|
|
DECLARE_OPCODE(disableHotspot);
|
2011-01-23 05:12:50 +00:00
|
|
|
DECLARE_OPCODE(stopSound);
|
2009-12-29 23:18:24 +00:00
|
|
|
DECLARE_OPCODE(changeCursor);
|
|
|
|
DECLARE_OPCODE(delay);
|
|
|
|
DECLARE_OPCODE(runExternalCommand);
|
|
|
|
DECLARE_OPCODE(transition);
|
|
|
|
DECLARE_OPCODE(refreshCard);
|
2016-08-04 07:19:51 +02:00
|
|
|
DECLARE_OPCODE(beginScreenUpdate);
|
|
|
|
DECLARE_OPCODE(applyScreenUpdate);
|
2009-12-29 23:18:24 +00:00
|
|
|
DECLARE_OPCODE(incrementVariable);
|
|
|
|
DECLARE_OPCODE(changeStack);
|
|
|
|
DECLARE_OPCODE(disableMovie);
|
|
|
|
DECLARE_OPCODE(disableAllMovies);
|
|
|
|
DECLARE_OPCODE(enableMovie);
|
2011-01-18 20:30:16 +00:00
|
|
|
DECLARE_OPCODE(playMovieBlocking);
|
2009-12-29 23:18:24 +00:00
|
|
|
DECLARE_OPCODE(playMovie);
|
|
|
|
DECLARE_OPCODE(stopMovie);
|
|
|
|
DECLARE_OPCODE(unk_36);
|
|
|
|
DECLARE_OPCODE(fadeAmbientSounds);
|
2011-03-22 20:31:54 -04:00
|
|
|
DECLARE_OPCODE(storeMovieOpcode);
|
2009-12-29 23:18:24 +00:00
|
|
|
DECLARE_OPCODE(activatePLST);
|
|
|
|
DECLARE_OPCODE(activateSLST);
|
|
|
|
DECLARE_OPCODE(activateMLSTAndPlay);
|
|
|
|
DECLARE_OPCODE(activateBLST);
|
|
|
|
DECLARE_OPCODE(activateFLST);
|
|
|
|
DECLARE_OPCODE(zipMode);
|
|
|
|
DECLARE_OPCODE(activateMLST);
|
2016-08-02 21:04:34 +02:00
|
|
|
|
|
|
|
const RivenOpcode *_opcodes;
|
|
|
|
|
|
|
|
int _type;
|
|
|
|
ArgumentArray _arguments;
|
2010-07-09 16:53:20 +00:00
|
|
|
};
|
|
|
|
|
2016-08-02 21:04:34 +02:00
|
|
|
/**
|
|
|
|
* A switch branch command
|
|
|
|
*
|
|
|
|
* Switch commands have a variable id and a list of branches.
|
|
|
|
* Each branch associates a value to a script.
|
|
|
|
* The branch matching the variable's value is executed,
|
|
|
|
* if not found an optional default branch can be executed.
|
|
|
|
*/
|
2016-08-02 18:56:55 +02:00
|
|
|
class RivenSwitchCommand : public RivenCommand {
|
2010-07-09 16:53:20 +00:00
|
|
|
public:
|
2016-08-02 18:56:55 +02:00
|
|
|
static RivenSwitchCommand *createFromStream(MohawkEngine_Riven *vm, int type, Common::ReadStream *stream);
|
|
|
|
virtual ~RivenSwitchCommand();
|
2010-07-09 16:53:20 +00:00
|
|
|
|
2016-08-02 18:56:55 +02:00
|
|
|
// RivenCommand API
|
2016-08-06 14:36:41 +02:00
|
|
|
virtual void dump(byte tabs) override;
|
2016-08-02 18:56:55 +02:00
|
|
|
virtual void execute() override;
|
2011-03-22 20:31:54 -04:00
|
|
|
|
2010-07-09 16:53:20 +00:00
|
|
|
private:
|
2016-08-02 18:56:55 +02:00
|
|
|
RivenSwitchCommand(MohawkEngine_Riven *vm);
|
2011-03-22 20:31:54 -04:00
|
|
|
|
2016-08-02 18:56:55 +02:00
|
|
|
struct Branch {
|
|
|
|
uint16 value;
|
|
|
|
RivenScriptPtr script;
|
|
|
|
};
|
|
|
|
|
|
|
|
uint16 _variableId;
|
|
|
|
Common::Array<Branch> _branches;
|
2009-12-29 23:18:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
} // End of namespace Mohawk
|
|
|
|
|
|
|
|
#undef DECLARE_OPCODE
|
|
|
|
|
|
|
|
#endif
|