re-added file "RocksBusy.ilbm" (that was accidentally deleted)
[rocksndiamonds.git] / src / init.c
index 48cb8973be387bf5d7d68985b3cfcd9cf2c275ec..6db427ff5333ec44191426f5346ee4c32258df1e 100644 (file)
@@ -551,6 +551,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 =
@@ -1048,6 +1053,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];
@@ -1055,6 +1062,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 !!! */
@@ -1280,6 +1289,8 @@ static void set_graphic_parameters_ext(int graphic, int *parameter,
   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;
@@ -1502,6 +1513,10 @@ static void set_graphic_parameters_ext(int graphic, int *parameter,
     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];
@@ -1927,6 +1942,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 !!! */
@@ -4683,25 +4700,6 @@ 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()
 {
   int i;
@@ -5053,11 +5051,15 @@ 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()
 {
   LoadSetup();                                 /* global setup info */
+  LoadSetup_AutoSetup();                       /* global auto setup info */
 
   /* set some options from setup file */
 
@@ -5071,6 +5073,7 @@ static void InitSetup()
 static void InitGameInfo()
 {
   game.restart_level = FALSE;
+  game.restart_game_message = NULL;
 }
 
 static void InitPlayerInfo()
@@ -5081,9 +5084,12 @@ 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()
@@ -5130,6 +5136,10 @@ static void InitArtworkConfig()
   {
     "name",
     "sort_priority",
+    "program_title",
+    "program_copyright",
+    "program_company",
+
     NULL
   };
   static char **ignore_image_tokens;
@@ -5235,6 +5245,17 @@ static void InitMixer()
   StartMixer();
 }
 
+static void InitVideoOverlay()
+{
+  // 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()
 {
   static int win_xsize_last = -1;
@@ -5434,6 +5455,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;
@@ -5467,6 +5489,8 @@ static void InitLevelInfo()
     if (leveldir_current == NULL)
       leveldir_current = getFirstValidTreeInfoEntry(leveldir_first);
   }
+
+  SetLevelSetInfo(leveldir_current->identifier, level_nr);
 }
 
 static void InitLevelArtworkInfo()
@@ -5585,27 +5609,39 @@ static void InitArtworkDone()
   InitGlobalAnimations();
 }
 
-void InitNetworkServer()
+void InitNetworkSettings()
 {
-#if defined(NETWORK_AVALIABLE)
-  int nr_wanted;
-#endif
+  InitNetworkInfo(options.network || setup.network_mode,
+                 FALSE,
+                 options.serveronly,
+                 options.server_host,
+                 options.server_port);
+}
 
-  if (!options.network)
+void InitNetworkServer()
+{
+  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 (!ConnectToServer(network.server_host, network.server_port))
+  {
+    network.enabled = FALSE;
 
-  SendToServer_PlayerName(setup.player_name);
-  SendToServer_ProtocolVersion();
+    setup.network_mode = FALSE;
+  }
+  else
+  {
+    SendToServer_ProtocolVersion();
+    SendToServer_PlayerName(setup.player_name);
+    SendToServer_NrWanted(setup.network_player_nr + 1);
 
-  if (nr_wanted)
-    SendToServer_NrWanted(nr_wanted);
-#endif
+    network.connected = TRUE;
+  }
+
+  /* short time to recognize result of network initialization */
+  Delay_WithScreenUpdates(1000);
 }
 
 static boolean CheckArtworkConfigForCustomElements(char *filename)
@@ -5890,6 +5926,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;
@@ -5974,10 +6014,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
@@ -6003,10 +6045,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]");
 
@@ -6044,6 +6086,7 @@ void OpenAll()
 
   em_open_all();
   sp_open_all();
+  mm_open_all();
 
   if (global.autoplay_leveldir)
   {
@@ -6061,6 +6104,8 @@ void OpenAll()
     return;
   }
 
+  InitNetworkServer();
+
   SetGameStatus(GAME_MODE_MAIN);
 
   FadeSetEnterScreen();
@@ -6073,8 +6118,6 @@ void OpenAll()
 
   DrawMainMenu();
 
-  InitNetworkServer();
-
 #if 0
   Error(ERR_DEBUG, "::: SDL_GetBasePath() == '%s'",
        SDL_GetBasePath());