X-Git-Url: https://git.artsoft.org/?a=blobdiff_plain;f=src%2Fgame.c;h=d4cc5ea8e0c5572bb737e62cb9202bdad128b344;hb=ef596d6fab46df4658603046b589b3e21bda9bca;hp=574d394f12dbce661af48c7ac3dad1762bac55b8;hpb=009c5cf7cf504775f90e2223241fe19131182e96;p=rocksndiamonds.git diff --git a/src/game.c b/src/game.c index 574d394f..d4cc5ea8 100644 --- a/src/game.c +++ b/src/game.c @@ -1106,7 +1106,7 @@ void ContinueMoving(int, int); void Bang(int, int); void InitMovDir(int, int); void InitAmoebaNr(int, int); -void NewHighScore(int); +void NewHighScore(int, boolean); void TestIfGoodThingHitsBadThing(int, int, int); void TestIfBadThingHitsGoodThing(int, int, int); @@ -3542,7 +3542,6 @@ void InitGame(void) int fade_mask = REDRAW_FIELD; boolean emulate_bd = TRUE; // unless non-BOULDERDASH elements found - boolean emulate_sb = TRUE; // unless non-SOKOBAN elements found boolean emulate_sp = TRUE; // unless non-SUPAPLEX elements found int initial_move_dir = MV_DOWN; int i, j, x, y; @@ -3886,8 +3885,6 @@ void InitGame(void) { if (emulate_bd && !IS_BD_ELEMENT(Tile[x][y])) emulate_bd = FALSE; - if (emulate_sb && !IS_SB_ELEMENT(Tile[x][y])) - emulate_sb = FALSE; if (emulate_sp && !IS_SP_ELEMENT(Tile[x][y])) emulate_sp = FALSE; @@ -3912,7 +3909,6 @@ void InitGame(void) } game.emulation = (emulate_bd ? EMU_BOULDERDASH : - emulate_sb ? EMU_SOKOBAN : emulate_sp ? EMU_SUPAPLEX : EMU_NONE); // initialize type of slippery elements @@ -4700,6 +4696,40 @@ void InitAmoebaNr(int x, int y) AmoebaCnt2[group_nr]++; } +static void LevelSolved_SetFinalGameValues(void) +{ + game.time_final = (game.no_time_limit ? TimePlayed : TimeLeft); + game.score_time_final = (level.use_step_counter ? TimePlayed : + TimePlayed * FRAMES_PER_SECOND + TimeFrames); + + game.score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ? + game_em.lev->score : + level.game_engine_type == GAME_ENGINE_TYPE_MM ? + game_mm.score : + game.score); + + game.health_final = (level.game_engine_type == GAME_ENGINE_TYPE_MM ? + MM_HEALTH(game_mm.laser_overload_value) : + game.health); + + game.LevelSolved_CountingTime = game.time_final; + game.LevelSolved_CountingScore = game.score_final; + game.LevelSolved_CountingHealth = game.health_final; +} + +static void LevelSolved_DisplayFinalGameValues(int time, int score, int health) +{ + game.LevelSolved_CountingTime = time; + game.LevelSolved_CountingScore = score; + game.LevelSolved_CountingHealth = health; + + game_panel_controls[GAME_PANEL_TIME].value = time; + game_panel_controls[GAME_PANEL_SCORE].value = score; + game_panel_controls[GAME_PANEL_HEALTH].value = health; + + DisplayGameControlValues(); +} + static void LevelSolved(void) { if (level.game_engine_type == GAME_ENGINE_TYPE_RND && @@ -4708,6 +4738,9 @@ static void LevelSolved(void) game.LevelSolved = TRUE; game.GameOver = TRUE; + + // needed here to display correct panel values while player walks into exit + LevelSolved_SetFinalGameValues(); } void GameWon(void) @@ -4730,23 +4763,8 @@ void GameWon(void) if (local_player->active && local_player->MovPos) return; - game.time_final = (game.no_time_limit ? TimePlayed : TimeLeft); - game.score_time_final = (level.use_step_counter ? TimePlayed : - TimePlayed * FRAMES_PER_SECOND + TimeFrames); - - game.score_final = (level.game_engine_type == GAME_ENGINE_TYPE_EM ? - game_em.lev->score : - level.game_engine_type == GAME_ENGINE_TYPE_MM ? - game_mm.score : - game.score); - - game.health_final = (level.game_engine_type == GAME_ENGINE_TYPE_MM ? - MM_HEALTH(game_mm.laser_overload_value) : - game.health); - - game.LevelSolved_CountingTime = game.time_final; - game.LevelSolved_CountingScore = game.score_final; - game.LevelSolved_CountingHealth = game.health_final; + // calculate final game values after player finished walking into exit + LevelSolved_SetFinalGameValues(); game.LevelSolved_GameWon = TRUE; game.LevelSolved_SaveTape = tape.recording; @@ -4772,6 +4790,10 @@ void GameWon(void) score = score_final = game.score_final; health = health_final = game.health_final; + // update game panel values before (delayed) counting of score (if any) + LevelSolved_DisplayFinalGameValues(time, score, health); + + // if level has time score defined, calculate new final game values if (time_score > 0) { int time_final_max = 999; @@ -4805,18 +4827,13 @@ void GameWon(void) game.health_final = health_final; } + // if not counting score after game, immediately update game panel values if (level_editor_test_game || !setup.count_score_after_game) { time = time_final; score = score_final; - game.LevelSolved_CountingTime = time; - game.LevelSolved_CountingScore = score; - - game_panel_controls[GAME_PANEL_TIME].value = time; - game_panel_controls[GAME_PANEL_SCORE].value = score; - - DisplayGameControlValues(); + LevelSolved_DisplayFinalGameValues(time, score, health); } if (level.game_engine_type == GAME_ENGINE_TYPE_RND) @@ -4893,13 +4910,7 @@ void GameWon(void) if (time == time_final) score = score_final; - game.LevelSolved_CountingTime = time; - game.LevelSolved_CountingScore = score; - - game_panel_controls[GAME_PANEL_TIME].value = time; - game_panel_controls[GAME_PANEL_SCORE].value = score; - - DisplayGameControlValues(); + LevelSolved_DisplayFinalGameValues(time, score, health); if (time == time_final) StopSound(SND_GAME_LEVELTIME_BONUS); @@ -4925,13 +4936,7 @@ void GameWon(void) health += health_count_dir; score += time_score; - game.LevelSolved_CountingHealth = health; - game.LevelSolved_CountingScore = score; - - game_panel_controls[GAME_PANEL_HEALTH].value = health; - game_panel_controls[GAME_PANEL_SCORE].value = score; - - DisplayGameControlValues(); + LevelSolved_DisplayFinalGameValues(time, score, health); if (health == health_final) StopSound(SND_GAME_LEVELTIME_BONUS); @@ -4960,6 +4965,7 @@ void GameEnd(void) { // used instead of "level_nr" (needed for network games) int last_level_nr = levelset.level_nr; + boolean tape_saved = FALSE; game.LevelSolved_GameEnd = TRUE; @@ -4969,7 +4975,8 @@ void GameEnd(void) if (!global.use_envelope_request) CloseDoor(DOOR_CLOSE_1); - SaveTapeChecked_LevelSolved(tape.level_nr); // ask to save tape + // ask to save tape + tape_saved = SaveTapeChecked_LevelSolved(tape.level_nr); // set unique basename for score tape (also saved in high score table) strcpy(tape.score_tape_basename, getScoreTapeBasename(setup.player_name)); @@ -5004,7 +5011,7 @@ void GameEnd(void) } // save score and score tape before potentially erasing tape below - NewHighScore(last_level_nr); + NewHighScore(last_level_nr, tape_saved); if (setup.increment_levels && level_nr < leveldir_current->last_level && @@ -5112,7 +5119,7 @@ static int addScoreEntry(struct ScoreInfo *list, struct ScoreEntry *new_entry, return -1; } -void NewHighScore(int level_nr) +void NewHighScore(int level_nr, boolean tape_saved) { struct ScoreEntry new_entry = {{ 0 }}; // (prevent warning from GCC bug 53119) boolean one_per_name = FALSE; @@ -5127,19 +5134,37 @@ void NewHighScore(int level_nr) scores.last_added = addScoreEntry(&scores, &new_entry, one_per_name); - if (scores.last_added >= 0) - { - SaveScore(level_nr); + if (scores.last_added < 0) + return; - // store last added local score entry (before merging server scores) - scores.last_added_local = scores.last_added; - } + SaveScore(level_nr); - if (game.LevelSolved_SaveTape) + // store last added local score entry (before merging server scores) + scores.last_added_local = scores.last_added; + + if (!game.LevelSolved_SaveTape) + return; + + SaveScoreTape(level_nr); + + if (setup.ask_for_using_api_server) { - SaveScoreTape(level_nr); - SaveServerScore(level_nr); + setup.use_api_server = + Request("Upload your score and tape to the high score server?", REQ_ASK); + + if (!setup.use_api_server) + Request("Not using high score server! Use setup menu to enable again!", + REQ_CONFIRM); + + runtime.use_api_server = setup.use_api_server; + + // after asking for using API server once, do not ask again + setup.ask_for_using_api_server = FALSE; + + SaveSetup_ServerSetup(); } + + SaveServerScore(level_nr, tape_saved); } void MergeServerScore(void) @@ -11706,7 +11731,7 @@ static void GameActionsExt(void) Warn("element '%s' caused endless loop in game engine", EL_NAME(recursion_loop_element)); - RequestQuitGameExt(FALSE, level_editor_test_game, message); + RequestQuitGameExt(program.headless, level_editor_test_game, message); recursion_loop_detected = FALSE; // if game should be continued @@ -13963,7 +13988,11 @@ static void TestFieldAfterSnapping(int x, int y, int element, int direction, if (level.finish_dig_collect) { int dig_side = MV_DIR_OPPOSITE(direction); + int change_event = (IS_DIGGABLE(element) ? CE_PLAYER_DIGS_X : + CE_PLAYER_COLLECTS_X); + CheckTriggeredElementChangeByPlayer(x, y, element, change_event, + player_index_bit, dig_side); CheckTriggeredElementChangeByPlayer(x, y, element, CE_PLAYER_SNAPS_X, player_index_bit, dig_side); } @@ -14527,7 +14556,7 @@ static int DigField(struct PlayerInfo *player, if (sokoban_task_solved && game.sokoban_fields_still_needed == 0 && game.sokoban_objects_still_needed == 0 && - (game.emulation == EMU_SOKOBAN || level.auto_exit_sokoban)) + level.auto_exit_sokoban) { game.players_still_needed = 0; @@ -16157,12 +16186,18 @@ static void UnmapGameButtonsAtSamePosition(int id) static void UnmapGameButtonsAtSamePosition_All(void) { - if (setup.show_snapshot_buttons) + if (setup.show_load_save_buttons) { UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_SAVE); UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PAUSE2); UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_LOAD); } + else if (setup.show_undo_redo_buttons) + { + UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_UNDO); + UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_PAUSE2); + UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_REDO); + } else { UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_STOP); @@ -16175,17 +16210,13 @@ static void UnmapGameButtonsAtSamePosition_All(void) } } -static void MapGameButtonsAtSamePosition(int id) +void MapLoadSaveButtons(void) { - int i; - - for (i = 0; i < NUM_GAME_BUTTONS; i++) - if (i != id && - gamebutton_info[i].pos->x == gamebutton_info[id].pos->x && - gamebutton_info[i].pos->y == gamebutton_info[id].pos->y) - MapGadget(game_gadget[i]); + UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_LOAD); + UnmapGameButtonsAtSamePosition(GAME_CTRL_ID_SAVE); - UnmapGameButtonsAtSamePosition_All(); + MapGadget(game_gadget[GAME_CTRL_ID_LOAD]); + MapGadget(game_gadget[GAME_CTRL_ID_SAVE]); } void MapUndoRedoButtons(void) @@ -16197,15 +16228,6 @@ void MapUndoRedoButtons(void) MapGadget(game_gadget[GAME_CTRL_ID_REDO]); } -void UnmapUndoRedoButtons(void) -{ - UnmapGadget(game_gadget[GAME_CTRL_ID_UNDO]); - UnmapGadget(game_gadget[GAME_CTRL_ID_REDO]); - - MapGameButtonsAtSamePosition(GAME_CTRL_ID_UNDO); - MapGameButtonsAtSamePosition(GAME_CTRL_ID_REDO); -} - void ModifyPauseButtons(void) { static int ids[] = @@ -16227,9 +16249,7 @@ static void MapGameButtonsExt(boolean on_tape) int i; for (i = 0; i < NUM_GAME_BUTTONS; i++) - if ((!on_tape || gamebutton_info[i].allowed_on_tape) && - i != GAME_CTRL_ID_UNDO && - i != GAME_CTRL_ID_REDO) + if (!on_tape || gamebutton_info[i].allowed_on_tape) MapGadget(game_gadget[i]); UnmapGameButtonsAtSamePosition_All(); @@ -16321,6 +16341,8 @@ static void GameUndoRedoExt(void) DrawVideoDisplay(VIDEO_STATE_FRAME_ON, FrameCounter); DrawVideoDisplay(VIDEO_STATE_1STEP(tape.single_step), 0); + ModifyPauseButtons(); + BackToFront(); } @@ -16329,8 +16351,12 @@ static void GameUndo(int steps) if (!CheckEngineSnapshotList()) return; + int tape_property_bits = tape.property_bits; + LoadEngineSnapshot_Undo(steps); + tape.property_bits |= tape_property_bits | TAPE_PROPERTY_SNAPSHOT; + GameUndoRedoExt(); } @@ -16339,8 +16365,12 @@ static void GameRedo(int steps) if (!CheckEngineSnapshotList()) return; + int tape_property_bits = tape.property_bits; + LoadEngineSnapshot_Redo(steps); + tape.property_bits |= tape_property_bits | TAPE_PROPERTY_SNAPSHOT; + GameUndoRedoExt(); }