- Cleanups
[supertux.git] / src / worldmap.cpp
index c402150..7f87ad4 100644 (file)
 #include <cassert>
 #include <unistd.h>
 
-#include "globals.h"
-#include "screen/surface.h"
-#include "screen/screen.h"
-#include "screen/drawing_context.h"
-#include "lispreader.h"
+#include "app/globals.h"
+#include "video/surface.h"
+#include "video/screen.h"
+#include "video/drawing_context.h"
+#include "utils/lispreader.h"
 #include "gameloop.h"
-#include "setup.h"
+#include "app/setup.h"
 #include "sector.h"
 #include "worldmap.h"
-#include "sound_manager.h"
+#include "audio/sound_manager.h"
 #include "resources.h"
-#include "gettext.h"
+#include "app/gettext.h"
+#include "misc.h"
+
+Menu* worldmap_menu  = 0;
 
 namespace WorldMapNS {
 
@@ -95,7 +98,7 @@ TileManager::TileManager()
   lisp_object_t* root_obj = lisp_read_from_file(stwt_filename);
  
   if (!root_obj)
-    st_abort("Couldn't load file", stwt_filename);
+    Termination::abort("Couldn't load file", stwt_filename);
 
   if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-worldmap-tiles") == 0)
     {
@@ -383,7 +386,7 @@ WorldMap::load_map()
 {
   lisp_object_t* root_obj = lisp_read_from_file(datadir + "/levels/worldmap/" + map_filename);
   if (!root_obj)
-    st_abort("Couldn't load file", datadir + "/levels/worldmap/" + map_filename);
+    Termination::abort("Couldn't load file", datadir + "/levels/worldmap/" + map_filename);
 
   if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-worldmap") == 0)
     {
@@ -429,10 +432,12 @@ WorldMap::load_map()
 
                       reader.read_string("extro-filename", level.extro_filename);
                       reader.read_string("map-message", level.display_map_message);
-                      reader.read_string("goto-world", level.goto_worldmap);
+                      reader.read_string("next-world", level.next_worldmap);
                       reader.read_string("level", level.name, true);
                       reader.read_int("x", level.x);
                       reader.read_int("y", level.y);
+                      level.auto_path = true;
+                      reader.read_bool("auto-path", level.auto_path);
                       level.swap_x = level.swap_y = -1;
                       reader.read_int("swap-x", level.swap_x);
                       reader.read_int("swap-y", level.swap_y);
@@ -489,33 +494,15 @@ void WorldMap::get_level_title(Level& level)
   /** get level's title */
   level.title = "<no title>";
 
-  FILE * fi;
-  lisp_object_t* root_obj = 0;
-  fi = fopen((datadir +  "/levels/" + level.name).c_str(), "r");
-  if (fi == NULL)
-  {
-    perror((datadir +  "/levels/" + level.name).c_str());
+  LispReader* reader = LispReader::load(datadir + "/levels/" + level.name, "supertux-level");
+  if(!reader)
+    {
+    std::cerr << "Error: Could not open level file. Ignoring...\n";
     return;
-  }
-
-  lisp_stream_t stream;
-  lisp_stream_init_file (&stream, fi);
-  root_obj = lisp_read (&stream);
-
-  if (root_obj->type == LISP_TYPE_EOF || root_obj->type == LISP_TYPE_PARSE_ERROR)
-  {
-    printf("World: Parse Error in file %s", level.name.c_str());
-  }
-
-  if (strcmp(lisp_symbol(lisp_car(root_obj)), "supertux-level") == 0)
-  {
-    LispReader reader(lisp_cdr(root_obj));
-    reader.read_string("name", level.title, true);
-  }
-
-  lisp_free(root_obj);
+    }
 
-  fclose(fi);
+  reader->read_string("name", level.title, true);
+  delete reader;
 }
 
 void
@@ -546,7 +533,7 @@ WorldMap::get_input()
           switch(event.type)
             {
             case SDL_QUIT:
-              st_abort("Received window close", "");
+              Termination::abort("Received window close", "");
               break;
           
             case SDL_KEYDOWN:
@@ -710,7 +697,7 @@ WorldMap::update(float delta)
                     else
                       player_status.bonus = PlayerStatus::NO_BONUS;
 
-                    if (old_level_state != level->solved)
+                    if (old_level_state != level->solved && level->auto_path)
                       { // Try to detect the next direction to which we should walk
                         // FIXME: Mostly a hack
                         Direction dir = D_NONE;
@@ -786,7 +773,7 @@ WorldMap::update(float delta)
                   break;
                 }
 
-              sound_manager->play_music(song);
+              SoundManager::get()->play_music(song);
               Menu::set_current(0);
               if (!savegame_file.empty())
                 savegame(savegame_file);
@@ -799,17 +786,17 @@ WorldMap::update(float delta)
         if (!level->extro_filename.empty())
           {
           // Display a text file
-          display_text_file(level->extro_filename, SCROLL_SPEED_MESSAGE);
+          display_text_file(level->extro_filename, SCROLL_SPEED_MESSAGE, white_big_text , white_text, white_small_text, blue_text );
           }
         if (level->swap_x != -1 && level->swap_y != -1)
           {
           // TODO: add an effect, like a camera scrolling, or at least, a fading
           tux->set_tile_pos(Vector(level->swap_x, level->swap_y));
           }
-        if (!level->goto_worldmap.empty())
+        if (!level->next_worldmap.empty())
           {
           // Load given worldmap
-          loadmap(level->goto_worldmap);
+          loadmap(level->next_worldmap);
           }
         if (level->quit_worldmap)
           quit = true;
@@ -969,13 +956,13 @@ WorldMap::display()
 
   quit = false;
 
-  song = sound_manager->load_music(datadir +  "/music/" + music);
-  sound_manager->play_music(song);
+  song = SoundManager::get()->load_music(datadir +  "/music/" + music);
+  SoundManager::get()->play_music(song);
   
   unsigned int last_update_time;
   unsigned int update_time;
 
-  last_update_time = update_time = st_get_ticks();
+  last_update_time = update_time = Ticks::get();
 
   DrawingContext context;
   while(!quit)
@@ -988,7 +975,7 @@ WorldMap::display()
         delta = .3f;
       
       last_update_time = update_time;
-      update_time      = st_get_ticks();
+      update_time      = Ticks::get();
 
       Vector tux_pos = tux->get_pos();
       if (1)