- turned menu into a class, still a lot of public variables around and menu_item...
[supertux.git] / src / setup.cpp
index ecc64ba..d1ccad6 100644 (file)
@@ -10,6 +10,7 @@
   April 11, 2000 - March 15, 2004
 */
 
+#include <assert.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <SDL_opengl.h>
 #endif
 
-#ifdef LINUX
-#include <pwd.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <dirent.h>
-#include <ctype.h>
+#ifndef WIN32
+#include <libgen.h>
 #endif
+#include <ctype.h>
 
 #include "defines.h"
 #include "globals.h"
 #include "menu.h"
 #include "gameloop.h"
 
+#ifdef WIN32
+#define mkdir(dir, mode)    mkdir(dir)
+// on win32 we typically don't want LFS paths
+#undef DATA_PREFIX
+#define DATA_PREFIX "./data"
+#endif
+
 /* Local function prototypes: */
 
 void seticon(void);
 void usage(char * prog, int ret);
 
 /* Does the given file exist and is it accessible? */
-int faccessible(char *filename)
+int faccessible(const char *filename)
 {
   struct stat filestat;
   if (stat(filename, &filestat) == -1)
     {
-      return NO;
+      return false;
     }
   else
     {
       if(S_ISREG(filestat.st_mode))
-        return YES;
+        return true;
       else
-        return NO;
+        return false;
     }
 }
 
 /* Can we write to this location? */
-int fwriteable(char *filename)
+int fwriteable(const char *filename)
 {
   FILE* fi;
   fi = fopen(filename, "wa");
   if (fi == NULL)
     {
-      return NO;
+      return false;
     }
-  return YES;
+  return true;
 }
 
 /* Makes sure a directory is created in either the SuperTux base directory or the SuperTux base directory.*/
-int fcreatedir(char* relative_dir)
+int fcreatedir(const char* relative_dir)
 {
   char path[1024];
   snprintf(path, 1024, "%s/%s/", st_dir, relative_dir);
   if(mkdir(path,0755) != 0)
     {
-      snprintf(path, 1024, "%s/%s/", DATA_PREFIX, relative_dir);
+      snprintf(path, 1024, "%s/%s/", datadir.c_str(), relative_dir);
       if(mkdir(path,0755) != 0)
         {
-          return NO;
+          return false;
         }
       else
         {
-          return YES;
+          return true;
         }
     }
   else
     {
-      return YES;
+      return true;
     }
 }
 
 /* Get all names of sub-directories in a certain directory. */
 /* Returns the number of sub-directories found. */
 /* Note: The user has to free the allocated space. */
-string_list_type dsubdirs(char *rel_path, char* expected_file)
+string_list_type dsubdirs(const char *rel_path,const  char* expected_file)
 {
   DIR *dirStructP;
   struct dirent *direntp;
-  int i = 0;
   string_list_type sdirs;
   char filename[1024];
   char path[1024];
@@ -132,7 +139,7 @@ string_list_type dsubdirs(char *rel_path, char* expected_file)
       closedir(dirStructP);
     }
 
-  sprintf(path,"%s/%s",DATA_PREFIX,rel_path);
+  sprintf(path,"%s/%s",datadir.c_str(),rel_path);
   if((dirStructP = opendir(path)) != NULL)
     {
       while((direntp = readdir(dirStructP)) != NULL)
@@ -168,13 +175,11 @@ string_list_type dsubdirs(char *rel_path, char* expected_file)
   return sdirs;
 }
 
-string_list_type dfiles(char *rel_path, char* glob, char* exception_str)
+string_list_type dfiles(const char *rel_path, const  char* glob, const  char* exception_str)
 {
   DIR *dirStructP;
   struct dirent *direntp;
-  int i = 0;
   string_list_type sdirs;
-  char filename[1024];
   char path[1024];
 
   string_list_init(&sdirs);
@@ -205,7 +210,7 @@ string_list_type dfiles(char *rel_path, char* glob, char* exception_str)
       closedir(dirStructP);
     }
 
-  sprintf(path,"%s/%s",DATA_PREFIX,rel_path);
+  sprintf(path,"%s/%s",datadir.c_str(),rel_path);
   if((dirStructP = opendir(path)) != NULL)
     {
       while((direntp = readdir(dirStructP)) != NULL)
@@ -256,7 +261,7 @@ void st_directory_setup(void)
     home = ".";
 
   st_dir = (char *) malloc(sizeof(char) * (strlen(home) +
-                           strlen("/.supertux") + 1));
+                                           strlen("/.supertux") + 1));
   strcpy(st_dir, home);
   strcat(st_dir, "/.supertux");
 
@@ -273,99 +278,116 @@ void st_directory_setup(void)
   strcat(st_save_dir,"/save");
 
   /* Create them. In the case they exist they won't destroy anything. */
-#ifdef LINUX
-
   mkdir(st_dir, 0755);
   mkdir(st_save_dir, 0755);
 
   sprintf(str, "%s/levels", st_dir);
   mkdir(str, 0755);
-#else
-  #ifdef WIN32
 
-  mkdir(st_dir);
-  mkdir(st_save_dir);
-  sprintf(str, "%s/levels", st_dir);
-  mkdir(str);
-#endif
+  // User has not that a datadir, so we try some magic
+  if (datadir.empty())
+    {
+#ifndef WIN32
+      // Detect datadir
+      char exe_file[PATH_MAX];
+      if (readlink("/proc/self/exe", exe_file, PATH_MAX) < 0)
+        {
+          puts("Couldn't read /proc/self/exe, using default path: " DATA_PREFIX);
+          datadir = DATA_PREFIX;
+        }
+      else
+        {
+          std::string exedir = std::string(dirname(exe_file)) + "/";
+          
+          datadir = exedir + "../data/"; // SuperTux run from source dir
+          if (access(datadir.c_str(), F_OK) != 0)
+            {
+              datadir = exedir + "../share/supertux/"; // SuperTux run from PATH
+              if (access(datadir.c_str(), F_OK) != 0) 
+                { // If all fails, fall back to compiled path
+                  datadir = DATA_PREFIX; 
+                }
+            }
+        }
+#else
+       datadir = DATA_PREFIX;
 #endif
-
+    }
+  printf("Datadir: %s\n", datadir.c_str());
 }
 
 /* Create and setup menus. */
 void st_menu(void)
 {
-  menu_init(&main_menu);
-  menu_additem(&main_menu,menu_item_create(MN_LABEL,"Main Menu",0,0));
-  menu_additem(&main_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&main_menu,menu_item_create(MN_ACTION,"Start Game",0,0));
-  menu_additem(&main_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu));
-  menu_additem(&main_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu));
-  menu_additem(&main_menu,menu_item_create(MN_ACTION,"Level editor",0,0));
-  menu_additem(&main_menu,menu_item_create(MN_ACTION,"Credits",0,0));
-  menu_additem(&main_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&main_menu,menu_item_create(MN_ACTION,"Quit",0,0));
-
-  menu_init(&options_menu);
-  menu_additem(&options_menu,menu_item_create(MN_LABEL,"Options",0,0));
-  menu_additem(&options_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Fullscreen",use_fullscreen,0));
-  if(audio_device == YES)
+  main_menu      = new Menu();
+  options_menu   = new Menu();
+  load_game_menu = new Menu();
+  save_game_menu = new Menu();
+  game_menu      = new Menu();
+  highscore_menu = new Menu();
+
+  main_menu->additem(MN_LABEL,"Main Menu",0,0);
+  main_menu->additem(MN_HL,"",0,0);
+  main_menu->additem(MN_ACTION,"Start Game",0,0);
+  main_menu->additem(MN_GOTO,"Load Game",0,load_game_menu);
+  main_menu->additem(MN_GOTO,"Options",0,options_menu);
+  main_menu->additem(MN_ACTION,"Level editor",0,0);
+  main_menu->additem(MN_ACTION,"Credits",0,0);
+  main_menu->additem(MN_HL,"",0,0);
+  main_menu->additem(MN_ACTION,"Quit",0,0);
+
+  options_menu->additem(MN_LABEL,"Options",0,0);
+  options_menu->additem(MN_HL,"",0,0);
+  options_menu->additem(MN_TOGGLE,"Fullscreen",use_fullscreen,0);
+  if(audio_device)
     {
-      menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Sound     ",use_sound,0));
-      menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Music     ",use_music,0));
+      options_menu->additem(MN_TOGGLE,"Sound     ",use_sound,0);
+      options_menu->additem(MN_TOGGLE,"Music     ",use_music,0);
     }
   else
     {
-      menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Sound     ",use_sound,0));
-      menu_additem(&options_menu,menu_item_create(MN_DEACTIVE,"Music     ",use_music,0));
+      options_menu->additem(MN_DEACTIVE,"Sound     ",use_sound,0);
+      options_menu->additem(MN_DEACTIVE,"Music     ",use_music,0);
     }
-  menu_additem(&options_menu,menu_item_create(MN_TOGGLE,"Show FPS  ",show_fps,0));
-  menu_additem(&options_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&options_menu,menu_item_create(MN_BACK,"Back",0,0));
-
-  menu_init(&load_game_menu);
-  menu_additem(&load_game_menu,menu_item_create(MN_LABEL,"Load Game",0,0));
-  menu_additem(&load_game_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 1",0,0));
-  menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 2",0,0));
-  menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 3",0,0));
-  menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 4",0,0));
-  menu_additem(&load_game_menu,menu_item_create(MN_DEACTIVE,"Slot 5",0,0));
-  menu_additem(&load_game_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&load_game_menu,menu_item_create(MN_BACK,"Back",0,0));
-
-  menu_init(&save_game_menu);
-  menu_additem(&save_game_menu,menu_item_create(MN_LABEL,"Save Game",0,0));
-  menu_additem(&save_game_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 1",0,0));
-  menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 2",0,0));
-  menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 3",0,0));
-  menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 4",0,0));
-  menu_additem(&save_game_menu,menu_item_create(MN_DEACTIVE,"Slot 5",0,0));
-  menu_additem(&save_game_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&save_game_menu,menu_item_create(MN_BACK,"Back",0,0));
-
-  menu_init(&game_menu);
-  menu_additem(&game_menu,menu_item_create(MN_LABEL,"InGame Menu",0,0));
-  menu_additem(&game_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&game_menu,menu_item_create(MN_ACTION,"Return To Game",0,0));
-  menu_additem(&game_menu,menu_item_create(MN_GOTO,"Save Game",0,&save_game_menu));
-  menu_additem(&game_menu,menu_item_create(MN_GOTO,"Load Game",0,&load_game_menu));
-  menu_additem(&game_menu,menu_item_create(MN_GOTO,"Options",0,&options_menu));
-  menu_additem(&game_menu,menu_item_create(MN_HL,"",0,0));
-  menu_additem(&game_menu,menu_item_create(MN_ACTION,"Quit Game",0,0));
-
-  menu_init(&highscore_menu);
-  menu_additem(&highscore_menu,menu_item_create(MN_TEXTFIELD,"Enter your name:",0,0));
-
+  options_menu->additem(MN_TOGGLE,"Show FPS  ",show_fps,0);
+  options_menu->additem(MN_HL,"",0,0);
+  options_menu->additem(MN_BACK,"Back",0,0);
+
+  load_game_menu->additem(MN_LABEL,"Load Game",0,0);
+  load_game_menu->additem(MN_HL,"",0,0);
+  load_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0);
+  load_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0);
+  load_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0);
+  load_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0);
+  load_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0);
+  load_game_menu->additem(MN_HL,"",0,0);
+  load_game_menu->additem(MN_BACK,"Back",0,0);
+
+  save_game_menu->additem(MN_LABEL,"Save Game",0,0);
+  save_game_menu->additem(MN_HL,"",0,0);
+  save_game_menu->additem(MN_DEACTIVE,"Slot 1",0,0);
+  save_game_menu->additem(MN_DEACTIVE,"Slot 2",0,0);
+  save_game_menu->additem(MN_DEACTIVE,"Slot 3",0,0);
+  save_game_menu->additem(MN_DEACTIVE,"Slot 4",0,0);
+  save_game_menu->additem(MN_DEACTIVE,"Slot 5",0,0);
+  save_game_menu->additem(MN_HL,"",0,0);
+  save_game_menu->additem(MN_BACK,"Back",0,0);
+
+  game_menu->additem(MN_LABEL,"InGame Menu",0,0);
+  game_menu->additem(MN_HL,"",0,0);
+  game_menu->additem(MN_ACTION,"Return To Game",0,0);
+  game_menu->additem(MN_GOTO,"Save Game",0,save_game_menu);
+  game_menu->additem(MN_GOTO,"Load Game",0,load_game_menu);
+  game_menu->additem(MN_GOTO,"Options",0,options_menu);
+  game_menu->additem(MN_HL,"",0,0);
+  game_menu->additem(MN_ACTION,"Quit Game",0,0);
+
+  highscore_menu->additem(MN_TEXTFIELD,"Enter your name:",0,0);
 }
 
-void update_load_save_game_menu(menu_type* pmenu, int load)
+void update_load_save_game_menu(Menu* pmenu, int load)
 {
-  int i;
-
-  for(i = 2; i < 7; ++i)
+  for(int i = 2; i < 7; ++i)
     {
       char *tmp;
       slotinfo(&tmp,i-1);
@@ -381,22 +403,22 @@ void update_load_save_game_menu(menu_type* pmenu, int load)
 void process_save_load_game_menu(int save)
 {
   int slot;
-  switch (slot = menu_check(save ? &save_game_menu : &load_game_menu))
+  switch (slot = (save ? save_game_menu->check() : load_game_menu->check()))
     {
     default:
       if(slot != -1)
         {
-          if(save == YES)
+          if(save == true)
             {
               savegame(slot - 1);
             }
           else
             {
-              if(game_started == NO)
+              if(game_started == false)
                 {
                   gameloop("default",slot - 1,ST_GL_LOAD_GAME);
-                  show_menu = YES;
-                  menu_set_current(&main_menu);
+                  show_menu = true;
+                  Menu::set_current(main_menu);
                 }
               else
                 loadgame(slot - 1);
@@ -410,33 +432,33 @@ void process_save_load_game_menu(int save)
 /* Handle changes made to global settings in the options menu. */
 void process_options_menu(void)
 {
-  switch (menu_check(&options_menu))
+  switch (options_menu->check())
     {
     case 2:
-      if(use_fullscreen != options_menu.item[2].toggled)
+      if(use_fullscreen != options_menu->item[2].toggled)
         {
           use_fullscreen = !use_fullscreen;
           st_video_setup();
         }
       break;
     case 3:
-      if(use_sound != options_menu.item[3].toggled)
+      if(use_sound != options_menu->item[3].toggled)
         use_sound = !use_sound;
       break;
     case 4:
-      if(use_music != options_menu.item[4].toggled)
+      if(use_music != options_menu->item[4].toggled)
         {
-          if(use_music == YES)
+          if(use_music == true)
             {
               if(playing_music())
                 {
                   halt_music();
                 }
-              use_music = NO;
+              use_music = false;
             }
           else
             {
-              use_music = YES;
+              use_music = true;
               if (!playing_music())
                 {
                   play_current_music();
@@ -445,7 +467,7 @@ void process_options_menu(void)
         }
       break;
     case 5:
-      if(show_fps != options_menu.item[5].toggled)
+      if(show_fps != options_menu->item[5].toggled)
         show_fps = !show_fps;
       break;
     }
@@ -467,21 +489,21 @@ void st_general_setup(void)
 
   /* Load global images: */
 
-  text_load(&black_text,DATA_PREFIX "/images/status/letters-black.png", TEXT_TEXT, 16,18);
-  text_load(&gold_text,DATA_PREFIX "/images/status/letters-gold.png", TEXT_TEXT, 16,18);
-  text_load(&blue_text,DATA_PREFIX "/images/status/letters-blue.png", TEXT_TEXT, 16,18);
-  text_load(&red_text,DATA_PREFIX "/images/status/letters-red.png", TEXT_TEXT, 16,18);
-  text_load(&white_text,DATA_PREFIX "/images/status/letters-white.png", TEXT_TEXT, 16,18);
-  text_load(&white_small_text,DATA_PREFIX "/images/status/letters-white-small.png", TEXT_TEXT, 8,9);
-  text_load(&white_big_text,DATA_PREFIX "/images/status/letters-white-big.png", TEXT_TEXT, 20,23);
-  text_load(&yellow_nums,DATA_PREFIX "/images/status/numbers.png", TEXT_NUM, 32,32);
+  text_load(&black_text, datadir + "/images/status/letters-black.png", TEXT_TEXT, 16,18);
+  text_load(&gold_text,datadir + "/images/status/letters-gold.png", TEXT_TEXT, 16,18);
+  text_load(&blue_text,datadir + "/images/status/letters-blue.png", TEXT_TEXT, 16,18);
+  text_load(&red_text,datadir + "/images/status/letters-red.png", TEXT_TEXT, 16,18);
+  text_load(&white_text,datadir + "/images/status/letters-white.png", TEXT_TEXT, 16,18);
+  text_load(&white_small_text,datadir + "/images/status/letters-white-small.png", TEXT_TEXT, 8,9);
+  text_load(&white_big_text,datadir + "/images/status/letters-white-big.png", TEXT_TEXT, 20,23);
+  text_load(&yellow_nums,datadir + "/images/status/numbers.png", TEXT_NUM, 32,32);
 
   /* Load GUI/menu images: */
-  texture_load(&checkbox, DATA_PREFIX "/images/status/checkbox.png", USE_ALPHA);
-  texture_load(&checkbox_checked, DATA_PREFIX "/images/status/checkbox-checked.png", USE_ALPHA);
-  texture_load(&back, DATA_PREFIX "/images/status/back.png", USE_ALPHA);
-  texture_load(&arrow_left, DATA_PREFIX "/images/icons/left.png", USE_ALPHA);
-  texture_load(&arrow_right, DATA_PREFIX "/images/icons/right.png", USE_ALPHA);
+  texture_load(&checkbox, datadir + "/images/status/checkbox.png", USE_ALPHA);
+  texture_load(&checkbox_checked, datadir + "/images/status/checkbox-checked.png", USE_ALPHA);
+  texture_load(&back, datadir + "/images/status/back.png", USE_ALPHA);
+  texture_load(&arrow_left, datadir + "/images/icons/left.png", USE_ALPHA);
+  texture_load(&arrow_right, datadir + "/images/icons/right.png", USE_ALPHA);
 
 }
 
@@ -506,14 +528,12 @@ void st_general_free(void)
   texture_free(&arrow_right);
 
   /* Free menus */
-
-  menu_free(&main_menu);
-  menu_free(&game_menu);
-  menu_free(&options_menu);
-  menu_free(&highscore_menu);
-  menu_free(&save_game_menu);
-  menu_free(&load_game_menu);
-
+  delete main_menu;
+  delete game_menu;
+  delete options_menu;
+  delete highscore_menu;
+  delete save_game_menu;
+  delete load_game_menu;
 }
 
 void st_video_setup(void)
@@ -552,7 +572,7 @@ void st_video_setup_sdl(void)
 {
   SDL_FreeSurface(screen);
 
-  if (use_fullscreen == YES)
+  if (use_fullscreen == true)
     {
       screen = SDL_SetVideoMode(640, 480, 0, SDL_FULLSCREEN ) ; /* | SDL_HWSURFACE); */
       if (screen == NULL)
@@ -562,7 +582,7 @@ void st_video_setup_sdl(void)
                   "640x480 mode.\n"
                   "The Simple DirectMedia error that occured was:\n"
                   "%s\n\n", SDL_GetError());
-          use_fullscreen = NO;
+          use_fullscreen = false;
         }
     }
   else
@@ -590,7 +610,7 @@ void st_video_setup_gl(void)
   SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
   SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 
-  if (use_fullscreen == YES)
+  if (use_fullscreen == true)
     {
       screen = SDL_SetVideoMode(640, 480, 0, SDL_FULLSCREEN | SDL_OPENGL) ; /* | SDL_HWSURFACE); */
       if (screen == NULL)
@@ -600,7 +620,7 @@ void st_video_setup_gl(void)
                   "640x480 mode.\n"
                   "The Simple DirectMedia error that occured was:\n"
                   "%s\n\n", SDL_GetError());
-          use_fullscreen = NO;
+          use_fullscreen = false;
         }
     }
   else
@@ -641,8 +661,7 @@ void st_joystick_setup(void)
 
   /* Init Joystick: */
 
-#ifdef JOY_YES
-  use_joystick = YES;
+  use_joystick = true;
 
   if (SDL_Init(SDL_INIT_JOYSTICK) < 0)
     {
@@ -650,29 +669,28 @@ void st_joystick_setup(void)
               "The Simple DirectMedia error that occured was:\n"
               "%s\n\n", SDL_GetError());
 
-      use_joystick = NO;
+      use_joystick = false;
     }
   else
     {
       /* Open joystick: */
-
       if (SDL_NumJoysticks() <= 0)
         {
           fprintf(stderr, "Warning: No joysticks are available.\n");
 
-          use_joystick = NO;
+          use_joystick = false;
         }
       else
         {
-          js = SDL_JoystickOpen(0);
+          js = SDL_JoystickOpen(joystick_num);
 
           if (js == NULL)
             {
-              fprintf(stderr, "Warning: Could not open joystick 1.\n"
+              fprintf(stderr, "Warning: Could not open joystick %d.\n"
                       "The Simple DirectMedia error that occured was:\n"
-                      "%s\n\n", SDL_GetError());
+                      "%s\n\n", joystick_num, SDL_GetError());
 
-              use_joystick = NO;
+              use_joystick = false;
             }
           else
             {
@@ -683,7 +701,7 @@ void st_joystick_setup(void)
                   fprintf(stderr,
                           "Warning: Joystick does not have enough axes!\n");
 
-                  use_joystick = NO;
+                  use_joystick = false;
                 }
               else
                 {
@@ -693,14 +711,12 @@ void st_joystick_setup(void)
                               "Warning: "
                               "Joystick does not have enough buttons!\n");
 
-                      use_joystick = NO;
+                      use_joystick = false;
                     }
                 }
             }
         }
     }
-#endif
-
 }
 
 void st_audio_setup(void)
@@ -708,14 +724,14 @@ void st_audio_setup(void)
 
   /* Init SDL Audio silently even if --disable-sound : */
 
-  if (audio_device == YES)
+  if (audio_device == true)
     {
       if (SDL_Init(SDL_INIT_AUDIO) < 0)
         {
           /* only print out message if sound or music
              was not disabled at command-line
            */
-          if (use_sound == YES || use_music == YES)
+          if (use_sound || use_music)
             {
               fprintf(stderr,
                       "\nWarning: I could not initialize audio!\n"
@@ -726,23 +742,23 @@ void st_audio_setup(void)
              because in this case, use_sound & use_music' values are ignored
              when there's no available audio device
           */
-          use_sound = NO;
-          use_music = NO;
-          audio_device = NO;
+          use_sound = false;
+          use_music = false;
+          audio_device = false;
         }
     }
 
 
   /* Open sound silently regarless the value of "use_sound": */
 
-  if (audio_device == YES)
+  if (audio_device == true)
     {
       if (open_audio(44100, AUDIO_S16, 2, 2048) < 0)
         {
           /* only print out message if sound or music
              was not disabled at command-line
            */
-          if ((use_sound == YES) || (use_music == YES))
+          if ((use_sound == true) || (use_music == true))
             {
               fprintf(stderr,
                       "\nWarning: I could not set up audio for 44100 Hz "
@@ -750,9 +766,9 @@ void st_audio_setup(void)
                       "The Simple DirectMedia error that occured was:\n"
                       "%s\n\n", SDL_GetError());
             }
-          use_sound = NO;
-          use_music = NO;
-          audio_device = NO;
+          use_sound = false;
+          use_music = false;
+          audio_device = false;
         }
     }
 
@@ -770,9 +786,9 @@ void st_shutdown(void)
 
 /* --- ABORT! --- */
 
-void st_abort(char * reason, char * details)
+void st_abort(const std::string& reason, const std::string& details)
 {
-  fprintf(stderr, "\nError: %s\n%s\n\n", reason, details);
+  fprintf(stderr, "\nError: %s\n%s\n\n", reason.c_str(), details.c_str());
   st_shutdown();
   exit(1);
 }
@@ -789,13 +805,13 @@ void seticon(void)
 
   /* Load icon into a surface: */
 
-  icon = IMG_Load(DATA_PREFIX "/images/icon.png");
+  icon = IMG_Load((datadir + "/images/icon.png").c_str());
   if (icon == NULL)
     {
       fprintf(stderr,
-              "\nError: I could not load the icon image: %s\n"
+              "\nError: I could not load the icon image: %s%s\n"
               "The Simple DirectMedia error that occured was:\n"
-              "%s\n\n", DATA_PREFIX "/images/icon.png", SDL_GetError());
+              "%s\n\n", datadir.c_str(), "/images/icon.png", SDL_GetError());
       exit(1);
     }
 
@@ -828,22 +844,14 @@ void parseargs(int argc, char * argv[])
   /* Set defaults: */
 
 
-  debug_mode = NO;
-  use_fullscreen = NO;
-  show_fps = NO;
-  use_gl = NO;
-
-#ifndef NOSOUND
-
-  use_sound = YES;
-  use_music = YES;
-  audio_device = YES;
-#else
+  debug_mode = false;
+  use_fullscreen = false;
+  show_fps = false;
+  use_gl = false;
 
-  use_sound = NO;
-  use_music = NO;
-  audio_device = NO;
-#endif
+  use_sound = true;
+  use_music = true;
+  audio_device = true;
 
   /* Parse arguments: */
 
@@ -854,13 +862,28 @@ void parseargs(int argc, char * argv[])
         {
           /* Use full screen: */
 
-          use_fullscreen = YES;
+          use_fullscreen = true;
+        }
+      else if (strcmp(argv[i], "--joystick") == 0 || strcmp(argv[i], "-j") == 0)
+        {
+          assert(i+1 < argc);
+          joystick_num = atoi(argv[++i]);
+        }
+      else if (strcmp(argv[i], "--worldmap") == 0)
+        {
+          launch_worldmap_mode = true;
+        }
+      else if (strcmp(argv[i], "--datadir") == 0 
+               || strcmp(argv[i], "-d") == 0 )
+        {
+          assert(i+1 < argc);
+          datadir = argv[++i];
         }
       else if (strcmp(argv[i], "--show-fps") == 0)
         {
           /* Use full screen: */
 
-          show_fps = YES;
+          show_fps = true;
         }
       else if (strcmp(argv[i], "--opengl") == 0 ||
                strcmp(argv[i], "-gl") == 0)
@@ -868,7 +891,7 @@ void parseargs(int argc, char * argv[])
 #ifndef NOOPENGL
           /* Use OpengGL: */
 
-          use_gl = YES;
+          use_gl = true;
 #endif
 
         }
@@ -888,68 +911,52 @@ void parseargs(int argc, char * argv[])
       else if (strcmp(argv[i], "--disable-sound") == 0)
         {
           /* Disable the compiled in sound feature */
-#ifndef NOSOUND
           printf("Sounds disabled \n");
-          use_sound = NO;
-#else
-
-          printf("Warning: Sound capability has not been compiled into this build.\n");
-#endif
-
+          use_sound = false;
         }
       else if (strcmp(argv[i], "--disable-music") == 0)
         {
           /* Disable the compiled in sound feature */
-#ifndef NOSOUND
           printf("Music disabled \n");
-          use_music = NO;
-#else
-
-          printf("Warning: Music feature is not compiled in \n");
-#endif
-
+          use_music = false;
         }
       else if (strcmp(argv[i], "--debug-mode") == 0)
         {
           /* Enable the debug-mode */
-          debug_mode = YES;
+          debug_mode = true;
 
         }
       else if (strcmp(argv[i], "--help") == 0)
         {        /* Show help: */
-
-          printf("Super Tux " VERSION "\n\n");
-
-          printf("----------  Command-line options  ----------\n\n");
-
-          printf("  --opengl            - If opengl support was compiled in, this will enable the EXPERIMENTAL OpenGL mode.\n\n");
-
-          printf("  --disable-sound     - If sound support was compiled in,  this will\n                        disable sound for this session of the game.\n\n");
-
-          printf("  --disable-music     - Like above, but this will disable music.\n\n");
-
-          printf("  --fullscreen        - Run in fullscreen mode.\n\n");
-
-          printf("  --debug-mode        - Enables the debug-mode, which is useful for developers.\n\n");
-
-          printf("  --help              - Display a help message summarizing command-line\n                        options, license and game controls.\n\n");
-
-          printf("  --usage             - Display a brief message summarizing command-line options.\n\n");
-
-          printf("  --version           - Display the version of SuperTux you're running.\n\n\n");
-
-
-          printf("----------          License       ----------\n\n");
-          printf("  This program comes with ABSOLUTELY NO WARRANTY.\n");
-          printf("  This is free software, and you are welcome to redistribute\n");
-          printf("  or modify it under certain conditions. See the file \n");
-          printf("  \"COPYING.txt\" for more details.\n\n\n");
-
-          printf("----------      Game controls     ----------\n\n");
-          printf("  Please see the file \"README.txt\"\n\n");
-
+          puts("Super Tux " VERSION "\n"
+               "  Please see the file \"README.txt\" for more details.\n");
+          printf("Usage: %s [OPTIONS] FILENAME\n\n", argv[0]);
+          puts("Display Options:\n"
+               "  --fullscreen        Run in fullscreen mode.\n"
+               "  --opengl            If opengl support was compiled in, this will enable\n"
+               "                      the EXPERIMENTAL OpenGL mode.\n"
+               "\n"
+               "Sound Options:\n"
+               "  --disable-sound     If sound support was compiled in,  this will\n"
+               "                      disable sound for this session of the game.\n"
+               "  --disable-music     Like above, but this will disable music.\n"
+               "\n"
+               "Misc Options:\n"
+               "  -j, --joystick NUM  Use joystick NUM (default: 0)\n" 
+               "  --worldmap          Start in worldmap-mode (EXPERIMENTAL)\n"          
+               "  -d, --datadir DIR   Load Game data from DIR (default: automatic)\n"
+               "  --debug-mode        Enables the debug-mode, which is useful for developers.\n"
+               "  --help              Display a help message summarizing command-line\n"
+               "                      options, license and game controls.\n"
+               "  --usage             Display a brief message summarizing command-line options.\n"
+               "  --version           Display the version of SuperTux you're running.\n\n"
+               );
           exit(0);
         }
+      else if (argv[i][0] != '-')
+        {
+          level_startup_file = argv[i];
+        }
       else
         {
           /* Unknown - complain! */
@@ -977,7 +984,7 @@ void usage(char * prog, int ret)
 
   /* Display the usage message: */
 
-  fprintf(fi, "Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version]\n",
+  fprintf(fi, "Usage: %s [--fullscreen] [--opengl] [--disable-sound] [--disable-music] [--debug-mode] | [--usage | --help | --version] [--worldmap] FILENAME\n",
           prog);