fixed bug with handling networking packets if request dialog is active
[rocksndiamonds.git] / src / init.c
index 8d2e4a1bd247fd32114f3ea4181318140dbb42ef..2167984b663649481289e4d4c0c5f14be1670312 100644 (file)
@@ -84,7 +84,11 @@ static int copy_properties[][5] =
 };
 
 
-void DrawInitAnim()
+/* forward declaration for internal use */
+static int get_graphic_parameter_value(char *, char *, int);
+
+
+static void DrawInitAnim(void)
 {
   struct GraphicInfo *graphic_info_last = graphic_info;
   int graphic = 0;
@@ -93,6 +97,9 @@ void DrawInitAnim()
   int sync_frame = FrameCounter;
   int x, y;
 
+  /* prevent OS (Windows) from complaining about program not responding */
+  CheckQuitEvent();
+
   if (game_status != GAME_MODE_LOADING)
     return;
 
@@ -129,7 +136,21 @@ void DrawInitAnim()
   FrameCounter++;
 }
 
-void FreeGadgets()
+static void DrawProgramInfo(void)
+{
+  int font1_nr = FC_YELLOW;
+  int font2_nr = FC_RED;
+  int font2_height = getFontHeight(font2_nr);
+  int ypos1 = 20;
+  int ypos2 = 50;
+  int ypos3 = WIN_YSIZE - 20 - font2_height;
+
+  DrawInitText(getProgramInitString(),           ypos1, font1_nr);
+  DrawInitText(setup.internal.program_copyright, ypos2, font2_nr);
+  DrawInitText(setup.internal.program_website,   ypos3, font2_nr);
+}
+
+static void FreeGadgets(void)
 {
   FreeLevelEditorGadgets();
   FreeGameButtons();
@@ -138,7 +159,7 @@ void FreeGadgets()
   FreeScreenGadgets();
 }
 
-void InitGadgets()
+void InitGadgets(void)
 {
   static boolean gadgets_initialized = FALSE;
 
@@ -164,7 +185,7 @@ inline static void InitElementSmallImagesScaledUp(int graphic)
   CreateImageWithSmallImages(graphic, g->scale_up_factor, g->tile_size);
 }
 
-void InitElementSmallImages()
+static void InitElementSmallImages(void)
 {
   print_timestamp_init("InitElementSmallImages");
 
@@ -226,7 +247,7 @@ inline static void InitScaledImagesScaledUp(int graphic)
   ScaleImage(graphic, g->scale_up_factor);
 }
 
-void InitScaledImages()
+static void InitScaledImages(void)
 {
   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
   int num_property_mappings = getImageListPropertyMappingSize();
@@ -241,7 +262,7 @@ void InitScaledImages()
     InitScaledImagesScaledUp(property_mapping[i].artwork_index);
 }
 
-void InitBitmapPointers()
+static void InitBitmapPointers(void)
 {
   int num_images = getImageListSize();
   int i;
@@ -252,7 +273,7 @@ void InitBitmapPointers()
       graphic_info[i].bitmap = graphic_info[i].bitmaps[IMG_BITMAP_STANDARD];
 }
 
-void InitImageTextures()
+void InitImageTextures(void)
 {
   int i, j, k;
 
@@ -326,7 +347,7 @@ static int getFontFromToken(char *token)
   return FONT_INITIAL_1;
 }
 
-void InitFontGraphicInfo()
+static void InitFontGraphicInfo(void)
 {
   static struct FontBitmapInfo *font_bitmap_info = NULL;
   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
@@ -409,7 +430,7 @@ void InitFontGraphicInfo()
     int special = property_mapping[i].ext3_index;
     int graphic = property_mapping[i].artwork_index;
 
-    if (font_nr < 0)
+    if (font_nr < 0 || font_nr >= NUM_FONTS)
       continue;
 
     if (IS_SPECIAL_GFX_ARG(special))
@@ -544,6 +565,11 @@ void InitFontGraphicInfo()
       font_bitmap_info[font_bitmap_id].width  = graphic_info[graphic].width;
       font_bitmap_info[font_bitmap_id].height = graphic_info[graphic].height;
 
+      font_bitmap_info[font_bitmap_id].offset_x =
+       graphic_info[graphic].offset_x;
+      font_bitmap_info[font_bitmap_id].offset_y =
+       graphic_info[graphic].offset_y;
+
       font_bitmap_info[font_bitmap_id].draw_xoffset =
        graphic_info[graphic].draw_xoffset;
       font_bitmap_info[font_bitmap_id].draw_yoffset =
@@ -560,7 +586,7 @@ void InitFontGraphicInfo()
               getFontBitmapID, getFontFromToken);
 }
 
-void InitGlobalAnimGraphicInfo()
+static void InitGlobalAnimGraphicInfo(void)
 {
   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
   int num_property_mappings = getImageListPropertyMappingSize();
@@ -604,6 +630,19 @@ void InitGlobalAnimGraphicInfo()
       special = GFX_SPECIAL_ARG_DEFAULT;
 
     global_anim_info[anim_nr].graphic[part_nr][special] = graphic;
+
+    /* fix default value for ".draw_masked" (for backward compatibility) */
+    struct GraphicInfo *g = &graphic_info[graphic];
+    struct FileInfo *image = getImageListEntryFromImageID(graphic);
+    char **parameter_raw = image->parameter;
+    int p = GFX_ARG_DRAW_MASKED;
+    int draw_masked = get_graphic_parameter_value(parameter_raw[p],
+                                                 image_config_suffix[p].token,
+                                                 image_config_suffix[p].type);
+
+    /* if ".draw_masked" parameter is undefined, use default value "TRUE" */
+    if (draw_masked == ARG_UNDEFINED_VALUE)
+      g->draw_masked = TRUE;
   }
 
 #if 0
@@ -619,7 +658,7 @@ void InitGlobalAnimGraphicInfo()
 #endif
 }
 
-void InitGlobalAnimSoundInfo()
+static void InitGlobalAnimSoundInfo(void)
 {
   struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
   int num_property_mappings = getSoundListPropertyMappingSize();
@@ -668,7 +707,7 @@ void InitGlobalAnimSoundInfo()
 #endif
 }
 
-void InitGlobalAnimMusicInfo()
+static void InitGlobalAnimMusicInfo(void)
 {
   struct PropertyMapping *property_mapping = getMusicListPropertyMapping();
   int num_property_mappings = getMusicListPropertyMappingSize();
@@ -717,7 +756,7 @@ void InitGlobalAnimMusicInfo()
 #endif
 }
 
-void InitElementGraphicInfo()
+static void InitElementGraphicInfo(void)
 {
   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
   int num_property_mappings = getImageListPropertyMappingSize();
@@ -1028,6 +1067,8 @@ void InitElementGraphicInfo()
        default_action_graphic = element_info[EL_SP_DEFAULT].graphic[act];
       if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].graphic[act] != -1)
        default_action_graphic = element_info[EL_SB_DEFAULT].graphic[act];
+      if (IS_MM_ELEMENT(i) && element_info[EL_MM_DEFAULT].graphic[act] != -1)
+       default_action_graphic = element_info[EL_MM_DEFAULT].graphic[act];
 
       if (IS_BD_ELEMENT(i) && element_info[EL_BD_DEFAULT].crumbled[act] != -1)
        default_action_crumbled = element_info[EL_BD_DEFAULT].crumbled[act];
@@ -1035,6 +1076,8 @@ void InitElementGraphicInfo()
        default_action_crumbled = element_info[EL_SP_DEFAULT].crumbled[act];
       if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].crumbled[act] != -1)
        default_action_crumbled = element_info[EL_SB_DEFAULT].crumbled[act];
+      if (IS_MM_ELEMENT(i) && element_info[EL_MM_DEFAULT].crumbled[act] != -1)
+       default_action_crumbled = element_info[EL_MM_DEFAULT].crumbled[act];
 
       /* !!! needed because EL_EMPTY_SPACE treated as IS_SP_ELEMENT !!! */
       /* !!! make this better !!! */
@@ -1094,7 +1137,7 @@ void InitElementGraphicInfo()
   UPDATE_BUSY_STATE();
 }
 
-void InitElementSpecialGraphicInfo()
+static void InitElementSpecialGraphicInfo(void)
 {
   struct PropertyMapping *property_mapping = getImageListPropertyMapping();
   int num_property_mappings = getImageListPropertyMappingSize();
@@ -1258,6 +1301,11 @@ static void set_graphic_parameters_ext(int graphic, int *parameter,
   g->anim_delay_random = 0;
   g->post_delay_fixed = 0;
   g->post_delay_random = 0;
+  g->init_event = ANIM_EVENT_DEFAULT;
+  g->anim_event = ANIM_EVENT_DEFAULT;
+  g->init_event_action = -1;
+  g->anim_event_action = -1;
+  g->draw_masked = FALSE;
   g->draw_order = 0;
   g->fade_mode = FADE_MODE_DEFAULT;
   g->fade_delay = -1;
@@ -1474,6 +1522,16 @@ static void set_graphic_parameters_ext(int graphic, int *parameter,
   if (parameter[GFX_ARG_POST_DELAY_RANDOM] != ARG_UNDEFINED_VALUE)
     g->post_delay_random = parameter[GFX_ARG_POST_DELAY_RANDOM];
 
+  /* used for global animations */
+  if (parameter[GFX_ARG_INIT_EVENT] != ARG_UNDEFINED_VALUE)
+    g->init_event = parameter[GFX_ARG_INIT_EVENT];
+  if (parameter[GFX_ARG_ANIM_EVENT] != ARG_UNDEFINED_VALUE)
+    g->anim_event = parameter[GFX_ARG_ANIM_EVENT];
+  if (parameter[GFX_ARG_INIT_EVENT_ACTION] != ARG_UNDEFINED_VALUE)
+    g->init_event_action = parameter[GFX_ARG_INIT_EVENT_ACTION];
+  if (parameter[GFX_ARG_ANIM_EVENT_ACTION] != ARG_UNDEFINED_VALUE)
+    g->anim_event_action = parameter[GFX_ARG_ANIM_EVENT_ACTION];
+
   /* used for toon animations and global animations */
   g->step_offset  = parameter[GFX_ARG_STEP_OFFSET];
   g->step_xoffset = parameter[GFX_ARG_STEP_XOFFSET];
@@ -1488,8 +1546,14 @@ static void set_graphic_parameters_ext(int graphic, int *parameter,
   g->draw_xoffset = parameter[GFX_ARG_DRAW_XOFFSET];
   g->draw_yoffset = parameter[GFX_ARG_DRAW_YOFFSET];
 
-  /* this is only used for drawing envelope graphics */
-  g->draw_masked = parameter[GFX_ARG_DRAW_MASKED];
+  /* use a different default value for global animations and toons */
+  if ((graphic >= IMG_GFX_GLOBAL_ANIM_1 && graphic <= IMG_GFX_GLOBAL_ANIM_8) ||
+      (graphic >= IMG_TOON_1            && graphic <= IMG_TOON_20))
+    g->draw_masked = TRUE;
+
+  /* this is used for drawing envelopes, global animations and toons */
+  if (parameter[GFX_ARG_DRAW_MASKED] != ARG_UNDEFINED_VALUE)
+    g->draw_masked = parameter[GFX_ARG_DRAW_MASKED];
 
   /* used for toon animations and global animations */
   if (parameter[GFX_ARG_DRAW_ORDER] != ARG_UNDEFINED_VALUE)
@@ -1589,7 +1653,7 @@ static void set_cloned_graphic_parameters(int graphic)
   }
 }
 
-static void InitGraphicInfo()
+static void InitGraphicInfo(void)
 {
   int fallback_graphic = IMG_CHAR_EXCLAM;
   int num_images = getImageListSize();
@@ -1682,10 +1746,10 @@ static void InitGraphicInfo()
 
   for (i = 0; i < num_images; i++)
   {
-    Bitmap *src_bitmap;
+    Bitmap *src_bitmap = graphic_info[i].bitmap;
     int src_x, src_y;
     int width, height;
-    int first_frame, last_frame;
+    int last_frame;
     int src_bitmap_width, src_bitmap_height;
 
     /* now check if no animation frames are outside of the loaded image */
@@ -1703,9 +1767,7 @@ static void InitGraphicInfo()
 
     /* check if first animation frame is inside specified bitmap */
 
-    first_frame = 0;
-    getFixedGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y);
-
+    /* do not use getGraphicSourceXY() here to get position of first frame; */
     /* this avoids calculating wrong start position for out-of-bounds frame */
     src_x = graphic_info[i].src_x;
     src_y = graphic_info[i].src_y;
@@ -1735,12 +1797,15 @@ static void InitGraphicInfo()
       Error(ERR_INFO_LINE, "-");
 
       graphic_info[i] = graphic_info[fallback_graphic];
+
+      /* if first frame out of bounds, do not check last frame anymore */
+      continue;
     }
 
     /* check if last animation frame is inside specified bitmap */
 
     last_frame = graphic_info[i].anim_frames - 1;
-    getFixedGraphicSource(i, last_frame, &src_bitmap, &src_x, &src_y);
+    getGraphicSourceXY(i, last_frame, &src_x, &src_y, FALSE);
 
     if (src_x < 0 || src_y < 0 ||
        src_x + width  > src_bitmap_width ||
@@ -1768,7 +1833,7 @@ static void InitGraphicInfo()
   }
 }
 
-static void InitGraphicCompatibilityInfo()
+static void InitGraphicCompatibilityInfo(void)
 {
   struct FileInfo *fi_global_door =
     getImageListEntryFromImageID(IMG_GLOBAL_DOOR);
@@ -1810,7 +1875,7 @@ static void InitGraphicCompatibilityInfo()
   InitGraphicCompatibilityInfo_Doors();
 }
 
-static void InitElementSoundInfo()
+static void InitElementSoundInfo(void)
 {
   struct PropertyMapping *property_mapping = getSoundListPropertyMapping();
   int num_property_mappings = getSoundListPropertyMappingSize();
@@ -1891,6 +1956,8 @@ static void InitElementSoundInfo()
        default_action_sound = element_info[EL_SP_DEFAULT].sound[act];
       if (IS_SB_ELEMENT(i) && element_info[EL_SB_DEFAULT].sound[act] != -1)
        default_action_sound = element_info[EL_SB_DEFAULT].sound[act];
+      if (IS_MM_ELEMENT(i) && element_info[EL_MM_DEFAULT].sound[act] != -1)
+       default_action_sound = element_info[EL_MM_DEFAULT].sound[act];
 
       /* !!! needed because EL_EMPTY_SPACE treated as IS_SP_ELEMENT !!! */
       /* !!! make this better !!! */
@@ -1912,7 +1979,7 @@ static void InitElementSoundInfo()
          element_info[copy_properties[i][0]].sound[act];
 }
 
-static void InitGameModeSoundInfo()
+static void InitGameModeSoundInfo(void)
 {
   int i;
 
@@ -1961,7 +2028,7 @@ static void set_sound_parameters(int sound, char **parameter_raw)
   sound_info[sound].priority = parameter[SND_ARG_PRIORITY];
 }
 
-static void InitSoundInfo()
+static void InitSoundInfo(void)
 {
   int *sound_effect_properties;
   int num_sounds = getSoundListSize();
@@ -2028,7 +2095,7 @@ static void InitSoundInfo()
   free(sound_effect_properties);
 }
 
-static void InitGameModeMusicInfo()
+static void InitGameModeMusicInfo(void)
 {
   struct PropertyMapping *property_mapping = getMusicListPropertyMapping();
   int num_property_mappings = getMusicListPropertyMappingSize();
@@ -2111,7 +2178,7 @@ static void set_music_parameters(int music, char **parameter_raw)
     music_info[music].loop = parameter[MUS_ARG_MODE_LOOP];
 }
 
-static void InitMusicInfo()
+static void InitMusicInfo(void)
 {
   int num_music = getMusicListSize();
   int i, j;
@@ -2147,7 +2214,7 @@ static void InitMusicInfo()
   }
 }
 
-static void ReinitializeGraphics()
+static void ReinitializeGraphics(void)
 {
   print_timestamp_init("ReinitializeGraphics");
 
@@ -2193,7 +2260,7 @@ static void ReinitializeGraphics()
   print_timestamp_done("ReinitializeGraphics");
 }
 
-static void ReinitializeSounds()
+static void ReinitializeSounds(void)
 {
   InitSoundInfo();             /* sound properties mapping */
   InitElementSoundInfo();      /* element game sound mapping */
@@ -2203,7 +2270,7 @@ static void ReinitializeSounds()
   InitPlayLevelSound();                /* internal game sound settings */
 }
 
-static void ReinitializeMusic()
+static void ReinitializeMusic(void)
 {
   InitMusicInfo();             /* music properties mapping */
   InitGameModeMusicInfo();     /* game mode music mapping */
@@ -2395,7 +2462,7 @@ void ResolveGroupElement(int group_element)
   ResolveGroupElementExt(group_element, 0);
 }
 
-void InitElementPropertiesStatic()
+void InitElementPropertiesStatic(void)
 {
   static boolean clipboard_elements_initialized = FALSE;
 
@@ -3607,12 +3674,8 @@ void InitElementPropertiesStatic()
     EL_INVISIBLE_WALL_ACTIVE,
     EL_SWITCHGATE_SWITCH_UP,
     EL_SWITCHGATE_SWITCH_DOWN,
-    EL_DC_SWITCHGATE_SWITCH_UP,
-    EL_DC_SWITCHGATE_SWITCH_DOWN,
     EL_TIMEGATE_SWITCH,
     EL_TIMEGATE_SWITCH_ACTIVE,
-    EL_DC_TIMEGATE_SWITCH,
-    EL_DC_TIMEGATE_SWITCH_ACTIVE,
     EL_EMC_WALL_1,
     EL_EMC_WALL_2,
     EL_EMC_WALL_3,
@@ -3681,6 +3744,12 @@ void InitElementPropertiesStatic()
     EL_SIGN_FRANKIE,
     EL_STEEL_EXIT_CLOSED,
     EL_STEEL_EXIT_OPEN,
+    EL_STEEL_EXIT_OPENING,
+    EL_STEEL_EXIT_CLOSING,
+    EL_EM_STEEL_EXIT_CLOSED,
+    EL_EM_STEEL_EXIT_OPEN,
+    EL_EM_STEEL_EXIT_OPENING,
+    EL_EM_STEEL_EXIT_CLOSING,
     EL_DC_STEELWALL_1_LEFT,
     EL_DC_STEELWALL_1_RIGHT,
     EL_DC_STEELWALL_1_TOP,
@@ -3733,14 +3802,34 @@ void InitElementPropertiesStatic()
     EL_EM_GATE_2_GRAY_ACTIVE,
     EL_EM_GATE_3_GRAY_ACTIVE,
     EL_EM_GATE_4_GRAY_ACTIVE,
+    EL_EMC_GATE_5,
+    EL_EMC_GATE_6,
+    EL_EMC_GATE_7,
+    EL_EMC_GATE_8,
+    EL_EMC_GATE_5_GRAY,
+    EL_EMC_GATE_6_GRAY,
+    EL_EMC_GATE_7_GRAY,
+    EL_EMC_GATE_8_GRAY,
+    EL_EMC_GATE_5_GRAY_ACTIVE,
+    EL_EMC_GATE_6_GRAY_ACTIVE,
+    EL_EMC_GATE_7_GRAY_ACTIVE,
+    EL_EMC_GATE_8_GRAY_ACTIVE,
+    EL_DC_GATE_WHITE,
+    EL_DC_GATE_WHITE_GRAY,
+    EL_DC_GATE_WHITE_GRAY_ACTIVE,
+    EL_DC_GATE_FAKE_GRAY,
     EL_SWITCHGATE_OPEN,
     EL_SWITCHGATE_OPENING,
     EL_SWITCHGATE_CLOSED,
     EL_SWITCHGATE_CLOSING,
+    EL_DC_SWITCHGATE_SWITCH_UP,
+    EL_DC_SWITCHGATE_SWITCH_DOWN,
     EL_TIMEGATE_OPEN,
     EL_TIMEGATE_OPENING,
     EL_TIMEGATE_CLOSED,
     EL_TIMEGATE_CLOSING,
+    EL_DC_TIMEGATE_SWITCH,
+    EL_DC_TIMEGATE_SWITCH_ACTIVE,
     EL_TUBE_ANY,
     EL_TUBE_VERTICAL,
     EL_TUBE_HORIZONTAL,
@@ -3752,6 +3841,9 @@ void InitElementPropertiesStatic()
     EL_TUBE_LEFT_DOWN,
     EL_TUBE_RIGHT_UP,
     EL_TUBE_RIGHT_DOWN,
+    EL_EXPANDABLE_STEELWALL_HORIZONTAL,
+    EL_EXPANDABLE_STEELWALL_VERTICAL,
+    EL_EXPANDABLE_STEELWALL_ANY,
 
     -1
   };
@@ -4225,6 +4317,8 @@ void InitElementPropertiesStatic()
     EL_INTERNAL_CASCADE_SP_ACTIVE,
     EL_INTERNAL_CASCADE_DC_ACTIVE,
     EL_INTERNAL_CASCADE_DX_ACTIVE,
+    EL_INTERNAL_CASCADE_MM_ACTIVE,
+    EL_INTERNAL_CASCADE_DF_ACTIVE,
     EL_INTERNAL_CASCADE_CHARS_ACTIVE,
     EL_INTERNAL_CASCADE_STEEL_CHARS_ACTIVE,
     EL_INTERNAL_CASCADE_CE_ACTIVE,
@@ -4246,6 +4340,8 @@ void InitElementPropertiesStatic()
     EL_INTERNAL_CASCADE_SP,
     EL_INTERNAL_CASCADE_DC,
     EL_INTERNAL_CASCADE_DX,
+    EL_INTERNAL_CASCADE_MM,
+    EL_INTERNAL_CASCADE_DF,
     EL_INTERNAL_CASCADE_CHARS,
     EL_INTERNAL_CASCADE_STEEL_CHARS,
     EL_INTERNAL_CASCADE_CE,
@@ -4488,8 +4584,8 @@ void InitElementPropertiesEngine(int engine_version)
     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)));
+      SET_PROPERTY(i, EP_DRAGONFIRE_PROOF, (IS_INDESTRUCTIBLE(i) &&
+                                           i != EL_ACID));
 
     /* ---------- EXPLOSION_PROOF ------------------------------------------ */
     if (i == EL_FLAMES)
@@ -4643,26 +4739,7 @@ void InitElementPropertiesEngine(int engine_version)
     InitElementGraphicInfo();
 }
 
-void InitElementPropertiesAfterLoading(int engine_version)
-{
-  int i;
-
-  /* set some other uninitialized values of custom elements in older levels */
-  if (engine_version < VERSION_IDENT(3,1,0,0))
-  {
-    for (i = 0; i < NUM_CUSTOM_ELEMENTS; i++)
-    {
-      int element = EL_CUSTOM_START + i;
-
-      element_info[element].access_direction = MV_ALL_DIRECTIONS;
-
-      element_info[element].explosion_delay = 17;
-      element_info[element].ignition_delay = 8;
-    }
-  }
-}
-
-void InitElementPropertiesGfxElement()
+void InitElementPropertiesGfxElement(void)
 {
   int i;
 
@@ -4674,7 +4751,7 @@ void InitElementPropertiesGfxElement()
   }
 }
 
-static void InitGlobal()
+static void InitGlobal(void)
 {
   int graphic;
   int i;
@@ -4690,6 +4767,16 @@ static void InitGlobal()
     element_info[i].editor_description= element_name_info[i].editor_description;
   }
 
+  for (i = 0; i < NUM_GLOBAL_ANIM_TOKENS + 1; i++)
+  {
+    /* check if global_anim_name_info defined for each entry in "main.h" */
+    if (i < NUM_GLOBAL_ANIM_TOKENS &&
+       global_anim_name_info[i].token_name == NULL)
+      Error(ERR_EXIT, "undefined 'global_anim_name_info' entry for anim %d", i);
+
+    global_anim_info[i].token_name = global_anim_name_info[i].token_name;
+  }
+
   /* create hash from image config list */
   image_config_hash = newSetupFileHash();
   for (i = 0; image_config[i].token != NULL; i++)
@@ -4793,6 +4880,7 @@ static void InitGlobal()
   global.create_images_dir = NULL;
 
   global.frames_per_second = 0;
+  global.show_frames_per_second = FALSE;
 
   global.border_status = GAME_MODE_LOADING;
   global.anim_status = global.anim_status_next = GAME_MODE_LOADING;
@@ -4800,7 +4888,7 @@ static void InitGlobal()
   global.use_envelope_request = FALSE;
 }
 
-void Execute_Command(char *command)
+static void Execute_Command(char *command)
 {
   int i;
 
@@ -4981,6 +5069,8 @@ void Execute_Command(char *command)
       *str_ptr++ = '\0';                       /* terminate leveldir string */
       global.convert_level_nr = atoi(str_ptr); /* get level_nr value */
     }
+
+    program.headless = TRUE;
   }
   else if (strPrefix(command, "create images "))
   {
@@ -5000,24 +5090,33 @@ void Execute_Command(char *command)
   {
     Error(ERR_EXIT_HELP, "unrecognized command '%s'", command);
   }
+
+  /* disable networking if any valid command was recognized */
+  options.network = setup.network_mode = FALSE;
 }
 
-static void InitSetup()
+static void InitSetup(void)
 {
   LoadSetup();                                 /* global setup info */
+  LoadSetup_AutoSetup();                       /* global auto setup info */
 
   /* set some options from setup file */
 
   if (setup.options.verbose)
     options.verbose = TRUE;
+
+  if (setup.debug.show_frames_per_second)
+    global.show_frames_per_second = TRUE;
 }
 
-static void InitGameInfo()
+static void InitGameInfo(void)
 {
   game.restart_level = FALSE;
+  game.restart_game_message = NULL;
+  game.request_active = FALSE;
 }
 
-static void InitPlayerInfo()
+static void InitPlayerInfo(void)
 {
   int i;
 
@@ -5025,12 +5124,15 @@ static void InitPlayerInfo()
   local_player = &stored_player[0];
 
   for (i = 0; i < MAX_PLAYERS; i++)
-    stored_player[i].connected = FALSE;
+  {
+    stored_player[i].connected_locally = FALSE;
+    stored_player[i].connected_network = FALSE;
+  }
 
-  local_player->connected = TRUE;
+  local_player->connected_locally = TRUE;
 }
 
-static void InitArtworkInfo()
+static void InitArtworkInfo(void)
 {
   LoadArtworkInfo();
 }
@@ -5056,7 +5158,7 @@ static char *get_level_id_suffix(int id_nr)
   return id_suffix;
 }
 
-static void InitArtworkConfig()
+static void InitArtworkConfig(void)
 {
   static char *image_id_prefix[MAX_NUM_ELEMENTS +
                               NUM_FONTS +
@@ -5074,6 +5176,10 @@ static void InitArtworkConfig()
   {
     "name",
     "sort_priority",
+    "program_title",
+    "program_copyright",
+    "program_company",
+
     NULL
   };
   static char **ignore_image_tokens;
@@ -5172,14 +5278,25 @@ static void InitArtworkConfig()
                level_id_suffix, ignore_music_tokens);
 }
 
-static void InitMixer()
+static void InitMixer(void)
 {
   OpenAudio();
 
   StartMixer();
 }
 
-void InitGfxBuffers()
+static void InitVideoOverlay(void)
+{
+  // if virtual buttons are not loaded from setup file, repeat initializing
+  // virtual buttons grid with default values now that video is initialized
+  if (!setup.touch.grid_initialized)
+    InitSetup();
+
+  InitTileCursorInfo();
+  InitOverlayInfo();
+}
+
+void InitGfxBuffers(void)
 {
   static int win_xsize_last = -1;
   static int win_ysize_last = -1;
@@ -5219,13 +5336,12 @@ void InitGfxBuffers()
   InitGfxBuffers_SP();
 }
 
-void InitGfx()
+static void InitGfx(void)
 {
   struct GraphicInfo *graphic_info_last = graphic_info;
   char *filename_font_initial = NULL;
   char *filename_anim_initial = NULL;
   Bitmap *bitmap_font_initial = NULL;
-  int font_height;
   int i, j;
 
   /* determine settings for initial font (for displaying startup messages) */
@@ -5276,12 +5392,7 @@ void InitGfx()
 
   InitFontGraphicInfo();
 
-  font_height = getFontHeight(FC_RED);
-
-  DrawInitText(getProgramInitString(), 20, FC_YELLOW);
-  DrawInitText(setup.internal.program_copyright, 50, FC_RED);
-  DrawInitText(setup.internal.program_website, WIN_YSIZE - 20 - font_height,
-              FC_RED);
+  DrawProgramInfo();
 
   DrawInitText("Loading graphics", 120, FC_GREEN);
 
@@ -5378,6 +5489,7 @@ void InitGfx()
   InitGfxDrawBusyAnimFunction(DrawInitAnim);
   InitGfxDrawGlobalAnimFunction(DrawGlobalAnimations);
   InitGfxDrawGlobalBorderFunction(DrawMaskedBorderToTarget);
+  InitGfxDrawTileCursorFunction(DrawTileCursor);
 
   gfx.fade_border_source_status = global.border_status;
   gfx.fade_border_target_status = global.border_status;
@@ -5387,7 +5499,7 @@ void InitGfx()
   init_last = init;
 }
 
-void InitGfxBackground()
+static void InitGfxBackground(void)
 {
   fieldbuffer = bitmap_db_field;
   SetDrawtoField(DRAW_TO_BACKBUFFER);
@@ -5397,7 +5509,7 @@ void InitGfxBackground()
   redraw_mask = REDRAW_ALL;
 }
 
-static void InitLevelInfo()
+static void InitLevelInfo(void)
 {
   LoadLevelInfo();                             /* global level info */
   LoadLevelSetup_LastSeries();                 /* last played series info */
@@ -5411,14 +5523,16 @@ static void InitLevelInfo()
     if (leveldir_current == NULL)
       leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
   }
+
+  SetLevelSetInfo(leveldir_current->identifier, level_nr);
 }
 
-static void InitLevelArtworkInfo()
+static void InitLevelArtworkInfo(void)
 {
   LoadLevelArtworkInfo();
 }
 
-static void InitImages()
+static void InitImages(void)
 {
   print_timestamp_init("InitImages");
 
@@ -5521,7 +5635,7 @@ static void InitMusic(char *identifier)
   print_timestamp_done("InitMusic");
 }
 
-static void InitArtworkDone()
+static void InitArtworkDone(void)
 {
   if (program.headless)
     return;
@@ -5529,27 +5643,50 @@ static void InitArtworkDone()
   InitGlobalAnimations();
 }
 
-void InitNetworkServer()
+static void InitNetworkSettings(void)
 {
-#if defined(NETWORK_AVALIABLE)
-  int nr_wanted;
-#endif
+  boolean network_enabled = (options.network || setup.network_mode);
+  char *network_server = (options.server_host != NULL ? options.server_host :
+                         setup.network_server_hostname);
+
+  if (strEqual(network_server, STR_NETWORK_AUTO_DETECT))
+    network_server = NULL;
+
+  InitNetworkInfo(network_enabled,
+                 FALSE,
+                 options.serveronly,
+                 network_server,
+                 options.server_port);
+}
 
-  if (!options.network)
+void InitNetworkServer(void)
+{
+  if (!network.enabled || network.connected)
     return;
 
-#if defined(NETWORK_AVALIABLE)
-  nr_wanted = Request("Choose player", REQ_PLAYER | REQ_STAY_CLOSED);
+  LimitScreenUpdates(FALSE);
 
-  if (!ConnectToServer(options.server_host, options.server_port))
-    Error(ERR_EXIT, "cannot connect to network game server");
+  if (game_status == GAME_MODE_LOADING)
+    DrawProgramInfo();
 
-  SendToServer_PlayerName(setup.player_name);
-  SendToServer_ProtocolVersion();
+  if (!ConnectToServer(network.server_host, network.server_port))
+  {
+    network.enabled = FALSE;
 
-  if (nr_wanted)
-    SendToServer_NrWanted(nr_wanted);
-#endif
+    setup.network_mode = FALSE;
+  }
+  else
+  {
+    SendToServer_ProtocolVersion();
+    SendToServer_PlayerName(setup.player_name);
+    SendToServer_NrWanted(setup.network_player_nr + 1);
+
+    network.connected = TRUE;
+  }
+
+  /* short time to recognize result of network initialization */
+  if (game_status == GAME_MODE_LOADING)
+    Delay_WithScreenUpdates(1000);
 }
 
 static boolean CheckArtworkConfigForCustomElements(char *filename)
@@ -5625,7 +5762,7 @@ static boolean CheckArtworkTypeForRedefinedCustomElements(int type)
   return redefined_ce_found;
 }
 
-static void InitOverrideArtwork()
+static void InitOverrideArtwork(void)
 {
   boolean redefined_ce_found = FALSE;
 
@@ -5826,7 +5963,7 @@ void ReloadCustomArtwork(int force_reload)
   LimitScreenUpdates(FALSE);
 }
 
-void KeyboardAutoRepeatOffUnlessAutoplay()
+void KeyboardAutoRepeatOffUnlessAutoplay(void)
 {
   if (global.autoplay_leveldir == NULL)
     KeyboardAutoRepeatOff();
@@ -5834,6 +5971,10 @@ void KeyboardAutoRepeatOffUnlessAutoplay()
 
 void DisplayExitMessage(char *format, va_list ap)
 {
+  // also check for initialized video (headless flag may be temporarily unset)
+  if (program.headless || !video.initialized)
+    return;
+
   // check if draw buffer and fonts for exit message are already available
   if (drawto == NULL || font_initial[NUM_INITIAL_FONTS - 1].bitmap == NULL)
     return;
@@ -5897,7 +6038,7 @@ void DisplayExitMessage(char *format, va_list ap)
 /* OpenAll()                                                                 */
 /* ========================================================================= */
 
-void OpenAll()
+void OpenAll(void)
 {
   print_timestamp_init("OpenAll");
 
@@ -5918,10 +6059,12 @@ void OpenAll()
   if (options.execute_command)
     Execute_Command(options.execute_command);
 
-  if (options.serveronly)
+  InitNetworkSettings();
+
+  if (network.serveronly)
   {
 #if defined(PLATFORM_UNIX)
-    NetworkServer(options.server_port, options.serveronly);
+    NetworkServer(network.server_port, TRUE);
 #else
     Error(ERR_WARN, "networking only supported in Unix version");
 #endif
@@ -5947,10 +6090,10 @@ void OpenAll()
 
   print_timestamp_time("[init setup/config stuff]");
 
+  InitVideoDefaults();
   InitVideoDisplay();
   InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
-
-  InitOverlayInfo();
+  InitVideoOverlay();
 
   print_timestamp_time("[init video stuff]");
 
@@ -5988,6 +6131,7 @@ void OpenAll()
 
   em_open_all();
   sp_open_all();
+  mm_open_all();
 
   if (global.autoplay_leveldir)
   {
@@ -6005,6 +6149,8 @@ void OpenAll()
     return;
   }
 
+  InitNetworkServer();
+
   SetGameStatus(GAME_MODE_MAIN);
 
   FadeSetEnterScreen();
@@ -6017,8 +6163,6 @@ void OpenAll()
 
   DrawMainMenu();
 
-  InitNetworkServer();
-
 #if 0
   Error(ERR_DEBUG, "::: SDL_GetBasePath() == '%s'",
        SDL_GetBasePath());
@@ -6030,10 +6174,10 @@ void OpenAll()
   Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStoragePath() == '%s'",
        SDL_AndroidGetExternalStoragePath());
   Error(ERR_DEBUG, "::: SDL_AndroidGetExternalStorageState() == '%s'",
-       (SDL_AndroidGetExternalStorageState() ==
-        SDL_ANDROID_EXTERNAL_STORAGE_READ ? "read" :
-        SDL_AndroidGetExternalStorageState() ==
-        SDL_ANDROID_EXTERNAL_STORAGE_WRITE ? "write" : "not available"));
+       (SDL_AndroidGetExternalStorageState() &
+        SDL_ANDROID_EXTERNAL_STORAGE_WRITE ? "writable" :
+        SDL_AndroidGetExternalStorageState() &
+        SDL_ANDROID_EXTERNAL_STORAGE_READ ? "readable" : "not available"));
 #endif
 #endif
 }
@@ -6064,7 +6208,7 @@ void CloseAllAndExit(int exit_value)
   CloseVideoDisplay();
   ClosePlatformDependentStuff();
 
-  if (exit_value != 0)
+  if (exit_value != 0 && !options.execute_command)
   {
     /* fall back to default level set (current set may have caused an error) */
     SaveLevelSetup_LastSeries_Deactivate();