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.
|
|
|
|
*
|
2021-12-26 18:47:58 +01:00
|
|
|
* 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 3 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
|
2021-12-26 18:47:58 +01:00
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2009-12-29 23:18:24 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef MYST_SCRIPTS_H
|
|
|
|
#define MYST_SCRIPTS_H
|
|
|
|
|
2010-11-18 05:47:16 +00:00
|
|
|
#include "common/ptr.h"
|
2009-12-29 23:18:24 +00:00
|
|
|
#include "common/scummsys.h"
|
|
|
|
#include "common/util.h"
|
|
|
|
|
2010-12-26 15:10:33 +00:00
|
|
|
#include "mohawk/myst_state.h"
|
2010-12-26 14:31:03 +00:00
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
namespace Mohawk {
|
|
|
|
|
2017-04-08 07:38:49 +02:00
|
|
|
typedef Common::Array<uint16> ArgumentsArray;
|
|
|
|
|
2017-07-22 12:12:02 +02:00
|
|
|
#define DECLARE_OPCODE(x) void x(uint16 var, const ArgumentsArray &args)
|
2009-12-29 23:18:24 +00:00
|
|
|
|
|
|
|
class MohawkEngine_Myst;
|
2016-02-06 13:54:02 +01:00
|
|
|
class MystArea;
|
2010-11-18 05:47:16 +00:00
|
|
|
|
|
|
|
enum MystScriptType {
|
|
|
|
kMystScriptNone,
|
|
|
|
kMystScriptNormal,
|
|
|
|
kMystScriptInit,
|
|
|
|
kMystScriptExit
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MystScriptEntry {
|
|
|
|
MystScriptEntry();
|
|
|
|
|
|
|
|
MystScriptType type;
|
2010-11-29 21:01:30 +00:00
|
|
|
uint16 resourceId;
|
2010-11-18 05:47:16 +00:00
|
|
|
uint16 opcode;
|
|
|
|
uint16 var;
|
2017-04-08 07:38:49 +02:00
|
|
|
ArgumentsArray args;
|
2010-11-18 05:47:16 +00:00
|
|
|
uint16 u1;
|
|
|
|
};
|
|
|
|
|
2018-05-27 20:39:26 +02:00
|
|
|
typedef Common::Array<MystScriptEntry> MystScript;
|
2009-12-29 23:18:24 +00:00
|
|
|
|
|
|
|
class MystScriptParser {
|
|
|
|
public:
|
2018-05-28 20:22:29 +02:00
|
|
|
MystScriptParser(MohawkEngine_Myst *vm, MystStack stackId);
|
2010-11-29 20:49:14 +00:00
|
|
|
virtual ~MystScriptParser();
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2018-05-27 20:39:26 +02:00
|
|
|
void runScript(const MystScript &script, MystArea *invokingResource = nullptr);
|
2017-04-08 07:38:49 +02:00
|
|
|
void runOpcode(uint16 op, uint16 var = 0, const ArgumentsArray &args = ArgumentsArray());
|
2010-12-16 16:12:38 +00:00
|
|
|
const Common::String getOpcodeDesc(uint16 op);
|
2010-11-18 05:47:16 +00:00
|
|
|
MystScript readScript(Common::SeekableReadStream *stream, MystScriptType type);
|
2016-02-06 13:54:02 +01:00
|
|
|
void setInvokingResource(MystArea *resource) { _invokingResource = resource; }
|
2010-01-25 01:39:44 +00:00
|
|
|
|
2017-07-09 14:22:18 +02:00
|
|
|
/**
|
|
|
|
* Is a script is running?
|
|
|
|
*
|
|
|
|
* Allows to detect if some inner loop is running instead of the main loop.
|
|
|
|
*/
|
|
|
|
bool isScriptRunning() const;
|
|
|
|
|
2010-11-29 21:00:05 +00:00
|
|
|
virtual void disablePersistentScripts() = 0;
|
|
|
|
virtual void runPersistentScripts() = 0;
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2010-11-29 20:49:42 +00:00
|
|
|
virtual uint16 getVar(uint16 var);
|
|
|
|
virtual void toggleVar(uint16 var);
|
|
|
|
virtual bool setVarValue(uint16 var, uint16 value);
|
|
|
|
|
2018-05-28 20:22:29 +02:00
|
|
|
MystStack getStackId() const { return _stackId; }
|
2011-05-15 14:53:05 +02:00
|
|
|
virtual uint16 getMap() { return 0; }
|
|
|
|
void showMap();
|
|
|
|
|
2017-04-08 07:38:49 +02:00
|
|
|
void animatedUpdate(const ArgumentsArray &args, uint16 delay);
|
2018-04-15 06:17:45 +02:00
|
|
|
void soundWaitStop() const;
|
2010-11-29 20:58:45 +00:00
|
|
|
|
2011-01-18 17:42:34 +00:00
|
|
|
// Common opcodes
|
2010-11-29 21:03:02 +00:00
|
|
|
DECLARE_OPCODE(o_toggleVar);
|
|
|
|
DECLARE_OPCODE(o_setVar);
|
2012-12-15 11:49:41 +01:00
|
|
|
DECLARE_OPCODE(o_changeCardSwitch4);
|
|
|
|
DECLARE_OPCODE(o_changeCardSwitchLtR);
|
|
|
|
DECLARE_OPCODE(o_changeCardSwitchRtL);
|
2010-11-29 21:03:02 +00:00
|
|
|
DECLARE_OPCODE(o_takePage);
|
|
|
|
DECLARE_OPCODE(o_redrawCard);
|
|
|
|
DECLARE_OPCODE(o_goToDest);
|
2012-12-15 11:49:41 +01:00
|
|
|
DECLARE_OPCODE(o_goToDestForward);
|
|
|
|
DECLARE_OPCODE(o_goToDestRight);
|
2017-07-22 12:12:02 +02:00
|
|
|
DECLARE_OPCODE(o_goToDestLeft);
|
2012-12-15 11:49:41 +01:00
|
|
|
DECLARE_OPCODE(o_goToDestUp);
|
2010-11-29 21:03:02 +00:00
|
|
|
DECLARE_OPCODE(o_triggerMovie);
|
|
|
|
DECLARE_OPCODE(o_toggleVarNoRedraw);
|
|
|
|
DECLARE_OPCODE(o_drawAreaState);
|
|
|
|
DECLARE_OPCODE(o_redrawAreaForVar);
|
|
|
|
DECLARE_OPCODE(o_changeCardDirectional);
|
|
|
|
DECLARE_OPCODE(o_changeCardPush);
|
|
|
|
DECLARE_OPCODE(o_changeCardPop);
|
|
|
|
DECLARE_OPCODE(o_enableAreas);
|
|
|
|
DECLARE_OPCODE(o_disableAreas);
|
|
|
|
DECLARE_OPCODE(o_directionalUpdate);
|
|
|
|
DECLARE_OPCODE(o_toggleAreasActivation);
|
|
|
|
DECLARE_OPCODE(o_playSound);
|
|
|
|
DECLARE_OPCODE(o_stopSoundBackground);
|
|
|
|
DECLARE_OPCODE(o_playSoundBlocking);
|
2010-12-14 19:11:16 +00:00
|
|
|
DECLARE_OPCODE(o_copyBackBufferToScreen);
|
|
|
|
DECLARE_OPCODE(o_copyImageToBackBuffer);
|
2010-12-18 13:12:56 +00:00
|
|
|
DECLARE_OPCODE(o_changeBackgroundSound);
|
2010-11-29 21:03:02 +00:00
|
|
|
DECLARE_OPCODE(o_soundPlaySwitch);
|
2010-12-14 19:11:16 +00:00
|
|
|
DECLARE_OPCODE(o_copyImageToScreen);
|
2010-11-29 21:03:02 +00:00
|
|
|
DECLARE_OPCODE(o_soundResumeBackground);
|
|
|
|
DECLARE_OPCODE(o_changeCard);
|
|
|
|
DECLARE_OPCODE(o_drawImageChangeCard);
|
|
|
|
DECLARE_OPCODE(o_changeMainCursor);
|
|
|
|
DECLARE_OPCODE(o_hideCursor);
|
|
|
|
DECLARE_OPCODE(o_showCursor);
|
|
|
|
DECLARE_OPCODE(o_delay);
|
|
|
|
DECLARE_OPCODE(o_changeStack);
|
|
|
|
DECLARE_OPCODE(o_changeCardPlaySoundDirectional);
|
|
|
|
DECLARE_OPCODE(o_directionalUpdatePlaySound);
|
|
|
|
DECLARE_OPCODE(o_saveMainCursor);
|
|
|
|
DECLARE_OPCODE(o_restoreMainCursor);
|
|
|
|
DECLARE_OPCODE(o_soundWaitStop);
|
2011-05-15 14:53:05 +02:00
|
|
|
DECLARE_OPCODE(o_exitMap);
|
2009-12-29 23:18:24 +00:00
|
|
|
|
2011-01-18 17:42:34 +00:00
|
|
|
// Used in multiple stacks
|
|
|
|
DECLARE_OPCODE(o_quit);
|
|
|
|
|
2009-12-29 23:18:24 +00:00
|
|
|
DECLARE_OPCODE(NOP);
|
2010-11-29 20:49:14 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
MohawkEngine_Myst *_vm;
|
2010-12-26 14:31:03 +00:00
|
|
|
MystGameState::Globals &_globals;
|
2010-11-29 20:49:14 +00:00
|
|
|
|
2017-07-22 13:53:32 +02:00
|
|
|
typedef Common::Functor2<uint16, const ArgumentsArray &, void> OpcodeProcMyst;
|
2010-11-29 20:49:14 +00:00
|
|
|
|
2017-07-22 13:53:32 +02:00
|
|
|
#define REGISTER_OPCODE(op, cls, method) \
|
|
|
|
registerOpcode( \
|
|
|
|
op, #method, new Common::Functor2Mem<uint16, const ArgumentsArray &, void, cls>(this, &cls::method) \
|
|
|
|
)
|
2010-12-01 03:30:00 +00:00
|
|
|
|
2017-07-22 13:53:32 +02:00
|
|
|
#define OVERRIDE_OPCODE(op, cls, method) \
|
|
|
|
overrideOpcode( \
|
|
|
|
op, #method, new Common::Functor2Mem<uint16, const ArgumentsArray &, void, cls>(this, &cls::method) \
|
|
|
|
)
|
2010-11-29 20:49:14 +00:00
|
|
|
|
2017-07-22 13:53:32 +02:00
|
|
|
void registerOpcode(uint16 op, const char *name, OpcodeProcMyst *command);
|
|
|
|
void overrideOpcode(uint16 op, const char *name, OpcodeProcMyst *command);
|
2010-11-29 20:49:14 +00:00
|
|
|
|
2010-11-29 20:56:21 +00:00
|
|
|
uint16 _savedCardId;
|
2011-05-15 14:53:05 +02:00
|
|
|
uint16 _savedMapCardId;
|
2010-11-29 20:56:21 +00:00
|
|
|
uint16 _savedCursorId;
|
2010-12-06 20:29:45 +00:00
|
|
|
int16 _tempVar; // Generic temp var used by the scripts
|
2010-12-11 11:40:12 +00:00
|
|
|
uint32 _startTime; // Generic start time used by the scripts
|
2010-11-29 20:56:21 +00:00
|
|
|
|
2018-05-28 20:22:29 +02:00
|
|
|
static const MystStack _stackMap[];
|
2010-12-01 14:57:05 +00:00
|
|
|
static const uint16 _startCard[];
|
2010-11-29 20:49:14 +00:00
|
|
|
|
2010-12-01 03:30:00 +00:00
|
|
|
void setupCommonOpcodes();
|
2016-02-06 17:41:50 +01:00
|
|
|
|
|
|
|
template<class T>
|
|
|
|
T *getInvokingResource() const;
|
|
|
|
|
|
|
|
private:
|
2017-07-22 13:53:32 +02:00
|
|
|
struct MystOpcode {
|
|
|
|
MystOpcode(uint16 o, OpcodeProcMyst *p, const char *d) : op(o), proc(p), desc(d) {}
|
|
|
|
|
|
|
|
uint16 op;
|
|
|
|
Common::SharedPtr<OpcodeProcMyst> proc;
|
|
|
|
const char *desc;
|
|
|
|
};
|
|
|
|
|
|
|
|
Common::Array<MystOpcode> _opcodes;
|
|
|
|
|
2016-02-06 17:41:50 +01:00
|
|
|
MystArea *_invokingResource;
|
2017-07-09 14:22:18 +02:00
|
|
|
int32 _scriptNestingLevel;
|
2017-07-22 12:12:02 +02:00
|
|
|
|
2018-05-28 20:22:29 +02:00
|
|
|
const MystStack _stackId;
|
|
|
|
|
2017-07-22 12:12:02 +02:00
|
|
|
Common::String describeCommand(const MystOpcode &command, uint16 var, const ArgumentsArray &args);
|
2009-12-29 23:18:24 +00:00
|
|
|
};
|
|
|
|
|
2016-02-06 17:41:50 +01:00
|
|
|
template<class T>
|
|
|
|
T *MystScriptParser::getInvokingResource() const {
|
|
|
|
T *resource = dynamic_cast<T *>(_invokingResource);
|
|
|
|
|
|
|
|
if (!resource) {
|
|
|
|
error("Invoking resource has unexpected type");
|
|
|
|
}
|
|
|
|
|
|
|
|
return resource;
|
|
|
|
}
|
|
|
|
|
2010-12-01 03:30:00 +00:00
|
|
|
} // End of namespace Mohawk
|
2009-12-29 23:18:24 +00:00
|
|
|
|
|
|
|
#undef DECLARE_OPCODE
|
|
|
|
|
|
|
|
#endif
|