aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWalter van Niftrik2016-03-18 11:22:01 +0100
committerWalter van Niftrik2016-06-06 20:35:49 +0200
commitf93ae5479e21877e3c527b7a7383f3e1edb8e22f (patch)
tree2cc5a3eb4cc1611b5da7ca5cdd3c597e7e49b668
parenta9afe17169295b69c50bc3a727f4dd8034c24f2e (diff)
downloadscummvm-rg350-f93ae5479e21877e3c527b7a7383f3e1edb8e22f.tar.gz
scummvm-rg350-f93ae5479e21877e3c527b7a7383f3e1edb8e22f.tar.bz2
scummvm-rg350-f93ae5479e21877e3c527b7a7383f3e1edb8e22f.zip
ADL: Make opcodes return arg count
-rw-r--r--engines/adl/adl.cpp160
-rw-r--r--engines/adl/adl.h59
2 files changed, 101 insertions, 118 deletions
diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp
index 069e3601f2..7128928664 100644
--- a/engines/adl/adl.cpp
+++ b/engines/adl/adl.cpp
@@ -278,7 +278,7 @@ void AdlEngine::checkInput(byte verb, byte noun) {
printMessage(_messageIds.dontUnderstand);
}
-typedef Common::Functor1Mem<ScriptEnv &, bool, AdlEngine> OpcodeV1;
+typedef Common::Functor1Mem<ScriptEnv &, int, AdlEngine> OpcodeV1;
#define SetOpcodeTable(x) table = &x;
#define Opcode(x) table->push_back(new OpcodeV1(this, &AdlEngine::x))
#define OpcodeUnImpl() table->push_back(new OpcodeV1(this, 0))
@@ -852,129 +852,111 @@ void AdlEngine::getInput(uint &verb, uint &noun) {
}
}
-typedef Common::Functor1Mem<ScriptEnv &, bool, AdlEngine> OpcodeV1;
+typedef Common::Functor1Mem<ScriptEnv &, int, AdlEngine> OpcodeV1;
-bool AdlEngine::o1_isItemInRoom(ScriptEnv &e) {
+int AdlEngine::o1_isItemInRoom(ScriptEnv &e) {
if (getItem(e.arg(1)).room != e.arg(2))
- return false;
- e.ip += 3;
- return true;
+ return -1;
+ return 2;
}
-bool AdlEngine::o1_isMovesGrEq(ScriptEnv &e) {
+int AdlEngine::o1_isMovesGrEq(ScriptEnv &e) {
if (e.arg(1) > _state.moves)
- return false;
- e.ip += 2;
- return true;
+ return -1;
+ return 1;
}
-bool AdlEngine::o1_isVarEq(ScriptEnv &e) {
+int AdlEngine::o1_isVarEq(ScriptEnv &e) {
if (getVar(e.arg(1)) != e.arg(2))
- return false;
- e.ip += 3;
- return true;
+ return -1;
+ return 2;
}
-bool AdlEngine::o1_isCurPicEq(ScriptEnv &e) {
+int AdlEngine::o1_isCurPicEq(ScriptEnv &e) {
if (getCurRoom().curPicture != e.arg(1))
- return false;
- e.ip += 2;
- return true;
+ return -1;
+ return 1;
}
-bool AdlEngine::o1_isItemPicEq(ScriptEnv &e) {
+int AdlEngine::o1_isItemPicEq(ScriptEnv &e) {
if (getItem(e.arg(1)).picture != e.arg(2))
- return false;
- e.ip += 3;
- return true;
+ return -1;
+ return 2;
}
-bool AdlEngine::o1_varAdd(ScriptEnv &e) {
+int AdlEngine::o1_varAdd(ScriptEnv &e) {
setVar(e.arg(2), getVar(e.arg(2) + e.arg(1)));
- e.ip += 3;
- return true;
+ return 2;
}
-bool AdlEngine::o1_varSub(ScriptEnv &e) {
+int AdlEngine::o1_varSub(ScriptEnv &e) {
setVar(e.arg(2), getVar(e.arg(2)) - e.arg(1));
- e.ip += 3;
- return true;
+ return 2;
}
-bool AdlEngine::o1_varSet(ScriptEnv &e) {
+int AdlEngine::o1_varSet(ScriptEnv &e) {
setVar(e.arg(1), e.arg(2));
- e.ip += 3;
- return true;
+ return 2;
}
-bool AdlEngine::o1_listInv(ScriptEnv &e) {
+int AdlEngine::o1_listInv(ScriptEnv &e) {
Common::Array<Item>::const_iterator item;
for (item = _state.items.begin(); item != _state.items.end(); ++item)
if (item->room == IDI_NONE)
printMessage(item->description);
- ++e.ip;
- return true;
+ return 0;
}
-bool AdlEngine::o1_moveItem(ScriptEnv &e) {
+int AdlEngine::o1_moveItem(ScriptEnv &e) {
getItem(e.arg(1)).room = e.arg(2);
- e.ip += 3;
- return true;
+ return 2;
}
-bool AdlEngine::o1_setRoom(ScriptEnv &e) {
+int AdlEngine::o1_setRoom(ScriptEnv &e) {
getCurRoom().curPicture = getCurRoom().picture;
_state.room = e.arg(1);
- e.ip += 2;
- return true;
+ return 1;
}
-bool AdlEngine::o1_setCurPic(ScriptEnv &e) {
+int AdlEngine::o1_setCurPic(ScriptEnv &e) {
getCurRoom().curPicture = e.arg(1);
- e.ip += 2;
- return true;
+ return 1;
}
-bool AdlEngine::o1_setPic(ScriptEnv &e) {
+int AdlEngine::o1_setPic(ScriptEnv &e) {
getCurRoom().picture = getCurRoom().curPicture = e.arg(1);
- e.ip += 2;
- return true;
+ return 1;
}
-bool AdlEngine::o1_printMsg(ScriptEnv &e) {
+int AdlEngine::o1_printMsg(ScriptEnv &e) {
printMessage(e.arg(1));
- e.ip += 2;
- return true;
+ return 1;
}
-bool AdlEngine::o1_setLight(ScriptEnv &e) {
+int AdlEngine::o1_setLight(ScriptEnv &e) {
_state.isDark = false;
- ++e.ip;
- return true;
+ return 0;
}
-bool AdlEngine::o1_setDark(ScriptEnv &e) {
+int AdlEngine::o1_setDark(ScriptEnv &e) {
_state.isDark = true;
- ++e.ip;
- return true;
+ return 0;
}
-bool AdlEngine::o1_save(ScriptEnv &e) {
+int AdlEngine::o1_save(ScriptEnv &e) {
saveGameState(0, "");
- ++e.ip;
- return true;
+ return 0;
}
-bool AdlEngine::o1_restore(ScriptEnv &e) {
+int AdlEngine::o1_restore(ScriptEnv &e) {
loadGameState(0);
- ++e.ip;
_isRestoring = false;
- return true;
+ return 0;
}
-bool AdlEngine::o1_restart(ScriptEnv &e) {
+int AdlEngine::o1_restart(ScriptEnv &e) {
_display->printString(_strings.playAgain);
Common::String input = inputString();
@@ -983,68 +965,62 @@ bool AdlEngine::o1_restart(ScriptEnv &e) {
_display->clear(0x00);
_display->updateHiResScreen();
restartGame();
- return false;
+ return -1;
}
return o1_quit(e);
}
-bool AdlEngine::o1_quit(ScriptEnv &e) {
+int AdlEngine::o1_quit(ScriptEnv &e) {
printMessage(_messageIds.thanksForPlaying);
quitGame();
- return false;
+ return -1;
}
-bool AdlEngine::o1_placeItem(ScriptEnv &e) {
+int AdlEngine::o1_placeItem(ScriptEnv &e) {
getItem(e.arg(1)).room = e.arg(2);
getItem(e.arg(1)).position.x = e.arg(3);
getItem(e.arg(1)).position.y = e.arg(4);
- e.ip += 5;
- return true;
+ return 4;
}
-bool AdlEngine::o1_setItemPic(ScriptEnv &e) {
+int AdlEngine::o1_setItemPic(ScriptEnv &e) {
getItem(e.arg(2)).picture = e.arg(1);
- e.ip += 3;
- return true;
+ return 2;
}
-bool AdlEngine::o1_resetPic(ScriptEnv &e) {
+int AdlEngine::o1_resetPic(ScriptEnv &e) {
getCurRoom().curPicture = getCurRoom().picture;
- ++e.ip;
- return true;
+ return 0;
}
template <Direction D>
-bool AdlEngine::o1_goDirection(ScriptEnv &e) {
+int AdlEngine::o1_goDirection(ScriptEnv &e) {
byte room = getCurRoom().connections[D];
if (room == 0) {
printMessage(_messageIds.cantGoThere);
- return false;
+ return -1;
}
getCurRoom().curPicture = getCurRoom().picture;
_state.room = room;
- return false;
+ return -1;
}
-bool AdlEngine::o1_takeItem(ScriptEnv &e) {
+int AdlEngine::o1_takeItem(ScriptEnv &e) {
takeItem(e.noun);
- ++e.ip;
- return true;
+ return 0;
}
-bool AdlEngine::o1_dropItem(ScriptEnv &e) {
+int AdlEngine::o1_dropItem(ScriptEnv &e) {
dropItem(e.noun);
- ++e.ip;
- return true;
+ return 0;
}
-bool AdlEngine::o1_setRoomPic(ScriptEnv &e) {
+int AdlEngine::o1_setRoomPic(ScriptEnv &e) {
getRoom(e.arg(1)).picture = getRoom(e.arg(1)).curPicture = e.arg(2);
- e.ip += 3;
- return true;
+ return 2;
}
bool AdlEngine::matchCommand(ScriptEnv &env, uint *actions) const {
@@ -1063,8 +1039,12 @@ bool AdlEngine::matchCommand(ScriptEnv &env, uint *actions) const {
if (!_condOpcodes[op] || !_condOpcodes[op]->isValid())
error("Unimplemented condition opcode %02x", op);
- if (!(*_condOpcodes[op])(env))
+ int numArgs = (*_condOpcodes[op])(env);
+
+ if (numArgs < 0)
return false;
+
+ env.ip += numArgs + 1;
}
if (actions)
@@ -1080,8 +1060,12 @@ void AdlEngine::doActions(ScriptEnv &env) {
if (!_actOpcodes[op] || !_actOpcodes[op]->isValid())
error("Unimplemented action opcode %02x", op);
- if (!(*_actOpcodes[op])(env))
+ int numArgs = (*_actOpcodes[op])(env);
+
+ if (numArgs < 0)
return;
+
+ env.ip += numArgs + 1;
}
}
diff --git a/engines/adl/adl.h b/engines/adl/adl.h
index 8e4a7fea0f..1d9355340f 100644
--- a/engines/adl/adl.h
+++ b/engines/adl/adl.h
@@ -50,8 +50,6 @@ class Speaker;
struct AdlGameDescription;
struct ScriptEnv;
-typedef Common::Functor1<ScriptEnv &, bool> Opcode;
-
// Conditional opcodes
#define IDO_CND_ITEM_IN_ROOM 0x03
#define IDO_CND_MOVES_GE 0x05
@@ -198,35 +196,35 @@ protected:
virtual void setupOpcodeTables();
// Opcodes
- bool o1_isItemInRoom(ScriptEnv &env);
- bool o1_isMovesGrEq(ScriptEnv &env);
- bool o1_isVarEq(ScriptEnv &env);
- bool o1_isCurPicEq(ScriptEnv &env);
- bool o1_isItemPicEq(ScriptEnv &env);
-
- bool o1_varAdd(ScriptEnv &env);
- bool o1_varSub(ScriptEnv &env);
- bool o1_varSet(ScriptEnv &env);
- bool o1_listInv(ScriptEnv &env);
- bool o1_moveItem(ScriptEnv &env);
- bool o1_setRoom(ScriptEnv &env);
- bool o1_setCurPic(ScriptEnv &env);
- bool o1_setPic(ScriptEnv &env);
- bool o1_printMsg(ScriptEnv &env);
- bool o1_setLight(ScriptEnv &env);
- bool o1_setDark(ScriptEnv &env);
- bool o1_save(ScriptEnv &env);
- bool o1_restore(ScriptEnv &env);
- bool o1_restart(ScriptEnv &env);
- bool o1_quit(ScriptEnv &env);
- bool o1_placeItem(ScriptEnv &env);
- bool o1_setItemPic(ScriptEnv &env);
- bool o1_resetPic(ScriptEnv &env);
+ 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);
template <Direction D>
- bool o1_goDirection(ScriptEnv &env);
- bool o1_takeItem(ScriptEnv &env);
- bool o1_dropItem(ScriptEnv &env);
- bool o1_setRoomPic(ScriptEnv &env);
+ int o1_goDirection(ScriptEnv &e);
+ int o1_takeItem(ScriptEnv &e);
+ int o1_dropItem(ScriptEnv &e);
+ int o1_setRoomPic(ScriptEnv &e);
// Graphics
void clearScreen() const;
@@ -256,6 +254,7 @@ protected:
Speaker *_speaker;
// Opcodes
+ typedef Common::Functor1<ScriptEnv &, int> Opcode;
Common::Array<const Opcode *> _condOpcodes, _actOpcodes;
// Message strings in data file
Common::Array<Common::String> _messages;