From 49448af6cb2613460fe37caf79bdb1ed4c206715 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 21 Jun 2010 21:34:06 +0000 Subject: AGI: Turn some more AGI static functions into AgiEngine methods svn-id: r50127 --- engines/agi/agi.h | 11 +++++++ engines/agi/op_test.cpp | 87 +++++++++++++++++++++---------------------------- 2 files changed, 48 insertions(+), 50 deletions(-) (limited to 'engines') diff --git a/engines/agi/agi.h b/engines/agi/agi.h index 301ffa1b6c..166470e6e4 100644 --- a/engines/agi/agi.h +++ b/engines/agi/agi.h @@ -939,6 +939,17 @@ public: int testIfCode(int); void executeAgiCommand(uint8, uint8 *); +private: + // Some submethods of testIfCode + uint8 testObjRight(uint8, uint8, uint8, uint8, uint8); + uint8 testObjCentre(uint8, uint8, uint8, uint8, uint8); + uint8 testObjInBox(uint8, uint8, uint8, uint8, uint8); + uint8 testPosn(uint8, uint8, uint8, uint8, uint8); + uint8 testSaid(uint8, uint8 *); + uint8 testController(uint8); + uint8 testKeypressed(); + uint8 testCompareStrings(uint8, uint8); + // View private: diff --git a/engines/agi/op_test.cpp b/engines/agi/op_test.cpp index 6967f6c665..ab4f6cadc5 100644 --- a/engines/agi/op_test.cpp +++ b/engines/agi/op_test.cpp @@ -29,35 +29,23 @@ namespace Agi { -static uint8 testObjRight(uint8, uint8, uint8, uint8, uint8); -static uint8 testObjCentre(uint8, uint8, uint8, uint8, uint8); -static uint8 testObjInBox(uint8, uint8, uint8, uint8, uint8); -static uint8 testPosn(uint8, uint8, uint8, uint8, uint8); -static uint8 testSaid(uint8, uint8 *); -static uint8 testController(uint8); -static uint8 testKeypressed(); -static uint8 testCompareStrings(uint8, uint8); - -static AgiEngine *g_agi; -#define game g_agi->_game - -#define ip (game.logics[lognum].cIP) -#define code (game.logics[lognum].data) - -#define testEqual(v1, v2) (g_agi->getvar(v1) == (v2)) -#define testLess(v1, v2) (g_agi->getvar(v1) < (v2)) -#define testGreater(v1, v2) (g_agi->getvar(v1) > (v2)) -#define testIsSet(flag) (g_agi->getflag(flag)) -#define testHas(obj) (g_agi->objectGetLocation(obj) == EGO_OWNED) -#define testObjInRoom(obj, v) (g_agi->objectGetLocation(obj) == g_agi->getvar(v)) - -static uint8 testCompareStrings(uint8 s1, uint8 s2) { +#define ip (_game.logics[lognum].cIP) +#define code (_game.logics[lognum].data) + +#define testEqual(v1, v2) (getvar(v1) == (v2)) +#define testLess(v1, v2) (getvar(v1) < (v2)) +#define testGreater(v1, v2) (getvar(v1) > (v2)) +#define testIsSet(flag) (getflag(flag)) +#define testHas(obj) (objectGetLocation(obj) == EGO_OWNED) +#define testObjInRoom(obj, v) (objectGetLocation(obj) == getvar(v)) + +uint8 AgiEngine::testCompareStrings(uint8 s1, uint8 s2) { char ms1[MAX_STRINGLEN]; char ms2[MAX_STRINGLEN]; int j, k, l; - strcpy(ms1, game.strings[s1]); - strcpy(ms2, game.strings[s2]); + strcpy(ms1, _game.strings[s1]); + strcpy(ms2, _game.strings[s2]); l = strlen(ms1); for (k = 0, j = 0; k < l; k++) { @@ -104,16 +92,16 @@ static uint8 testCompareStrings(uint8 s1, uint8 s2) { return !strcmp(ms1, ms2); } -static uint8 testKeypressed() { - int x = game.keypress; +uint8 AgiEngine::testKeypressed() { + int x = _game.keypress; - game.keypress = 0; + _game.keypress = 0; if (!x) { - InputMode mode = game.inputMode; + InputMode mode = _game.inputMode; - game.inputMode = INPUT_NONE; - g_agi->mainCycle(); - game.inputMode = mode; + _game.inputMode = INPUT_NONE; + mainCycle(); + _game.inputMode = mode; } if (x) @@ -122,12 +110,12 @@ static uint8 testKeypressed() { return x; } -static uint8 testController(uint8 cont) { - return (game.controllerOccured[cont] ? 1 : 0); +uint8 AgiEngine::testController(uint8 cont) { + return (_game.controllerOccured[cont] ? 1 : 0); } -static uint8 testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) { - VtEntry *v = &game.viewTable[n]; +uint8 AgiEngine::testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) { + VtEntry *v = &_game.viewTable[n]; uint8 r; r = v->xPos >= x1 && v->yPos >= y1 && v->xPos <= x2 && v->yPos <= y2; @@ -137,35 +125,35 @@ static uint8 testPosn(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) { return r; } -static uint8 testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) { - VtEntry *v = &game.viewTable[n]; +uint8 AgiEngine::testObjInBox(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) { + VtEntry *v = &_game.viewTable[n]; return v->xPos >= x1 && v->yPos >= y1 && v->xPos + v->xSize - 1 <= x2 && v->yPos <= y2; } // if n is in centre of box -static uint8 testObjCentre(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) { - VtEntry *v = &game.viewTable[n]; +uint8 AgiEngine::testObjCentre(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) { + VtEntry *v = &_game.viewTable[n]; return v->xPos + v->xSize / 2 >= x1 && v->xPos + v->xSize / 2 <= x2 && v->yPos >= y1 && v->yPos <= y2; } // if nect N is in right corner -static uint8 testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) { - VtEntry *v = &game.viewTable[n]; +uint8 AgiEngine::testObjRight(uint8 n, uint8 x1, uint8 y1, uint8 x2, uint8 y2) { + VtEntry *v = &_game.viewTable[n]; return v->xPos + v->xSize - 1 >= x1 && v->xPos + v->xSize - 1 <= x2 && v->yPos >= y1 && v->yPos <= y2; } // When player has entered something, it is parsed elsewhere -static uint8 testSaid(uint8 nwords, uint8 *cc) { - int c, n = game.numEgoWords; +uint8 AgiEngine::testSaid(uint8 nwords, uint8 *cc) { + int c, n = _game.numEgoWords; int z = 0; - if (g_agi->getflag(fSaidAcceptedInput) || !g_agi->getflag(fEnteredCli)) + if (getflag(fSaidAcceptedInput) || !getflag(fEnteredCli)) return false; // FR: @@ -196,7 +184,7 @@ static uint8 testSaid(uint8 nwords, uint8 *cc) { case 1: // any word break; default: - if (game.egoWords[c].id != z) + if (_game.egoWords[c].id != z) return false; break; } @@ -211,13 +199,12 @@ static uint8 testSaid(uint8 nwords, uint8 *cc) { if (nwords != 0 && READ_LE_UINT16(cc) != 9999) return false; - g_agi->setflag(fSaidAcceptedInput, true); + setflag(fSaidAcceptedInput, true); return true; } int AgiEngine::testIfCode(int lognum) { - g_agi = this; int ec = true; int retval = true; uint8 op = 0; @@ -317,7 +304,7 @@ int AgiEngine::testIfCode(int lognum) { ip++; // skip num_words opcode break; case 0x0F: - debugC(7, kDebugLevelScripts, "comparing [%s], [%s]", game.strings[p[0]], game.strings[p[1]]); + debugC(7, kDebugLevelScripts, "comparing [%s], [%s]", _game.strings[p[0]], _game.strings[p[1]]); ec = testCompareStrings(p[0], p[1]); break; case 0x10: @@ -336,7 +323,7 @@ int AgiEngine::testIfCode(int lognum) { // This command is used at least in the Amiga version of Gold Rush! v2.05 1989-03-09 // (AGI 2.316) in logics 1, 3, 5, 6, 137 and 192 (Logic.192 revealed this command's nature). // TODO: Check this command's implementation using disassembly just to be sure. - ec = game.viewTable[0].flags & ADJ_EGO_XY; + ec = _game.viewTable[0].flags & ADJ_EGO_XY; debugC(7, kDebugLevelScripts, "op_test: in.motion.using.mouse = %s (Amiga-specific testcase 19)", ec ? "true" : "false"); break; default: -- cgit v1.2.3