diff options
| author | Walter van Niftrik | 2019-03-26 23:41:23 +0100 |
|---|---|---|
| committer | Walter van Niftrik | 2019-03-30 23:18:02 +0100 |
| commit | fa7688a93199f25e84d7c39ca232a4f20a629274 (patch) | |
| tree | bcb44cb7606e0bd515a69cf3a724061e0408ff14 /engines/adl/adl.cpp | |
| parent | 658af785d1d6cb448e1dcf0251f80e2e9f62794a (diff) | |
| download | scummvm-rg350-fa7688a93199f25e84d7c39ca232a4f20a629274.tar.gz scummvm-rg350-fa7688a93199f25e84d7c39ca232a4f20a629274.tar.bz2 scummvm-rg350-fa7688a93199f25e84d7c39ca232a4f20a629274.zip | |
ADL: Refactor opcodes
Diffstat (limited to 'engines/adl/adl.cpp')
| -rw-r--r-- | engines/adl/adl.cpp | 158 |
1 files changed, 65 insertions, 93 deletions
diff --git a/engines/adl/adl.cpp b/engines/adl/adl.cpp index f4f306aa8f..17fdd28892 100644 --- a/engines/adl/adl.cpp +++ b/engines/adl/adl.cpp @@ -415,69 +415,42 @@ bool AdlEngine::isInputValid(const Commands &commands, byte verb, byte noun, boo return false; } -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)) - void AdlEngine::setupOpcodeTables() { - Common::Array<const Opcode *> *table = 0; - - SetOpcodeTable(_condOpcodes); - // 0x00 - OpcodeUnImpl(); - OpcodeUnImpl(); - OpcodeUnImpl(); - Opcode(o1_isItemInRoom); - // 0x04 - OpcodeUnImpl(); - Opcode(o1_isMovesGT); - Opcode(o1_isVarEQ); - OpcodeUnImpl(); - // 0x08 - OpcodeUnImpl(); - Opcode(o1_isCurPicEQ); - Opcode(o1_isItemPicEQ); - - SetOpcodeTable(_actOpcodes); - // 0x00 - OpcodeUnImpl(); - Opcode(o1_varAdd); - Opcode(o1_varSub); - Opcode(o1_varSet); - // 0x04 - Opcode(o1_listInv); - Opcode(o1_moveItem); - Opcode(o1_setRoom); - Opcode(o1_setCurPic); - // 0x08 - Opcode(o1_setPic); - Opcode(o1_printMsg); - Opcode(o1_setLight); - Opcode(o1_setDark); - // 0x0c - OpcodeUnImpl(); - Opcode(o1_quit); - OpcodeUnImpl(); - Opcode(o1_save); - // 0x10 - Opcode(o1_restore); - Opcode(o1_restart); - Opcode(o1_placeItem); - Opcode(o1_setItemPic); - // 0x14 - Opcode(o1_resetPic); - Opcode(o1_goDirection<IDI_DIR_NORTH>); - Opcode(o1_goDirection<IDI_DIR_SOUTH>); - Opcode(o1_goDirection<IDI_DIR_EAST>); - // 0x18 - Opcode(o1_goDirection<IDI_DIR_WEST>); - Opcode(o1_goDirection<IDI_DIR_UP>); - Opcode(o1_goDirection<IDI_DIR_DOWN>); - Opcode(o1_takeItem); - // 0x1c - Opcode(o1_dropItem); - Opcode(o1_setRoomPic); + _condOpcodes.resize(0x0b); + _condOpcodes[0x03] = opcode(&AdlEngine::o_isItemInRoom); + _condOpcodes[0x05] = opcode(&AdlEngine::o_isMovesGT); + _condOpcodes[0x06] = opcode(&AdlEngine::o_isVarEQ); + _condOpcodes[0x09] = opcode(&AdlEngine::o_isCurPicEQ); + _condOpcodes[0x0a] = opcode(&AdlEngine::o_isItemPicEQ); + + _actOpcodes.resize(0x1e); + _actOpcodes[0x01] = opcode(&AdlEngine::o_varAdd); + _actOpcodes[0x02] = opcode(&AdlEngine::o_varSub); + _actOpcodes[0x03] = opcode(&AdlEngine::o_varSet); + _actOpcodes[0x04] = opcode(&AdlEngine::o_listInv); + _actOpcodes[0x05] = opcode(&AdlEngine::o_moveItem); + _actOpcodes[0x06] = opcode(&AdlEngine::o_setRoom); + _actOpcodes[0x07] = opcode(&AdlEngine::o_setCurPic); + _actOpcodes[0x08] = opcode(&AdlEngine::o_setPic); + _actOpcodes[0x09] = opcode(&AdlEngine::o_printMsg); + _actOpcodes[0x0a] = opcode(&AdlEngine::o_setLight); + _actOpcodes[0x0b] = opcode(&AdlEngine::o_setDark); + _actOpcodes[0x0d] = opcode(&AdlEngine::o_quit); + _actOpcodes[0x0f] = opcode(&AdlEngine::o_save); + _actOpcodes[0x10] = opcode(&AdlEngine::o_restore); + _actOpcodes[0x11] = opcode(&AdlEngine::o_restart); + _actOpcodes[0x12] = opcode(&AdlEngine::o_placeItem); + _actOpcodes[0x13] = opcode(&AdlEngine::o_setItemPic); + _actOpcodes[0x14] = opcode(&AdlEngine::o_resetPic); + _actOpcodes[0x15] = opcode(&AdlEngine::o_goNorth); + _actOpcodes[0x16] = opcode(&AdlEngine::o_goSouth); + _actOpcodes[0x17] = opcode(&AdlEngine::o_goEast); + _actOpcodes[0x18] = opcode(&AdlEngine::o_goWest); + _actOpcodes[0x19] = opcode(&AdlEngine::o_goUp); + _actOpcodes[0x1a] = opcode(&AdlEngine::o_goDown); + _actOpcodes[0x1b] = opcode(&AdlEngine::o_takeItem); + _actOpcodes[0x1c] = opcode(&AdlEngine::o_dropItem); + _actOpcodes[0x1d] = opcode(&AdlEngine::o_setRoomPic); } void AdlEngine::initState() { @@ -1129,7 +1102,7 @@ bool AdlEngine::op_debug(const char *fmt, ...) const { return false; } -int AdlEngine::o1_isItemInRoom(ScriptEnv &e) { +int AdlEngine::o_isItemInRoom(ScriptEnv &e) { OP_DEBUG_2("\t&& GET_ITEM_ROOM(%s) == %s", itemStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str()); if (getItem(e.arg(1)).room == roomArg(e.arg(2))) @@ -1138,7 +1111,7 @@ int AdlEngine::o1_isItemInRoom(ScriptEnv &e) { return -1; } -int AdlEngine::o1_isMovesGT(ScriptEnv &e) { +int AdlEngine::o_isMovesGT(ScriptEnv &e) { OP_DEBUG_1("\t&& MOVES > %d", e.arg(1)); if (_state.moves > e.arg(1)) @@ -1147,7 +1120,7 @@ int AdlEngine::o1_isMovesGT(ScriptEnv &e) { return -1; } -int AdlEngine::o1_isVarEQ(ScriptEnv &e) { +int AdlEngine::o_isVarEQ(ScriptEnv &e) { OP_DEBUG_2("\t&& VARS[%d] == %d", e.arg(1), e.arg(2)); if (getVar(e.arg(1)) == e.arg(2)) @@ -1156,7 +1129,7 @@ int AdlEngine::o1_isVarEQ(ScriptEnv &e) { return -1; } -int AdlEngine::o1_isCurPicEQ(ScriptEnv &e) { +int AdlEngine::o_isCurPicEQ(ScriptEnv &e) { OP_DEBUG_1("\t&& GET_CURPIC() == %d", e.arg(1)); if (_state.curPicture == e.arg(1)) @@ -1165,7 +1138,7 @@ int AdlEngine::o1_isCurPicEQ(ScriptEnv &e) { return -1; } -int AdlEngine::o1_isItemPicEQ(ScriptEnv &e) { +int AdlEngine::o_isItemPicEQ(ScriptEnv &e) { OP_DEBUG_2("\t&& GET_ITEM_PIC(%s) == %d", itemStr(e.arg(1)).c_str(), e.arg(2)); if (getItem(e.arg(1)).picture == e.arg(2)) @@ -1174,28 +1147,28 @@ int AdlEngine::o1_isItemPicEQ(ScriptEnv &e) { return -1; } -int AdlEngine::o1_varAdd(ScriptEnv &e) { +int AdlEngine::o_varAdd(ScriptEnv &e) { OP_DEBUG_2("\tVARS[%d] += %d", e.arg(2), e.arg(1)); setVar(e.arg(2), getVar(e.arg(2)) + e.arg(1)); return 2; } -int AdlEngine::o1_varSub(ScriptEnv &e) { +int AdlEngine::o_varSub(ScriptEnv &e) { OP_DEBUG_2("\tVARS[%d] -= %d", e.arg(2), e.arg(1)); setVar(e.arg(2), getVar(e.arg(2)) - e.arg(1)); return 2; } -int AdlEngine::o1_varSet(ScriptEnv &e) { +int AdlEngine::o_varSet(ScriptEnv &e) { OP_DEBUG_2("\tVARS[%d] = %d", e.arg(1), e.arg(2)); setVar(e.arg(1), e.arg(2)); return 2; } -int AdlEngine::o1_listInv(ScriptEnv &e) { +int AdlEngine::o_listInv(ScriptEnv &e) { OP_DEBUG_0("\tLIST_INVENTORY()"); Common::List<Item>::const_iterator item; @@ -1207,63 +1180,63 @@ int AdlEngine::o1_listInv(ScriptEnv &e) { return 0; } -int AdlEngine::o1_moveItem(ScriptEnv &e) { +int AdlEngine::o_moveItem(ScriptEnv &e) { OP_DEBUG_2("\tSET_ITEM_ROOM(%s, %s)", itemStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str()); getItem(e.arg(1)).room = e.arg(2); return 2; } -int AdlEngine::o1_setRoom(ScriptEnv &e) { +int AdlEngine::o_setRoom(ScriptEnv &e) { OP_DEBUG_1("\tROOM = %d", e.arg(1)); switchRoom(e.arg(1)); return 1; } -int AdlEngine::o1_setCurPic(ScriptEnv &e) { +int AdlEngine::o_setCurPic(ScriptEnv &e) { OP_DEBUG_1("\tSET_CURPIC(%d)", e.arg(1)); getCurRoom().curPicture = e.arg(1); return 1; } -int AdlEngine::o1_setPic(ScriptEnv &e) { +int AdlEngine::o_setPic(ScriptEnv &e) { OP_DEBUG_1("\tSET_PIC(%d)", e.arg(1)); getCurRoom().picture = getCurRoom().curPicture = e.arg(1); return 1; } -int AdlEngine::o1_printMsg(ScriptEnv &e) { +int AdlEngine::o_printMsg(ScriptEnv &e) { OP_DEBUG_1("\tPRINT(%s)", msgStr(e.arg(1)).c_str()); printMessage(e.arg(1)); return 1; } -int AdlEngine::o1_setLight(ScriptEnv &e) { +int AdlEngine::o_setLight(ScriptEnv &e) { OP_DEBUG_0("\tLIGHT()"); _state.isDark = false; return 0; } -int AdlEngine::o1_setDark(ScriptEnv &e) { +int AdlEngine::o_setDark(ScriptEnv &e) { OP_DEBUG_0("\tDARK()"); _state.isDark = true; return 0; } -int AdlEngine::o1_save(ScriptEnv &e) { +int AdlEngine::o_save(ScriptEnv &e) { OP_DEBUG_0("\tSAVE_GAME()"); saveGameState(0, ""); return 0; } -int AdlEngine::o1_restore(ScriptEnv &e) { +int AdlEngine::o_restore(ScriptEnv &e) { OP_DEBUG_0("\tRESTORE_GAME()"); loadGameState(0); @@ -1271,7 +1244,7 @@ int AdlEngine::o1_restore(ScriptEnv &e) { return 0; } -int AdlEngine::o1_restart(ScriptEnv &e) { +int AdlEngine::o_restart(ScriptEnv &e) { OP_DEBUG_0("\tRESTART_GAME()"); _display->printString(_strings.playAgain); @@ -1287,10 +1260,10 @@ int AdlEngine::o1_restart(ScriptEnv &e) { return -1; } - return o1_quit(e); + return o_quit(e); } -int AdlEngine::o1_quit(ScriptEnv &e) { +int AdlEngine::o_quit(ScriptEnv &e) { OP_DEBUG_0("\tQUIT_GAME()"); printMessage(_messageIds.thanksForPlaying); @@ -1304,7 +1277,7 @@ int AdlEngine::o1_quit(ScriptEnv &e) { return -1; } -int AdlEngine::o1_placeItem(ScriptEnv &e) { +int AdlEngine::o_placeItem(ScriptEnv &e) { OP_DEBUG_4("\tPLACE_ITEM(%s, %s, (%d, %d))", itemStr(e.arg(1)).c_str(), itemRoomStr(e.arg(2)).c_str(), e.arg(3), e.arg(4)); Item &item = getItem(e.arg(1)); @@ -1315,25 +1288,24 @@ int AdlEngine::o1_placeItem(ScriptEnv &e) { return 4; } -int AdlEngine::o1_setItemPic(ScriptEnv &e) { +int AdlEngine::o_setItemPic(ScriptEnv &e) { OP_DEBUG_2("\tSET_ITEM_PIC(%s, %d)", itemStr(e.arg(2)).c_str(), e.arg(1)); getItem(e.arg(2)).picture = e.arg(1); return 2; } -int AdlEngine::o1_resetPic(ScriptEnv &e) { +int AdlEngine::o_resetPic(ScriptEnv &e) { OP_DEBUG_0("\tRESET_PIC()"); getCurRoom().curPicture = getCurRoom().picture; return 0; } -template <Direction D> -int AdlEngine::o1_goDirection(ScriptEnv &e) { - OP_DEBUG_0((Common::String("\tGO_") + dirStr(D) + "()").c_str()); +int AdlEngine::goDirection(ScriptEnv &e, Direction dir) { + OP_DEBUG_0((Common::String("\tGO_") + dirStr(dir) + "()").c_str()); - byte room = getCurRoom().connections[D]; + byte room = getCurRoom().connections[dir]; if (room == 0) { printMessage(_messageIds.cantGoThere); @@ -1344,21 +1316,21 @@ int AdlEngine::o1_goDirection(ScriptEnv &e) { return -1; } -int AdlEngine::o1_takeItem(ScriptEnv &e) { +int AdlEngine::o_takeItem(ScriptEnv &e) { OP_DEBUG_0("\tTAKE_ITEM()"); takeItem(e.getNoun()); return 0; } -int AdlEngine::o1_dropItem(ScriptEnv &e) { +int AdlEngine::o_dropItem(ScriptEnv &e) { OP_DEBUG_0("\tDROP_ITEM()"); dropItem(e.getNoun()); return 0; } -int AdlEngine::o1_setRoomPic(ScriptEnv &e) { +int AdlEngine::o_setRoomPic(ScriptEnv &e) { OP_DEBUG_2("\tSET_ROOM_PIC(%d, %d)", e.arg(1), e.arg(2)); getRoom(e.arg(1)).picture = getRoom(e.arg(1)).curPicture = e.arg(2); |
