+#if 0
+ for (j=EP_ACCESSIBLE_OVER; j < NUM_ELEMENT_PROPERTIES; j++)
+ SET_PROPERTY(i, j, FALSE);
+#endif
+
+ /* ---------- INACTIVE ------------------------------------------------- */
+ if (i >= EL_CHAR_START && i <= EL_CHAR_END)
+ SET_PROPERTY(i, EP_INACTIVE, TRUE);
+
+ /* ---------- WALKABLE, PASSABLE, ACCESSIBLE --------------------------- */
+ SET_PROPERTY(i, EP_WALKABLE, (IS_WALKABLE_OVER(i) ||
+ IS_WALKABLE_INSIDE(i) ||
+ IS_WALKABLE_UNDER(i)));
+
+ SET_PROPERTY(i, EP_PASSABLE, (IS_PASSABLE_OVER(i) ||
+ IS_PASSABLE_INSIDE(i) ||
+ IS_PASSABLE_UNDER(i)));
+
+ SET_PROPERTY(i, EP_ACCESSIBLE_OVER, (IS_WALKABLE_OVER(i) ||
+ IS_PASSABLE_OVER(i)));
+
+ SET_PROPERTY(i, EP_ACCESSIBLE_INSIDE, (IS_WALKABLE_INSIDE(i) ||
+ IS_PASSABLE_INSIDE(i)));
+
+ SET_PROPERTY(i, EP_ACCESSIBLE_UNDER, (IS_WALKABLE_UNDER(i) ||
+ IS_PASSABLE_UNDER(i)));
+
+ SET_PROPERTY(i, EP_ACCESSIBLE, (IS_WALKABLE(i) ||
+ IS_PASSABLE(i)));
+
+ /* ---------- COLLECTIBLE ---------------------------------------------- */
+ SET_PROPERTY(i, EP_COLLECTIBLE, (IS_COLLECTIBLE_ONLY(i) ||
+ IS_DROPPABLE(i)));
+
+ /* ---------- SNAPPABLE ------------------------------------------------ */
+ SET_PROPERTY(i, EP_SNAPPABLE, (IS_DIGGABLE(i) ||
+ IS_COLLECTIBLE(i) ||
+ IS_SWITCHABLE(i) ||
+ i == EL_BD_ROCK));
+
+ /* ---------- WALL ----------------------------------------------------- */
+ SET_PROPERTY(i, EP_WALL, TRUE); /* default: element is wall */
+
+ for (j=0; no_wall_properties[j] != -1; j++)
+ if (HAS_PROPERTY(i, no_wall_properties[j]) ||
+ i >= EL_FIRST_RUNTIME_UNREAL)
+ SET_PROPERTY(i, EP_WALL, FALSE);
+
+ if (IS_HISTORIC_WALL(i))
+ SET_PROPERTY(i, EP_WALL, TRUE);
+
+ /* ---------- SOLID_FOR_PUSHING ---------------------------------------- */
+ if (engine_version < VERSION_IDENT(2,2,0))
+ SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, IS_HISTORIC_SOLID(i));
+ else
+ SET_PROPERTY(i, EP_SOLID_FOR_PUSHING, (!IS_WALKABLE(i) &&
+ !IS_DIGGABLE(i) &&
+ !IS_COLLECTIBLE(i)));
+
+ /* ---------- DRAGONFIRE_PROOF ----------------------------------------- */
+
+ if (IS_HISTORIC_SOLID(i) || i == EL_EXPLOSION)
+ SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, TRUE);
+ else
+ SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, (IS_CUSTOM_ELEMENT(i) &&
+ IS_INDESTRUCTIBLE(i)));
+
+ /* ---------- EXPLOSION_PROOF ------------------------------------------ */
+ if (i == EL_FLAMES)
+ SET_PROPERTY(i, EP_EXPLOSION_PROOF, TRUE);
+ else if (engine_version < VERSION_IDENT(2,2,0))
+ SET_PROPERTY(i, EP_EXPLOSION_PROOF, IS_INDESTRUCTIBLE(i));
+ else
+ SET_PROPERTY(i, EP_EXPLOSION_PROOF, (IS_INDESTRUCTIBLE(i) &&
+ !IS_WALKABLE_OVER(i) &&
+ !IS_WALKABLE_UNDER(i)));
+
+ if (IS_CUSTOM_ELEMENT(i))
+ {
+ /* ---------- DONT_COLLIDE_WITH / DONT_RUN_INTO ---------------------- */
+ if (DONT_TOUCH(i))
+ SET_PROPERTY(i, EP_DONT_COLLIDE_WITH, TRUE);
+ if (DONT_COLLIDE_WITH(i))
+ SET_PROPERTY(i, EP_DONT_RUN_INTO, TRUE);
+
+ /* ---------- CAN_SMASH_ENEMIES / CAN_SMASH_PLAYER ------------------- */
+ if (CAN_SMASH_EVERYTHING(i))
+ SET_PROPERTY(i, EP_CAN_SMASH_ENEMIES, TRUE);
+ if (CAN_SMASH_ENEMIES(i))
+ SET_PROPERTY(i, EP_CAN_SMASH_PLAYER, TRUE);
+ }
+
+ /* ---------- CAN_SMASH ------------------------------------------------ */
+ SET_PROPERTY(i, EP_CAN_SMASH, (CAN_SMASH_PLAYER(i) ||
+ CAN_SMASH_ENEMIES(i) ||
+ CAN_SMASH_EVERYTHING(i)));
+
+ /* ---------- CAN_EXPLODE ---------------------------------------------- */
+ SET_PROPERTY(i, EP_CAN_EXPLODE, (CAN_EXPLODE_BY_FIRE(i) ||
+ CAN_EXPLODE_SMASHED(i) ||
+ CAN_EXPLODE_IMPACT(i)));
+
+ /* ---------- CAN_EXPLODE_3X3 ------------------------------------------ */
+ SET_PROPERTY(i, EP_CAN_EXPLODE_3X3, (CAN_EXPLODE(i) &&
+ !CAN_EXPLODE_1X1(i)));
+
+ /* ---------- CAN_BE_CRUMBLED ------------------------------------------ */
+ SET_PROPERTY(i, EP_CAN_BE_CRUMBLED,
+ element_info[i].crumbled[ACTION_DEFAULT] != IMG_EMPTY);
+
+#if 0
+ if (CAN_BE_CRUMBLED(i))
+ printf("::: '%s' can be crumbled [%d]\n",
+ element_info[i].token_name,
+ element_info[i].crumbled[ACTION_DEFAULT]);
+#endif
+
+ /* ---------- CAN_CHANGE ----------------------------------------------- */
+ SET_PROPERTY(i, EP_CAN_CHANGE, FALSE); /* default: cannot change */
+ for (j=0; j < element_info[i].num_change_pages; j++)
+ if (element_info[i].change_page[j].can_change)
+ SET_PROPERTY(i, EP_CAN_CHANGE, TRUE);
+ }
+
+#if 0
+ /* determine inactive elements (used for engine main loop optimization) */
+ for (i=0; i < MAX_NUM_ELEMENTS; i++)
+ {
+ boolean active = FALSE;
+
+ for (j=0; i < NUM_ELEMENT_PROPERTIES; j++)
+ {
+ if (HAS_PROPERTY(i, j))
+ active = TRUE;
+ }
+
+#if 0
+ if (!active)
+ SET_PROPERTY(i, EP_INACTIVE, TRUE);
+#endif
+ }
+#endif
+
+ /* dynamically adjust element properties according to game engine version */
+ {
+ static int ep_em_slippery_wall[] =
+ {
+ EL_STEELWALL,
+ EL_WALL,
+ EL_EXPANDABLE_WALL,
+ EL_EXPANDABLE_WALL_HORIZONTAL,
+ EL_EXPANDABLE_WALL_VERTICAL,
+ EL_EXPANDABLE_WALL_ANY,
+ -1
+ };
+
+ /* special EM style gems behaviour */
+ for (i=0; ep_em_slippery_wall[i] != -1; i++)
+ SET_PROPERTY(ep_em_slippery_wall[i], EP_EM_SLIPPERY_WALL,
+ level.em_slippery_gems);
+
+ /* "EL_EXPANDABLE_WALL_GROWING" wasn't slippery for EM gems in 2.0.1 */
+ SET_PROPERTY(EL_EXPANDABLE_WALL_GROWING, EP_EM_SLIPPERY_WALL,
+ (level.em_slippery_gems &&
+ engine_version > VERSION_IDENT(2,0,1)));
+ }
+
+#if 0
+ /* dynamically adjust element properties according to game engine version */
+#if 0
+ if (engine_version < RELEASE_IDENT(2,2,0,7))
+#endif
+ {
+ for (i=0; i < NUM_CUSTOM_ELEMENTS; i++)
+ {
+ int element = EL_CUSTOM_START + i;
+
+ element_info[element].push_delay_fixed = 2;
+ element_info[element].push_delay_random = 8;
+ }
+ }
+#endif
+}
+
+static void InitGlobal()
+{
+ global.autoplay_leveldir = NULL;
+
+ global.frames_per_second = 0;
+ global.fps_slowdown = FALSE;
+ global.fps_slowdown_factor = 1;
+}
+
+void Execute_Command(char *command)
+{
+ if (strcmp(command, "print graphicsinfo.conf") == 0)
+ {
+ int i;
+
+ printf("# You can configure additional/alternative image files here.\n");
+ printf("# (The images below are default and therefore commented out.)\n");
+ printf("\n");
+ printf("%s\n", getFormattedSetupEntry("name", "Classic Graphics"));
+ printf("\n");
+ printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
+ printf("\n");
+
+ for (i=0; image_config[i].token != NULL; i++)
+ printf("# %s\n",
+ getFormattedSetupEntry(image_config[i].token,
+ image_config[i].value));
+
+ exit(0);
+ }
+ else if (strcmp(command, "print soundsinfo.conf") == 0)
+ {
+ int i;
+
+ printf("# You can configure additional/alternative sound files here.\n");
+ printf("# (The sounds below are default and therefore commented out.)\n");
+ printf("\n");
+ printf("%s\n", getFormattedSetupEntry("name", "Classic Sounds"));
+ printf("\n");
+ printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
+ printf("\n");
+
+ for (i=0; sound_config[i].token != NULL; i++)
+ printf("# %s\n",
+ getFormattedSetupEntry(sound_config[i].token,
+ sound_config[i].value));
+
+ exit(0);
+ }
+ else if (strcmp(command, "print musicinfo.conf") == 0)
+ {
+ printf("# (Currently only \"name\" and \"sort_priority\" recognized.)\n");
+ printf("\n");
+ printf("%s\n", getFormattedSetupEntry("name", "Classic Music"));
+ printf("\n");
+ printf("%s\n", getFormattedSetupEntry("sort_priority", "100"));
+
+ exit(0);
+ }
+ else if (strncmp(command, "dump level ", 11) == 0)
+ {
+ char *filename = &command[11];
+
+ if (access(filename, F_OK) != 0)
+ Error(ERR_EXIT, "cannot open file '%s'", filename);
+
+ LoadLevelFromFilename(&level, filename);
+ DumpLevel(&level);
+
+ exit(0);
+ }
+ else if (strncmp(command, "dump tape ", 10) == 0)
+ {
+ char *filename = &command[10];
+
+ if (access(filename, F_OK) != 0)
+ Error(ERR_EXIT, "cannot open file '%s'", filename);
+
+ LoadTapeFromFilename(filename);
+ DumpTape(&tape);
+
+ exit(0);
+ }
+ else if (strncmp(command, "autoplay ", 9) == 0)
+ {
+ char *str_copy = getStringCopy(&command[9]);
+ char *str_ptr = strchr(str_copy, ' ');
+
+ global.autoplay_leveldir = str_copy;
+ global.autoplay_level_nr = -1;
+
+ if (str_ptr != NULL)
+ {
+ *str_ptr++ = '\0'; /* terminate leveldir string */
+ global.autoplay_level_nr = atoi(str_ptr); /* get level_nr value */
+ }
+ }
+ else
+ {
+ Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
+ }
+}
+
+static void InitSetup()
+{
+ LoadSetup(); /* global setup info */
+
+ /* set some options from setup file */
+
+ if (setup.options.verbose)
+ options.verbose = TRUE;
+}
+
+static void InitPlayerInfo()
+{
+ int i;
+
+ /* choose default local player */
+ local_player = &stored_player[0];
+
+ for (i=0; i<MAX_PLAYERS; i++)
+ stored_player[i].connected = FALSE;
+
+ local_player->connected = TRUE;
+}
+
+static void InitArtworkInfo()
+{
+ LoadArtworkInfo();
+}
+
+static char *get_string_in_brackets(char *string)
+{
+ char *string_in_brackets = checked_malloc(strlen(string) + 3);
+
+ sprintf(string_in_brackets, "[%s]", string);
+
+ return string_in_brackets;
+}
+
+#if 0
+static char *get_element_class_token(int element)
+{
+ char *element_class_name = element_info[element].class_name;
+ char *element_class_token = checked_malloc(strlen(element_class_name) + 3);
+
+ sprintf(element_class_token, "[%s]", element_class_name);
+
+ return element_class_token;
+}
+
+static char *get_action_class_token(int action)
+{
+ char *action_class_name = &element_action_info[action].suffix[1];
+ char *action_class_token = checked_malloc(strlen(action_class_name) + 3);
+
+ sprintf(action_class_token, "[%s]", action_class_name);
+
+ return action_class_token;
+}
+#endif
+
+static void InitArtworkConfig()
+{
+ static char *image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS + 1];
+ static char *sound_id_prefix[2 * MAX_NUM_ELEMENTS + 1];
+ static char *action_id_suffix[NUM_ACTIONS + 1];
+ static char *direction_id_suffix[NUM_DIRECTIONS + 1];
+ static char *special_id_suffix[NUM_SPECIAL_GFX_ARGS + 1];
+ static char *dummy[1] = { NULL };
+ static char *ignore_generic_tokens[] =
+ {
+ "name",
+ "sort_priority",
+ NULL
+ };
+ static char **ignore_image_tokens, **ignore_sound_tokens;
+ int num_ignore_generic_tokens;
+ int num_ignore_image_tokens, num_ignore_sound_tokens;
+ int i;
+
+ /* dynamically determine list of generic tokens to be ignored */
+ num_ignore_generic_tokens = 0;
+ for (i=0; ignore_generic_tokens[i] != NULL; i++)
+ num_ignore_generic_tokens++;
+
+ /* dynamically determine list of image tokens to be ignored */
+ num_ignore_image_tokens = num_ignore_generic_tokens;
+ for (i=0; image_config_vars[i].token != NULL; i++)
+ num_ignore_image_tokens++;
+ ignore_image_tokens =
+ checked_malloc((num_ignore_image_tokens + 1) * sizeof(char *));
+ for (i=0; i < num_ignore_generic_tokens; i++)
+ ignore_image_tokens[i] = ignore_generic_tokens[i];
+ for (i=0; i < num_ignore_image_tokens - num_ignore_generic_tokens; i++)
+ ignore_image_tokens[num_ignore_generic_tokens + i] =
+ image_config_vars[i].token;
+ ignore_image_tokens[num_ignore_image_tokens] = NULL;
+
+ /* dynamically determine list of sound tokens to be ignored */
+ num_ignore_sound_tokens = num_ignore_generic_tokens;
+ ignore_sound_tokens =
+ checked_malloc((num_ignore_sound_tokens + 1) * sizeof(char *));
+ for (i=0; i < num_ignore_generic_tokens; i++)
+ ignore_sound_tokens[i] = ignore_generic_tokens[i];
+ ignore_sound_tokens[num_ignore_sound_tokens] = NULL;
+
+ for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ image_id_prefix[i] = element_info[i].token_name;
+ for (i=0; i<NUM_FONTS; i++)
+ image_id_prefix[MAX_NUM_ELEMENTS + i] = font_info[i].token_name;
+ image_id_prefix[MAX_NUM_ELEMENTS + NUM_FONTS] = NULL;
+
+ for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ sound_id_prefix[i] = element_info[i].token_name;
+ for (i=0; i<MAX_NUM_ELEMENTS; i++)
+ sound_id_prefix[MAX_NUM_ELEMENTS + i] =
+ get_string_in_brackets(element_info[i].class_name);
+ sound_id_prefix[2 * MAX_NUM_ELEMENTS] = NULL;
+
+ for (i=0; i<NUM_ACTIONS; i++)
+ action_id_suffix[i] = element_action_info[i].suffix;
+ action_id_suffix[NUM_ACTIONS] = NULL;
+
+ for (i=0; i<NUM_DIRECTIONS; i++)
+ direction_id_suffix[i] = element_direction_info[i].suffix;
+ direction_id_suffix[NUM_DIRECTIONS] = NULL;
+
+ for (i=0; i<NUM_SPECIAL_GFX_ARGS; i++)
+ special_id_suffix[i] = special_suffix_info[i].suffix;
+ special_id_suffix[NUM_SPECIAL_GFX_ARGS] = NULL;
+
+ InitImageList(image_config, NUM_IMAGE_FILES, image_config_suffix,
+ image_id_prefix, action_id_suffix, direction_id_suffix,
+ special_id_suffix, ignore_image_tokens);
+ InitSoundList(sound_config, NUM_SOUND_FILES, sound_config_suffix,
+ sound_id_prefix, action_id_suffix, dummy,
+ special_id_suffix, ignore_sound_tokens);
+}
+
+static void InitMixer()
+{
+ OpenAudio();
+ StartMixer();
+}
+
+void InitGfx()
+{
+ char *filename_font_initial = NULL;
+ Bitmap *bitmap_font_initial = NULL;
+ int i, j;
+
+ /* determine settings for initial font (for displaying startup messages) */
+ for (i=0; image_config[i].token != NULL; i++)
+ {
+ for (j=0; j < NUM_INITIAL_FONTS; j++)
+ {
+ char font_token[128];
+ int len_font_token;
+
+ sprintf(font_token, "%s_%d", CONFIG_TOKEN_FONT_INITIAL, j + 1);
+ len_font_token = strlen(font_token);
+
+ if (strcmp(image_config[i].token, font_token) == 0)
+ filename_font_initial = image_config[i].value;
+ else if (strlen(image_config[i].token) > len_font_token &&
+ strncmp(image_config[i].token, font_token, len_font_token) == 0)
+ {
+ if (strcmp(&image_config[i].token[len_font_token], ".x") == 0)
+ font_initial[j].src_x = atoi(image_config[i].value);
+ else if (strcmp(&image_config[i].token[len_font_token], ".y") == 0)
+ font_initial[j].src_y = atoi(image_config[i].value);
+ else if (strcmp(&image_config[i].token[len_font_token], ".width") == 0)
+ font_initial[j].width = atoi(image_config[i].value);
+ else if (strcmp(&image_config[i].token[len_font_token],".height") == 0)
+ font_initial[j].height = atoi(image_config[i].value);
+ }
+ }
+ }
+
+ for (j=0; j < NUM_INITIAL_FONTS; j++)
+ {
+ font_initial[j].num_chars = DEFAULT_NUM_CHARS_PER_FONT;
+ font_initial[j].num_chars_per_line = DEFAULT_NUM_CHARS_PER_LINE;
+ }
+
+ if (filename_font_initial == NULL) /* should not happen */
+ Error(ERR_EXIT, "cannot get filename for '%s'", CONFIG_TOKEN_FONT_INITIAL);
+
+ /* create additional image buffers for double-buffering */
+ bitmap_db_field = CreateBitmap(FXSIZE, FYSIZE, DEFAULT_DEPTH);
+ bitmap_db_door = CreateBitmap(3 * DXSIZE, DYSIZE + VYSIZE, DEFAULT_DEPTH);
+
+ /* initialize screen properties */
+ InitGfxFieldInfo(SX, SY, SXSIZE, SYSIZE,
+ REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE,
+ bitmap_db_field);
+ InitGfxDoor1Info(DX, DY, DXSIZE, DYSIZE);
+ InitGfxDoor2Info(VX, VY, VXSIZE, VYSIZE);
+ InitGfxScrollbufferInfo(FXSIZE, FYSIZE);
+
+ bitmap_font_initial = LoadCustomImage(filename_font_initial);
+
+ for (j=0; j < NUM_INITIAL_FONTS; j++)
+ font_initial[j].bitmap = bitmap_font_initial;
+
+ InitFontGraphicInfo();
+
+ DrawInitText(WINDOW_TITLE_STRING, 20, FC_YELLOW);
+ DrawInitText(WINDOW_SUBTITLE_STRING, 50, FC_RED);
+
+ DrawInitText("Loading graphics:", 120, FC_GREEN);
+
+ InitTileClipmasks();
+}
+
+void InitGfxBackground()
+{
+ int x, y;
+
+ drawto = backbuffer;
+ fieldbuffer = bitmap_db_field;
+ SetDrawtoField(DRAW_BACKBUFFER);
+
+ BlitBitmap(graphic_info[IMG_GLOBAL_BORDER].bitmap, backbuffer,
+ 0, 0, WIN_XSIZE, WIN_YSIZE, 0, 0);
+ ClearRectangle(backbuffer, REAL_SX, REAL_SY, FULL_SXSIZE, FULL_SYSIZE);
+ ClearRectangle(bitmap_db_door, 0, 0, 3 * DXSIZE, DYSIZE + VYSIZE);
+
+ for (x=0; x<MAX_BUF_XSIZE; x++)
+ for (y=0; y<MAX_BUF_YSIZE; y++)
+ redraw[x][y] = 0;
+ redraw_tiles = 0;
+ redraw_mask = REDRAW_ALL;
+}
+
+static void InitLevelInfo()
+{
+ LoadLevelInfo(); /* global level info */
+ LoadLevelSetup_LastSeries(); /* last played series info */
+ LoadLevelSetup_SeriesInfo(); /* last played level info */
+}
+
+void InitLevelArtworkInfo()
+{
+ LoadLevelArtworkInfo();
+}
+
+static void InitImages()
+{
+#if 1
+ setLevelArtworkDir(artwork.gfx_first);
+#endif
+
+#if 0
+ printf("::: InitImages for '%s' ['%s', '%s'] ['%s', '%s']\n",
+ leveldir_current->identifier,
+ artwork.gfx_current_identifier,
+ artwork.gfx_current->identifier,
+ leveldir_current->graphics_set,
+ leveldir_current->graphics_path);
+#endif
+
+ ReloadCustomImages();
+
+ LoadCustomElementDescriptions();
+ LoadSpecialMenuDesignSettings();
+
+ ReinitializeGraphics();
+}
+
+static void InitSound(char *identifier)
+{
+ if (identifier == NULL)
+ identifier = artwork.snd_current->identifier;
+
+#if 1
+ /* set artwork path to send it to the sound server process */
+ setLevelArtworkDir(artwork.snd_first);
+#endif
+
+ InitReloadCustomSounds(identifier);
+ ReinitializeSounds();
+}
+
+static void InitMusic(char *identifier)
+{
+ if (identifier == NULL)
+ identifier = artwork.mus_current->identifier;
+
+#if 1
+ /* set artwork path to send it to the sound server process */
+ setLevelArtworkDir(artwork.mus_first);
+#endif
+
+ InitReloadCustomMusic(identifier);
+ ReinitializeMusic();
+}
+
+void InitNetworkServer()
+{
+#if defined(PLATFORM_UNIX)
+ int nr_wanted;
+#endif
+
+ if (!options.network)
+ return;
+
+#if defined(PLATFORM_UNIX)
+ nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
+
+ if (!ConnectToServer(options.server_host, options.server_port))
+ Error(ERR_EXIT, "cannot connect to network game server");
+
+ SendToServer_PlayerName(setup.player_name);
+ SendToServer_ProtocolVersion();
+
+ if (nr_wanted)
+ SendToServer_NrWanted(nr_wanted);
+#endif
+}
+
+static char *getNewArtworkIdentifier(int type)
+{
+ static char *leveldir_current_identifier[3] = { NULL, NULL, NULL };
+ static boolean last_override_level_artwork[3] = { FALSE, FALSE, FALSE };
+ static boolean last_has_level_artwork_set[3] = { FALSE, FALSE, FALSE };
+ static boolean initialized[3] = { FALSE, FALSE, FALSE };
+ TreeInfo *artwork_first_node = ARTWORK_FIRST_NODE(artwork, type);
+ boolean setup_override_artwork = SETUP_OVERRIDE_ARTWORK(setup, type);
+ char *setup_artwork_set = SETUP_ARTWORK_SET(setup, type);
+ char *leveldir_identifier = leveldir_current->identifier;
+#if 1
+ /* !!! setLevelArtworkDir() should be moved to an earlier stage !!! */
+ char *leveldir_artwork_set = setLevelArtworkDir(artwork_first_node);
+#else
+ char *leveldir_artwork_set = LEVELDIR_ARTWORK_SET(leveldir_current, type);
+#endif
+ boolean has_level_artwork_set = (leveldir_artwork_set != NULL);
+ char *artwork_current_identifier;
+ char *artwork_new_identifier = NULL; /* default: nothing has changed */
+
+ /* leveldir_current may be invalid (level group, parent link) */
+ if (!validLevelSeries(leveldir_current))
+ return NULL;
+
+ /* 1st step: determine artwork set to be activated in descending order:
+ --------------------------------------------------------------------
+ 1. setup artwork (when configured to override everything else)
+ 2. artwork set configured in "levelinfo.conf" of current level set
+ (artwork in level directory will have priority when loading later)
+ 3. artwork in level directory (stored in artwork sub-directory)
+ 4. setup artwork (currently configured in setup menu) */
+
+ if (setup_override_artwork)
+ artwork_current_identifier = setup_artwork_set;
+ else if (leveldir_artwork_set != NULL)
+ artwork_current_identifier = leveldir_artwork_set;
+ else if (getTreeInfoFromIdentifier(artwork_first_node, leveldir_identifier))
+ artwork_current_identifier = leveldir_identifier;
+ else
+ artwork_current_identifier = setup_artwork_set;
+
+
+ /* 2nd step: check if it is really needed to reload artwork set
+ ------------------------------------------------------------ */
+
+#if 0
+ if (type == ARTWORK_TYPE_GRAPHICS)
+ printf("::: 0: '%s' ['%s', '%s'] ['%s' ('%s')]\n",
+ artwork_new_identifier,
+ ARTWORK_CURRENT_IDENTIFIER(artwork, type),
+ artwork_current_identifier,
+ leveldir_current->graphics_set,
+ leveldir_current->identifier);
+#endif
+
+ /* ---------- reload if level set and also artwork set has changed ------- */
+ if (leveldir_current_identifier[type] != leveldir_identifier &&
+ (last_has_level_artwork_set[type] || has_level_artwork_set))
+ artwork_new_identifier = artwork_current_identifier;
+
+ leveldir_current_identifier[type] = leveldir_identifier;
+ last_has_level_artwork_set[type] = has_level_artwork_set;
+
+#if 0
+ if (type == ARTWORK_TYPE_GRAPHICS)
+ printf("::: 1: '%s'\n", artwork_new_identifier);
+#endif
+
+ /* ---------- reload if "override artwork" setting has changed ----------- */
+ if (last_override_level_artwork[type] != setup_override_artwork)
+ artwork_new_identifier = artwork_current_identifier;
+
+ last_override_level_artwork[type] = setup_override_artwork;
+
+#if 0
+ if (type == ARTWORK_TYPE_GRAPHICS)
+ printf("::: 2: '%s'\n", artwork_new_identifier);
+#endif
+
+ /* ---------- reload if current artwork identifier has changed ----------- */
+ if (strcmp(ARTWORK_CURRENT_IDENTIFIER(artwork, type),
+ artwork_current_identifier) != 0)
+ artwork_new_identifier = artwork_current_identifier;
+
+ *(&(ARTWORK_CURRENT_IDENTIFIER(artwork, type))) = artwork_current_identifier;
+
+#if 0
+ if (type == ARTWORK_TYPE_GRAPHICS)
+ printf("::: 3: '%s'\n", artwork_new_identifier);
+#endif
+
+ /* ---------- do not reload directly after starting ---------------------- */
+ if (!initialized[type])
+ artwork_new_identifier = NULL;
+
+ initialized[type] = TRUE;
+
+#if 0
+ if (type == ARTWORK_TYPE_GRAPHICS)
+ printf("::: 4: '%s'\n", artwork_new_identifier);
+#endif
+
+#if 0
+ if (type == ARTWORK_TYPE_GRAPHICS)
+ printf("CHECKING OLD/NEW GFX:\n- OLD: %s\n- NEW: %s ['%s', '%s'] ['%s']\n",
+ artwork.gfx_current_identifier, artwork_current_identifier,
+ artwork.gfx_current->identifier, leveldir_current->graphics_set,
+ artwork_new_identifier);
+#endif
+
+ return artwork_new_identifier;
+}
+
+void ReloadCustomArtwork()
+{
+ char *gfx_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_GRAPHICS);
+ char *snd_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_SOUNDS);
+ char *mus_new_identifier = getNewArtworkIdentifier(ARTWORK_TYPE_MUSIC);
+ boolean redraw_screen = FALSE;
+
+ if (gfx_new_identifier != NULL)