diff options
Diffstat (limited to 'engines/mutationofjb')
-rw-r--r-- | engines/mutationofjb/commands/changecommand.cpp | 42 | ||||
-rw-r--r-- | engines/mutationofjb/commands/changecommand.h | 2 | ||||
-rw-r--r-- | engines/mutationofjb/commands/endblockcommand.cpp | 26 | ||||
-rw-r--r-- | engines/mutationofjb/commands/endblockcommand.h | 1 | ||||
-rw-r--r-- | engines/mutationofjb/debug.cpp | 104 | ||||
-rw-r--r-- | engines/mutationofjb/debug.h | 5 | ||||
-rw-r--r-- | engines/mutationofjb/script.cpp | 18 | ||||
-rw-r--r-- | engines/mutationofjb/script.h | 6 |
8 files changed, 158 insertions, 46 deletions
diff --git a/engines/mutationofjb/commands/changecommand.cpp b/engines/mutationofjb/commands/changecommand.cpp index a4316bde3b..f2639b620e 100644 --- a/engines/mutationofjb/commands/changecommand.cpp +++ b/engines/mutationofjb/commands/changecommand.cpp @@ -37,16 +37,30 @@ namespace MutationOfJB { // <ii> 2B Entity ID. // <val> VL Value. -bool ChangeCommandParser::parseValueString(const Common::String &valueString, uint8 &sceneId, uint8 &entityId, ChangeCommand::ChangeRegister ®, ChangeCommand::ChangeOperation &op, ChangeCommandValue &ccv) { - if (valueString.size() < 8) { - return false; +bool ChangeCommandParser::parseValueString(const Common::String &valueString, bool changeEntity, uint8 &sceneId, uint8 &entityId, ChangeCommand::ChangeRegister ®, ChangeCommand::ChangeOperation &op, ChangeCommandValue &ccv) { + if (changeEntity) { + if (valueString.size() < 8) { + return false; + } + } else { + if (valueString.size() < 7) { + return false; + } } sceneId = atoi(valueString.c_str() + 3); - entityId = atoi(valueString.c_str() + 6); + if (changeEntity) { + entityId = atoi(valueString.c_str() + 6); + } const char *val = nullptr; - if (valueString.size() >= 9) { - val = valueString.c_str() + 9; + if (changeEntity) { + if (valueString.size() >= 9) { + val = valueString.c_str() + 9; + } + } else { + if (valueString.size() >= 6) { + val = valueString.c_str() + 6; + } } if (valueString.hasPrefix("NM")) { @@ -137,7 +151,7 @@ bool ChangeDoorCommandParser::parse(const Common::String &line, ScriptParseConte ChangeCommand::ChangeRegister reg; ChangeCommand::ChangeOperation op; ChangeCommandValue val; - if (!parseValueString(line.c_str() + 8, sceneId, objectId, reg, op, val)) { + if (!parseValueString(line.c_str() + 8, true, sceneId, objectId, reg, op, val)) { return false; } @@ -154,7 +168,7 @@ bool ChangeObjectCommandParser::parse(const Common::String &line, ScriptParseCon ChangeCommand::ChangeRegister reg; ChangeCommand::ChangeOperation op; ChangeCommandValue val; - if (!parseValueString(line.c_str() + 8, sceneId, objectId, reg, op, val)) { + if (!parseValueString(line.c_str() + 8, true, sceneId, objectId, reg, op, val)) { return false; } @@ -171,7 +185,7 @@ bool ChangeStaticCommandParser::parse(const Common::String &line, ScriptParseCon ChangeCommand::ChangeRegister reg; ChangeCommand::ChangeOperation op; ChangeCommandValue val; - if (!parseValueString(line.c_str() + 8, sceneId, objectId, reg, op, val)) { + if (!parseValueString(line.c_str() + 8, true, sceneId, objectId, reg, op, val)) { return false; } @@ -188,7 +202,7 @@ bool ChangeSceneCommandParser::parse(const Common::String &line, ScriptParseCont ChangeCommand::ChangeRegister reg; ChangeCommand::ChangeOperation op; ChangeCommandValue val; - if (!parseValueString(line.c_str() + 8, sceneId, objectId, reg, op, val)) { + if (!parseValueString(line.c_str() + 7, false, sceneId, objectId, reg, op, val)) { return false; } @@ -351,7 +365,7 @@ Command::ExecuteResult ChangeDoorCommand::execute(ScriptExecutionContext &script } Common::String ChangeDoorCommand::debugString() const { - return Common::String::format("scene%d.door%d.%s %s %s", _sceneId, _entityId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); + return Common::String::format("SCENE%d.DOOR%d.%s %s %s", _sceneId, _entityId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); } Command::ExecuteResult ChangeObjectCommand::execute(ScriptExecutionContext &scriptExecCtx) { @@ -414,7 +428,7 @@ Command::ExecuteResult ChangeObjectCommand::execute(ScriptExecutionContext &scri } Common::String ChangeObjectCommand::debugString() const { - return Common::String::format("scene%d.object%d.%s %s %s", _sceneId, _entityId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); + return Common::String::format("SCENE%d.OBJECT%d.%s %s %s", _sceneId, _entityId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); } Command::ExecuteResult ChangeStaticCommand::execute(ScriptExecutionContext &scriptExecCtx) { @@ -465,7 +479,7 @@ Command::ExecuteResult ChangeStaticCommand::execute(ScriptExecutionContext &scri } Common::String ChangeStaticCommand::debugString() const { - return Common::String::format("scene%d.static%d.%s %s %s", _sceneId, _entityId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); + return Common::String::format("SCENE%d.STATIC%d.%s %s %s", _sceneId, _entityId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); } Command::ExecuteResult ChangeSceneCommand::execute(ScriptExecutionContext &scriptExecCtx) { @@ -508,6 +522,6 @@ Command::ExecuteResult ChangeSceneCommand::execute(ScriptExecutionContext &scrip } Common::String ChangeSceneCommand::debugString() const { - return Common::String::format("scene%d.%s %s %s", _sceneId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); + return Common::String::format("SCENE%d.%s %s %s", _sceneId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); } } diff --git a/engines/mutationofjb/commands/changecommand.h b/engines/mutationofjb/commands/changecommand.h index dde5cd1487..f5d7cf5e52 100644 --- a/engines/mutationofjb/commands/changecommand.h +++ b/engines/mutationofjb/commands/changecommand.h @@ -84,7 +84,7 @@ protected: class ChangeCommandParser : public SeqCommandParser { protected: - bool parseValueString(const Common::String &valueString, uint8 &sceneId, uint8 &entityId, ChangeCommand::ChangeRegister ®, ChangeCommand::ChangeOperation &op, ChangeCommandValue &ccv); + bool parseValueString(const Common::String &valueString, bool changeEntity, uint8 &sceneId, uint8 &entityId, ChangeCommand::ChangeRegister ®, ChangeCommand::ChangeOperation &op, ChangeCommandValue &ccv); int parseInteger(const char *val, ChangeCommand::ChangeOperation &op); }; diff --git a/engines/mutationofjb/commands/endblockcommand.cpp b/engines/mutationofjb/commands/endblockcommand.cpp index 53ea74a97b..492a4244b3 100644 --- a/engines/mutationofjb/commands/endblockcommand.cpp +++ b/engines/mutationofjb/commands/endblockcommand.cpp @@ -25,6 +25,7 @@ #include "mutationofjb/commands/conditionalcommand.h" #include "common/str.h" #include "common/debug.h" +#include "common/translation.h" /* ("#L " | "-L ") <object> @@ -107,6 +108,8 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext } } else if (line.size() >= 8 && line.hasPrefix("#MACRO")) { _foundMacro = line.c_str() + 7; + } else if (line.size() >= 10 && line.hasPrefix("#STARTUP")) { + _foundStartup = line.c_str() + 9; } if (firstChar == '#') { @@ -138,11 +141,26 @@ void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *, _ifTag = 0; } - if (!_foundMacro.empty() && newCommand) { - if (!parseCtx._macros.contains(_foundMacro)) { - parseCtx._macros[_foundMacro] = newCommand; + if (!_foundMacro.empty()) { + if (newCommand) { + if (!parseCtx._macros.contains(_foundMacro)) { + parseCtx._macros[_foundMacro] = newCommand; + } else { + warning(_("Macro '%s' already exists."), _foundMacro.c_str()); + } + } + _foundMacro.clear(); + } + if (!_foundStartup.empty()) { + if (newCommand) { + const uint8 startupId = atoi(_foundStartup.c_str()); + if (!parseCtx._startups.contains(startupId)) { + parseCtx._startups[startupId] = newCommand; + } else { + warning(_("Startup %u already exists."), (unsigned int) startupId); + } } - _foundMacro = ""; + _foundStartup.clear(); } if (newCommandParser != this) { diff --git a/engines/mutationofjb/commands/endblockcommand.h b/engines/mutationofjb/commands/endblockcommand.h index 4c0d23b609..eb77f435d4 100644 --- a/engines/mutationofjb/commands/endblockcommand.h +++ b/engines/mutationofjb/commands/endblockcommand.h @@ -45,6 +45,7 @@ private: Common::Array<uint> _pendingActionInfos; Common::String _foundMacro; + Common::String _foundStartup; }; class EndBlockCommand : public Command { diff --git a/engines/mutationofjb/debug.cpp b/engines/mutationofjb/debug.cpp index b4c2e773a8..e5333392ea 100644 --- a/engines/mutationofjb/debug.cpp +++ b/engines/mutationofjb/debug.cpp @@ -55,24 +55,37 @@ static Common::String convertToASCII(const Common::String &str) { } Console::Console(MutationOfJBEngine *vm) : _vm(vm) { + registerCmd("showallcommands", WRAP_METHOD(Console, cmd_showallcommands)); registerCmd("listsections", WRAP_METHOD(Console, cmd_listsections)); registerCmd("showsection", WRAP_METHOD(Console, cmd_showsection)); registerCmd("listmacros", WRAP_METHOD(Console, cmd_listmacros)); registerCmd("showmacro", WRAP_METHOD(Console, cmd_showmacro)); + registerCmd("liststartups", WRAP_METHOD(Console, cmd_liststartups)); + registerCmd("showstartup", WRAP_METHOD(Console, cmd_showstartup)); registerCmd("changescene", WRAP_METHOD(Console, cmd_changescene)); } +bool Console::cmd_showallcommands(int argc, const char **argv) { + if (argc == 2) { + Script *const script = getScriptFromArg(argv[1]); + if (script) { + const Commands &commands = script->getAllCommands(); + + for (Commands::const_iterator it = commands.begin(); it != commands.end(); ++it) { + debugPrintf("%s\n", convertToASCII((*it)->debugString()).c_str()); + } + } + } else { + debugPrintf(_("showallcommands <G|L>\n")); + } + + return true; +} + bool Console::cmd_listsections(int argc, const char **argv) { if (argc == 3) { - Script *script = nullptr; - if (strcmp(argv[1], "G") == 0) { - script = _vm->getGame().getGlobalScript(); - } else if (strcmp(argv[1], "L") == 0) { - script = _vm->getGame().getLocalScript(); - } - if (!script) { - debugPrintf(_("Choose 'G' (global) or 'L' (local) script.\n")); - } else { + Script *const script = getScriptFromArg(argv[1]); + if (script) { if (strcmp(argv[2], "L") == 0) { const ActionInfos &actionInfos = script->getLookActionInfos(); for (ActionInfos::const_iterator it = actionInfos.begin(); it != actionInfos.end(); ++it) { @@ -140,15 +153,8 @@ void Console::showCommands(Command *command, int indentLevel) { bool Console::cmd_showsection(int argc, const char **argv) { if (argc >= 4) { - Script *script = nullptr; - if (strcmp(argv[1], "G") == 0) { - script = _vm->getGame().getGlobalScript(); - } else if (strcmp(argv[1], "L") == 0) { - script = _vm->getGame().getLocalScript(); - } - if (!script) { - debugPrintf(_("Choose 'G' (global) or 'L' (local) script.\n")); - } else { + Script *const script = getScriptFromArg(argv[1]); + if (script) { Command *command = nullptr; bool found = false; if (strcmp(argv[2], "L") == 0) { @@ -212,15 +218,8 @@ bool Console::cmd_showsection(int argc, const char **argv) { bool Console::cmd_listmacros(int argc, const char **argv) { if (argc == 2) { - Script *script = nullptr; - if (strcmp(argv[1], "G") == 0) { - script = _vm->getGame().getGlobalScript(); - } else if (strcmp(argv[1], "L") == 0) { - script = _vm->getGame().getLocalScript(); - } - if (!script) { - debugPrintf(_("Choose 'G' (global) or 'L' (local) script.\n")); - } else { + Script *const script = getScriptFromArg(argv[1]); + if (script) { const Macros ¯os = script->getMacros(); for (Macros::const_iterator it = macros.begin(); it != macros.end(); ++it) { debugPrintf("%s\n", it->_key.c_str()); @@ -261,6 +260,43 @@ bool Console::cmd_showmacro(int argc, const char **argv) { return true; } +bool Console::cmd_liststartups(int argc, const char **argv) { + if (argc == 2) { + Script *const script = getScriptFromArg(argv[1]); + if (script) { + const Startups &startups = script->getStartups(); + for (Startups::const_iterator it = startups.begin(); it != startups.end(); ++it) { + debugPrintf("%u\n", (unsigned int) it->_key); + } + } + } else { + debugPrintf(_("liststartups <G|L>\n")); + } + + return true; +} + +bool Console::cmd_showstartup(int argc, const char **argv) { + if (argc == 3) { + Script *const script = getScriptFromArg(argv[1]); + if (script) { + const Startups &startups = script->getStartups(); + Startups::const_iterator itMacro = startups.find((uint8) atoi(argv[2])); + if (itMacro != startups.end()) { + if (itMacro->_value) { + showCommands(itMacro->_value); + } + } else { + debugPrintf("Startup not found.\n"); + } + } + } else { + debugPrintf(_("showstartup <G|L> <startupid>\n")); + } + + return true; +} + bool Console::cmd_changescene(int argc, const char **argv) { if (argc == 2) { const uint8 sceneId = atoi(argv[1]); @@ -274,4 +310,18 @@ bool Console::cmd_changescene(int argc, const char **argv) { return true; } +Script *Console::getScriptFromArg(const char *arg) { + Script *script = nullptr; + if (strcmp(arg, "G") == 0) { + script = _vm->getGame().getGlobalScript(); + } else if (strcmp(arg, "L") == 0) { + script = _vm->getGame().getLocalScript(); + } + if (!script) { + debugPrintf(_("Choose 'G' (global) or 'L' (local) script.\n")); + } + + return script; +} + } diff --git a/engines/mutationofjb/debug.h b/engines/mutationofjb/debug.h index 2f35a9c1dc..8df51679bf 100644 --- a/engines/mutationofjb/debug.h +++ b/engines/mutationofjb/debug.h @@ -29,20 +29,25 @@ namespace MutationOfJB { class MutationOfJBEngine; class Command; +class Script; class Console : public GUI::Debugger { public: Console(MutationOfJBEngine *vm); virtual ~Console(void) {} private: + bool cmd_showallcommands(int argc, const char **argv); bool cmd_listsections(int argc, const char **argv); bool cmd_showsection(int argc, const char **argv); bool cmd_listmacros(int argc, const char **argv); bool cmd_showmacro(int argc, const char **argv); + bool cmd_liststartups(int argc, const char **argv); + bool cmd_showstartup(int argc, const char **argv); bool cmd_changescene(int argc, const char **argv); void showIndent(int indentLevel); void showCommands(Command *command, int indentLevel = 0); + Script *getScriptFromArg(const char *arg); MutationOfJBEngine *_vm; }; diff --git a/engines/mutationofjb/script.cpp b/engines/mutationofjb/script.cpp index e3aa3e6785..8dc5e40fe7 100644 --- a/engines/mutationofjb/script.cpp +++ b/engines/mutationofjb/script.cpp @@ -221,6 +221,7 @@ bool Script::loadFromStream(Common::SeekableReadStream &stream) { } _macros = parseCtx._macros; + _startups = parseCtx._startups; return true; } @@ -252,6 +253,10 @@ const ActionInfos &Script::getUseActionInfos() const { return _useActionInfos; } +const Commands &Script::getAllCommands() const { + return _allCommands; +} + const Macros &Script::getMacros() const { return _macros; } @@ -265,4 +270,17 @@ Command *Script::getMacro(const Common::String &name) const { return it->_value; } +const Startups &Script::getStartups() const { + return _startups; +} + +Command *Script::getStartup(uint8 startupId) const { + Startups::const_iterator it = _startups.find(startupId); + if (it == _startups.end()) { + return nullptr; + } + + return it->_value; +} + } diff --git a/engines/mutationofjb/script.h b/engines/mutationofjb/script.h index 823210675f..316aab52ea 100644 --- a/engines/mutationofjb/script.h +++ b/engines/mutationofjb/script.h @@ -64,6 +64,7 @@ struct ActionInfo { typedef Common::Array<ActionInfo> ActionInfos; typedef Common::Array<GotoCommand *> GotoCommands; typedef Common::HashMap<Common::String, Command *> Macros; +typedef Common::HashMap<uint8, Command *> Startups; class ScriptParseContext { public: @@ -92,6 +93,7 @@ public: ActionInfos _actionInfos; Macros _macros; + Startups _startups; private: }; @@ -126,8 +128,11 @@ public: const ActionInfos &getWalkActionInfos() const; const ActionInfos &getTalkActionInfos() const; const ActionInfos &getUseActionInfos() const; + const Commands &getAllCommands() const; const Macros &getMacros() const; + const Startups &getStartups() const; Command *getMacro(const Common::String &name) const; + Command *getStartup(uint8 startupId) const; private: void destroy(); @@ -137,6 +142,7 @@ private: ActionInfos _talkActionInfos; ActionInfos _useActionInfos; Macros _macros; + Startups _startups; }; } |