+ case SAMPLE_door:
+ PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
+ break;
+
+ case SAMPLE_exit_open:
+ PlayLevelSoundElementAction(x, y, element, ACTION_OPENING);
+ break;
+
+ case SAMPLE_exit_leave:
+ PlayLevelSoundElementAction(x, y, element, ACTION_PASSING);
+ break;
+
+ case SAMPLE_dynamite:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DROPPING);
+ break;
+
+ case SAMPLE_tick:
+ PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
+ break;
+
+ case SAMPLE_press:
+ PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVATING);
+ break;
+
+ case SAMPLE_wheel:
+ PlayLevelSoundElementAction(x, y, element, ACTION_ACTIVE);
+ break;
+
+ case SAMPLE_boom:
+ PlayLevelSoundElementAction(x, y, element, ACTION_EXPLODING);
+ break;
+
+ case SAMPLE_die:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DYING);
+ break;
+
+ case SAMPLE_time:
+ PlaySound(SND_GAME_RUNNING_OUT_OF_TIME);
+ break;
+
+ default:
+ PlayLevelSoundElementAction(x, y, element, ACTION_DEFAULT);
+ break;
+ }
+}
+
+void PlayLevelSound_SP(int xx, int yy, int element_sp, int action_sp)
+{
+ int element = map_element_SP_to_RND(element_sp);
+ int action = map_action_SP_to_RND(action_sp);
+ int offset = (setup.sp_show_border_elements ? 0 : 1);
+ int x = xx - offset;
+ int y = yy - offset;
+
+ PlayLevelSoundElementAction(x, y, element, action);
+}
+
+void RaiseScore(int value)
+{
+ local_player->score += value;
+
+ game_panel_controls[GAME_PANEL_SCORE].value = local_player->score;
+
+ DisplayGameControlValues();
+}
+
+void RaiseScoreElement(int element)
+{
+ switch (element)
+ {
+ case EL_EMERALD:
+ case EL_BD_DIAMOND:
+ case EL_EMERALD_YELLOW:
+ case EL_EMERALD_RED:
+ case EL_EMERALD_PURPLE:
+ case EL_SP_INFOTRON:
+ RaiseScore(level.score[SC_EMERALD]);
+ break;
+ case EL_DIAMOND:
+ RaiseScore(level.score[SC_DIAMOND]);
+ break;
+ case EL_CRYSTAL:
+ RaiseScore(level.score[SC_CRYSTAL]);
+ break;
+ case EL_PEARL:
+ RaiseScore(level.score[SC_PEARL]);
+ break;
+ case EL_BUG:
+ case EL_BD_BUTTERFLY:
+ case EL_SP_ELECTRON:
+ RaiseScore(level.score[SC_BUG]);
+ break;
+ case EL_SPACESHIP:
+ case EL_BD_FIREFLY:
+ case EL_SP_SNIKSNAK:
+ RaiseScore(level.score[SC_SPACESHIP]);
+ break;
+ case EL_YAMYAM:
+ case EL_DARK_YAMYAM:
+ RaiseScore(level.score[SC_YAMYAM]);
+ break;
+ case EL_ROBOT:
+ RaiseScore(level.score[SC_ROBOT]);
+ break;
+ case EL_PACMAN:
+ RaiseScore(level.score[SC_PACMAN]);
+ break;
+ case EL_NUT:
+ RaiseScore(level.score[SC_NUT]);
+ break;
+ case EL_DYNAMITE:
+ case EL_EM_DYNAMITE:
+ case EL_SP_DISK_RED:
+ case EL_DYNABOMB_INCREASE_NUMBER:
+ case EL_DYNABOMB_INCREASE_SIZE:
+ case EL_DYNABOMB_INCREASE_POWER:
+ RaiseScore(level.score[SC_DYNAMITE]);
+ break;
+ case EL_SHIELD_NORMAL:
+ case EL_SHIELD_DEADLY:
+ RaiseScore(level.score[SC_SHIELD]);
+ break;
+ case EL_EXTRA_TIME:
+ RaiseScore(level.extra_time_score);
+ break;
+ case EL_KEY_1:
+ case EL_KEY_2:
+ case EL_KEY_3:
+ case EL_KEY_4:
+ case EL_EM_KEY_1:
+ case EL_EM_KEY_2:
+ case EL_EM_KEY_3:
+ case EL_EM_KEY_4:
+ case EL_EMC_KEY_5:
+ case EL_EMC_KEY_6:
+ case EL_EMC_KEY_7:
+ case EL_EMC_KEY_8:
+ case EL_DC_KEY_WHITE:
+ RaiseScore(level.score[SC_KEY]);
+ break;
+ default:
+ RaiseScore(element_info[element].collect_score);
+ break;
+ }
+}
+
+void RequestQuitGameExt(boolean skip_request, boolean quick_quit, char *message)
+{
+ if (skip_request || Request(message, REQ_ASK | REQ_STAY_CLOSED))
+ {
+ /* closing door required in case of envelope style request dialogs */
+ if (!skip_request)
+ CloseDoor(DOOR_CLOSE_1);
+
+#if defined(NETWORK_AVALIABLE)
+ if (options.network)
+ SendToServer_StopPlaying(NETWORK_STOP_BY_PLAYER);
+ else
+#endif
+ {
+ if (quick_quit)
+ FadeSkipNextFadeIn();
+
+ SetGameStatus(GAME_MODE_MAIN);
+
+ DrawMainMenu();
+ }
+ }
+ else /* continue playing the game */
+ {
+ if (tape.playing && tape.deactivate_display)
+ TapeDeactivateDisplayOff(TRUE);
+
+ OpenDoor(DOOR_OPEN_1 | DOOR_COPY_BACK);
+
+ if (tape.playing && tape.deactivate_display)
+ TapeDeactivateDisplayOn();
+ }
+}
+
+void RequestQuitGame(boolean ask_if_really_quit)
+{
+ boolean quick_quit = (!ask_if_really_quit || level_editor_test_game);
+ boolean skip_request = AllPlayersGone || quick_quit;
+
+ RequestQuitGameExt(skip_request, quick_quit,
+ "Do you really want to quit the game?");
+}
+
+
+/* ------------------------------------------------------------------------- */
+/* random generator functions */
+/* ------------------------------------------------------------------------- */
+
+unsigned int InitEngineRandom_RND(int seed)
+{
+ game.num_random_calls = 0;
+
+ return InitEngineRandom(seed);
+}
+
+unsigned int RND(int max)
+{
+ if (max > 0)
+ {
+ game.num_random_calls++;
+
+ return GetEngineRandom(max);
+ }
+
+ return 0;
+}
+
+
+/* ------------------------------------------------------------------------- */
+/* game engine snapshot handling functions */
+/* ------------------------------------------------------------------------- */
+
+struct EngineSnapshotInfo
+{
+ /* runtime values for custom element collect score */
+ int collect_score[NUM_CUSTOM_ELEMENTS];
+
+ /* runtime values for group element choice position */
+ int choice_pos[NUM_GROUP_ELEMENTS];
+
+ /* runtime values for belt position animations */
+ int belt_graphic[4][NUM_BELT_PARTS];
+ int belt_anim_mode[4][NUM_BELT_PARTS];
+};
+
+static struct EngineSnapshotInfo engine_snapshot_rnd;
+static char *snapshot_level_identifier = NULL;
+static int snapshot_level_nr = -1;
+
+static void SaveEngineSnapshotValues_RND()
+{
+ static int belt_base_active_element[4] =
+ {
+ EL_CONVEYOR_BELT_1_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT_2_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT_3_LEFT_ACTIVE,
+ EL_CONVEYOR_BELT_4_LEFT_ACTIVE
+ };
+ int i, j;
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ engine_snapshot_rnd.collect_score[i] = element_info[element].collect_score;
+ }
+
+ for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
+ {
+ int element = EL_GROUP_START + i;
+
+ engine_snapshot_rnd.choice_pos[i] = element_info[element].group->choice_pos;
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ for (j = 0; j < NUM_BELT_PARTS; j++)
+ {
+ int element = belt_base_active_element[i] + j;
+ int graphic = el2img(element);
+ int anim_mode = graphic_info[graphic].anim_mode;
+
+ engine_snapshot_rnd.belt_graphic[i][j] = graphic;
+ engine_snapshot_rnd.belt_anim_mode[i][j] = anim_mode;
+ }
+ }
+}
+
+static void LoadEngineSnapshotValues_RND()
+{
+ unsigned int num_random_calls = game.num_random_calls;
+ int i, j;
+
+ for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ element_info[element].collect_score = engine_snapshot_rnd.collect_score[i];
+ }
+
+ for (i = 0; i < NUM_GROUP_ELEMENTS; i++)
+ {
+ int element = EL_GROUP_START + i;
+
+ element_info[element].group->choice_pos = engine_snapshot_rnd.choice_pos[i];
+ }
+
+ for (i = 0; i < 4; i++)
+ {
+ for (j = 0; j < NUM_BELT_PARTS; j++)
+ {
+ int graphic = engine_snapshot_rnd.belt_graphic[i][j];
+ int anim_mode = engine_snapshot_rnd.belt_anim_mode[i][j];
+
+ graphic_info[graphic].anim_mode = anim_mode;
+ }
+ }
+
+ if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
+ {
+ InitRND(tape.random_seed);
+ for (i = 0; i < num_random_calls; i++)
+ RND(1);
+ }
+
+ if (game.num_random_calls != num_random_calls)
+ {
+ Error(ERR_INFO, "number of random calls out of sync");
+ Error(ERR_INFO, "number of random calls should be %d", num_random_calls);
+ Error(ERR_INFO, "number of random calls is %d", game.num_random_calls);
+ Error(ERR_EXIT, "this should not happen -- please debug");
+ }
+}
+
+void FreeEngineSnapshotSingle()
+{
+ FreeSnapshotSingle();
+
+ setString(&snapshot_level_identifier, NULL);
+ snapshot_level_nr = -1;
+}
+
+void FreeEngineSnapshotList()
+{
+ FreeSnapshotList();
+}
+
+ListNode *SaveEngineSnapshotBuffers()
+{
+ ListNode *buffers = NULL;
+
+ /* copy some special values to a structure better suited for the snapshot */
+
+ if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
+ SaveEngineSnapshotValues_RND();
+ if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+ SaveEngineSnapshotValues_EM();
+ if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
+ SaveEngineSnapshotValues_SP(&buffers);
+
+ /* save values stored in special snapshot structure */
+
+ if (level.game_engine_type == GAME_ENGINE_TYPE_RND)
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_rnd));
+ if (level.game_engine_type == GAME_ENGINE_TYPE_EM)
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_em));
+ if (level.game_engine_type == GAME_ENGINE_TYPE_SP)
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(engine_snapshot_sp));
+
+ /* save further RND engine values */
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(stored_player));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(game));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(tape));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ZX));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ZY));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ExitX));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ExitY));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(FrameCounter));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(TimeFrames));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(TimePlayed));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(TimeLeft));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(TapeTime));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ScreenMovDir));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ScreenMovPos));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ScreenGfxPos));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ScrollStepSize));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(AllPlayersGone));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(AmoebaCnt));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(AmoebaCnt2));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(Feld));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(MovPos));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(MovDir));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(MovDelay));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ChangeDelay));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ChangePage));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(CustomValue));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(Store));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(Store2));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(StorePlayer));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(Back));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(AmoebaNr));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(WasJustMoving));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(WasJustFalling));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(CheckCollision));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(CheckImpact));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(Stop));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(Pushed));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ChangeCount));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ChangeEvent));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ExplodePhase));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ExplodeDelay));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(ExplodeField));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(RunnerVisit));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(PlayerVisit));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(GfxFrame));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(GfxRandom));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(GfxElement));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(GfxAction));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(GfxDir));
+
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(scroll_x));
+ SaveSnapshotBuffer(&buffers, ARGS_ADDRESS_AND_SIZEOF(scroll_y));
+
+#if 0
+ ListNode *node = engine_snapshot_list_rnd;
+ int num_bytes = 0;
+
+ while (node != NULL)
+ {
+ num_bytes += ((struct EngineSnapshotNodeInfo *)node->content)->size;
+
+ node = node->next;
+ }
+
+ printf("::: size of engine snapshot: %d bytes\n", num_bytes);
+#endif
+
+ return buffers;
+}
+
+void SaveEngineSnapshotSingle()
+{
+ ListNode *buffers = SaveEngineSnapshotBuffers();
+
+ /* finally save all snapshot buffers to single snapshot */
+ SaveSnapshotSingle(buffers);