diff options
author | Ľubomír Remák | 2018-03-01 23:35:24 +0100 |
---|---|---|
committer | Eugene Sandulenko | 2018-08-25 23:12:01 +0200 |
commit | bbd3750aeec2bdb91a8ab31eca8672c34ce61f83 (patch) | |
tree | 56412dfa75172d010c6335f6eb69ce45c289ec80 /engines/mutationofjb/commands | |
parent | 6d926ff55b2fccbf8e96495f88b3d4dda6e906d7 (diff) | |
download | scummvm-rg350-bbd3750aeec2bdb91a8ab31eca8672c34ce61f83.tar.gz scummvm-rg350-bbd3750aeec2bdb91a8ab31eca8672c34ce61f83.tar.bz2 scummvm-rg350-bbd3750aeec2bdb91a8ab31eca8672c34ce61f83.zip |
MUTATIONOFJB: Add change scene command, implement listsections and showsection debug console commands.
Diffstat (limited to 'engines/mutationofjb/commands')
-rw-r--r-- | engines/mutationofjb/commands/changecommand.cpp | 180 | ||||
-rw-r--r-- | engines/mutationofjb/commands/changecommand.h | 31 | ||||
-rw-r--r-- | engines/mutationofjb/commands/command.cpp | 2 | ||||
-rw-r--r-- | engines/mutationofjb/commands/command.h | 3 | ||||
-rw-r--r-- | engines/mutationofjb/commands/endblockcommand.cpp | 41 | ||||
-rw-r--r-- | engines/mutationofjb/commands/endblockcommand.h | 7 | ||||
-rw-r--r-- | engines/mutationofjb/commands/ifcommand.cpp | 7 | ||||
-rw-r--r-- | engines/mutationofjb/commands/ifcommand.h | 3 |
8 files changed, 253 insertions, 21 deletions
diff --git a/engines/mutationofjb/commands/changecommand.cpp b/engines/mutationofjb/commands/changecommand.cpp index 54c6d1e616..e9bb9cc2e6 100644 --- a/engines/mutationofjb/commands/changecommand.cpp +++ b/engines/mutationofjb/commands/changecommand.cpp @@ -96,6 +96,30 @@ bool ChangeCommandParser::parseValueString(const Common::String &valueString, ui } else if (valueString.hasPrefix("CA")) { reg = ChangeCommand::CA; ccv._byteVal = parseInteger(val, op); + } else if (valueString.hasPrefix("DS")) { + reg = ChangeCommand::DS; + ccv._byteVal = parseInteger(val, op); + } else if (valueString.hasPrefix("DL")) { + reg = ChangeCommand::DL; + ccv._byteVal = parseInteger(val, op); + } else if (valueString.hasPrefix("ND")) { + reg = ChangeCommand::ND; + ccv._byteVal = parseInteger(val, op); + } else if (valueString.hasPrefix("NO")) { + reg = ChangeCommand::NO; + ccv._byteVal = parseInteger(val, op); + } else if (valueString.hasPrefix("NS")) { + reg = ChangeCommand::NS; + ccv._byteVal = parseInteger(val, op); + } else if (valueString.hasPrefix("PF")) { + reg = ChangeCommand::PF; + ccv._byteVal = parseInteger(val, op); + } else if (valueString.hasPrefix("PL")) { + reg = ChangeCommand::PL; + ccv._byteVal = parseInteger(val, op); + } else if (valueString.hasPrefix("PD")) { + reg = ChangeCommand::PD; + ccv._byteVal = parseInteger(val, op); } return true; @@ -115,7 +139,7 @@ bool ChangeDoorCommandParser::parse(const Common::String &line, ScriptParseConte return false; } - command = new ChangeObjectCommand(sceneId, objectId, reg, op, val); + command = new ChangeDoorCommand(sceneId, objectId, reg, op, val); return true; } @@ -149,7 +173,24 @@ bool ChangeStaticCommandParser::parse(const Common::String &line, ScriptParseCon return false; } - command = new ChangeObjectCommand(sceneId, objectId, reg, op, val); + command = new ChangeStaticCommand(sceneId, objectId, reg, op, val); + return true; +} + +bool ChangeSceneCommandParser::parse(const Common::String &line, ScriptParseContext &, Command *&command) { + if (!line.hasPrefix("CHANGE ")) { + return false; + } + uint8 sceneId = 0; + uint8 objectId = 0; + ChangeCommand::ChangeRegister reg; + ChangeCommand::ChangeOperation op; + ChangeCommandValue val; + if (!parseValueString(line.c_str() + 8, sceneId, objectId, reg, op, val)) { + return false; + } + + command = new ChangeSceneCommand(sceneId, objectId, reg, op, val); return true; } @@ -173,6 +214,86 @@ int ChangeCommandParser::parseInteger(const char *val, ChangeCommand::ChangeOper return atoi(val); } + +const char *ChangeCommand::getRegisterAsString() const { + switch (_register) { + case NM: return "NM"; + case LT: return "LT"; + case SX: return "SX"; + case SY: return "SY"; + case XX: return "XX"; + case YY: return "YY"; + case XL: return "XL"; + case YL: return "YL"; + case WX: return "WX"; + case WY: return "WY"; + case SP: return "SP"; + case AC: return "AC"; + case FA: return "FA"; + case FR: return "FR"; + case NA: return "NA"; + case FS: return "FS"; + case CA: return "CA"; + case DS: return "DS"; + case DL: return "DL"; + case ND: return "ND"; + case NO: return "NO"; + case NS: return "NS"; + case PF: return "PF"; + case PL: return "PL"; + case PD: return "PD"; + default: return "(unknown)"; + } +} + +Common::String ChangeCommand::getValueAsString() const { + switch (_register) { + case NM: + return Common::String::format("\"%s\"", _value._strVal); + case LT: + case YY: + case YL: + case WY: + case SP: + case AC: + case FA: + case FR: + case NA: + case FS: + case CA: + case DS: + case DL: + case ND: + case NO: + case NS: + case PF: + case PL: + case PD: + return Common::String::format("%d", (int)_value._byteVal); + case SX: + case SY: + case XX: + case XL: + case WX: + return Common::String::format("%d", (int)_value._wordVal); + default: + return "(unknown)"; + } +} + +const char *ChangeCommand::getOperationAsString() const { + switch (_operation) { + case SetValue: + return "="; + case AddValue: + return "+="; + case SubtractValue: + return "-="; + default: + return "(unknown)"; + } +} + Command::ExecuteResult ChangeDoorCommand::execute(GameData &gameData) { Scene *const scene = gameData.getScene(_sceneId); if (!scene) { @@ -226,6 +347,10 @@ Command::ExecuteResult ChangeDoorCommand::execute(GameData &gameData) { return Finished; } +Common::String ChangeDoorCommand::debugString() const { + return Common::String::format("scene%d.door%d.%s %s %s", _sceneId, _entityId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); +} + Command::ExecuteResult ChangeObjectCommand::execute(GameData &gameData) { Scene *const scene = gameData.getScene(_sceneId); if (!scene) { @@ -285,6 +410,10 @@ Command::ExecuteResult ChangeObjectCommand::execute(GameData &gameData) { return Finished; } +Common::String ChangeObjectCommand::debugString() const { + return Common::String::format("scene%d.object%d.%s %s %s", _sceneId, _entityId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); +} + Command::ExecuteResult ChangeStaticCommand::execute(GameData &gameData) { Scene *const scene = gameData.getScene(_sceneId); if (!scene) { @@ -331,4 +460,51 @@ Command::ExecuteResult ChangeStaticCommand::execute(GameData &gameData) { return Finished; } + +Common::String ChangeStaticCommand::debugString() const { + return Common::String::format("scene%d.static%d.%s %s %s", _sceneId, _entityId, getRegisterAsString(), getOperationAsString(), getValueAsString().c_str()); +} + +Command::ExecuteResult ChangeSceneCommand::execute(GameData &gameData) { + Scene *const scene = gameData.getScene(_sceneId); + if (!scene) { + return Finished; + } + + switch (_register) { + case DS: + scene->_startup = _value._byteVal; + break; + case DL: + scene->_DL = _value._byteVal; + break; + case ND: + scene->_noDoors = _value._byteVal; + break; + case NO: + scene->_noObjects = _value._byteVal; + break; + case NS: + scene->_noStatics = _value._byteVal; + break; + case PF: + scene->_palRotStart = _value._byteVal; + break; + case PL: + scene->_palRotEnd = _value._byteVal; + break; + case PD: + scene->_palRotPeriod = _value._byteVal; + break; + default: + warning("Scene does not support changing this register."); + break; + } + + return Finished; +} + +Common::String ChangeSceneCommand::debugString() const { + 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 5b9a91e47e..d590fa5518 100644 --- a/engines/mutationofjb/commands/changecommand.h +++ b/engines/mutationofjb/commands/changecommand.h @@ -50,7 +50,15 @@ public: FR, NA, FS, - CA + CA, + DS, // Startup + DL, + ND, // Number of doors + NO, // Number of objects + NS, // Number of statics + PF, // Palette rotation first + PL, // Palette rotation last + PD // Palette rotation delay }; enum ChangeOperation { @@ -63,6 +71,10 @@ public: _sceneId(sceneId), _entityId(entityId), _register(reg), _operation(op), _value(val) {} protected: + const char *getRegisterAsString() const; + Common::String getValueAsString() const; + const char *getOperationAsString() const; + uint8 _sceneId; uint8 _entityId; ChangeRegister _register; @@ -91,7 +103,10 @@ public: virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) override; }; - +class ChangeSceneCommandParser : public ChangeCommandParser { +public: + virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) override; +}; class ChangeDoorCommand : public ChangeCommand { public: @@ -99,6 +114,7 @@ public: : ChangeCommand(sceneId, doorId, reg, op, val) {} virtual ExecuteResult execute(GameData &gameData) override; + virtual Common::String debugString() const; }; class ChangeObjectCommand : public ChangeCommand { @@ -107,6 +123,7 @@ public: : ChangeCommand(sceneId, objectId, reg, op, val) {} virtual ExecuteResult execute(GameData &gameData) override; + virtual Common::String debugString() const; }; class ChangeStaticCommand : public ChangeCommand { @@ -115,6 +132,16 @@ public: : ChangeCommand(sceneId, staticId, reg, op, val) {} virtual ExecuteResult execute(GameData &gameData) override; + virtual Common::String debugString() const; +}; + +class ChangeSceneCommand : public ChangeCommand { +public: + ChangeSceneCommand(uint8 sceneId, uint8 staticId, ChangeRegister reg, ChangeOperation op, const ChangeCommandValue& val) + : ChangeCommand(sceneId, staticId, reg, op, val) + {} + virtual ExecuteResult execute(GameData &gameData) override; + virtual Common::String debugString() const; }; } diff --git a/engines/mutationofjb/commands/command.cpp b/engines/mutationofjb/commands/command.cpp index af4c28e7eb..943986e89d 100644 --- a/engines/mutationofjb/commands/command.cpp +++ b/engines/mutationofjb/commands/command.cpp @@ -25,7 +25,7 @@ namespace MutationOfJB { -void CommandParser::transition(ScriptParseContext &, Command *, Command *) {} +void CommandParser::transition(ScriptParseContext &, Command *, Command *, CommandParser *) {} CommandParser::~CommandParser() {} Command::~Command() {} diff --git a/engines/mutationofjb/commands/command.h b/engines/mutationofjb/commands/command.h index f8c160e3cb..ccfdea25f0 100644 --- a/engines/mutationofjb/commands/command.h +++ b/engines/mutationofjb/commands/command.h @@ -42,7 +42,7 @@ public: virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command) = 0; /* Old command - created by this parser. */ - virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand); + virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser); }; class Command { @@ -59,6 +59,7 @@ public: virtual Command *next() const = 0; virtual SeqCommand *asSeqCommand(); + virtual Common::String debugString() const = 0; }; } diff --git a/engines/mutationofjb/commands/endblockcommand.cpp b/engines/mutationofjb/commands/endblockcommand.cpp index 218be1a31f..be610c7c9a 100644 --- a/engines/mutationofjb/commands/endblockcommand.cpp +++ b/engines/mutationofjb/commands/endblockcommand.cpp @@ -41,15 +41,17 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext // This is the start or end of section/block. if (line.size() >= 4 && (line.hasPrefix("#L ") || line.hasPrefix("-L "))) { - ScriptParseContext::ActionInfo ai = {ScriptParseContext::Look, line.c_str() + 3, "", firstChar == '#'}; - parseCtx._actionInfos.push_back(ai); - debug("# Look: %s", line.c_str() + 3); + ActionInfo ai = {ActionInfo::Look, line.c_str() + 3, "", firstChar == '#', nullptr}; + parseCtx._lookActionInfos.push_back(ai); + _pendingActionInfos.push_back(&parseCtx._lookActionInfos.back()); } else if (line.size() >= 4 && (line.hasPrefix("#W ") || line.hasPrefix("-W "))) { - ScriptParseContext::ActionInfo ai = {ScriptParseContext::Walk, line.c_str() + 3, "", firstChar == '#'}; - parseCtx._actionInfos.push_back(ai); + ActionInfo ai = {ActionInfo::Walk, line.c_str() + 3, "", firstChar == '#', nullptr}; + parseCtx._walkActionInfos.push_back(ai); + _pendingActionInfos.push_back(&parseCtx._walkActionInfos.back()); } else if (line.size() >= 4 && (line.hasPrefix("#T ") || line.hasPrefix("-T "))) { - ScriptParseContext::ActionInfo ai = {ScriptParseContext::Talk, line.c_str() + 3, "", firstChar == '#'}; - parseCtx._actionInfos.push_back(ai); + ActionInfo ai = {ActionInfo::Talk, line.c_str() + 3, "", firstChar == '#', nullptr}; + parseCtx._talkActionInfos.push_back(ai); + _pendingActionInfos.push_back(&parseCtx._talkActionInfos.back()); } else if (line.size() >= 4 && (line.hasPrefix("#U ") || line.hasPrefix("-U "))) { int secondObjPos = -1; for (int i = 3; i < (int) line.size(); ++i) { @@ -58,13 +60,15 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext break; } } - ScriptParseContext::ActionInfo ai = { - ScriptParseContext::Talk, + ActionInfo ai = { + ActionInfo::Use, line.c_str() + 3, (secondObjPos != -1) ? line.c_str() + secondObjPos : "", - firstChar == '#' + firstChar == '#', + nullptr }; - parseCtx._actionInfos.push_back(ai); + parseCtx._useActionInfos.push_back(ai); + _pendingActionInfos.push_back(&parseCtx._useActionInfos.back()); } else if ((line.hasPrefix("#ELSE") || line.hasPrefix("=ELSE"))) { _elseFound = true; _ifTag = 0; @@ -78,7 +82,7 @@ bool EndBlockCommandParser::parse(const Common::String &line, ScriptParseContext return true; } -void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *, Command *newCommand) { +void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *, Command *newCommand, CommandParser *newCommandParser) { if (_elseFound) { if (newCommand) { ScriptParseContext::ConditionalCommandInfos::iterator it = parseCtx._pendingCondCommands.begin(); @@ -96,6 +100,14 @@ void EndBlockCommandParser::transition(ScriptParseContext &parseCtx, Command *, _elseFound = false; _ifTag = 0; } + + if (!_pendingActionInfos.empty() && newCommandParser != this) { + debug("Fixing pending action info.\n"); + for (Common::Array<ActionInfo *>::iterator it = _pendingActionInfos.begin(); it != _pendingActionInfos.end(); ++it) { + (*it)->_command = newCommand; + } + _pendingActionInfos.clear(); + } } Command::ExecuteResult EndBlockCommand::execute(GameData &) { @@ -105,4 +117,9 @@ Command::ExecuteResult EndBlockCommand::execute(GameData &) { Command *EndBlockCommand::next() const { return nullptr; } + +Common::String EndBlockCommand::debugString() const { + return "ENDBLOCK"; +} + } diff --git a/engines/mutationofjb/commands/endblockcommand.h b/engines/mutationofjb/commands/endblockcommand.h index 1ac636c6d5..51f799367c 100644 --- a/engines/mutationofjb/commands/endblockcommand.h +++ b/engines/mutationofjb/commands/endblockcommand.h @@ -25,19 +25,23 @@ #include "mutationofjb/commands/command.h" #include "common/scummsys.h" +#include "common/array.h" namespace MutationOfJB { +class ActionInfo; + class EndBlockCommandParser : public CommandParser { public: EndBlockCommandParser() : _elseFound(false), _ifTag(0) {} virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command); - virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand); + virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser); private: bool _elseFound; char _ifTag; + Common::Array<ActionInfo*> _pendingActionInfos; }; class EndBlockCommand : public Command { @@ -46,6 +50,7 @@ public: virtual ExecuteResult execute(GameData &gameData) override; virtual Command *next() const override; + virtual Common::String debugString() const; }; } diff --git a/engines/mutationofjb/commands/ifcommand.cpp b/engines/mutationofjb/commands/ifcommand.cpp index 8026c841e1..a41875f33b 100644 --- a/engines/mutationofjb/commands/ifcommand.cpp +++ b/engines/mutationofjb/commands/ifcommand.cpp @@ -58,7 +58,7 @@ bool IfCommandParser::parse(const Common::String &line, ScriptParseContext &pars return true; } -void IfCommandParser::transition(ScriptParseContext &, Command *oldCommand, Command *newCommand) { +void IfCommandParser::transition(ScriptParseContext &, Command *oldCommand, Command *newCommand, CommandParser *) { if (!oldCommand || !newCommand) { warning(_("Unexpected empty command in transition")); return; @@ -92,5 +92,10 @@ Command::ExecuteResult IfCommand::execute(GameData &gameData) { return Finished; } + +Common::String IfCommand::debugString() const { + return Common::String::format("IF scene%d.object%d.WX %s %d", _sceneId, _objectId, _negative ? "!=" : "==", _value); +} + } diff --git a/engines/mutationofjb/commands/ifcommand.h b/engines/mutationofjb/commands/ifcommand.h index 290260be93..9462278483 100644 --- a/engines/mutationofjb/commands/ifcommand.h +++ b/engines/mutationofjb/commands/ifcommand.h @@ -33,7 +33,7 @@ class ScriptParseContext; class IfCommandParser : public CommandParser { public: virtual bool parse(const Common::String &line, ScriptParseContext &parseCtx, Command *&command); - virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand); + virtual void transition(ScriptParseContext &parseCtx, Command *oldCommand, Command *newCommand, CommandParser *newCommandParser); }; class IfCommand : public ConditionalCommand { @@ -43,6 +43,7 @@ public: IfCommand(uint8 sceneId, uint8 objectId, uint16 value, bool negative); virtual ExecuteResult execute(GameData &gameData) override; + virtual Common::String debugString() const; private: uint8 _sceneId; |