Common::Error AgiEngine::go() { CursorMan.showMouse(true); if (_game.state < STATE_LOADED) { do { mainCycle(); } while (_game.state < STATE_RUNNING); } runGame(); return Common::kNoError; }
void MainWindow::createStartCommands() { Command comm(-1, -1, 0x6c); commLst.push_front(comm); comm.setCommand(-1, -1, 0x61); commLst.push_front(comm); unsigned char prm[2]; prm[0] = 0xFF; prm[1] = 0xFF; for(int i = 0; i < 5; i++) { comm.setCommand(i, -1, 0x15, prm, 2); commLst.push_front(comm); } QTimer::singleShot(60000, this, SLOT(slotTimeout0x01())); mainCycle(); }
uint8 AgiEngine::testKeypressed() { int x = _game.keypress; _game.keypress = 0; if (!x) { InputMode mode = _game.inputMode; _game.inputMode = INPUT_NONE; mainCycle(); _game.inputMode = mode; } if (x) debugC(5, kDebugLevelScripts | kDebugLevelInput, "keypress = %02x", x); return x; }
/** * Execute a logic script * @param n Number of the logic resource to execute */ int AgiEngine::runLogic(int n) { AgiGame *state = &_game; uint8 op = 0; uint8 p[CMD_BSIZE] = { 0 }; int num = 0; ScriptPos sp; //int logic_index = 0; state->logic_list[0] = 0; state->max_logics = 0; debugC(2, kDebugLevelScripts, "================="); debugC(2, kDebugLevelScripts, "runLogic(%d)", n); sp.script = n; sp.curIP = 0; _game.execStack.push_back(sp); // If logic not loaded, load it if (~_game.dirLogic[n].flags & RES_LOADED) { debugC(4, kDebugLevelScripts, "logic %d not loaded!", n); agiLoadResource(rLOGIC, n); } _game.lognum = n; _game._curLogic = &_game.logics[_game.lognum]; _game._curLogic->cIP = _game._curLogic->sIP; _timerHack = 0; while (ip < _game.logics[n].size && !(shouldQuit() || _restartGame)) { if (_debug.enabled) { if (_debug.steps > 0) { if (_debug.logic0 || n) { debugConsole(n, lCOMMAND_MODE, NULL); _debug.steps--; } } else { _sprites->blitBoth(); _sprites->commitBoth(); do { mainCycle(); } while (!_debug.steps && _debug.enabled); _sprites->eraseBoth(); } } _game.execStack.back().curIP = ip; char st[101]; int sz = MIN(_game.execStack.size(), 100u); memset(st, '.', sz); st[sz] = 0; switch (op = *(code + ip++)) { case 0xff: // if (open/close) testIfCode(n); break; case 0xfe: // goto // +2 covers goto size ip += 2 + ((int16)READ_LE_UINT16(code + ip)); // timer must keep running even in goto loops, // but AGI engine can't do that :( if (_timerHack > 20) { pollTimer(); updateTimer(); _timerHack = 0; } break; case 0x00: // return debugC(2, kDebugLevelScripts, "%sreturn() // Logic %d", st, n); debugC(2, kDebugLevelScripts, "================="); // if (getVersion() < 0x2000) { // if (logic_index < state->max_logics) { // n = state->logic_list[++logic_index]; // state->_curLogic = &state->logics[n]; // state->lognum = n; // ip = 2; // warning("running logic %d\n", n); // break; // } // _v[13]=0; // } _game.execStack.pop_back(); return 1; default: num = logicNamesCmd[op].argumentsLength(); memmove(p, code + ip, num); memset(p + num, 0, CMD_BSIZE - num); debugC(2, kDebugLevelScripts, "%s%s(%d %d %d)", st, logicNamesCmd[op].name, p[0], p[1], p[2]); _agiCommands[op](&_game, p); ip += num; } // if ((op == 0x0B || op == 0x3F || op == 0x40) && logic_index < state->max_logics) { // n = state->logic_list[++logic_index]; // state->_curLogic = &state->logics[n]; // state->lognum = n; // ip = 2; // warning("running logic %d\n", n); // } if (_game.exitAllLogics) break; } _game.execStack.pop_back(); return 0; // after executing new.room() }
int AgiEngine::print(const char *p, int lin, int col, int len) { if (p == NULL) return 0; debugC(4, kDebugLevelText, "print(): lin = %d, col = %d, len = %d", lin, col, len); if (col == 0 && lin == 0 && len == 0) lin = col = -1; if (len == 0) len = 30; blitTextbox(p, lin, col, len); if (getflag(fOutputMode)) { // non-blocking window setflag(fOutputMode, false); return 1; } // blocking _noSaveLoadAllowed = true; if (_game.vars[vWindowReset] == 0) { int k; setvar(vKey, 0); k = waitKey(); closeWindow(); _noSaveLoadAllowed = false; return k; } // timed window debugC(3, kDebugLevelText, "f15==0, v21==%d => timed", getvar(21)); _game.msgBoxTicks = getvar(vWindowReset) * 10; setvar(vKey, 0); _menuSelected = false; do { if (getflag(fRestoreJustRan)) break; if (_menuSelected) break; mainCycle(); if (_game.keypress == KEY_ENTER) { debugC(4, kDebugLevelText, "KEY_ENTER"); setvar(vWindowReset, 0); _game.keypress = 0; break; } } while (_game.msgBoxTicks > 0 && !(shouldQuit() || _restartGame)); setvar(vWindowReset, 0); closeWindow(); _noSaveLoadAllowed = false; return 0; }
void MainWindow::slotInterview(bool flag) { if(flag) mainCycle(); }
int AgiEngine::playGame() { int ec = errOK; debugC(2, kDebugLevelMain, "initializing..."); debugC(2, kDebugLevelMain, "game version = 0x%x", getVersion()); _sound->stopSound(); _gfx->clearScreen(0); _game.horizon = HORIZON; _game.playerControl = false; setflag(fLogicZeroFirsttime, true); // not in 2.917 setflag(fNewRoomExec, true); // needed for MUMG and SQ2! setflag(fSoundOn, true); // enable sound setvar(vTimeDelay, 2); // "normal" speed _game.gfxMode = true; _game.clockEnabled = true; _game.lineUserInput = 22; // We run AGIMOUSE always as a side effect if (getFeatures() & GF_AGIMOUSE || true) debug(1, "Using AGI Mouse 1.0 protocol"); if (getFeatures() & GF_AGIPAL) debug(1, "Running AGIPAL game"); debug(0, "Running AGI script.\n"); setflag(fEnteredCli, false); setflag(fSaidAcceptedInput, false); _game.vars[vWordNotFound] = 0; _game.vars[vKey] = 0; debugC(2, kDebugLevelMain, "Entering main loop"); bool firstLoop = !getflag(fRestartGame); // Do not restore on game restart do { if (!mainCycle()) continue; if (getvar(vTimeDelay) == 0 || (1 + _clockCount) % getvar(vTimeDelay) == 0) { if (!_game.hasPrompt && _game.inputMode == INPUT_NORMAL) { writePrompt(); _game.hasPrompt = 1; } else if (_game.hasPrompt && _game.inputMode == INPUT_NONE) { writePrompt(); _game.hasPrompt = 0; } interpretCycle(); // Check if the user has asked to load a game from the command line // or the launcher if (firstLoop) { checkQuickLoad(); firstLoop = false; } setflag(fEnteredCli, false); setflag(fSaidAcceptedInput, false); _game.vars[vWordNotFound] = 0; _game.vars[vKey] = 0; } if (shouldPerformAutoSave(_lastSaveTime)) { saveGame(getSavegameFilename(0), "Autosave"); } } while (!(shouldQuit() || _restartGame)); _sound->stopSound(); return ec; }
int AgiEngine::saveGameDialog() { char *desc; const char *buttons[] = { "Do as I say!", "I regret", NULL }; char dstr[200]; int rc, slot = 0; int hm, vm, hp, vp; int w; hm = 1; vm = 3; hp = hm * CHAR_COLS; vp = vm * CHAR_LINES; w = (40 - 2 * hm) - 1; do { drawWindow(hp, vp, GFX_WIDTH - hp, GFX_HEIGHT - vp); printText("Select a slot in which you wish to\nsave the game:", 0, hm + 1, vm + 1, w, MSG_BOX_TEXT, MSG_BOX_COLOR); slot = selectSlot(); if (slot + _firstSlot == 0) messageBox("That slot is for Autosave only."); else if (slot < 0) return errOK; } while (slot + _firstSlot == 0); drawWindow(hp, vp + 5 * CHAR_LINES, GFX_WIDTH - hp, GFX_HEIGHT - vp - 9 * CHAR_LINES); printText("Enter a description for this game:", 0, hm + 1, vm + 6, w, MSG_BOX_TEXT, MSG_BOX_COLOR); _gfx->drawRectangle(3 * CHAR_COLS, 11 * CHAR_LINES - 1, 37 * CHAR_COLS, 12 * CHAR_LINES, MSG_BOX_TEXT); _gfx->flushBlock(3 * CHAR_COLS, 11 * CHAR_LINES - 1, 37 * CHAR_COLS, 12 * CHAR_LINES); // The description field of the save/restore dialog holds 32 characters // but we use four of them for the slot number. The input field is a // bit wider than that, so we don't have to worry about leaving space // for the cursor. getString(2, 11, 28, MAX_STRINGS); // If we're saving over an old slot, show the old description. We can't // access that buffer directly, so we have to feed the characters to // the input handler one at a time. char name[40]; int numChars; getSavegameDescription(_firstSlot + slot, name, false); for (numChars = 0; numChars < 28 && name[numChars]; numChars++) handleGetstring(name[numChars]); _gfx->printCharacter(numChars + 3, 11, _game.cursorChar, MSG_BOX_COLOR, MSG_BOX_TEXT); do { mainCycle(); } while (_game.inputMode == INPUT_GETSTRING); closeWindow(); desc = _game.strings[MAX_STRINGS]; sprintf(dstr, "Are you sure you want to save the game " "described as:\n\n%s\n\nin slot %d?\n\n\n", desc, _firstSlot + slot); rc = selectionBox(dstr, buttons); if (rc != 0) { messageBox("Game NOT saved."); return errOK; } Common::String fileName = getSavegameFilename(_firstSlot + slot); debugC(8, kDebugLevelMain | kDebugLevelResources, "file is [%s]", fileName.c_str()); // Make sure all graphics was blitted to screen. This fixes bug // #2960567: "AGI: Ego partly erased in Load/Save thumbnails" _gfx->doUpdate(); int result = saveGame(fileName, desc); if (result == errOK) messageBox("Game saved."); else messageBox("Error saving game."); return result; }