void DrasculaEngine::selectVerbFromBar() { for (int n = 0; n < 7; n++) { if (mouseX > _verbBarX[n] && mouseX < _verbBarX[n + 1] && n > 0) { selectVerb(n); return; } } // no verb selected selectVerb(kVerbNone); }
bool DrasculaEngine::pickupObject() { int obj = pickedObject; checkFlags = 1; updateRoom(); showMenu(); updateScreen(); // Objects with an ID smaller than 7 are the inventory verbs if (pickedObject >= 7) { int n = whichObject(); if (n != 0 && inventoryObjects[n] == 0) { inventoryObjects[n] = obj; takeObject = 0; checkFlags = 0; } } if (checkFlags == 1) { if (checkMenuFlags()) return true; } updateEvents(); if (takeObject == 0) selectVerb(kVerbNone); return false; }
bool DrasculaEngine::loadGame(const char *gameName) { int l, savedChapter, roomNum = 0; Common::InSaveFile *sav; previousMusic = roomMusic; _menuScreen = false; if (currentChapter != 1) clearRoom(); if (!(sav = _saveFileMan->openForLoading(gameName))) { error("missing savegame file"); } savedChapter = sav->readSint32LE(); if (savedChapter != currentChapter) { strcpy(saveName, gameName); currentChapter = savedChapter - 1; loadedDifferentChapter = 1; return false; } sav->read(currentData, 20); curX = sav->readSint32LE(); curY = sav->readSint32LE(); trackProtagonist = sav->readSint32LE(); for (l = 1; l < ARRAYSIZE(inventoryObjects); l++) { inventoryObjects[l] = sav->readSint32LE(); } for (l = 0; l < NUM_FLAGS; l++) { flags[l] = sav->readSint32LE(); } takeObject = sav->readSint32LE(); pickedObject = sav->readSint32LE(); loadedDifferentChapter = 0; if (!sscanf(currentData, "%d.ald", &roomNum)) { error("Bad save format"); } enterRoom(roomNum); selectVerb(kVerbNone); return true; }
void DrasculaEngine::volumeControls() { if (_lang == kSpanish) loadPic(95, tableSurface); copyRect(1, 56, 73, 63, 177, 97, tableSurface, screenSurface); updateScreen(73, 63, 73, 63, 177, 97, screenSurface); setCursor(kCursorCrosshair); showCursor(); while (!shouldQuit()) { int masterVolume = CLIP((_mixer->getVolumeForSoundType(Audio::Mixer::kPlainSoundType) / 16), 0, 15); int voiceVolume = CLIP((_mixer->getVolumeForSoundType(Audio::Mixer::kSpeechSoundType) / 16), 0, 15); int musicVolume = CLIP((_mixer->getVolumeForSoundType(Audio::Mixer::kMusicSoundType) / 16), 0, 15); int masterVolumeY = 72 + 61 - masterVolume * 4; int voiceVolumeY = 72 + 61 - voiceVolume * 4; int musicVolumeY = 72 + 61 - musicVolume * 4; updateRoom(); copyRect(1, 56, 73, 63, 177, 97, tableSurface, screenSurface); copyBackground(183, 56, 82, masterVolumeY, 39, 2 + masterVolume * 4, tableSurface, screenSurface); copyBackground(183, 56, 138, voiceVolumeY, 39, 2 + voiceVolume * 4, tableSurface, screenSurface); copyBackground(183, 56, 194, musicVolumeY, 39, 2 + musicVolume * 4, tableSurface, screenSurface); updateScreen(); updateEvents(); // we're ignoring keypresses, so just empty the keyboard buffer while (getScan()) ; if (rightMouseButton == 1) { delay(100); break; } if (leftMouseButton == 1) { delay(100); if (mouseX > 80 && mouseX < 121) { updateVolume(Audio::Mixer::kPlainSoundType, masterVolumeY); } if (mouseX > 136 && mouseX < 178) { updateVolume(Audio::Mixer::kSpeechSoundType, voiceVolumeY); } if (mouseX > 192 && mouseX < 233) { updateVolume(Audio::Mixer::kMusicSoundType, musicVolumeY); } } } if (_lang == kSpanish) loadPic(974, tableSurface); selectVerb(kVerbNone); updateEvents(); }
bool DrasculaEngine::runCurrentChapter() { int n; rightMouseButton = 0; previousMusic = -1; if (currentChapter != 2) { int soc = 0; for (n = 0; n < 6; n++) { soc = soc + CHARACTER_WIDTH; _frameX[n] = soc; } } for (n = 1; n < ARRAYSIZE(inventoryObjects); n++) inventoryObjects[n] = 0; for (n = 0; n < NUM_FLAGS; n++) flags[n] = 0; if (currentChapter == 2) { flags[16] = 1; flags[17] = 1; flags[27] = 1; } for (n = 1; n < 7; n++) inventoryObjects[n] = n; if (currentChapter == 1) { pickObject(28); if (loadedDifferentChapter == 0) animation_1_1(); selectVerb(kVerbNone); loadPic("2aux62.alg", drawSurface2); trackProtagonist = 1; objExit = 104; if (loadedDifferentChapter != 0) { if (!loadGame(saveName)) { return true; } } else { enterRoom(62); curX = -20; curY = 56; gotoObject(65, 145); } } else if (currentChapter == 2) { addObject(kItemPhone); trackProtagonist = 3; objExit = 162; if (loadedDifferentChapter == 0) enterRoom(14); else { if (!loadGame(saveName)) { return true; } } } else if (currentChapter == 3) { addObject(kItemPhone); addObject(kItemEarplugs); addObject(kItemSickle); addObject(kItemHandbag); addObject(kItemCross); addObject(kItemReefer); addObject(kItemOneCoin); flags[1] = 1; trackProtagonist = 1; objExit = 99; if (loadedDifferentChapter == 0) enterRoom(20); else { if (!loadGame(saveName)) { return true; } } // From here onwards the items have different IDs } else if (currentChapter == 4) { addObject(kItemPhone2); addObject(kItemCross2); addObject(kItemReefer2); addObject(kItemOneCoin2); objExit = 100; if (loadedDifferentChapter == 0) { enterRoom(21); trackProtagonist = 0; curX = 235; curY = 164; } else { if (!loadGame(saveName)) { return true; } } } else if (currentChapter == 5) { addObject(28); addObject(7); addObject(9); addObject(11); addObject(13); addObject(14); addObject(15); addObject(17); addObject(20); trackProtagonist = 1; objExit = 100; if (loadedDifferentChapter == 0) { enterRoom(45); } else { if (!loadGame(saveName)) { return true; } } } else if (currentChapter == 6) { addObject(28); addObject(9); trackProtagonist = 1; objExit = 104; if (loadedDifferentChapter == 0) { enterRoom(58); animation_1_6(); } else { if (!loadGame(saveName)) { return true; } loadPic("auxdr.alg", drawSurface2); } } showCursor(); while (!shouldQuit()) { if (characterMoved == 0) { stepX = STEP_X; stepY = STEP_Y; } if (characterMoved == 0 && walkToObject == 1) { trackProtagonist = trackFinal; walkToObject = 0; } if (currentChapter == 2) { // NOTE: the checks for room number 14 below are a hack used in the original // game, and move the character to a place where his feet are not drawn above // the pianist's head. Originally, walkToObject was not updated properly, which // lead to an incorrect setting of the protagonist's tracking flag (above). This // made the character start walking off screen, as his actual position was // different than the displayed one if (roomNumber == 3 && (curX == 279) && (curY + curHeight == 101)) { gotoObject(178, 121); gotoObject(169, 135); } else if (roomNumber == 14 && (curX == 214) && (curY + curHeight == 121)) { walkToObject = 1; gotoObject(190, 130); } else if (roomNumber == 14 && (curX == 246) && (curY + curHeight == 112)) { walkToObject = 1; gotoObject(190, 130); } } moveCursor(); updateScreen(); if (currentChapter == 2) { if (musicStatus() == 0 && roomMusic != 0) playMusic(roomMusic); } else { if (musicStatus() == 0) playMusic(roomMusic); } delay(25); #ifndef _WIN32_WCE // FIXME // This and the following #ifndefs disable the excess updateEvents() calls *within* the game loop. // Events such as keypresses or mouse clicks are dropped on the ground with no processing // by these calls. They are properly handled by the implicit call through getScan() below. // It is not a good practice to not process events and indeed this created problems with synthesized // events in the wince port. updateEvents(); #endif if (!_menuScreen && takeObject == 1) checkObjects(); #ifdef _WIN32_WCE if (rightMouseButton) if (_menuScreen) { #else if (rightMouseButton == 1 && _menuScreen) { #endif rightMouseButton = 0; delay(100); if (currentChapter == 2) { loadPic(menuBackground, cursorSurface); loadPic(menuBackground, backSurface); } else { loadPic(99, cursorSurface); loadPic(99, backSurface); } setPalette((byte *)&gamePalette); _menuScreen = false; #ifndef _WIN32_WCE // FIXME: This call here is in hope that it will catch the rightmouseup event so the // next if block won't be executed. This too is not a good coding practice. I've recoded it // with a mutual exclusive if block for the menu. I would commit this properly but I cannot test // for other (see Desktop) ports right now. updateEvents(); #endif #ifdef _WIN32_WCE } else { #else } // Do not show the inventory screen in chapter 5, if the right mouse button is clicked // while the plug (object 16) is held // Fixes bug #2059621 - "DRASCULA: Plug bug" if (rightMouseButton == 1 && !_menuScreen && !(currentChapter == 5 && pickedObject == 16)) { #endif rightMouseButton = 0; delay(100); characterMoved = 0; if (trackProtagonist == 2) trackProtagonist = 1; if (currentChapter == 4) { loadPic("icons2.alg", backSurface); loadPic("icons2.alg", cursorSurface); } else if (currentChapter == 5) { loadPic("icons3.alg", backSurface); loadPic("icons3.alg", cursorSurface); } else if (currentChapter == 6) { loadPic("iconsp.alg", backSurface); loadPic("iconsp.alg", cursorSurface); } else { loadPic("icons.alg", backSurface); loadPic("icons.alg", cursorSurface); } _menuScreen = true; #ifndef _WIN32_WCE updateEvents(); #endif selectVerb(kVerbNone); } if (leftMouseButton == 1 && _menuBar) { delay(100); selectVerbFromBar(); } else if (leftMouseButton == 1 && takeObject == 0) { delay(100); if (verify1()) return true; } else if (leftMouseButton == 1 && takeObject == 1) { if (verify2()) return true; } _menuBar = (mouseY < 24 && !_menuScreen) ? true : false; Common::KeyCode key = getScan(); if (key == Common::KEYCODE_F1 && !_menuScreen) { selectVerb(kVerbLook); } else if (key == Common::KEYCODE_F2 && !_menuScreen) { selectVerb(kVerbPick); } else if (key == Common::KEYCODE_F3 && !_menuScreen) { selectVerb(kVerbOpen); } else if (key == Common::KEYCODE_F4 && !_menuScreen) { selectVerb(kVerbClose); } else if (key == Common::KEYCODE_F5 && !_menuScreen) { selectVerb(kVerbTalk); } else if (key == Common::KEYCODE_F6 && !_menuScreen) { selectVerb(kVerbMove); } else if (key == Common::KEYCODE_F9) { volumeControls(); } else if (key == Common::KEYCODE_F10) { if (!saveLoadScreen()) return true; } else if (key == Common::KEYCODE_F8) { selectVerb(kVerbNone); } else if (key == Common::KEYCODE_v) { _subtitlesDisabled = true; ConfMan.setBool("subtitles", !_subtitlesDisabled); print_abc(_textsys[2], 96, 86); updateScreen(); delay(1410); } else if (key == Common::KEYCODE_t) { _subtitlesDisabled = false; ConfMan.setBool("subtitles", !_subtitlesDisabled); print_abc(_textsys[3], 94, 86); updateScreen(); delay(1460); } else if (key == Common::KEYCODE_ESCAPE) { if (!confirmExit()) return false; } else if (key == Common::KEYCODE_TILDE || key == Common::KEYCODE_BACKQUOTE) { _console->attach(); _console->onFrame(); } else if (currentChapter == 6 && key == Common::KEYCODE_0 && roomNumber == 61) { loadPic("alcbar.alg", bgSurface, 255); } if (leftMouseButton != 0 || rightMouseButton != 0 || key != 0) if (currentChapter != 3) framesWithoutAction = 0; if (framesWithoutAction == 15000) { screenSaver(); if (currentChapter != 3) framesWithoutAction = 0; } if (currentChapter != 3) framesWithoutAction++; } return false; } bool DrasculaEngine::verify1() { int l; if (_menuScreen) removeObject(); else { for (l = 0; l < numRoomObjs; l++) { if (mouseX >= x1[l] && mouseY >= y1[l] && mouseX <= x2[l] && mouseY <= y2[l] && doBreak == 0) { if (exitRoom(l)) return true; if (doBreak == 1) break; } } if (mouseX > curX && mouseY > curY && mouseX < curX + curWidth && mouseY < curY + curHeight) doBreak = 1; for (l = 0; l < numRoomObjs; l++) { if (mouseX > x1[l] && mouseY > y1[l] && mouseX < x2[l] && mouseY < y2[l] && doBreak == 0) { roomX = roomObjX[l]; roomY = roomObjY[l]; trackFinal = trackObj[l]; doBreak = 1; walkToObject = 1; startWalking(); } } if (doBreak == 0) { roomX = CLIP(mouseX, floorX1, floorX2); roomY = CLIP(mouseY, floorY1 + feetHeight, floorY2); startWalking(); } doBreak = 0; } return false; }
bool DrasculaEngine::saveLoadScreen() { char names[10][23]; char file[50]; char fileEpa[50]; int n, n2, num_sav = 0, y = 27; Common::InSaveFile *sav; clearRoom(); snprintf(fileEpa, 50, "%s.epa", _targetName.c_str()); if (!(sav = _saveFileMan->openForLoading(fileEpa))) { Common::OutSaveFile *epa; if (!(epa = _saveFileMan->openForSaving(fileEpa))) error("Can't open %s file", fileEpa); for (n = 0; n < NUM_SAVES; n++) epa->writeString("*\n"); epa->finalize(); delete epa; if (!(sav = _saveFileMan->openForLoading(fileEpa))) { error("Can't open %s file", fileEpa); } } for (n = 0; n < NUM_SAVES; n++) { strncpy(names[n], sav->readLine().c_str(), 23); names[n][22] = '\0'; // make sure the savegame name is 0-terminated } delete sav; loadPic("savescr.alg", bgSurface, HALF_PAL); color_abc(kColorLightGreen); select[0] = 0; _system->setFeatureState(OSystem::kFeatureVirtualKeyboard, true); setCursor(kCursorCrosshair); while (!shouldQuit()) { y = 27; copyBackground(); for (n = 0; n < NUM_SAVES; n++) { print_abc(names[n], 116, y); y = y + 9; } print_abc(select, 117, 15); updateScreen(); y = 27; updateEvents(); if (leftMouseButton == 1) { delay(50); for (n = 0; n < NUM_SAVES; n++) { if (mouseX > 115 && mouseY > y + (9 * n) && mouseX < 115 + 175 && mouseY < y + 10 + (9 * n)) { strcpy(select, names[n]); if (strcmp(select, "*")) selectionMade = 1; else { enterName(); strcpy(names[n], select); if (selectionMade == 1) { snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1); saveGame(file); Common::OutSaveFile *tsav; if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { error("Can't open %s file", fileEpa); } for (n = 0; n < NUM_SAVES; n++) { tsav->writeString(names[n]); tsav->writeString("\n"); } tsav->finalize(); delete tsav; } } print_abc(select, 117, 15); y = 27; for (n2 = 0; n2 < NUM_SAVES; n2++) { print_abc(names[n2], 116, y); y = y + 9; } if (selectionMade == 1) { snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1); } num_sav = n; } } if (mouseX > 117 && mouseY > 15 && mouseX < 295 && mouseY < 24 && selectionMade == 1) { enterName(); strcpy(names[num_sav], select); print_abc(select, 117, 15); y = 27; for (n2 = 0; n2 < NUM_SAVES; n2++) { print_abc(names[n2], 116, y); y = y + 9; } if (selectionMade == 1) { snprintf(file, 50, "%s%02d", _targetName.c_str(), n + 1); saveGame(file); Common::OutSaveFile *tsav; if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { error("Can't open %s file", fileEpa); } for (n = 0; n < NUM_SAVES; n++) { tsav->writeString(names[n]); tsav->writeString("\n"); } tsav->finalize(); delete tsav; } } if (mouseX > 125 && mouseY > 123 && mouseX < 199 && mouseY < 149 && selectionMade == 1) { if (!loadGame(file)) { _system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false); return false; } break; } else if (mouseX > 208 && mouseY > 123 && mouseX < 282 && mouseY < 149 && selectionMade == 1) { saveGame(file); Common::OutSaveFile *tsav; if (!(tsav = _saveFileMan->openForSaving(fileEpa))) { error("Can't open %s file", fileEpa); } for (n = 0; n < NUM_SAVES; n++) { tsav->writeString(names[n]); tsav->writeString("\n"); } tsav->finalize(); delete tsav; } else if (mouseX > 168 && mouseY > 154 && mouseX < 242 && mouseY < 180) break; else if (selectionMade == 0) { print_abc("Please select a slot", 117, 15); } updateScreen(); delay(200); } y = 26; delay(5); } selectVerb(kVerbNone); clearRoom(); loadPic(roomNumber, bgSurface, HALF_PAL); selectionMade = 0; _system->setFeatureState(OSystem::kFeatureVirtualKeyboard, false); return true; }
void DrasculaEngine::converse(int index) { debug(4, "converse(%d)", index); char fileName[20]; sprintf(fileName, "op_%d.cal", index); Common::SeekableReadStream *stream = _archives.open(fileName); if (!stream) error("missing data file %s", fileName); int game1 = kDialogOptionUnselected, game2 = kDialogOptionUnselected, game3 = kDialogOptionUnselected; char phrase1[128], phrase2[128], phrase3[128], phrase4[128]; char sound1[13], sound2[13], sound3[13], sound4[13]; int phrase1_bottom, phrase2_bottom, phrase3_bottom, phrase4_bottom; int answer1, answer2, answer3; breakOut = 0; selectVerb(kVerbNone); TextResourceParser p(stream, DisposeAfterUse::YES); p.parseString(phrase1); p.parseString(phrase2); p.parseString(phrase3); p.parseString(phrase4); p.parseString(sound1); p.parseString(sound2); p.parseString(sound3); p.parseString(sound4); p.parseInt(answer1); p.parseInt(answer2); p.parseInt(answer3); // no need to delete the stream, since TextResourceParser takes ownership // delete stream; if (currentChapter == 2 && !strcmp(fileName, "op_5.cal") && flags[38] == 1 && flags[33] == 1) { Common::strlcpy(phrase3, _text[405], 128); strcpy(sound3, "405.als"); answer3 = 31; } if (currentChapter == 6 && !strcmp(fileName, "op_12.cal") && flags[7] == 1) { Common::strlcpy(phrase3, _text[273], 128); strcpy(sound3, "273.als"); answer3 = 14; } if (currentChapter == 6 && !strcmp(fileName, "op_12.cal") && flags[10] == 1) { Common::strlcpy(phrase3, _text[274], 128); strcpy(sound3, "274.als"); answer3 = 15; } cleanupString(phrase1); cleanupString(phrase2); cleanupString(phrase3); cleanupString(phrase4); loadPic("car.alg", backSurface); // TODO code here should limit y position for mouse in dialog menu, // but we can't implement this as there is lack in backend functionality // from 1(top) to 31 color_abc(kColorLightGreen); while (breakOut == 0 && !shouldQuit()) { updateRoom(); if (musicStatus() == 0 && roomMusic != 0) { if (currentChapter == 3 || currentChapter == 5) { playMusic(roomMusic); } else { // chapters 1, 2, 4, 6 if (flags[11] == 0) playMusic(roomMusic); } } updateEvents(); flushKeyBuffer(); phrase1_bottom = 8 * print_abc_opc(phrase1, 2, game1); phrase2_bottom = phrase1_bottom + 8 * print_abc_opc(phrase2, phrase1_bottom + 2, game2); phrase3_bottom = phrase2_bottom + 8 * print_abc_opc(phrase3, phrase2_bottom + 2, game3); phrase4_bottom = phrase3_bottom + 8 * print_abc_opc(phrase4, phrase3_bottom + 2, kDialogOptionUnselected); if (_mouseY > 0 && _mouseY < phrase1_bottom) { if (game1 == kDialogOptionClicked && _color != kColorWhite) color_abc(kColorWhite); else if (game1 != kDialogOptionClicked && _color != kColorLightGreen) color_abc(kColorLightGreen); print_abc_opc(phrase1, 2, kDialogOptionSelected); if (_leftMouseButton == 1) { delay(100); game1 = kDialogOptionClicked; talk(phrase1, sound1); response(answer1); } } else if (_mouseY > phrase1_bottom && _mouseY < phrase2_bottom) { if (game2 == kDialogOptionClicked && _color != kColorWhite) color_abc(kColorWhite); else if (game2 != kDialogOptionClicked && _color != kColorLightGreen) color_abc(kColorLightGreen); print_abc_opc(phrase2, phrase1_bottom + 2, kDialogOptionSelected); if (_leftMouseButton == 1) { delay(100); game2 = kDialogOptionClicked; talk(phrase2, sound2); response(answer2); } } else if (_mouseY > phrase2_bottom && _mouseY < phrase3_bottom) { if (game3 == kDialogOptionClicked && _color != kColorWhite) color_abc(kColorWhite); else if (game3 != kDialogOptionClicked && _color != kColorLightGreen) color_abc(kColorLightGreen); print_abc_opc(phrase3, phrase2_bottom + 2, kDialogOptionSelected); if (_leftMouseButton == 1) { delay(100); game3 = kDialogOptionClicked; talk(phrase3, sound3); response(answer3); } } else if (_mouseY > phrase3_bottom && _mouseY < phrase4_bottom) { print_abc_opc(phrase4, phrase3_bottom + 2, kDialogOptionSelected); if (_leftMouseButton == 1) { delay(100); talk(phrase4, sound4); breakOut = 1; } } else if (_color != kColorLightGreen) color_abc(kColorLightGreen); _system->delayMillis(10); updateScreen(); } // while (breakOut == 0) if (currentChapter == 2) loadPic(menuBackground, backSurface); else loadPic(99, backSurface); }