ViewerWindow::ViewerWindow(QWidget* parent, Qt::WindowFlags flags) : QMainWindow(parent, flags), gameData(nullptr), gameWorld(nullptr), renderer(nullptr) { setMinimumSize(640, 480); QMenuBar* mb = this->menuBar(); QMenu* file = mb->addMenu("&File"); file->addAction("Open &Game", this, SLOT(loadGame())); file->addSeparator(); for(int i = 0; i < MaxRecentGames; ++i) { QAction* r = file->addAction(""); recentGames.append(r); connect(r, SIGNAL(triggered()), SLOT(openRecent())); } recentSep = file->addSeparator(); auto ex = file->addAction("E&xit"); ex->setShortcut(QKeySequence::Quit); connect(ex, SIGNAL(triggered()), QApplication::instance(), SLOT(closeAllWindows())); viewerWidget = new ViewerWidget; viewerWidget->context()->makeCurrent(); glewExperimental = 1; glewInit(); objectViewer = new ObjectViewer(viewerWidget); connect(this, SIGNAL(loadedData(GameWorld*)), objectViewer, SLOT(showData(GameWorld*))); connect(this, SIGNAL(loadedData(GameWorld*)), viewerWidget, SLOT(dataLoaded(GameWorld*))); modelViewer = new ModelViewer(viewerWidget); connect(this, SIGNAL(loadedData(GameWorld*)), modelViewer, SLOT(showData(GameWorld*))); viewSwitcher = new QStackedWidget; viewSwitcher->addWidget(objectViewer); viewSwitcher->addWidget(modelViewer); //connect(objectViewer, SIGNAL(modelChanged(Model*)), modelViewer, SLOT(showModel(Model*))); connect(objectViewer, SIGNAL(showObjectModel(uint16_t)), this, SLOT(showObjectModel(uint16_t))); objectViewer->setViewerWidget( viewerWidget ); QMenu* view = mb->addMenu("&View"); QAction* objectAction = view->addAction("&Object"); QAction* modelAction = view->addAction("&Model"); objectAction->setData(0); modelAction->setData(1); connect(objectAction, SIGNAL(triggered()), this, SLOT(switchWidget())); connect(modelAction, SIGNAL(triggered()), this, SLOT(switchWidget())); QMenu* data = mb->addMenu("&Data"); //data->addAction("Export &Model", objectViewer, SLOT(exportModel())); QMenu* anim = mb->addMenu("&Animation"); anim->addAction("Load &Animations", this, SLOT(openAnimations())); this->setCentralWidget(viewSwitcher); updateRecentGames(); }
Window::Window() : m_seed(0), m_difficulty(QSettings().value("Difficulty", 5).toInt()), m_algorithm(QSettings().value("Algorithm", 1).toInt()) { // Create board QUndoStack* moves = new QUndoStack(this); m_board = new Board(moves, this); m_seed = QSettings().value("Current/Seed").toInt(); setCentralWidget(m_board); // Create menubar QMenu* game_menu = menuBar()->addMenu(tr("&Game")); QAction* new_action = game_menu->addAction(QIcon::fromTheme("document-new"), tr("&New"), this, SLOT(newGame()), QKeySequence::New); QAction* restart_action = game_menu->addAction(QIcon::fromTheme("view-refresh"), tr("&Restart Game"), this, SLOT(restartGame()), QKeySequence::Refresh); game_menu->addAction(tr("&Details"), this, SLOT(showDetails())); game_menu->addSeparator(); QAction* quit_action = game_menu->addAction(QIcon::fromTheme("application-exit"), tr("Quit"), this, SLOT(close()), QKeySequence::Quit); quit_action->setMenuRole(QAction::QuitRole); QMenu* move_menu = menuBar()->addMenu(tr("&Move")); QAction* undo_action = move_menu->addAction(QIcon::fromTheme("edit-undo"), tr("&Undo"), moves, SLOT(undo()), QKeySequence::Undo); undo_action->setEnabled(false); connect(moves, &QUndoStack::canUndoChanged, undo_action, &QAction::setEnabled); QAction* redo_action = move_menu->addAction(QIcon::fromTheme("edit-redo"), tr("&Redo"), moves, SLOT(redo()), QKeySequence::Redo); redo_action->setEnabled(false); connect(moves, &QUndoStack::canRedoChanged, redo_action, &QAction::setEnabled); QMenu* appearance_menu = menuBar()->addMenu(tr("&Appearance")); QMap<QString, QString> colors; colors.insert(tr("Blue"), "#0055ff"); colors.insert(tr("Charcoal"), "#3d3d3d"); colors.insert(tr("Green"), "#00aa00"); colors.insert(tr("Midnight"), "#00007f"); colors.insert(tr("Plum"), "#aa007f"); colors.insert(tr("Red"), "#ff0000"); colors.insert(tr("Yellow"), "#ffff00"); QString selected_color = QSettings().value("Appearance", "#0055ff").toString(); m_colors = new QActionGroup(this); QMapIterator<QString, QString> i(colors); while (i.hasNext()) { i.next(); QAction* color_action = appearance_menu->addAction(i.key()); color_action->setData(i.value()); color_action->setCheckable(true); m_colors->addAction(color_action); if (i.value() == selected_color) { color_action->setChecked(true); } } connect(m_colors, &QActionGroup::triggered, this, &Window::changeAppearance); appearance_menu->addAction(tr("Custom..."), this, SLOT(changeAppearanceCustom())); QMenu* settings_menu = menuBar()->addMenu(tr("&Settings")); settings_menu->addAction(tr("Application &Language..."), this, SLOT(setLocale())); QMenu* help_menu = menuBar()->addMenu(tr("&Help")); QAction* about_action = help_menu->addAction(tr("&About"), this, SLOT(about())); about_action->setMenuRole(QAction::AboutRole); QAction* about_qt_action = help_menu->addAction(tr("About &Qt"), qApp, SLOT(aboutQt())); about_qt_action->setMenuRole(QAction::AboutQtRole); // Create toolbar QToolBar* toolbar = new QToolBar(this); toolbar->setIconSize(QSize(22, 22)); toolbar->setFloatable(false); toolbar->setMovable(false); toolbar->setToolButtonStyle(Qt::ToolButtonFollowStyle); toolbar->addAction(new_action); toolbar->addAction(restart_action); toolbar->addSeparator(); toolbar->addAction(undo_action); toolbar->addAction(redo_action); addToolBar(toolbar); setContextMenuPolicy(Qt::NoContextMenu); // Restore size and position resize(400,400); restoreGeometry(QSettings().value("Geometry").toByteArray()); // Restore current game loadGame(); }
void toMenu() { BITMAP *menuBuffer = NULL; menuBuffer = create_bitmap(1024,768); //Create an empty bitmap. BITMAP *menuBackground = NULL; menuBackground = load_bitmap("Menu Background.bmp", NULL); // Load our picture BITMAP *highlighter = NULL; highlighter = load_bitmap("Menu Highlighter.bmp", NULL); // Load our picture BITMAP *smoke = NULL; smoke = load_bitmap("Menu Smoke.bmp", NULL); // Load our picture MIDI *menuMusic = NULL; menuMusic = load_midi("Soundtrack1.mid"); SAMPLE *menuClick = load_sample("Click.wav"); clear_bitmap(menuBuffer); // Clear the contents of the buffer bitmap int highlightedOption = 1; int inMenu = 1; int smokePosition = 1024; int smokePosition2 = 1024; draw_sprite(menuBuffer, menuBackground, 0, 0); draw_sprite(menuBuffer, highlighter, 6, 186); blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen play_midi(menuMusic, 1); while (inMenu == 1) { draw_sprite(menuBuffer, menuBackground, 0, 0); smokePosition --; smokePosition2 -= 3; if (smokePosition <= -1024) { smokePosition = 0; } readkey(); if(key[KEY_UP]) { play_sample(menuClick, 155, 0, 2000, 0); highlightedOption--; if (highlightedOption <= 0) { highlightedOption = 5; } } else if(key[KEY_DOWN]) { play_sample(menuClick, 155, 0, 2000, 0); highlightedOption++; if (highlightedOption >= 6) { highlightedOption = 1; } } else if(key[KEY_ENTER]) { play_sample(menuClick, 155, 0, 4000, 0); switch (highlightedOption) { case 1: isXenoPatriots = selectRace(); newGame(); startGame(); play_midi(menuMusic, 1); break; case 2: loadGame(); break; case 3: gameOptions(); break; case 4: break; case 5: quitGame(); inMenu ^= 0; return; break; } } switch (highlightedOption) { case 1: draw_sprite(menuBuffer, highlighter, 6, 186); break; case 2: draw_sprite(menuBuffer, highlighter, 6, 278); break; case 3: draw_sprite(menuBuffer, highlighter, 6, 373); break; case 4: draw_sprite(menuBuffer, highlighter, 6, 465); break; case 5: draw_sprite(menuBuffer, highlighter, 6, 629); break; } /*draw_sprite(menuBuffer, smoke, smokePosition, 0); draw_sprite(menuBuffer, smoke, smokePosition + 1024, 0); draw_sprite(menuBuffer, smoke, smokePosition2, 0); draw_sprite(menuBuffer, smoke, smokePosition2 + 1024, 0);*/ blit(menuBuffer, screen, 0,0,0,0,1024,768);//Draw the buffer to the screen } }
void LevelManager::load(){ loadGame(); }
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; }
int handleButtonClicked_loadFromSlotWindow(SDL_Event e){ Button *lst = currentPage.btnList; int len = currentPage.btnListLen; Button curr; int quit = 0; int isSuccess = 1; for (int i = 0; i < len; i++){ curr = lst[i]; if (isClickInRect(e, curr.buttonsDestRect) == 1){ if (curr.id >=1 && curr.id <=NUM_OF_SLOTS){ // a slot was chosen - load from slot char path[100]; if (userGuiSettings.savedSlot != 0){ // need to deselect the prevButton Button prevChosenButton = getButtonAccordingToId(lst, len, userGuiSettings.savedSlot); sprintf(path, "%s%d%s", SLOT_BTN_URL, userGuiSettings.savedSlot, "_btn.bmp"); isSuccess = deselectButton(path, prevChosenButton); } if (isSuccess == 1){ userGuiSettings.savedSlot = curr.id; sprintf(path, "%s%d%s", SLOT_SELECTED_BTN_URL, userGuiSettings.savedSlot, "_btn.bmp"); isSuccess = selectButton(path, curr); } } else{ switch (curr.id) { case NUM_OF_SLOTS+1: isSuccess = navigatToPage("mainMenu"); break; case NUM_OF_SLOTS+2: // load from chosen slot //check if there is no slot chosen if (userGuiSettings.savedSlot != 0){ char path[100]; char *slot = "./slots/slot"; char *xmlStr = ".xml"; sprintf(path, "%s%d%s", slot, userGuiSettings.savedSlot, xmlStr); clearBoard(); fileData data = loadGame(path); isSuccess = saveLoadedData(data, 0); if (!isSuccess){ // TBD - what do we need to do? Show a dialog? } // navigate to selection page isSuccess = navigatToPage("selectionWindow"); } break; } } break; } } quit = !isSuccess; return quit; }
bool kpok::loadGame() { kapp->config()->setGroup("Save"); return loadGame(kapp->config()); }
int main() { unsigned int pos = 0; int sizes[] = {235, 300, 250, 150}; sf::RenderWindow window(sf::VideoMode(600,600), "SFML Works"); window.setFramerateLimit(60); sf::Font font; sf::Text newGame("New Game", font, 30); sf::Text loadGame("Load Game", font,30); sf::Text settings("Settings", font, 30); sf::Text quit("Quit", font, 30); newGame.setPosition(200, 150); loadGame.setPosition(200, 250); settings.setPosition(200, 350); quit.setPosition(200, 450); sf::RectangleShape select(sf::Vector2f(300, 150)); select.setPosition(200, 150); select.setSize(sf::Vector2f(235, 50)); select.setFillColor(sf::Color(150, 50, 200)); if (!font.loadFromFile("dlxfont.ttf")) { return 1; } while (window.isOpen()) { sf::Event event; if (window.pollEvent(event)) { if (event.type == sf::Event::Closed) { window.close(); } } if (sf::Keyboard::isKeyPressed(sf::Keyboard::W) || sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) { pos = abs((pos - 1) % 4); select.setPosition(200, (pos * 100 + 150)); select.setSize(sf::Vector2f(sizes[pos], 50)); usleep(100000); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::S) || sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) { pos = abs((pos + 1) % 4); select.setPosition(200, (pos * 100 + 150)); select.setSize(sf::Vector2f(sizes[pos], 50)); usleep(100000); } if (sf::Keyboard::isKeyPressed(sf::Keyboard::Return)) { usleep(100000); switch(pos) { case 0: window.close(); Game_Main(); break; case 1: std::cout << "Load Game"; break; case 2: Settings_Menu(); break; case 3: window.close(); break; default: std::cout << "ERROR"; } } window.clear(); window.draw(select); window.draw(newGame); window.draw(loadGame); window.draw(settings); window.draw(quit); window.display(); } }
int executeButton(int buttonId){ if (buttonId >= 200){ char path[12]; sprintf(path, "slot%02d.xml", buttonId-200); loadGame(path); return setScreenToPlayerSettings(); } if (buttonId >= 100){ char path[12]; sprintf(path, "slot%02d.xml", buttonId-100); saveGame(path); return setScreenToGame(0); } switch(buttonId){ case MAIN_MENU: return setScreenToMainMenu(); case RETURN_TO_PLAYER_SETTINGS_WITHOUT_SAVING: if (copyOfMainBoard){ Board_free(copyOfMainBoard); } return setScreenToPlayerSettings(); case RETURN_TO_PLAYER_SETTINGS: return setScreenToPlayerSettings(); case NEW: resetToDefaults(); return setScreenToPlayerSettings(); case LOAD: gameEnded = 0; isInCheck = 0; return setScreenToSaveLoad(0); case SAVE: return setScreenToSaveLoad(1); case RETURN_TO_GAME: return setScreenToGame(0); case HINT: if (gameEnded){ return 0; } return setSelectedMoveToBest(); case QUIT: exit(0); break; case INSTRUCTIONS: return setScreenToInstructions(); case CLEAR: Board_clear(copyOfMainBoard); PieceCounter_reset(copyOfMainPieceCounter); settingInvalidPiece = 0; return 0; case BLACK_KING: kingIsMissing = 0; modifyingPiece = Board_BLACK_KING; return 0; case BLACK_QUEEN: kingIsMissing = 0; modifyingPiece = Board_BLACK_QUEEN; return 0; case BLACK_ROOK: kingIsMissing = 0; modifyingPiece = Board_BLACK_ROOK; return 0; case BLACK_BISHOP: kingIsMissing = 0; modifyingPiece = Board_BLACK_BISHOP; return 0; case BLACK_KNIGHT: kingIsMissing = 0; modifyingPiece = Board_BLACK_KNIGHT; return 0; case BLACK_PAWN: kingIsMissing = 0; modifyingPiece = Board_BLACK_PAWN; return 0; case WHITE_KING: kingIsMissing = 0; modifyingPiece = Board_WHITE_KING; return 0; case WHITE_QUEEN: kingIsMissing = 0; modifyingPiece = Board_WHITE_QUEEN; return 0; case WHITE_ROOK: kingIsMissing = 0; modifyingPiece = Board_WHITE_ROOK; return 0; case WHITE_BISHOP: kingIsMissing = 0; modifyingPiece = Board_WHITE_BISHOP; return 0; case WHITE_KNIGHT: kingIsMissing = 0; modifyingPiece = Board_WHITE_KNIGHT; return 0; case WHITE_PAWN: kingIsMissing = 0; modifyingPiece = Board_WHITE_PAWN; return 0; case REMOVE_PIECE: kingIsMissing = 0; modifyingPiece = Board_EMPTY; return 0; case PROMOTE_TO_BLACK_QUEEN: performPromotion(Board_WHITE_QUEEN); return 0; case PROMOTE_TO_BLACK_BISHOP: performPromotion(Board_BLACK_BISHOP); return 0; case PROMOTE_TO_BLACK_ROOK: performPromotion(Board_BLACK_ROOK); return 0; case PROMOTE_TO_BLACK_KNIGHT: performPromotion(Board_BLACK_KNIGHT); return 0; case PROMOTE_TO_WHITE_QUEEN: performPromotion(Board_WHITE_QUEEN); return 0; case PROMOTE_TO_WHITE_BISHOP: performPromotion(Board_WHITE_BISHOP); return 0; case PROMOTE_TO_WHITE_ROOK: performPromotion(Board_WHITE_ROOK); return 0; case PROMOTE_TO_WHITE_KNIGHT: performPromotion(Board_WHITE_KNIGHT); return 0; case SET_BOARD: settingInvalidPiece = 0; kingIsMissing = 0; return setScreenToBoardSettings(); case PLAY: return (setScreenToGame(1) || GUI_paint()); case AI_SETTINGS: return setScreenToAISettings(); case FINISHED_SETTING_BOARD: settingInvalidPiece = 0; kingIsMissing = 0; if (PieceCounter_kingIsMissing(copyOfMainPieceCounter)){ kingIsMissing = 1; } else{ Board_copy(&board, copyOfMainBoard); Board_free(copyOfMainBoard); PieceCounter_copy(counter, copyOfMainPieceCounter); if (setScreenToPlayerSettings()){ return 1; } } return 0; default: return 0; } }
// start the game with hookd3d.dll void CharactorMaker::loadGame(char * _gameName){ loadGame(_gameName, "HookD3D.dll"); }
void Kolf::initGUI() { newAction = KStdGameAction::gameNew(this, SLOT(newGame()), actionCollection()); newAction->setText(newAction->text() + QString("...")); endAction = KStdGameAction::end(this, SLOT(closeGame()), actionCollection()); printAction = KStdGameAction::print(this, SLOT(print()), actionCollection()); (void) KStdGameAction::quit(this, SLOT(close()), actionCollection()); saveAction = KStdAction::save(this, SLOT(save()), actionCollection(), "game_save"); saveAction->setText(i18n("Save &Course")); saveAsAction = KStdAction::saveAs(this, SLOT(saveAs()), actionCollection(), "game_save_as"); saveAsAction->setText(i18n("Save &Course As...")); saveGameAction = new KAction(i18n("&Save Game"), 0, this, SLOT(saveGame()), actionCollection(), "savegame"); saveGameAsAction = new KAction(i18n("&Save Game As..."), 0, this, SLOT(saveGameAs()), actionCollection(), "savegameas"); loadGameAction = KStdGameAction::load(this, SLOT(loadGame()), actionCollection()); loadGameAction->setText(i18n("Load Saved Game...")); highScoreAction = KStdGameAction::highscores(this, SLOT(showHighScores()), actionCollection()); editingAction = new KToggleAction(i18n("&Edit"), "pencil", CTRL+Key_E, this, SLOT(emptySlot()), actionCollection(), "editing"); newHoleAction = new KAction(i18n("&New"), "filenew", CTRL+SHIFT+Key_N, this, SLOT(emptySlot()), actionCollection(), "newhole"); clearHoleAction = new KAction(KStdGuiItem::clear().text(), "locationbar_erase", CTRL+Key_Delete, this, SLOT(emptySlot()), actionCollection(), "clearhole"); resetHoleAction = new KAction(i18n("&Reset"), CTRL+Key_R, this, SLOT(emptySlot()), actionCollection(), "resethole"); undoShotAction = KStdAction::undo(this, SLOT(emptySlot()), actionCollection(), "undoshot"); undoShotAction->setText(i18n("&Undo Shot")); //replayShotAction = new KAction(i18n("&Replay Shot"), 0, this, SLOT(emptySlot()), actionCollection(), "replay"); holeAction = new KListAction(i18n("Switch to Hole"), 0, this, SLOT(emptySlot()), actionCollection(), "switchhole"); nextAction = new KAction(i18n("&Next Hole"), "forward", KStdAccel::shortcut(KStdAccel::Forward), this, SLOT(emptySlot()), actionCollection(), "nexthole"); prevAction = new KAction(i18n("&Previous Hole"), "back", KStdAccel::shortcut(KStdAccel::Back), this, SLOT(emptySlot()), actionCollection(), "prevhole"); firstAction = new KAction(i18n("&First Hole"), "gohome", KStdAccel::shortcut(KStdAccel::Home), this, SLOT(emptySlot()), actionCollection(), "firsthole"); lastAction = new KAction(i18n("&Last Hole"), CTRL+SHIFT+Key_End, this, SLOT(emptySlot()), actionCollection(), "lasthole"); randAction = new KAction(i18n("&Random Hole"), "goto", 0, this, SLOT(emptySlot()), actionCollection(), "randhole"); useMouseAction = new KToggleAction(i18n("Enable &Mouse for Moving Putter"), 0, this, SLOT(emptySlot()), actionCollection(), "usemouse"); useMouseAction->setCheckedState(i18n("Disable &Mouse for Moving Putter")); connect(useMouseAction, SIGNAL(toggled(bool)), this, SLOT(useMouseChanged(bool))); KConfig *config = kapp->config(); config->setGroup("Settings"); useMouseAction->setChecked(config->readBoolEntry("useMouse", true)); useAdvancedPuttingAction = new KToggleAction(i18n("Enable &Advanced Putting"), 0, this, SLOT(emptySlot()), actionCollection(), "useadvancedputting"); useAdvancedPuttingAction->setCheckedState(i18n("Disable &Advanced Putting")); connect(useAdvancedPuttingAction, SIGNAL(toggled(bool)), this, SLOT(useAdvancedPuttingChanged(bool))); useAdvancedPuttingAction->setChecked(config->readBoolEntry("useAdvancedPutting", false)); showInfoAction = new KToggleAction(i18n("Show &Info"), "info", CTRL+Key_I, this, SLOT(emptySlot()), actionCollection(), "showinfo"); showInfoAction->setCheckedState(i18n("Hide &Info")); connect(showInfoAction, SIGNAL(toggled(bool)), this, SLOT(showInfoChanged(bool))); showInfoAction->setChecked(config->readBoolEntry("showInfo", false)); showGuideLineAction = new KToggleAction(i18n("Show Putter &Guideline"), 0, this, SLOT(emptySlot()), actionCollection(), "showguideline"); showGuideLineAction->setCheckedState(i18n("Hide Putter &Guideline")); connect(showGuideLineAction, SIGNAL(toggled(bool)), this, SLOT(showGuideLineChanged(bool))); showGuideLineAction->setChecked(config->readBoolEntry("showGuideLine", true)); KToggleAction *act=new KToggleAction(i18n("Enable All Dialog Boxes"), 0, this, SLOT(enableAllMessages()), actionCollection(), "enableAll"); act->setCheckedState(i18n("Disable All Dialog Boxes")); soundAction = new KToggleAction(i18n("Play &Sounds"), 0, this, SLOT(emptySlot()), actionCollection(), "sound"); connect(soundAction, SIGNAL(toggled(bool)), this, SLOT(soundChanged(bool))); soundAction->setChecked(config->readBoolEntry("sound", true)); (void) new KAction(i18n("&Reload Plugins"), 0, this, SLOT(initPlugins()), actionCollection(), "reloadplugins"); (void) new KAction(i18n("Show &Plugins"), 0, this, SLOT(showPlugins()), actionCollection(), "showplugins"); aboutAction = new KAction(i18n("&About Course"), 0, this, SLOT(emptySlot()), actionCollection(), "aboutcourse"); tutorialAction = new KAction(i18n("&Tutorial"), 0, this, SLOT(tutorial()), actionCollection(), "tutorial"); statusBar(); setupGUI(); }
InGame::InGame(Configuration& newConfig, std::unique_ptr<StartInfo> startInfo) : config(newConfig) { loadGame(startInfo); }
int main(int argc, char *argv[]) { float td; long then, lastFrameTime, frames; long expireTextTimer; SDL_Event event; memset(&app, 0, sizeof(App)); memset(&dev, 0, sizeof(Dev)); handleLoggingArgs(argc, argv); atexit(cleanup); srand(time(NULL)); init18N(argc, argv); initLookups(); initSDL(); initGameSystem(); createScreenshotFolder(); if (fileExists(getSaveFilePath(SAVE_FILENAME))) { loadGame(); } handleMissionArgs(argc, argv); dev.fps = frames = td = 0; then = SDL_GetTicks(); lastFrameTime = SDL_GetTicks() + 1000; expireTextTimer = SDL_GetTicks() + (1000 * 10); while (1) { td += (SDL_GetTicks() - then); then = SDL_GetTicks(); while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_MOUSEMOTION: doMouseMotion(&event.motion); break; case SDL_MOUSEWHEEL: doMouseWheel(&event.wheel); break; case SDL_MOUSEBUTTONDOWN: doMouseDown(&event.button); break; case SDL_MOUSEBUTTONUP: doMouseUp(&event.button); break; case SDL_KEYDOWN: doKeyDown(&event.key); break; case SDL_KEYUP: doKeyUp(&event.key); break; case SDL_QUIT: exit(0); break; } } if (app.modalDialog.type != MD_NONE) { doModalDialog(); } while (td >= LOGIC_RATE) { /* let the delegate decide during logic() */ app.doTrophyAlerts = 0; app.delegate.logic(); td -= LOGIC_RATE; if (app.doTrophyAlerts) { doTrophyAlerts(); } if (app.resetTimeDelta) { td = 0; then = SDL_GetTicks(); app.resetTimeDelta = 0; } game.stats[STAT_TIME]++; } prepareScene(); app.delegate.draw(); if (app.doTrophyAlerts) { drawTrophyAlert(); } if (app.modalDialog.type != MD_NONE) { drawModalDialog(); } presentScene(); doDevKeys(); frames++; if (SDL_GetTicks() > lastFrameTime) { dev.fps = frames; frames = 0; lastFrameTime = SDL_GetTicks() + 1000; if (dev.takeScreenshots) { saveScreenshot(); } } if (isControl(CONTROL_SCREENSHOT)) { saveScreenshot(); clearControl(CONTROL_SCREENSHOT); } if (SDL_GetTicks() > expireTextTimer) { expireTexts(0); expireTextTimer = SDL_GetTicks() + (1000 * 10); } /* don't save more than once per request, and not in the middle of battle */ if (app.saveGame && battle.status != MS_IN_PROGRESS) { saveGame(); app.saveGame = 0; } /* always zero the mouse motion */ app.mouse.dx = app.mouse.dy = 0; SDL_Delay(1); } return 0; }
/* VaultShopMain */ VaultShopMain::VaultShopMain() { // Basic Form Settings setWindowTitle("VaultShop " PLASMASHOP_VERSION); //setWindowIcon(QIcon(":/res/VaultShop.png")); // Set up actions fActions[kFileOpenVault] = new QAction(qStdIcon("document-open"), tr("&Load Vault..."), this); fActions[kFileSaveVault] = new QAction(qStdIcon("document-save"), tr("&Save Vault"), this); fActions[kFileExit] = new QAction(tr("E&xit"), this); fActions[kVaultOpenNode] = new QAction(tr("Subscribe to &Node..."), this); fActions[kNodeUnLink] = new QAction(tr("Remove"), this); fActions[kNodeLink] = new QAction(tr("Add Node..."), this); fActions[kNodeCreate] = new QAction(tr("Create Node"), this); fActions[kNodeUnsubscribe] = new QAction(tr("Un-subscribe"), this); //fActions[kNodeRenameVault] = new QAction(tr("Rename Vault..."), this); fActions[kFileOpenVault]->setShortcut(Qt::CTRL + Qt::Key_O); fActions[kFileSaveVault]->setShortcut(Qt::CTRL + Qt::Key_S); fActions[kFileExit]->setShortcut(Qt::ALT + Qt::Key_F4); fActions[kVaultOpenNode]->setShortcut(Qt::Key_F2); // Main Menus QMenu* fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(fActions[kFileOpenVault]); fileMenu->addAction(fActions[kFileSaveVault]); fileMenu->addSeparator(); fileMenu->addAction(fActions[kFileExit]); QMenu* vaultMenu = menuBar()->addMenu(tr("&Vault")); vaultMenu->addAction(fActions[kVaultOpenNode]); // Toolbars QToolBar* fileTbar = addToolBar(tr("File Toolbar")); fileTbar->setObjectName("FileToolBar"); fileTbar->addAction(fActions[kFileOpenVault]); fileTbar->addAction(fActions[kFileSaveVault]); statusBar(); // Main Splitter QSplitter* splitter = new QSplitter(Qt::Horizontal, this); splitter->setObjectName("Splitter"); // Node Browser fVaultTree = new QTreeWidget(splitter); fVaultTree->setUniformRowHeights(true); fVaultTree->setHeaderHidden(true); fVaultTree->setContextMenuPolicy(Qt::CustomContextMenu); // Property Editor fNodeTab = new QTabWidget(splitter); fGenericEditor = new QVaultNode(fNodeTab); fNodeTab->addTab(fGenericEditor, tr("Node Properties")); fCustomEditor = NULL; fSavEditor = NULL; fEditorTabPreference = 0; // Layout splitter->addWidget(fVaultTree); splitter->addWidget(fNodeTab); setCentralWidget(splitter); splitter->setSizes(QList<int>() << 160 << 320); // Global UI Signals connect(fActions[kFileExit], SIGNAL(triggered()), this, SLOT(close())); connect(fActions[kFileOpenVault], SIGNAL(triggered()), this, SLOT(openGame())); connect(fActions[kFileSaveVault], SIGNAL(triggered()), this, SLOT(performSave())); connect(fActions[kVaultOpenNode], SIGNAL(triggered()), this, SLOT(openNode())); connect(fActions[kNodeUnLink], SIGNAL(triggered()), this, SLOT(unlinkNode())); connect(fActions[kNodeLink], SIGNAL(triggered()), this, SLOT(linkNode())); connect(fActions[kNodeCreate], SIGNAL(triggered()), this, SLOT(createNode())); connect(fActions[kNodeUnsubscribe], SIGNAL(triggered()), this, SLOT(closeNode())); //connect(fActions[kNodeRenameVault], SIGNAL(triggered()), this, SLOT(renameVault())); connect(fVaultTree, SIGNAL(currentItemChanged(QTreeWidgetItem*, QTreeWidgetItem*)), this, SLOT(treeItemChanged(QTreeWidgetItem*, QTreeWidgetItem*))); connect(fVaultTree, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(treeContextMenu(const QPoint&))); connect(fNodeTab, SIGNAL(currentChanged(int)), this, SLOT(tabChanged(int))); connect(fGenericEditor, SIGNAL(typeModified()), this, SLOT(typeModified())); connect(this, SIGNAL(nodeChanged(unsigned int)), this, SLOT(refreshNode(unsigned int))); // Load UI Settings QSettings settings("PlasmaShop", "VaultShop"); resize(settings.value("WinSize", QSize(480, 600)).toSize()); if (settings.contains("WinPos")) move(settings.value("WinPos").toPoint()); if (settings.value("WinMaximized", false).toBool()) showMaximized(); if (settings.contains("WinState")) restoreState(settings.value("WinState").toByteArray()); fLastDir = settings.value("LastDir").toString(); if (!fLastDir.isEmpty()) loadGame(fLastDir); }
void Sudoku::newGame() { if (okToContinue()) { int randomGame = e() % gameCount + 1; loadGame(QString::number(randomGame)); } }
void COverlappedWindow::OnCommand(WPARAM wParam, LPARAM lParam) { if (isPause) { return; } switch (LOWORD(wParam)) { case ID_ACCELERATOR_FAST_QUIT: ::PostMessage(handle, WM_QUIT, (WPARAM)0, (LPARAM)0); break; case ID_ACCELERATOR_NEW_GAME: if (!isPause) { startNewGame(); } break; case ID_EXIT: ::PostMessage(handle, WM_CLOSE, (WPARAM)0, (LPARAM)0); break; case ID_HELP: break; case ID_SETTINGS: if (!isPause) { OnViewSettings(); isPause = true; } break; case ID_NEW_SMALL: if (isDoneFirstStep) { if (!OnSaveDlg()) { break; } } startNewGame(10, 10); break; case ID_NEW_MEDIUM: if (isDoneFirstStep) { if (!OnSaveDlg()) { break; } } startNewGame(12, 12); break; case ID_NEW_BIG: if (isDoneFirstStep) { if (!OnSaveDlg()) { break; } } startNewGame(30, 15); break; case ID_NEW_CUSTOM: if (isDoneFirstStep) { if (!OnSaveDlg()) { break; } } if (!isPause) { OnCustomGame(); isPause = true; } break; case ID_GAME_LOAD: if (!loadGame()) { //sad } else { ::InvalidateRect(handle, 0, 0); } break; case ID_GAME_SAVE: if (saveGame()) { isDoneFirstStep = false; } break; } }
int loadGame(int slot) { char itemName[MAX_MESSAGE_LENGTH], mapName[MAX_MESSAGE_LENGTH], backup[MAX_PATH_LENGTH]; char saveFile[MAX_PATH_LENGTH], *line, *savePtr, completion[5]; double version = 0; float percentage, steps; unsigned char *buffer; int patchGame = FALSE, foundResources; FILE *fp; savePtr = NULL; snprintf(saveFile, sizeof(saveFile), "%ssave%d", gameSavePath, slot); fp = fopen(saveFile, "rb"); if (fp == NULL) { return FALSE; } fclose(fp); freeGameResources(); initGame(); buffer = decompressFile(saveFile); line = strtok_r((char *)buffer, "\n", &savePtr); foundResources = FALSE; while (line != NULL) { if (line[strlen(line) - 1] == '\n') { line[strlen(line) - 1] = '\0'; } if (line[strlen(line) - 1] == '\r') { line[strlen(line) - 1] = '\0'; } sscanf(line, "%s", itemName); if (strcmpignorecase("VERSION", itemName) == 0) { sscanf(line, "%*s %s\n", itemName); version = atof(itemName); if (version > VERSION) { printf("Save file version is newer than game version. This game might not work correctly.\n"); } } else if (strcmpignorecase("PLAY_TIME", itemName) == 0) { sscanf(line, "%*s %ld\n", &game.playTime); } else if (strcmpignorecase("PLAYER_KILLS", itemName) == 0) { sscanf(line, "%*s %d\n", &game.kills); } else if (strcmpignorecase("BATS_DROWNED", itemName) == 0) { sscanf(line, "%*s %d\n", &game.batsDrowned); } else if (strcmpignorecase("TIMES_EATEN", itemName) == 0) { sscanf(line, "%*s %d\n", &game.timesEaten); } else if (strcmpignorecase("DISTANCE_TRAVELLED", itemName) == 0) { sscanf(line, "%*s %u\n", &game.distanceTravelled); } else if (strcmpignorecase("ATTACKS_BLOCKED", itemName) == 0) { sscanf(line, "%*s %d\n", &game.attacksBlocked); } else if (strcmpignorecase("SLIME_TIME", itemName) == 0) { sscanf(line, "%*s %d\n", &game.timeSpentAsSlime); } else if (strcmpignorecase("ARROWS_FIRED", itemName) == 0) { sscanf(line, "%*s %d\n", &game.arrowsFired); } else if (strcmpignorecase("SECRETS_FOUND", itemName) == 0) { sscanf(line, "%*s %d\n", &game.secretsFound); } else if (strcmpignorecase("CONTINUES", itemName) == 0) { sscanf(line, "%*s %d\n", &game.continues); } else if (strcmpignorecase("CHEATING", itemName) == 0) { sscanf(line, "%*s %d\n", &game.cheating); } else if (strcmpignorecase("PLAYER_LOCATION", itemName) == 0) { if (version < VERSION) { patchGame = TRUE; break; } sscanf(line, "%*s %s\n", itemName); loadMap(itemName, FALSE); snprintf(mapName, sizeof(mapName), "MAP_NAME %s", itemName); } else if (strcmpignorecase(line, mapName) == 0) { foundResources = TRUE; loadResources(savePtr); } line = strtok_r(NULL, "\n", &savePtr); } if (patchGame == TRUE) { free(buffer); steps = (VERSION * 100) - (version * 100); steps = 100 / steps; percentage = 0; version += 0.01; /* Back up the original save file */ snprintf(backup, sizeof(backup), "%s.bak", saveFile); copyFile(saveFile, backup); showPatchMessage("0%"); while (TRUE) { getInput(IN_TITLE); patchSaveGame(saveFile, version); version += 0.01; percentage += steps; snprintf(completion, 5, "%d%%", (int)percentage); if ((int)(version * 100) > (int)(VERSION * 100)) { break; } showPatchMessage(completion); } return loadGame(slot); } /* Fudge to make a game saved in the new Village map still load OK */ if (foundResources == FALSE) { sscanf(mapName, "%*s %s\n", itemName); loadMap(itemName, TRUE); } free(buffer); copyFile(saveFile, tempFile); buffer = decompressFile(tempFile); free(buffer); cameraSnapToTargetEntity(); freeMessageQueue(); temporaryDataExists = TRUE; return TRUE; }
bool CGEEngine::showTitle(const char *name) { if (_eventManager->_quitFlag) return false; _bitmapPalette = _vga->_sysPal; BitmapPtr *LB = new BitmapPtr[2]; LB[0] = new Bitmap(this, name); LB[1] = NULL; _bitmapPalette = NULL; Sprite D(this, LB); D._flags._kill = true; D._flags._bDel = true; D.center(); D.show(2); if (_mode == 2) { inf(kSavegame0Name); _talk->show(2); } _vga->sunset(); _vga->copyPage(1, 2); _vga->copyPage(0, 1); selectPocket(-1); _vga->sunrise(_vga->_sysPal); if (_mode < 2 && !_soundOk) { _vga->copyPage(1, 2); _vga->copyPage(0, 1); _vga->_showQ->append(_mouse); _mouse->on(); for (; !_commandHandler->idle() || Vmenu::_addr;) { mainLoop(); if (_eventManager->_quitFlag) return false; } _mouse->off(); _vga->_showQ->clear(); _vga->copyPage(0, 2); _soundOk = 2; if (_music) _midiPlayer->loadMidi(0); } if (_mode < 2) { // At this point the game originally set the protection variables // used by the copy protection check movie(kPaylistExt); // paylist _vga->copyPage(1, 2); _vga->copyPage(0, 1); _vga->_showQ->append(_mouse); // In the original game, the user had to enter his name // As it was only used to name savegames, it has been removed _vga->_showQ->clear(); _vga->copyPage(0, 2); if (_mode == 0) { // The auto-load of savegame #0 is currently disabled #if 0 if (savegameExists(0)) { // Load the savegame loadGame(0, NULL, true); // only system vars _vga->setColors(_vga->_sysPal, 64); _vga->update(); if (_flag[3]) { //flag FINIS _mode++; _flag[3] = false; } } else #endif _mode++; } } if (_mode < 2) movie(kWinkExt); _vga->copyPage(0, 2); return true; }
// game scene SceneGame::SceneGame() { IGScene::IGScene(); IGLog("SceneGame init"); unsigned int i, j; // load the game phraseId = 0; savedGameDB = new SQLite3Wrapper("savedGame.db"); loadGame(); // init physical keyboard array s3eKeys[0]=s3eKeyA; s3eKeys[1]=s3eKeyB; s3eKeys[2]=s3eKeyC; s3eKeys[3]=s3eKeyD; s3eKeys[4]=s3eKeyE; s3eKeys[5]=s3eKeyF; s3eKeys[6]=s3eKeyG; s3eKeys[7]=s3eKeyH; s3eKeys[8]=s3eKeyI; s3eKeys[9]=s3eKeyJ; s3eKeys[10]=s3eKeyK; s3eKeys[11]=s3eKeyL; s3eKeys[12]=s3eKeyM; s3eKeys[13]=s3eKeyN; s3eKeys[14]=s3eKeyO; s3eKeys[15]=s3eKeyP; s3eKeys[16]=s3eKeyQ; s3eKeys[17]=s3eKeyR; s3eKeys[18]=s3eKeyS; s3eKeys[19]=s3eKeyT; s3eKeys[20]=s3eKeyU; s3eKeys[21]=s3eKeyV; s3eKeys[22]=s3eKeyW; s3eKeys[23]=s3eKeyX; s3eKeys[24]=s3eKeyY; s3eKeys[25]=s3eKeyZ; // load resources, background image IGSprite* spriteBackground = NULL; switch(Settings::getInstance()->theme) { case SettingsThemeHacker: IwGetResManager()->LoadGroup("game_hacker.group"); spriteBackground = new IGSprite("GameHackerBackground", IGPoint(240,160), 0); break; case SettingsThemeDetective: IwGetResManager()->LoadGroup("game_detective.group"); spriteBackground = new IGSprite("GameDetectiveBackground", IGPoint(240,160), 0); break; case SettingsThemeEspionage: IwGetResManager()->LoadGroup("game_espionage.group"); spriteBackground = new IGSprite("GameEspionageBackground", IGPoint(240,160), 0); break; } this->addChild(spriteBackground); // buttons GameButtonNewPuzzle* buttonNewPuzzle = new GameButtonNewPuzzle(); GameButtonHint* buttonHint = new GameButtonHint(); GameButtonMenu* buttonMenu = new GameButtonMenu(); this->addChild(buttonNewPuzzle); this->addChild(buttonHint); this->addChild(buttonMenu); // time int sec = (int)(time%60); int min = (int)(time/60); GameTimeLabel* timeLabel = new GameTimeLabel(min,sec); this->addChild(timeLabel); // draw the phrase const unsigned int maxCols = 18; // used to be 21 const unsigned int maxRows = 4; int columnCount[4] = {0,0,0,0}; // count number of columns per row unsigned int col = 0; unsigned int row = 0; for(i=0; i<strlen(ciphertext); i++) { // if it's a space in the first column, skip this one while(col == 0 && ciphertext[i] == ' ') i++; // if it's a word, see if there's enough space in this line if(ciphertext[i] != ' ') { for(j=i+1; j<strlen(ciphertext); j++) { if(ciphertext[j] == ' ' || ciphertext[j] == '\0') break; } if(col + (j-i) >= maxCols) { col = 0; row++; } } // if it's a letter, draw empty box and an empty plaintext label if(ciphertext[i] >= 'A' && ciphertext[i] <= 'Z') { GameSlot* slot = new GameSlot(row, col, SceneGameTagSlots+i); GamePlaintextLabel* plaintextLabel = new GamePlaintextLabel(' ', row, col, SceneGameTagPlaintextLabels+i); this->addChild(slot); this->addChild(plaintextLabel); } // otherwise draw the character else { if(ciphertext[i] != ' ') { GamePlaintextLabel* plaintextLabel = new GamePlaintextLabel(ciphertext[i], row, col, SceneGameTagPlaintextLabels+i); this->addChild(plaintextLabel); } } // draw the ciphertext if(ciphertext[i] != ' ') { GameCiphertextLabel* ciphertextLabel = new GameCiphertextLabel(ciphertext[i], row, col, SceneGameTagCiphertextLabels+i); this->addChild(ciphertextLabel); } // count the columns columnCount[row]++; // increment the column col++; if(col == maxCols) { col = 0; row++; } } // center the text, total width=468, letter width=26 for(i=0; i<4; i++) { int width = columnCount[i]; int index = -1; for(j=0; j<=i; j++) index += columnCount[j]; if(ciphertext[index] == ' ') width--; centerOffset[i] = (468 - (width*26)) / 2; } row = 0; for(i=0; i<strlen(ciphertext); i++) { GameSlot* slot = (GameSlot*)this->getChildByTag(SceneGameTagSlots+i); if(slot != NULL) { row = slot->row; slot->position.x += centerOffset[row]; } GamePlaintextLabel* plaintextLabel = (GamePlaintextLabel*)this->getChildByTag(SceneGameTagPlaintextLabels+i); if(plaintextLabel != NULL) plaintextLabel->position.x += centerOffset[row]; GameCiphertextLabel* ciphertextLabel = (GameCiphertextLabel*)this->getChildByTag(SceneGameTagCiphertextLabels+i); if(ciphertextLabel != NULL) ciphertextLabel->position.x += centerOffset[row]; } // draw the key IGLabel* labelAlphabet = new IGLabel("FontFixedSys14", "alphabet: ", IGPoint(123,230), IGRect(90,20), 2, SceneGameTagLabelAlphabet); IGLabel* labelAnswerKey = new IGLabel("FontFixedSys14", " key: ", IGPoint(123,250), IGRect(90,20), 2, SceneGameTagLabelAnswerKey); IGLabel* labelAlphabetLetter = new IGLabel("FontFixedSys14", "ABCDEFGHIJKLMNOPQRSTUVWXYZ", IGPoint(294,230), IGRect(234,20), 2, SceneGameTagLabelAlphabetLetters); IGLabel* labelAnswerKeyLetter = new IGLabel("FontFixedSys14", "__________________________", IGPoint(294,250), IGRect(234,20), 2, SceneGameTagLabelAnswerKeyLetters); switch(Settings::getInstance()->theme) { case SettingsThemeHacker: labelAnswerKey->setColor(140,140,140,255); labelAlphabet->setColor(140,140,140,255); labelAnswerKeyLetter->setColor(210,220,210,255); labelAlphabetLetter->setColor(210,220,210,255); break; case SettingsThemeDetective: case SettingsThemeEspionage: labelAnswerKey->setColor(80,80,80,255); labelAlphabet->setColor(80,80,80,255); labelAnswerKeyLetter->setColor(20,20,20,255); labelAlphabetLetter->setColor(20,20,20,255); break; break; } this->addChild(labelAnswerKey); this->addChild(labelAlphabet); this->addChild(labelAnswerKeyLetter); this->addChild(labelAlphabetLetter); // keyboard keyboardUp = false; // update the phrase updatePhrase(); }
int main(void) { gamestate game; SDL_Window* window = NULL; game.renderer = NULL; SDL_Init(SDL_INIT_VIDEO); time_t t; srand(time(&t)); window = SDL_CreateWindow( "Game Window", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, 640, 480, 0 ); if (window == NULL) { printf("Window initialization failed: %s\n", SDL_GetError()); return 1; } game.renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); TTF_Init(); if (game.renderer == NULL) { printf("Rendering failed: %s\n", SDL_GetError()); return 1; } loadGame(&game); int done = 0; while (!done) { processEvents(window, &done, &game); process(&game); collisionDetect(&game); doRender(&game); } SDL_DestroyTexture(game.spook[0]); SDL_DestroyTexture(game.spook[1]); SDL_DestroyTexture(game.spook[2]); SDL_DestroyTexture(game.tile); if (game.label != NULL) { SDL_DestroyTexture(game.label); } TTF_CloseFont(game.font); SDL_DestroyWindow(window); SDL_DestroyRenderer(game.renderer); TTF_Quit(); SDL_Quit(); return 0; }
int ClientInterface::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QMainWindow::qt_metacall(_c, _id, _a); if (_id < 0) return _id; if (_c == QMetaObject::InvokeMetaMethod) { switch (_id) { case 0: sendMessage(); break; case 1: chat((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[4]))); break; case 2: changeServerInformations((*reinterpret_cast< ServerInformations(*)>(_a[1]))); break; case 3: changeClientID((*reinterpret_cast< CLID(*)>(_a[1]))); break; case 4: changeClientNickname((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 5: showError((*reinterpret_cast< ENUM_TYPE(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 6: changeGameMaster((*reinterpret_cast< CLID(*)>(_a[1]))); break; case 7: clientVoted((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< CLID(*)>(_a[2]))); break; case 8: connectionEtablished(); break; case 9: connectionLost(); break; case 10: diceRolled((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< quint16(*)>(_a[2])),(*reinterpret_cast< quint16(*)>(_a[3]))); break; case 11: sanctionned((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< ENUM_TYPE(*)>(_a[2])),(*reinterpret_cast< QString(*)>(_a[3]))); break; case 12: rollDice(); break; case 13: rollSpecialDice(); break; case 14: serverName((*reinterpret_cast< QString(*)>(_a[1]))); break; case 15: motdChanged((*reinterpret_cast< QString(*)>(_a[1]))); break; case 16: gameLaunched(); break; case 17: setTitle(); break; case 18: playSound((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 19: updatePlayerList(); break; case 20: clientJoined((*reinterpret_cast< CLID(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 21: clientLeft((*reinterpret_cast< CLID(*)>(_a[1]))); break; case 22: updateGMLabel(); break; case 23: updateGMPanel(); break; case 24: { bool _r = addLanguage(); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 25: { bool _r = addLanguage((*reinterpret_cast< const QString(*)>(_a[1])),(*reinterpret_cast< const QString(*)>(_a[2]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 26: languageListMenu((*reinterpret_cast< const QPoint(*)>(_a[1]))); break; case 27: { bool _r = removeLanguage((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< bool*>(_a[0]) = _r; } break; case 28: removeLanguageMenu(); break; case 29: importLanguageList(); break; case 30: sendLanguageList(); break; case 31: { CLID _r = CLIDFromString((*reinterpret_cast< const QString(*)>(_a[1]))); if (_a[0]) *reinterpret_cast< CLID*>(_a[0]) = _r; } break; case 32: switchConnectionState(); break; case 33: openSettings(); break; case 34: openSoundsGUI(); break; case 35: aboutUs(); break; case 36: aboutServer(); break; case 37: openMapEditor(); break; case 38: clearMapEditor(); break; case 39: mapFlare(); break; case 40: resetData(); break; case 41: setCSS((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 42: setCSS(); break; case 43: setInterface((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 44: setInterface(); break; case 45: playerListMenu((*reinterpret_cast< const QPoint(*)>(_a[1]))); break; case 46: actionKick(); break; case 47: actionBan(); break; case 48: actionVoteGM(); break; case 49: actionChangeGM(); break; case 50: refresh(); break; case 51: textChanged(); break; case 52: narrationChanged((*reinterpret_cast< QString(*)>(_a[1]))); break; case 53: syncSoundLibs((*reinterpret_cast< QList<SoundLibInformations>(*)>(_a[1]))); break; case 54: syncLanguagesList((*reinterpret_cast< QList<QPair<QString,QString> >(*)>(_a[1]))); break; case 55: syncDictionariesList((*reinterpret_cast< QStringList(*)>(_a[1]))); break; case 56: requestScriptDownload((*reinterpret_cast< QString(*)>(_a[1]))); break; case 57: sendScriptToServer((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 58: deleteScript((*reinterpret_cast< QString(*)>(_a[1]))); break; case 59: renameScript((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 60: makeEntity((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 61: deleteEntity((*reinterpret_cast< const QString(*)>(_a[1]))); break; case 62: injectCode((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 63: scriptToGMMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 64: scriptToOwnerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 65: scriptActionMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 66: scriptToPlayerMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 67: scriptMsg((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 68: scriptError((*reinterpret_cast< QString(*)>(_a[1])),(*reinterpret_cast< QString(*)>(_a[2]))); break; case 69: sendMapToServer((*reinterpret_cast< const MapInformations*const(*)>(_a[1])),(*reinterpret_cast< const QMap<QString,RSID>(*)>(_a[2]))); break; case 70: addDictionnary(); break; case 71: saveGame(); break; case 72: loadGame(); break; case 73: VOIPRemoveClient(); break; case 74: VOIPAddClient(); break; case 75: VOIPClientVolume(); break; case 76: dataPerSecond((*reinterpret_cast< int(*)>(_a[1])),(*reinterpret_cast< int(*)>(_a[2]))); break; default: ; } _id -= 77; } return _id; }
void AGOSEngine_DIMP::odp_loadUserGame() { // 133: load usergame loadGame(genSaveName(1)); }
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; }
Common::Error AvalancheEngine::loadGameState(int slot) { return (loadGame(slot) ? Common::kNoError : Common::kReadingFailed); }
void MWState::StateManager::quickLoad() { if (Character* mCurrentCharacter = getCurrentCharacter (false)) if (const MWState::Slot* slot = &*mCurrentCharacter->begin()) //Get newest save loadGame (mCurrentCharacter, slot); }
int main(int argc, char *argv[]) { unsigned int frameLimit; int go, i, mapID, loadSlot, recordingID, replayingID; int joystick, showCredits, languageID; go = TRUE; loadSlot = -1; game.fps = 1000 / 60; languageID = mapID = recordingID = replayingID = -1; joystick = 0; showCredits = FALSE; /* Load the resources */ for (i=1;i<argc;i++) { if (strcmpignorecase("-record", argv[i]) == 0) { if (i + 1 >= argc) { printf("You must specify a file to record to\n"); printf("Type %s -h for help\n", argv[0]); exit(1); } if (recordingID == -1) { recordingID = i + 1; } i++; } else if (strcmpignorecase("-playback", argv[i]) == 0) { if (i + 1 >= argc) { printf("You must specify a file to playback from\n"); printf("Type %s -h for help\n", argv[0]); exit(1); } if (replayingID == -1) { replayingID = i + 1; } i++; } else if (strcmpignorecase("-load", argv[i]) == 0) { if (i + 1 >= argc) { printf("You must specify a slot to load from\n"); printf("Type %s -h for help\n", argv[0]); exit(1); } loadSlot = atoi(argv[i + 1]); i++; } else if (strcmpignorecase("-nojoystick", argv[i]) == 0) { game.disableJoystick = TRUE; } else if (strcmpignorecase("-joystick", argv[i]) == 0) { if (i + 1 >= argc) { printf("You must specify a joystick slot to use\n"); printf("Type %s -h for help\n", argv[0]); exit(1); } joystick = atoi(argv[i + 1]); i++; } else if (strcmpignorecase("-showcredits", argv[i]) == 0) { showCredits = TRUE; } else if (strstr(argv[i], "-lang") != NULL) { if (i + 1 >= argc) { printf("You must specify a language to use\n"); printf("Type %s -h for help\n", argv[0]); exit(1); } languageID = i + 1; i++; } else if (strstr(argv[i], "-h") != NULL || strstr(argv[i], "-help") != NULL) { printf("The Legend of Edgar options\n\n"); printf("\t-record <filename>: Captures keyboard input\n"); printf("\t-playback <filename>: Replays keyboard input\n"); printf("\t-load <save_slot>: Loads the game in slot <save_slot>. Slots start at 0\n"); printf("\t-nojoystick: Disables the joystick\n"); printf("\t-joystick <joystick_slot>: Use joystick <joystick_slot>. Slots start at 0\n"); printf("\t-showcredits: Shows the end credits\n"); printf("\t-language <language_code>: Use language <language_code>. e.g. en_US, es, pl\n\n"); exit(0); } #if DEV == 1 else if (strcmpignorecase("-saveonexit", argv[i]) == 0) { game.saveOnExit = TRUE; } else if (strcmpignorecase("-bmpwrite", argv[i]) == 0) { setScreenshotDir(argv[i + 1]); i++; } else { mapID = i; } #endif } setLanguage("edgar", languageID == -1 ? NULL : argv[languageID]); printf("Numeric is %s\n", setlocale(LC_NUMERIC, "C")); printf("atof(2.75) is %f\n", atof("2.75")); /* Call the cleanup function when the program exits */ atexit(cleanup); /* Start up SDL */ init(_("The Legend of Edgar"), joystick); loadRequiredResources(); if (replayingID != -1 && recordingID != -1) { showErrorAndExit("Cannot record and replay at the same time"); } #if DEV == 0 verifyVersion(); #endif /* Initialise the game variables */ freeGameResources(); initGame(); if (loadSlot == -1) { if (recordingID != -1) { setRecordData(argv[recordingID]); setMapFile(mapID == -1 ? "map01" : argv[mapID]); } else if (replayingID != -1) { setReplayData(argv[replayingID], TRUE); setMapFile(mapID == -1 ? "map01" : argv[mapID]); } if (mapID != -1) { startOnMap(argv[mapID]); } else if (game.firstRun == TRUE) { tutorial(); } else { game.status = IN_TITLE; } } else { if (recordingID != -1) { game.gameType = RECORDING; } else if (replayingID != -1) { game.gameType = REPLAYING; } if (loadGame(loadSlot) == FALSE) { showErrorAndExit("No saved game in slot %d", loadSlot); } if (recordingID != -1) { setRecordData(argv[recordingID]); setMapFile(getMapFilename()); } else if (replayingID != -1) { setReplayData(argv[replayingID], TRUE); } } /* Loop indefinitely for messages */ game.startTicks = SDL_GetTicks(); #if DEV == 1 printf("DEV Version\n"); #else printf("Production Version\n"); #endif frameLimit = SDL_GetTicks() + game.fps; if (showCredits == TRUE) { game.status = IN_CREDITS; } while (go == TRUE) { getInput(game.gameType); switch (game.status) { case IN_TITLE: doTitle(); break; case IN_GAME: freeCollisionGrid(); clearDrawLayers(); doGame(); doPlayer(); doInventory(); doMap(); doEntities(); doDecorations(); doCollisions(); doHud(); doDialogBox(); processMedals(); break; case IN_INVENTORY: doInventoryMenu(); break; case IN_MENU: doMenu(); break; case IN_CREDITS: freeCollisionGrid(); clearDrawLayers(); doGame(); doCredits(); doDecorations(); doCollisions(); break; default: doMenu(); break; } draw(); /* Sleep briefly to stop sucking up all the CPU time */ delay(frameLimit); frameLimit = SDL_GetTicks() + game.fps; game.frames++; } /* Exit the program */ exit(0); }
// load up the data for a level bool levLoadData(const char* name, char *pSaveName, GAME_TYPE saveType) { LEVEL_DATASET *psNewLevel, *psBaseData, *psChangeLevel; SDWORD i; bool bCamChangeSaveGame; debug(LOG_WZ, "Loading level %s (%s, type %d)", name, pSaveName, (int)saveType); if (saveType == GTYPE_SAVE_START || saveType == GTYPE_SAVE_MIDMISSION) { if (!levReleaseAll()) { debug(LOG_ERROR, "Failed to unload old data"); return false; } } levelLoadType = saveType; // find the level dataset psNewLevel = levFindDataSet(name); if (psNewLevel == NULL) { debug(LOG_WZ, "Dataset %s not found - trying to load as WRF", name); return levLoadSingleWRF(name); } debug(LOG_WZ, "** Data set found is %s type %d", psNewLevel->pName, (int)psNewLevel->type); /* Keep a copy of the present level name */ sstrcpy(currentLevelName, name); bCamChangeSaveGame = false; if (pSaveName && saveType == GTYPE_SAVE_START) { if (psNewLevel->psChange != NULL) { bCamChangeSaveGame = true; debug(LOG_WZ, "** CAMCHANGE FOUND"); } } // select the change dataset if there is one psChangeLevel = NULL; if (((psNewLevel->psChange != NULL) && (psCurrLevel != NULL)) || bCamChangeSaveGame) { //store the level name debug(LOG_WZ, "Found CAMCHANGE dataset"); psChangeLevel = psNewLevel; psNewLevel = psNewLevel->psChange; } // ensure the correct dataset is loaded if (psNewLevel->type == LDS_CAMPAIGN) { debug(LOG_ERROR, "Cannot load a campaign dataset (%s)", psNewLevel->pName); return false; } else { if (psCurrLevel != NULL) { if ((psCurrLevel->psBaseData != psNewLevel->psBaseData) || (psCurrLevel->type < LDS_NONE && psNewLevel->type >= LDS_NONE) || (psCurrLevel->type >= LDS_NONE && psNewLevel->type < LDS_NONE)) { // there is a dataset loaded but it isn't the correct one debug(LOG_WZ, "Incorrect base dataset loaded (%p != %p, %d - %d)", psCurrLevel->psBaseData, psNewLevel->psBaseData, (int)psCurrLevel->type, (int)psNewLevel->type); if (!levReleaseAll()) // this sets psCurrLevel to NULL { return false; } } else { debug(LOG_WZ, "Correct base dataset already loaded."); } } // setup the correct dataset to load if necessary if (psCurrLevel == NULL) { if (psNewLevel->psBaseData != NULL) { debug(LOG_WZ, "Setting base dataset to load: %s", psNewLevel->psBaseData->pName); } psBaseData = psNewLevel->psBaseData; } else { debug(LOG_WZ, "No base dataset to load"); psBaseData = NULL; } } setCurrentMap(psNewLevel->pName, psNewLevel->players); if (!rebuildSearchPath(psNewLevel->dataDir, true)) { return false; } // reset the old mission data if necessary if (psCurrLevel != NULL) { debug(LOG_WZ, "Reseting old mission data"); if (!levReleaseMissionData()) { return false; } } // need to free the current map and droids etc for a save game if ((psBaseData == NULL) && (pSaveName != NULL)) { if (!saveGameReset()) { return false; } } // initialise if necessary if (psNewLevel->type == LDS_COMPLETE || //psNewLevel->type >= LDS_MULTI_TYPE_START || psBaseData != NULL) { debug(LOG_WZ, "Calling stageOneInitialise!"); if (!stageOneInitialise()) { return false; } } // load up a base dataset if necessary if (psBaseData != NULL) { debug(LOG_WZ, "Loading base dataset %s", psBaseData->pName); for(i=0; i<LEVEL_MAXFILES; i++) { if (psBaseData->apDataFiles[i]) { // load the data debug(LOG_WZ, "Loading [directory: %s] %s ...", PHYSFS_getRealDir(psBaseData->apDataFiles[i]), psBaseData->apDataFiles[i]); if (!resLoad(psBaseData->apDataFiles[i], i)) { return false; } } } } if (psNewLevel->type == LDS_CAMCHANGE) { if (!campaignReset()) { return false; } } if (psNewLevel->game == -1) //no .gam file to load - BETWEEN missions (for Editor games only) { ASSERT( psNewLevel->type == LDS_BETWEEN, "levLoadData: only BETWEEN missions do not need a .gam file" ); debug(LOG_WZ, "No .gam file for level: BETWEEN mission"); if (pSaveName != NULL) { if (psBaseData != NULL) { if (!stageTwoInitialise()) { return false; } } //set the mission type before the saveGame data is loaded if (saveType == GTYPE_SAVE_MIDMISSION) { debug(LOG_WZ, "Init mission stuff"); if (!startMissionSave(psNewLevel->type)) { return false; } debug(LOG_NEVER, "dataSetSaveFlag"); dataSetSaveFlag(); } debug(LOG_NEVER, "Loading savegame: %s", pSaveName); if (!loadGame(pSaveName, false, true,true)) { return false; } } if ((pSaveName == NULL) || (saveType == GTYPE_SAVE_START)) { debug(LOG_NEVER, "Start mission - no .gam"); if (!startMission((LEVEL_TYPE)psNewLevel->type, NULL)) { return false; } } } //we need to load up the save game data here for a camchange if (bCamChangeSaveGame) { if (pSaveName != NULL) { if (psBaseData != NULL) { if (!stageTwoInitialise()) { return false; } } debug(LOG_NEVER, "loading savegame: %s", pSaveName); if (!loadGame(pSaveName, false, true,true)) { return false; } if (!campaignReset()) { return false; } } } // load the new data debug(LOG_NEVER, "Loading mission dataset: %s", psNewLevel->pName); for(i=0; i < LEVEL_MAXFILES; i++) { if (psNewLevel->game == i) { // do some more initialising if necessary if (psNewLevel->type == LDS_COMPLETE || psNewLevel->type >= LDS_MULTI_TYPE_START || (psBaseData != NULL && !bCamChangeSaveGame)) { if (!stageTwoInitialise()) { return false; } } // load a savegame if there is one - but not if already done so if (pSaveName != NULL && !bCamChangeSaveGame) { //set the mission type before the saveGame data is loaded if (saveType == GTYPE_SAVE_MIDMISSION) { debug(LOG_WZ, "Init mission stuff"); if (!startMissionSave(psNewLevel->type)) { return false; } debug(LOG_NEVER, "dataSetSaveFlag"); dataSetSaveFlag(); } debug(LOG_NEVER, "Loading save game %s", pSaveName); if (!loadGame(pSaveName, false, true,true)) { return false; } } if ((pSaveName == NULL) || (saveType == GTYPE_SAVE_START)) { // load the game debug(LOG_WZ, "Loading scenario file %s", psNewLevel->apDataFiles[i]); switch (psNewLevel->type) { case LDS_COMPLETE: case LDS_CAMSTART: debug(LOG_WZ, "LDS_COMPLETE / LDS_CAMSTART"); if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i])) { return false; } break; case LDS_BETWEEN: debug(LOG_WZ, "LDS_BETWEEN"); if (!startMission(LDS_BETWEEN, psNewLevel->apDataFiles[i])) { return false; } break; case LDS_MKEEP: debug(LOG_WZ, "LDS_MKEEP"); if (!startMission(LDS_MKEEP, psNewLevel->apDataFiles[i])) { return false; } break; case LDS_CAMCHANGE: debug(LOG_WZ, "LDS_CAMCHANGE"); if (!startMission(LDS_CAMCHANGE, psNewLevel->apDataFiles[i])) { return false; } break; case LDS_EXPAND: debug(LOG_WZ, "LDS_EXPAND"); if (!startMission(LDS_EXPAND, psNewLevel->apDataFiles[i])) { return false; } break; case LDS_EXPAND_LIMBO: debug(LOG_WZ, "LDS_LIMBO"); if (!startMission(LDS_EXPAND_LIMBO, psNewLevel->apDataFiles[i])) { return false; } break; case LDS_MCLEAR: debug(LOG_WZ, "LDS_MCLEAR"); if (!startMission(LDS_MCLEAR, psNewLevel->apDataFiles[i])) { return false; } break; case LDS_MKEEP_LIMBO: debug(LOG_WZ, "LDS_MKEEP_LIMBO"); if (!startMission(LDS_MKEEP_LIMBO, psNewLevel->apDataFiles[i])) { return false; } break; default: ASSERT( psNewLevel->type >= LDS_MULTI_TYPE_START, "levLoadData: Unexpected mission type" ); debug(LOG_WZ, "default (MULTIPLAYER)"); if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i])) { return false; } break; } } } else if (psNewLevel->apDataFiles[i]) { // load the data debug(LOG_WZ, "Loading %s", psNewLevel->apDataFiles[i]); if (!resLoad(psNewLevel->apDataFiles[i], i + CURRENT_DATAID)) { return false; } } } if (pSaveName != NULL) { //load MidMission Extras if (!loadMissionExtras(pSaveName, psNewLevel->type)) { return false; } } if (pSaveName != NULL && saveType == GTYPE_SAVE_MIDMISSION) { //load script stuff // load the event system state here for a save game debug(LOG_NEVER, "Loading script system state"); if (!loadScriptState(pSaveName)) { return false; } } if (!stageThreeInitialise()) { return false; } dataClearSaveFlag(); //this enables us to to start cam2/cam3 without going via a save game and get the extra droids //in from the script-controlled Transporters if (!pSaveName && psNewLevel->type == LDS_CAMSTART) { eventFireCallbackTrigger((TRIGGER_TYPE)CALL_NO_REINFORCEMENTS_LEFT); } //restore the level name for comparisons on next mission load up if (psChangeLevel == NULL) { psCurrLevel = psNewLevel; } else { psCurrLevel = psChangeLevel; } { // Copy this info to be used by the crash handler for the dump file char buf[256]; ssprintf(buf, "Current Level/map is %s", psCurrLevel->pName); addDumpInfo(buf); } return true; }
// load up the data for a level bool levLoadData(char const *name, Sha256 const *hash, char *pSaveName, GAME_TYPE saveType) { LEVEL_DATASET *psNewLevel, *psBaseData, *psChangeLevel; bool bCamChangeSaveGame; debug(LOG_WZ, "Loading level %s hash %s (%s, type %d)", name, hash == nullptr ? "builtin" : hash->toString().c_str(), pSaveName, (int)saveType); if (saveType == GTYPE_SAVE_START || saveType == GTYPE_SAVE_MIDMISSION) { if (!levReleaseAll()) { debug(LOG_ERROR, "Failed to unload old data"); return false; } } levelLoadType = saveType; // find the level dataset psNewLevel = levFindDataSet(name, hash); if (psNewLevel == nullptr) { debug(LOG_INFO, "Dataset %s not found - trying to load as WRF", name); return levLoadSingleWRF(name); } debug(LOG_WZ, "** Data set found is %s type %d", psNewLevel->pName, (int)psNewLevel->type); /* Keep a copy of the present level name */ sstrcpy(currentLevelName, name); bCamChangeSaveGame = false; if (pSaveName && saveType == GTYPE_SAVE_START) { if (psNewLevel->psChange != nullptr) { bCamChangeSaveGame = true; debug(LOG_WZ, "** CAMCHANGE FOUND"); } } // select the change dataset if there is one psChangeLevel = nullptr; if (((psNewLevel->psChange != nullptr) && (psCurrLevel != nullptr)) || bCamChangeSaveGame) { //store the level name debug(LOG_WZ, "Found CAMCHANGE dataset"); psChangeLevel = psNewLevel; psNewLevel = psNewLevel->psChange; } // ensure the correct dataset is loaded if (psNewLevel->type == LDS_CAMPAIGN) { debug(LOG_ERROR, "Cannot load a campaign dataset (%s)", psNewLevel->pName); return false; } else { if (psCurrLevel != nullptr) { if ((psCurrLevel->psBaseData != psNewLevel->psBaseData) || (psCurrLevel->type < LDS_NONE && psNewLevel->type >= LDS_NONE) || (psCurrLevel->type >= LDS_NONE && psNewLevel->type < LDS_NONE)) { // there is a dataset loaded but it isn't the correct one debug(LOG_WZ, "Incorrect base dataset loaded (%p != %p, %d - %d)", psCurrLevel->psBaseData, psNewLevel->psBaseData, (int)psCurrLevel->type, (int)psNewLevel->type); if (!levReleaseAll()) // this sets psCurrLevel to NULL { debug(LOG_ERROR, "Failed to release old data"); return false; } } else { debug(LOG_WZ, "Correct base dataset already loaded."); } } // setup the correct dataset to load if necessary if (psCurrLevel == nullptr) { if (psNewLevel->psBaseData != nullptr) { debug(LOG_WZ, "Setting base dataset to load: %s", psNewLevel->psBaseData->pName); } psBaseData = psNewLevel->psBaseData; } else { debug(LOG_WZ, "No base dataset to load"); psBaseData = nullptr; } } if (!rebuildSearchPath(psNewLevel->dataDir, true, psNewLevel->realFileName)) { debug(LOG_ERROR, "Failed to rebuild search path"); return false; } // reset the old mission data if necessary if (psCurrLevel != nullptr) { debug(LOG_WZ, "Reseting old mission data"); if (!levReleaseMissionData()) { debug(LOG_ERROR, "Failed to unload old mission data"); return false; } } // need to free the current map and droids etc for a save game if (psBaseData == nullptr && pSaveName != nullptr) { if (!saveGameReset()) { debug(LOG_ERROR, "Failed to saveGameReset()!"); return false; } } // initialise if necessary if (psNewLevel->type == LDS_COMPLETE || psBaseData != nullptr) { debug(LOG_WZ, "Calling stageOneInitialise!"); if (!stageOneInitialise()) { debug(LOG_ERROR, "Failed stageOneInitialise!"); return false; } } // load up a base dataset if necessary if (psBaseData != nullptr) { debug(LOG_WZ, "Loading base dataset %s", psBaseData->pName); for (int i = 0; i < LEVEL_MAXFILES; i++) { if (psBaseData->apDataFiles[i]) { // load the data debug(LOG_WZ, "Loading [directory: %s] %s ...", PHYSFS_getRealDir(psBaseData->apDataFiles[i]), psBaseData->apDataFiles[i]); if (!resLoad(psBaseData->apDataFiles[i], i)) { debug(LOG_ERROR, "Failed resLoad(%s)!", psBaseData->apDataFiles[i]); return false; } } } } if (psNewLevel->type == LDS_CAMCHANGE) { if (!campaignReset()) { debug(LOG_ERROR, "Failed campaignReset()!"); return false; } } if (psNewLevel->game == -1) //no .gam file to load - BETWEEN missions (for Editor games only) { ASSERT(psNewLevel->type == LDS_BETWEEN, "Only BETWEEN missions do not need a .gam file"); debug(LOG_WZ, "No .gam file for level: BETWEEN mission"); if (pSaveName != nullptr) { if (psBaseData != nullptr) { if (!stageTwoInitialise()) { debug(LOG_ERROR, "Failed stageTwoInitialise()!"); return false; } } //set the mission type before the saveGame data is loaded if (saveType == GTYPE_SAVE_MIDMISSION) { debug(LOG_WZ, "Init mission stuff"); if (!startMissionSave(psNewLevel->type)) { debug(LOG_ERROR, "Failed startMissionSave(%d)!", psNewLevel->type); return false; } debug(LOG_NEVER, "dataSetSaveFlag"); dataSetSaveFlag(); } debug(LOG_NEVER, "Loading savegame: %s", pSaveName); if (!loadGame(pSaveName, false, true, true)) { debug(LOG_ERROR, "Failed loadGame(%s)!", pSaveName); return false; } } if (pSaveName == nullptr || saveType == GTYPE_SAVE_START) { debug(LOG_NEVER, "Start mission - no .gam"); if (!startMission((LEVEL_TYPE)psNewLevel->type, nullptr)) { debug(LOG_ERROR, "Failed startMission(%d)!", psNewLevel->type); return false; } } } //we need to load up the save game data here for a camchange if (bCamChangeSaveGame) { if (pSaveName != nullptr) { if (psBaseData != nullptr) { if (!stageTwoInitialise()) { debug(LOG_ERROR, "Failed stageTwoInitialise() [camchange]!"); return false; } } debug(LOG_NEVER, "loading savegame: %s", pSaveName); if (!loadGame(pSaveName, false, true, true)) { debug(LOG_ERROR, "Failed loadGame(%s)!", pSaveName); return false; } campaignReset(); } } // load the new data debug(LOG_NEVER, "Loading mission dataset: %s", psNewLevel->pName); for (int i = 0; i < LEVEL_MAXFILES; i++) { if (psNewLevel->game == i) { // do some more initialising if necessary if (psNewLevel->type == LDS_COMPLETE || psNewLevel->type >= LDS_MULTI_TYPE_START || (psBaseData != nullptr && !bCamChangeSaveGame)) { if (!stageTwoInitialise()) { debug(LOG_ERROR, "Failed stageTwoInitialise() [newdata]!"); return false; } } // load a savegame if there is one - but not if already done so if (pSaveName != nullptr && !bCamChangeSaveGame) { //set the mission type before the saveGame data is loaded if (saveType == GTYPE_SAVE_MIDMISSION) { debug(LOG_WZ, "Init mission stuff"); if (!startMissionSave(psNewLevel->type)) { debug(LOG_ERROR, "Failed startMissionSave(%d)!", psNewLevel->type); return false; } debug(LOG_NEVER, "dataSetSaveFlag"); dataSetSaveFlag(); } debug(LOG_NEVER, "Loading save game %s", pSaveName); if (!loadGame(pSaveName, false, true, true)) { debug(LOG_ERROR, "Failed loadGame(%s)!", pSaveName); return false; } } if (pSaveName == nullptr || saveType == GTYPE_SAVE_START) { // load the game debug(LOG_WZ, "Loading scenario file %s", psNewLevel->apDataFiles[i]); switch (psNewLevel->type) { case LDS_COMPLETE: case LDS_CAMSTART: debug(LOG_WZ, "LDS_COMPLETE / LDS_CAMSTART"); if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_CAMSTART, psNewLevel->apDataFiles[i]); return false; } break; case LDS_BETWEEN: debug(LOG_WZ, "LDS_BETWEEN"); if (!startMission(LDS_BETWEEN, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_BETWEEN, psNewLevel->apDataFiles[i]); return false; } break; case LDS_MKEEP: debug(LOG_WZ, "LDS_MKEEP"); if (!startMission(LDS_MKEEP, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MKEEP, psNewLevel->apDataFiles[i]); return false; } break; case LDS_CAMCHANGE: debug(LOG_WZ, "LDS_CAMCHANGE"); if (!startMission(LDS_CAMCHANGE, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_CAMCHANGE, psNewLevel->apDataFiles[i]); return false; } break; case LDS_EXPAND: debug(LOG_WZ, "LDS_EXPAND"); if (!startMission(LDS_EXPAND, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_EXPAND, psNewLevel->apDataFiles[i]); return false; } break; case LDS_EXPAND_LIMBO: debug(LOG_WZ, "LDS_LIMBO"); if (!startMission(LDS_EXPAND_LIMBO, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_EXPAND_LIMBO, psNewLevel->apDataFiles[i]); return false; } break; case LDS_MCLEAR: debug(LOG_WZ, "LDS_MCLEAR"); if (!startMission(LDS_MCLEAR, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MCLEAR, psNewLevel->apDataFiles[i]); return false; } break; case LDS_MKEEP_LIMBO: debug(LOG_WZ, "LDS_MKEEP_LIMBO"); if (!startMission(LDS_MKEEP_LIMBO, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s)!", LDS_MKEEP_LIMBO, psNewLevel->apDataFiles[i]); return false; } break; default: ASSERT(psNewLevel->type >= LDS_MULTI_TYPE_START, "Unexpected mission type"); debug(LOG_WZ, "default (MULTIPLAYER)"); if (!startMission(LDS_CAMSTART, psNewLevel->apDataFiles[i])) { debug(LOG_ERROR, "Failed startMission(%d, %s) (default)!", LDS_CAMSTART, psNewLevel->apDataFiles[i]); return false; } break; } } } else if (psNewLevel->apDataFiles[i]) { // load the data debug(LOG_WZ, "Loading %s", psNewLevel->apDataFiles[i]); if (!resLoad(psNewLevel->apDataFiles[i], i + CURRENT_DATAID)) { debug(LOG_ERROR, "Failed resLoad(%s, %d) (default)!", psNewLevel->apDataFiles[i], i + CURRENT_DATAID); return false; } } } if (bMultiPlayer) { // This calls resLoadFile("SMSG", "multiplay.txt"). Must be before loadMissionExtras, which calls loadSaveMessage, which calls getViewData. loadMultiScripts(); } if (pSaveName != nullptr) { //load MidMission Extras if (!loadMissionExtras(pSaveName, psNewLevel->type)) { debug(LOG_ERROR, "Failed loadMissionExtras(%s, %d)!", pSaveName, psNewLevel->type); return false; } } if (pSaveName != nullptr && saveType == GTYPE_SAVE_MIDMISSION) { //load script stuff // load the event system state here for a save game debug(LOG_SAVE, "Loading script system state"); if (!loadScriptState(pSaveName)) { debug(LOG_ERROR, "Failed loadScriptState(%s)!", pSaveName); return false; } } if (!stageThreeInitialise()) { debug(LOG_ERROR, "Failed stageThreeInitialise()!"); return false; } dataClearSaveFlag(); //this enables us to to start cam2/cam3 without going via a save game and get the extra droids //in from the script-controlled Transporters if (!pSaveName && psNewLevel->type == LDS_CAMSTART) { eventFireCallbackTrigger((TRIGGER_TYPE)CALL_NO_REINFORCEMENTS_LEFT); } //restore the level name for comparisons on next mission load up if (psChangeLevel == nullptr) { psCurrLevel = psNewLevel; } else { psCurrLevel = psChangeLevel; } // Copy this info to be used by the crash handler for the dump file char buf[256]; ssprintf(buf, "Current Level/map is %s", psCurrLevel->pName); addDumpInfo(buf); triggerEvent(TRIGGER_GAME_LOADED); if (autogame_enabled()) { gameTimeSetMod(Rational(500)); if (hostlaunch != 2) // tests will specify the AI manually { jsAutogameSpecific("multiplay/skirmish/semperfi.js", selectedPlayer); } } return true; }
State onMainMenu(Game* game) { int choice = 0; char cmd[255]; char userInput[255]; cmd[0] = 0; /* Print initial Main Menu */ printMainMenu(game); /* get choices: Possible choices are New Game, Load Game, Set up board, How to play */ choice = getInput(); /* Added by Cesar 1/26/2014 */ /* handling the cases mentioned above */ switch(choice){ case 0: /* Start a new game */ return NewGame; case 1: /* Load an old game */ printf("Enter the file name you want to load: "); scanf("%s", userInput); printf("\n"); fseek(stdin,0,SEEK_END); loadGame(game, userInput); return NewGame; case 2: /* Setup custom board */ while(cmd[0]!='0') { /* printf("Enter the file name you want to save \n"); scanf("%s", userInput); saveLog(game, userInput); fseek(stdin,0,SEEK_END); */ printBoard(game); printf("Please input move to move piece (input 0 to start game): "); getGameInput(cmd); printf("\n"); directMoveNotation(game, cmd); } return NewGame; case 3: /* How to play */ printRules(); return MainMenu; case 4: /* Reset board/game */ resetGame(game); printf("Board/game has been reset.\n\n"); return MainMenu; case 5: /* displays help */ help(); return MainMenu; case 9: return Exit; default: return MainMenu; } /* end code added by Cesar */ /* old code, commented out on 1/26/2014 switch(choice) { case 0: return NewGame; case 1: loadGame(game); return NewGame; case 2: game->setting->allowRedo ^= 1; return MainMenu; case 3: game->setting->allowIllegalMove ^= 1; return MainMenu; case 4: selectOpponent(game); return MainMenu; case 5: selectDifficulty(game); return MainMenu; case 6: return Exit; default: return MainMenu; } End old code */ }
void Menu::on_btnLoad_clicked() { emit loadGame(); hide(); }