static int getDecimalInteger (BrailleDisplay *brl, unsigned int *integer, unsigned int width, const char *description) { char buffer[width + 1]; memset(buffer, '0', width); buffer[width] = 0; for (;;) { wchar_t character; char prompt[0X40]; snprintf(prompt, sizeof(prompt), "%s: %s", description, buffer); writePrompt(brl, prompt); switch ((character = getCharacter(brl))) { default: continue; case WC_C('\r'): *integer = atoi(buffer); return 1; case '\b': return 0; case WC_C('0'): case WC_C('1'): case WC_C('2'): case WC_C('3'): case WC_C('4'): case WC_C('5'): case WC_C('6'): case WC_C('7'): case WC_C('8'): case WC_C('9'): memmove(buffer, buffer+1, width-1); buffer[width-1] = character; break; } } }
/** * Set up new room. * This function is called when ego enters a new room. * @param n room number */ void AgiEngine::newRoom(int n) { VtEntry *v; int i; // Simulate slowww computer. // Many effects rely on it. pause(kPauseRoom); debugC(4, kDebugLevelMain, "*** room %d ***", n); _sound->stopSound(); i = 0; for (v = _game.viewTable; v < &_game.viewTable[MAX_VIEWTABLE]; v++) { v->entry = i++; v->flags &= ~(ANIMATED | DRAWN); v->flags |= UPDATE; v->stepTime = 1; v->stepTimeCount = 1; v->cycleTime = 1; v->cycleTimeCount = 1; v->stepSize = 1; } agiUnloadResources(); _game.playerControl = true; _game.block.active = false; _game.horizon = 36; _game.vars[vPrevRoom] = _game.vars[vCurRoom]; _game.vars[vCurRoom] = n; _game.vars[vBorderTouchObj] = 0; _game.vars[vBorderCode] = 0; _game.vars[vEgoViewResource] = _game.viewTable[0].currentView; agiLoadResource(rLOGIC, n); // Reposition ego in the new room switch (_game.vars[vBorderTouchEgo]) { case 1: _game.viewTable[0].yPos = _HEIGHT - 1; break; case 2: _game.viewTable[0].xPos = 0; break; case 3: _game.viewTable[0].yPos = HORIZON + 1; break; case 4: _game.viewTable[0].xPos = _WIDTH - _game.viewTable[0].xSize; break; } _game.vars[vBorderTouchEgo] = 0; setflag(fNewRoomExec, true); _game.exitAllLogics = true; writeStatus(); writePrompt(); }
void getCommand(Funix *funix, char *command) { writePrompt(funix); fgets(command, 80, stdin); } // writes prompt and reads command
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; }
static int getHexadecimalCharacter (BrailleDisplay *brl, unsigned char *character) { *character = 0X00; for (;;) { unsigned char digit; char prompt[0X40]; snprintf(prompt, sizeof(prompt), "hex char: %2.2x %c", *character, *character); writePrompt(brl, prompt); switch (getCharacter(brl)) { default: continue; case WC_C('\r'): return 1; case WC_C('\b'): return 0; case WC_C('0'): digit = 0X0; break; case WC_C('1'): digit = 0X1; break; case WC_C('2'): digit = 0X2; break; case WC_C('3'): digit = 0X3; break; case WC_C('4'): digit = 0X4; break; case WC_C('5'): digit = 0X5; break; case WC_C('6'): digit = 0X6; break; case WC_C('7'): digit = 0X7; break; case WC_C('8'): digit = 0X8; break; case WC_C('9'): digit = 0X9; break; case WC_C('a'): digit = 0XA; break; case WC_C('b'): digit = 0XB; break; case WC_C('c'): digit = 0XC; break; case WC_C('d'): digit = 0XD; break; case WC_C('e'): digit = 0XE; break; case WC_C('f'): digit = 0XF; break; } *character = (*character << 4) | digit; } }