From 065d04900828214f545db984a332ac3889fcc796 Mon Sep 17 00:00:00 2001 From: sluicebox <22204938+sluicebox@users.noreply.github.com> Date: Sat, 9 Mar 2024 08:43:47 -0700 Subject: [PATCH] AGI: op_cmd cleanup --- engines/agi/op_cmd.cpp | 281 ++++++++++++++++++++--------------------- 1 file changed, 135 insertions(+), 146 deletions(-) diff --git a/engines/agi/op_cmd.cpp b/engines/agi/op_cmd.cpp index 53da0ace7b8..baaeef7b8e6 100644 --- a/engines/agi/op_cmd.cpp +++ b/engines/agi/op_cmd.cpp @@ -257,32 +257,32 @@ void cmdToggleV(AgiGame *state, AgiEngine *vm, uint8 *parameter) { void cmdNewRoom(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 newRoomNr = parameter[0]; - state->_vm->newRoom(newRoomNr); + vm->newRoom(newRoomNr); } void cmdNewRoomF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 varNr = parameter[0]; byte value = vm->getVar(varNr); - state->_vm->newRoom(value); + vm->newRoom(value); } void cmdLoadView(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 resourceNr = parameter[0]; - state->_vm->agiLoadResource(RESOURCETYPE_VIEW, resourceNr); + vm->agiLoadResource(RESOURCETYPE_VIEW, resourceNr); } void cmdLoadLogic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 resourceNr = parameter[0]; - state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr); + vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr); } void cmdLoadSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 resourceNr = parameter[0]; - state->_vm->agiLoadResource(RESOURCETYPE_SOUND, resourceNr); + vm->agiLoadResource(RESOURCETYPE_SOUND, resourceNr); } void cmdLoadViewF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -296,13 +296,13 @@ void cmdLoadLogicF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 varNr = parameter[0]; byte value = vm->getVar(varNr); - state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, value); + vm->agiLoadResource(RESOURCETYPE_LOGIC, value); } void cmdDiscardView(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 resourceNr = parameter[0]; - state->_vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr); + vm->agiUnloadResource(RESOURCETYPE_VIEW, resourceNr); } void cmdObjectOnAnything(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -414,14 +414,14 @@ void cmdStartUpdate(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 objectNr = parameter[0]; ScreenObjEntry *screenObj = &state->screenObjTable[objectNr]; - state->_vm->startUpdate(screenObj); + vm->startUpdate(screenObj); } void cmdStopUpdate(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 objectNr = parameter[0]; ScreenObjEntry *screenObj = &state->screenObjTable[objectNr]; - state->_vm->stopUpdate(screenObj); + vm->stopUpdate(screenObj); } void cmdCurrentView(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -483,7 +483,7 @@ void cmdSetView(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 viewNr = parameter[1]; ScreenObjEntry *screenObj = &state->screenObjTable[objectNr]; - state->_vm->setView(screenObj, viewNr); + vm->setView(screenObj, viewNr); } void cmdSetViewF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -492,7 +492,7 @@ void cmdSetViewF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { ScreenObjEntry *screenObj = &state->screenObjTable[objectNr]; byte value = vm->getVar(varNr); - state->_vm->setView(screenObj, value); + vm->setView(screenObj, value); } void cmdSetLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -500,7 +500,7 @@ void cmdSetLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 loopNr = parameter[1]; ScreenObjEntry *screenObj = &state->screenObjTable[objectNr]; - state->_vm->setLoop(screenObj, loopNr); + vm->setLoop(screenObj, loopNr); } void cmdSetLoopF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -509,7 +509,7 @@ void cmdSetLoopF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { ScreenObjEntry *screenObj = &state->screenObjTable[objectNr]; byte value = vm->getVar(varNr); - state->_vm->setLoop(screenObj, value); + vm->setLoop(screenObj, value); } void cmdNumberOfLoops(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -609,7 +609,7 @@ void cmdGetRoomF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 varNr2 = parameter[1]; byte varVal1 = vm->getVar(varNr1); - vm->setVar(varNr2, state->_vm->objectGetLocation(varVal1)); + vm->setVar(varNr2, vm->objectGetLocation(varVal1)); } void cmdPut(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -626,39 +626,39 @@ void cmdPutF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { byte varVal1 = vm->getVar(varNr1); byte varVal2 = vm->getVar(varNr2); - state->_vm->objectSetLocation(varVal1, varVal2); + vm->objectSetLocation(varVal1, varVal2); } void cmdDrop(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 objectNr = parameter[0]; - state->_vm->objectSetLocation(objectNr, 0); + vm->objectSetLocation(objectNr, 0); } void cmdGet(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 objectNr = parameter[0]; - state->_vm->objectSetLocation(objectNr, EGO_OWNED); + vm->objectSetLocation(objectNr, EGO_OWNED); } void cmdGetV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 objectNr = parameter[0]; - state->_vm->objectSetLocation(objectNr, EGO_OWNED_V1); + vm->objectSetLocation(objectNr, EGO_OWNED_V1); } void cmdGetF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 varNr = parameter[0]; byte varVal = vm->getVar(varNr); - state->_vm->objectSetLocation(varVal, EGO_OWNED); + vm->objectSetLocation(varVal, EGO_OWNED); } void cmdWordToString(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 stringNr = parameter[0]; uint16 wordNr = parameter[1]; - Common::strlcpy(state->strings[stringNr], state->_vm->_words->getEgoWord(wordNr), MAX_STRINGLEN); + Common::strlcpy(state->strings[stringNr], vm->_words->getEgoWord(wordNr), MAX_STRINGLEN); } void cmdOpenDialogue(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -674,41 +674,41 @@ void cmdCloseWindow(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdStatusLineOn(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *text = state->_vm->_text; + TextMgr *text = vm->_text; text->statusEnable(); text->statusDraw(); } void cmdStatusLineOff(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *text = state->_vm->_text; + TextMgr *text = vm->_text; text->statusDisable(); - state->_vm->_text->statusClear(); + text->statusClear(); } void cmdShowObj(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 objectNr = parameter[0]; - state->_vm->_sprites->showObject(objectNr); + vm->_sprites->showObject(objectNr); } void cmdShowObjV(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 varNr = parameter[0]; byte varVal = vm->getVar(varNr); - state->_vm->_sprites->showObject(varVal); + vm->_sprites->showObject(varVal); } void cmdSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 resourceNr = parameter[0]; uint16 flagNr = parameter[1]; - state->_vm->_sound->startSound(resourceNr, flagNr); + vm->_sound->startSound(resourceNr, flagNr); } void cmdStopSound(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - state->_vm->_sound->stopSound(); + vm->_sound->stopSound(); } void cmdMenuInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -720,17 +720,17 @@ void cmdMenuInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) { void cmdEnableItem(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 controlCode = parameter[0]; - state->_vm->_menu->itemEnable(controlCode); + vm->_menu->itemEnable(controlCode); } void cmdDisableItem(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 controlCode = parameter[0]; - state->_vm->_menu->itemDisable(controlCode); + vm->_menu->itemDisable(controlCode); } void cmdSubmitMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - state->_vm->_menu->submit(); + vm->_menu->submit(); } void cmdSetScanStart(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -744,7 +744,7 @@ void cmdResetScanStart(AgiGame *state, AgiEngine *vm, uint8 *parameter) { void cmdSaveGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) { if (vm->getVersion() >= 0x2272) { // this was only donce since 2.272 - state->_vm->_sound->stopSound(); + vm->_sound->stopSound(); } PauseToken pt = vm->pauseEngine(); @@ -763,7 +763,7 @@ void cmdSaveGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) { void cmdLoadGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) { if (vm->getVersion() >= 0x2272) { // this was only done since 2.272 - state->_vm->_sound->stopSound(); + vm->_sound->stopSound(); } PauseToken pt = vm->pauseEngine(); @@ -841,7 +841,7 @@ void cmdTraceInfo(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdShowMem(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - state->_vm->_text->messageBox("Enough memory"); + vm->_text->messageBox("Enough memory"); } void cmdInitJoy(AgiGame *state, AgiEngine *vm, uint8 *parameter) { // do nothing @@ -925,7 +925,7 @@ void cmdObjStatusF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { screenObj->stepSize, cycleDesc, motionDesc); - state->_vm->_text->messageBox(msg); + vm->_text->messageBox(msg); } // unknown commands: @@ -937,7 +937,7 @@ void cmdObjStatusF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { // unk_177: Disable menus completely -- j5 // unk_181: Deactivate keypressed control (default control of ego) void cmdSetSimple(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - if (!(state->_vm->getFeatures() & GF_AGI256)) { + if (!(vm->getFeatures() & GF_AGI256)) { // set.simple is called by Larry 1 on Apple IIgs at the store, after answering the 555-6969 phone. // load.sound(16) is called right before it. Interpreter is 2.440-like. // it's called with parameter 16. @@ -952,12 +952,10 @@ void cmdSetSimple(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } int16 stringNr = parameter[0]; - const char *textPtr = nullptr; - state->automaticSave = false; // Try to get description for automatic saves - textPtr = state->strings[stringNr]; + const char *textPtr = state->strings[stringNr]; strncpy(state->automaticSaveDescription, textPtr, sizeof(state->automaticSaveDescription)); state->automaticSaveDescription[sizeof(state->automaticSaveDescription) - 1] = 0; @@ -966,10 +964,9 @@ void cmdSetSimple(AgiGame *state, AgiEngine *vm, uint8 *parameter) { // We got it and it's set, so enable automatic saving state->automaticSave = true; } - } else { // AGI256 and AGI256-2 use this unknown170 command to load 256 color pictures. // Load the picture. Similar to void cmdLoad_pic(AgiGame *state, AgiEngine *vm, uint8 *p). - SpritesMgr *spritesMgr = state->_vm->_sprites; + SpritesMgr *spritesMgr = vm->_sprites; uint16 varNr = parameter[0]; uint16 resourceNr = vm->getVar(varNr); @@ -1013,7 +1010,7 @@ void cmdShowMouse(AgiGame *state, AgiEngine *vm, uint8 *parameter) { if (state->mouseEnabled) { state->mouseHidden = false; - g_system->showMouse(true); + vm->_system->showMouse(true); } } @@ -1036,7 +1033,7 @@ void cmdHideMouse(AgiGame *state, AgiEngine *vm, uint8 *parameter) { if (state->mouseEnabled) { state->mouseHidden = true; - g_system->showMouse(false); + vm->_system->showMouse(false); } } @@ -1050,9 +1047,9 @@ void cmdAllowMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 allowed = parameter[0]; if (allowed) { - state->_vm->_menu->accessAllow(); + vm->_menu->accessAllow(); } else { - state->_vm->_menu->accessDeny(); + vm->_menu->accessDeny(); } } @@ -1130,27 +1127,24 @@ void cmdAdjEgoMoveToXY(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdParse(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *text = state->_vm->_text; uint16 stringNr = parameter[0]; vm->setVar(VM_VAR_WORD_NOT_FOUND, 0); vm->setFlag(VM_FLAG_ENTERED_CLI, false); vm->setFlag(VM_FLAG_SAID_ACCEPTED_INPUT, false); - vm->_words->parseUsingDictionary(text->stringPrintf(state->strings[stringNr])); + vm->_words->parseUsingDictionary(vm->_text->stringPrintf(state->strings[stringNr])); } void cmdCall(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 logicNr = parameter[0]; - int oldCIP; - int oldLognum; // CM: we don't save sIP because set.scan.start can be // used in a called script (fixes xmas demo) - oldCIP = state->_curLogic->cIP; - oldLognum = state->curLogicNr; + int oldCIP = state->_curLogic->cIP; + int oldLognum = state->curLogicNr; - state->_vm->runLogic(logicNr); + vm->runLogic(logicNr); state->curLogicNr = oldLognum; state->_curLogic = &state->logics[state->curLogicNr]; @@ -1169,7 +1163,7 @@ void cmdDrawPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 resourceNr = vm->getVar(varNr); debugC(6, kDebugLevelScripts, "=== draw pic V1 %d ===", resourceNr); - state->_vm->_picture->decodePicture(resourceNr, true); + vm->_picture->decodePicture(resourceNr, true); // TODO: check, if this was really done vm->_text->promptClear(); @@ -1179,7 +1173,7 @@ void cmdDrawPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdDrawPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - SpritesMgr *spritesMgr = state->_vm->_sprites; + SpritesMgr *spritesMgr = vm->_sprites; uint16 varNr = parameter[0]; uint16 resourceNr = vm->getVar(varNr); @@ -1224,7 +1218,7 @@ void cmdShowPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdLoadPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - SpritesMgr *spritesMgr = state->_vm->_sprites; + SpritesMgr *spritesMgr = vm->_sprites; uint16 varNr = parameter[0]; uint16 resourceNr = vm->getVar(varNr); @@ -1238,7 +1232,7 @@ void cmdLoadPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 varNr = parameter[0]; uint16 resourceNr = vm->getVar(varNr); - state->_vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr); + vm->agiLoadResource(RESOURCETYPE_PICTURE, resourceNr); } void cmdDiscardPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -1247,7 +1241,7 @@ void cmdDiscardPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdOverlayPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - SpritesMgr *spritesMgr = state->_vm->_sprites; + SpritesMgr *spritesMgr = vm->_sprites; uint16 varNr = parameter[0]; uint16 resourceNr = vm->getVar(varNr); @@ -1265,13 +1259,11 @@ void cmdOverlayPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdShowPriScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - GfxMgr *gfx = state->_vm->_gfx; - - gfx->debugShowMap(1); // switch to priority map + vm->_gfx->debugShowMap(1); // switch to priority map state->_vm->waitKey(); - gfx->debugShowMap(0); // switch back to visual map + vm->_gfx->debugShowMap(0); // switch back to visual map } void cmdAnimateObj(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -1299,11 +1291,9 @@ void cmdAnimateObj(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdUnanimateAll(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - int i; + vm->_sprites->eraseSprites(); - state->_vm->_sprites->eraseSprites(); - - for (i = 0; i < SCREENOBJECTS_MAX; i++) + for (int i = 0; i < SCREENOBJECTS_MAX; i++) state->screenObjTable[i].flags &= ~(fAnimated | fDrawn); } @@ -1321,30 +1311,30 @@ void cmdDraw(AgiGame *state, AgiEngine *vm, uint8 *parameter) { screenObj->flags |= fUpdate; if (vm->getVersion() >= 0x3000) { - state->_vm->setLoop(screenObj, screenObj->currentLoopNr); - state->_vm->setCel(screenObj, screenObj->currentCelNr); + vm->setLoop(screenObj, screenObj->currentLoopNr); + vm->setCel(screenObj, screenObj->currentCelNr); } - SpritesMgr *sprites = state->_vm->_sprites; + SpritesMgr *spritesMgr = vm->_sprites; - state->_vm->fixPosition(objectNr); + vm->fixPosition(objectNr); screenObj->xPos_prev = screenObj->xPos; screenObj->yPos_prev = screenObj->yPos; screenObj->xSize_prev = screenObj->xSize; screenObj->ySize_prev = screenObj->ySize; //screenObj->celData2 = screenObj->celData; - sprites->eraseRegularSprites(); + spritesMgr->eraseRegularSprites(); screenObj->flags |= fDrawn; - sprites->buildRegularSpriteList(); - sprites->drawRegularSpriteList(); - sprites->showSprite(screenObj); + spritesMgr->buildRegularSpriteList(); + spritesMgr->drawRegularSpriteList(); + spritesMgr->showSprite(screenObj); screenObj->flags &= ~fDontUpdate; debugC(4, kDebugLevelScripts, "vt entry #%d flags = %02x", objectNr, screenObj->flags); } void cmdErase(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - SpritesMgr *sprites = state->_vm->_sprites; + SpritesMgr *spritesMgr = vm->_sprites; uint16 objectNr = parameter[0]; ScreenObjEntry *screenObj = &state->screenObjTable[objectNr]; @@ -1353,21 +1343,21 @@ void cmdErase(AgiGame *state, AgiEngine *vm, uint8 *parameter) { if (!(screenObj->flags & fDrawn)) return; - sprites->eraseRegularSprites(); + spritesMgr->eraseRegularSprites(); if ((screenObj->flags & fUpdate) == 0) { noUpdateFlag = true; - sprites->eraseStaticSprites(); + spritesMgr->eraseStaticSprites(); } screenObj->flags &= ~fDrawn; if (noUpdateFlag) { - sprites->buildStaticSpriteList(); - sprites->drawStaticSpriteList(); + spritesMgr->buildStaticSpriteList(); + spritesMgr->drawStaticSpriteList(); } - sprites->buildRegularSpriteList(); - sprites->drawRegularSpriteList(); - sprites->showSprite(screenObj); + spritesMgr->buildRegularSpriteList(); + spritesMgr->drawRegularSpriteList(); + spritesMgr->showSprite(screenObj); } void cmdPosition(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -1452,7 +1442,7 @@ void cmdReposition(AgiGame *state, AgiEngine *vm, uint8 *parameter) { else screenObj->yPos += dy; - state->_vm->fixPosition(objectNr); + vm->fixPosition(objectNr); } void cmdRepositionV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -1478,7 +1468,7 @@ void cmdRepositionTo(AgiGame *state, AgiEngine *vm, uint8 *parameter) { screenObj->xPos = xPos; screenObj->yPos = yPos; screenObj->flags |= fUpdatePos; - state->_vm->fixPosition(objectNr); + vm->fixPosition(objectNr); } void cmdRepositionToF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -1490,7 +1480,7 @@ void cmdRepositionToF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { screenObj->xPos = vm->getVar(varNr1); screenObj->yPos = vm->getVar(varNr2); screenObj->flags |= fUpdatePos; - state->_vm->fixPosition(objectNr); + vm->fixPosition(objectNr); } void cmdAddToPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -1502,7 +1492,7 @@ void cmdAddToPic(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 priority = parameter[5]; uint16 border = parameter[6]; - state->_vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border); + vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border); } void cmdAddToPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -1513,7 +1503,7 @@ void cmdAddToPicV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 yPos = parameter[4]; uint16 priority = parameter[5]; - state->_vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, -1); + vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, -1); } void cmdAddToPicF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -1525,11 +1515,11 @@ void cmdAddToPicF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 priority = vm->getVar(parameter[5]); uint16 border = vm->getVar(parameter[6]); - state->_vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border); + vm->_sprites->addToPic(viewNr, loopNr, celNr, xPos, yPos, priority, border); } void cmdForceUpdate(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - SpritesMgr *spritesMgr = state->_vm->_sprites; + SpritesMgr *spritesMgr = vm->_sprites; spritesMgr->eraseSprites(); spritesMgr->buildAllSpriteLists(); @@ -1546,7 +1536,7 @@ void cmdReverseLoop(AgiGame *state, AgiEngine *vm, uint8 *parameter) { screenObj->cycle = kCycleRevLoop; screenObj->flags |= (fDontUpdate | fUpdate | fCycling); screenObj->loop_flag = loopFlag; - state->_vm->setFlag(screenObj->loop_flag, false); + vm->setFlag(screenObj->loop_flag, false); vm->cyclerActivated(screenObj); } @@ -1558,7 +1548,7 @@ void cmdReverseLoopV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { debugC(4, kDebugLevelScripts, "o%d, f%d", objectNr, loopFlag); screenObj->cycle = kCycleRevLoop; - state->_vm->setCel(screenObj, 0); + vm->setCel(screenObj, 0); screenObj->flags |= (fDontUpdate | fUpdate | fCycling); screenObj->loop_flag = loopFlag; //screenObj->parm3 = 0; @@ -1585,7 +1575,7 @@ void cmdEndOfLoopV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { debugC(4, kDebugLevelScripts, "o%d, f%d", objectNr, loopFlag); screenObj->cycle = kCycleEndOfLoop; - state->_vm->setCel(screenObj, 0); + vm->setCel(screenObj, 0); screenObj->flags |= (fDontUpdate | fUpdate | fCycling); screenObj->loop_flag = loopFlag; //screenObj->parm3 = 0; @@ -1623,7 +1613,7 @@ void cmdStopMotion(AgiGame *state, AgiEngine *vm, uint8 *parameter) { screenObj->direction = 0; screenObj->motionType = kMotionNormal; if (objectNr == 0) { // ego only - state->_vm->setVar(VM_VAR_EGO_DIRECTION, 0); + vm->setVar(VM_VAR_EGO_DIRECTION, 0); state->playerControl = false; } } @@ -1641,7 +1631,7 @@ void cmdStartMotion(AgiGame *state, AgiEngine *vm, uint8 *parameter) { screenObj->motionType = kMotionNormal; if (objectNr == 0) { // ego only - state->_vm->setVar(VM_VAR_EGO_DIRECTION, 0); + vm->setVar(VM_VAR_EGO_DIRECTION, 0); state->playerControl = true; } } @@ -1789,7 +1779,7 @@ void cmdPause(AgiGame *state, AgiEngine *vm, uint8 *parameter) { // Show pause message box PauseToken pt = vm->pauseEngine(); - state->_vm->_systemUI->pauseDialog(); + vm->_systemUI->pauseDialog(); } void cmdSetMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -1800,7 +1790,7 @@ void cmdSetMenu(AgiGame *state, AgiEngine *vm, uint8 *parameter) { if (state->_curLogic->texts != nullptr && (textNr - 1) <= state->_curLogic->numTexts) { const char *menuText = state->_curLogic->texts[textNr - 1]; - state->_vm->_menu->addMenu(menuText); + vm->_menu->addMenu(menuText); } } @@ -1813,7 +1803,7 @@ void cmdSetMenuItem(AgiGame *state, AgiEngine *vm, uint8 *parameter) { if (state->_curLogic->texts != nullptr && textNr <= state->_curLogic->numTexts) { const char *menuItemText = state->_curLogic->texts[textNr]; - state->_vm->_menu->addMenuItem(menuItemText, controllerSlot); + vm->_menu->addMenuItem(menuItemText, controllerSlot); } } @@ -1836,11 +1826,11 @@ void cmdVersion(AgiGame *state, AgiEngine *vm, uint8 *parameter) { verMsg += (maj == 2 ? ver2Msg : ver3Msg); verMsg = Common::String::format(verMsg.c_str(), gScummVMVersion, maj, min); - state->_vm->_text->messageBox(verMsg.c_str()); + vm->_text->messageBox(verMsg.c_str()); } void cmdConfigureScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *textMgr = state->_vm->_text; + TextMgr *textMgr = vm->_text; uint16 gameRow = parameter[0]; uint16 promptRow = parameter[1]; uint16 statusRow = parameter[2]; @@ -1851,8 +1841,8 @@ void cmdConfigureScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdTextScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - GfxMgr *gfxMgr = state->_vm->_gfx; - TextMgr *textMgr = state->_vm->_text; + GfxMgr *gfxMgr = vm->_gfx; + TextMgr *textMgr = vm->_text; debugC(4, kDebugLevelScripts, "switching to text mode"); @@ -1866,18 +1856,17 @@ void cmdTextScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) { void cmdGraphics(AgiGame *state, AgiEngine *vm, uint8 *parameter) { debugC(4, kDebugLevelScripts, "switching to graphics mode"); - state->_vm->redrawScreen(); + vm->redrawScreen(); } void cmdSetTextAttribute(AgiGame *state, AgiEngine *vm, uint8 *parameter) { int16 foreground = parameter[0]; int16 background = parameter[1]; - state->_vm->_text->charAttrib_Set(foreground, background); + vm->_text->charAttrib_Set(foreground, background); } void cmdStatus(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *textMgr = state->_vm->_text; - InventoryMgr *inventoryMgr = state->_vm->_inventory; + TextMgr *textMgr = vm->_text; textMgr->inputEditOn(); textMgr->charAttrib_Push(); @@ -1885,35 +1874,35 @@ void cmdStatus(AgiGame *state, AgiEngine *vm, uint8 *parameter) { cmdTextScreen(state, vm, parameter); - inventoryMgr->show(); + vm->_inventory->show(); //invent_state = 0; textMgr->charAttrib_Pop(); - state->_vm->redrawScreen(); + vm->redrawScreen(); } void cmdQuit(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 withoutPrompt = parameter[0]; - state->_vm->_sound->stopSound(); + vm->_sound->stopSound(); if (withoutPrompt) { - state->_vm->quitGame(); + vm->quitGame(); } else { - if (state->_vm->_systemUI->quitDialog()) { - state->_vm->quitGame(); + if (vm->_systemUI->quitDialog()) { + vm->quitGame(); } } } void cmdQuitV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - state->_vm->_sound->stopSound(); - state->_vm->quitGame(); + vm->_sound->stopSound(); + vm->quitGame(); } void cmdRestartGame(AgiGame *state, AgiEngine *vm, uint8 *parameter) { bool doRestart = false; - state->_vm->_sound->stopSound(); + vm->_sound->stopSound(); if (vm->getFlag(VM_FLAG_AUTO_RESTART)) { doRestart = true; @@ -1984,7 +1973,7 @@ void cmdDistance(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdAcceptInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *textMgr = state->_vm->_text; + TextMgr *textMgr = vm->_text; debugC(4, kDebugLevelInput, "input normal"); @@ -1993,7 +1982,7 @@ void cmdAcceptInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdPreventInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *textMgr = state->_vm->_text; + TextMgr *textMgr = vm->_text; debugC(4, kDebugLevelInput, "no input"); @@ -2004,11 +1993,11 @@ void cmdPreventInput(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdCancelLine(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - state->_vm->_text->promptCancelLine(); + vm->_text->promptCancelLine(); } void cmdEchoLine(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *textMgr = state->_vm->_text; + TextMgr *textMgr = vm->_text; if (textMgr->promptIsEnabled()) { textMgr->promptEchoLine(); @@ -2016,7 +2005,7 @@ void cmdEchoLine(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdGetString(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *textMgr = state->_vm->_text; + TextMgr *textMgr = vm->_text; int16 stringDestNr = parameter[0]; int16 leadInTextNr = parameter[1] - 1; int16 stringRow = parameter[2]; @@ -2055,14 +2044,14 @@ void cmdGetString(AgiGame *state, AgiEngine *vm, uint8 *parameter) { textMgr->displayText(leadInTextPtr); } - state->_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETSTRING); + vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETSTRING); textMgr->stringSet(""); textMgr->stringEdit(stringMaxLen); // copy string to destination // TODO: not sure if set all the time or only when ENTER is pressed - Common::strlcpy(&state->_vm->_game.strings[stringDestNr][0], (char *)textMgr->_inputString, MAX_STRINGLEN); + Common::strlcpy(&vm->_game.strings[stringDestNr][0], (char *)textMgr->_inputString, MAX_STRINGLEN); textMgr->charPos_Pop(); @@ -2072,7 +2061,7 @@ void cmdGetString(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdGetNum(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *textMgr = state->_vm->_text; + TextMgr *textMgr = vm->_text; int16 leadInTextNr = parameter[0] - 1; int16 numberDestVarNr = parameter[1]; const char *leadInTextPtr = nullptr; @@ -2094,7 +2083,7 @@ void cmdGetNum(AgiGame *state, AgiEngine *vm, uint8 *parameter) { textMgr->inputEditOff(); - state->_vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETNUMBER); + vm->cycleInnerLoopActive(CYCLE_INNERLOOP_GETNUMBER); textMgr->stringSet(""); textMgr->stringEdit(3); @@ -2108,7 +2097,7 @@ void cmdGetNum(AgiGame *state, AgiEngine *vm, uint8 *parameter) { } void cmdSetCursorChar(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - TextMgr *textMgr = state->_vm->_text; + TextMgr *textMgr = vm->_text; uint16 textNr = parameter[0] - 1; if (state->_curLogic->texts != nullptr && textNr <= state->_curLogic->numTexts) { @@ -2159,7 +2148,7 @@ void cmdDisplay(AgiGame *state, AgiEngine *vm, uint8 *parameter) { int16 textRow = parameter[0]; int16 textColumn = parameter[1]; - state->_vm->_text->display(textNr, textRow, textColumn); + vm->_text->display(textNr, textRow, textColumn); } void cmdDisplayF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -2167,7 +2156,7 @@ void cmdDisplayF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { int16 textColumn = vm->getVar(parameter[1]); int16 textNr = vm->getVar(parameter[2]); - state->_vm->_text->display(textNr, textRow, textColumn); + vm->_text->display(textNr, textRow, textColumn); } void cmdClearTextRect(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -2175,9 +2164,9 @@ void cmdClearTextRect(AgiGame *state, AgiEngine *vm, uint8 *parameter) { int16 textUpperColumn = parameter[1]; int16 textLowerRow = parameter[2]; int16 textLowerColumn = parameter[3]; - int16 color = state->_vm->_text->calculateTextBackground(parameter[4]); + int16 color = vm->_text->calculateTextBackground(parameter[4]); - state->_vm->_text->clearBlock(textUpperRow, textUpperColumn, textLowerRow, textLowerColumn, color); + vm->_text->clearBlock(textUpperRow, textUpperColumn, textLowerRow, textLowerColumn, color); } void cmdToggleMonitor(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -2187,7 +2176,7 @@ void cmdToggleMonitor(AgiGame *state, AgiEngine *vm, uint8 *parameter) { void cmdClearLines(AgiGame *state, AgiEngine *vm, uint8 *parameter) { int16 textRowUpper = parameter[0]; int16 textRowLower = parameter[1]; - int16 color = state->_vm->_text->calculateTextBackground(parameter[2]); + int16 color = vm->_text->calculateTextBackground(parameter[2]); // Residence 44 calls clear.lines(24,0,0), see Sarien bug #558423 // Agent06 incorrectly calls clear.lines(1,150,0), see ScummVM bugs @@ -2196,19 +2185,19 @@ void cmdClearLines(AgiGame *state, AgiEngine *vm, uint8 *parameter) { warning("cmdClearLines: RowUpper higher than RowLower"); textRowLower = textRowUpper; } - state->_vm->_text->clearLines(textRowUpper, textRowLower, color); + vm->_text->clearLines(textRowUpper, textRowLower, color); } void cmdPrint(AgiGame *state, AgiEngine *vm, uint8 *parameter) { int16 textNr = parameter[0]; - state->_vm->_text->print(textNr); + vm->_text->print(textNr); } void cmdPrintF(AgiGame *state, AgiEngine *vm, uint8 *parameter) { int16 textNr = vm->getVar(parameter[0]); - state->_vm->_text->print(textNr); + vm->_text->print(textNr); } void cmdPrintAt(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -2219,7 +2208,7 @@ void cmdPrintAt(AgiGame *state, AgiEngine *vm, uint8 *parameter) { debugC(4, kDebugLevelScripts, "%d %d %d %d", textNr, textRow, textColumn, textWidth); - state->_vm->_text->printAt(textNr, textRow, textColumn, textWidth); + vm->_text->printAt(textNr, textRow, textColumn, textWidth); } void cmdPrintAtV(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -2230,7 +2219,7 @@ void cmdPrintAtV(AgiGame *state, AgiEngine *vm, uint8 *parameter) { debugC(4, kDebugLevelScripts, "%d %d %d %d", textNr, textRow, textColumn, textWidth); - state->_vm->_text->printAt(textNr, textRow, textColumn, textWidth); + vm->_text->printAt(textNr, textRow, textColumn, textWidth); } // push.script was not available until 2.425, and also not available in 2.440 @@ -2246,7 +2235,7 @@ void cmdPushScript(AgiGame *state, AgiEngine *vm, uint8 *parameter) { // The AGIMOUSE interpreter modified push.script to set variables 27-29 to mouse state void cmdAgiMousePushScript(AgiGame *state, AgiEngine *vm, uint8 *parameter) { - vm->setVar(VM_VAR_MOUSE_BUTTONSTATE, state->_vm->_mouse.button); + vm->setVar(VM_VAR_MOUSE_BUTTONSTATE, vm->_mouse.button); vm->setVar(VM_VAR_MOUSE_X, vm->_mouse.pos.x / 2); vm->setVar(VM_VAR_MOUSE_Y, vm->_mouse.pos.y); } @@ -2270,7 +2259,7 @@ void cmdSetPriBase(AgiGame *state, AgiEngine *vm, uint8 *parameter) { debug(0, "Priority base set to %d", priorityBase); - state->_vm->_gfx->setPriorityTable(priorityBase); + vm->_gfx->setPriorityTable(priorityBase); } void cmdGetMousePosn(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -2291,11 +2280,11 @@ void cmdShakeScreen(AgiGame *state, AgiEngine *vm, uint8 *parameter) { // AGIPAL uses shake.screen values between 100 and 109 to set the palette // (Checked the original AGIPAL-hack's shake.screen-routine's disassembly). if (shakeCount >= 100 && shakeCount < 110) { - state->_vm->_gfx->setAGIPal(shakeCount); + vm->_gfx->setAGIPal(shakeCount); return; } - state->_vm->_gfx->shakeScreen(shakeCount); + vm->_gfx->shakeScreen(shakeCount); } void cmdSetSpeed(AgiGame *state, AgiEngine *vm, uint8 *parameter) { @@ -2314,7 +2303,7 @@ void cmdSetItemView(AgiGame *state, AgiEngine *vm, uint8 *parameter) { void cmdCallV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 resourceNr = parameter[0]; - state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr); + vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr); // FIXME: The following instruction looks incomplete. // Maybe something is meant to be assigned to, or read from, // the logic_list entry? @@ -2328,7 +2317,7 @@ void cmdNewRoomV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 resourceNr = parameter[0]; warning("cmdNewRoomV1()"); - state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr); + vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr); state->max_logics = 1; state->logic_list[1] = resourceNr; vm->setVar(13, 1); @@ -2338,7 +2327,7 @@ void cmdNewRoomVV1(AgiGame *state, AgiEngine *vm, uint8 *parameter) { uint16 resourceNr = vm->getVar(parameter[0]); warning("cmdNewRoomVV1()"); - state->_vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr); + vm->agiLoadResource(RESOURCETYPE_LOGIC, resourceNr); state->max_logics = 1; state->logic_list[1] = resourceNr; vm->setVar(13, 1); @@ -2362,10 +2351,6 @@ void cmdUnknown(AgiGame *state, AgiEngine *vm, uint8 *parameter) { */ int AgiEngine::runLogic(int16 logicNr) { AgiGame *state = &_game; - uint8 op = 0; - uint8 p[CMD_BSIZE] = { 0 }; - int curParameterSize = 0; - ScriptPos sp; //int logic_index = 0; state->logic_list[0] = 0; @@ -2374,6 +2359,7 @@ int AgiEngine::runLogic(int16 logicNr) { debugC(2, kDebugLevelScripts, "================="); debugC(2, kDebugLevelScripts, "runLogic(%d)", logicNr); + ScriptPos sp; sp.script = logicNr; sp.curIP = 0; _game.execStack.push_back(sp); @@ -2419,7 +2405,8 @@ int AgiEngine::runLogic(int16 logicNr) { memset(st, '.', sz); st[sz] = 0; - switch (op = *(state->_curLogic->data + state->_curLogic->cIP++)) { + uint8 op = *(state->_curLogic->data + state->_curLogic->cIP++); + switch (op) { case 0xff: // if (open/close) testIfCode(logicNr); break; @@ -2445,12 +2432,13 @@ int AgiEngine::runLogic(int16 logicNr) { _game.execStack.pop_back(); return 1; - default: + default: { if (!_opCodes[op].functionPtr) { error("Illegal opcode %2X (%d) in logic %d, ip %d", op, op, state->curLogicNr, state->_curLogic->cIP); } - curParameterSize = _opCodes[op].parameterSize; + uint8 p[CMD_BSIZE]; + int curParameterSize = _opCodes[op].parameterSize; memmove(p, state->_curLogic->data + state->_curLogic->cIP, curParameterSize); memset(p + curParameterSize, 0, CMD_BSIZE - curParameterSize); @@ -2459,6 +2447,7 @@ int AgiEngine::runLogic(int16 logicNr) { _opCodes[op].functionPtr(&_game, this, p); state->_curLogic->cIP += curParameterSize; } + } // if ((op == 0x0B || op == 0x3F || op == 0x40) && logic_index < state->max_logics) { // n = state->logic_list[++logic_index];