updated squirrel version
[supertux.git] / src / worldmap.cpp
index 872c285..9e5c0ee 100644 (file)
@@ -352,17 +352,13 @@ WorldMap::WorldMap()
   tux = new Tux(this);
   add_object(tux);
     
-  leveldot_green
-    = new Surface(datadir + "/images/tiles/worldmap/leveldot_green.png", true);
-  leveldot_red
-    = new Surface(datadir + "/images/tiles/worldmap/leveldot_red.png", true);
-  messagedot
-    = new Surface(datadir + "/images/tiles/worldmap/messagedot.png", true);
-  teleporterdot
-    = new Surface(datadir + "/images/tiles/worldmap/teleporterdot.png", true);
+  leveldot_green= new Surface("images/tiles/worldmap/leveldot_green.png", true);
+  leveldot_red = new Surface("images/tiles/worldmap/leveldot_red.png", true);
+  messagedot = new Surface("images/tiles/worldmap/messagedot.png", true);
+  teleporterdot = new Surface("images/tiles/worldmap/teleporterdot.png", true);
 
   name = "<no title>";
-  music = "salcon.mod";
+  music = "salcon.ogg";
   intro_displayed = false;
 
   total_stats.reset();
@@ -415,12 +411,11 @@ WorldMap::load_map()
 
   try {
     lisp::Parser parser;
-    std::string filename = get_resource_filename(map_filename);
-    std::auto_ptr<lisp::Lisp> root (parser.parse(filename));
+    std::auto_ptr<lisp::Lisp> root (parser.parse(map_filename));
 
     const lisp::Lisp* lisp = root->get_lisp("supertux-worldmap");
     if(!lisp)
-      throw new std::runtime_error("file isn't a supertux-worldmap file.");
+      throw std::runtime_error("file isn't a supertux-worldmap file.");
 
     clear_objects();
     lisp::ListIterator iter(lisp);
@@ -548,8 +543,7 @@ WorldMap::get_level_title(Level& level)
 
   try {
     lisp::Parser parser;
-    std::auto_ptr<lisp::Lisp> root (
-        parser.parse(get_resource_filename(levels_path + level.name)));
+    std::auto_ptr<lisp::Lisp> root (parser.parse(levels_path + level.name));
 
     const lisp::Lisp* level_lisp = root->get_lisp("supertux-level");
     if(!level_lisp)
@@ -719,7 +713,7 @@ WorldMap::update(float delta)
         if (special_tile->teleport_dest != Vector(-1,-1))
           {
           // TODO: an animation, camera scrolling or a fading would be a nice touch
-          sound_manager->play_sound("warp");
+          sound_manager->play("sounds/warp.wav");
           tux->back_direction = D_NONE;
           tux->set_tile_pos(special_tile->teleport_dest);
           SDL_Delay(1000);
@@ -745,7 +739,7 @@ WorldMap::update(float delta)
           // do a shriking fade to the level
           shrink_fade(Vector((level->pos.x*32 + 16 + offset.x),
                              (level->pos.y*32 + 16 + offset.y)), 500);
-          GameSession session(get_resource_filename(levels_path + level->name),
+          GameSession session(levels_path + level->name,
                               ST_GL_LOAD_LEVEL_FILE, &level->statistics);
 
           switch (session.run())
@@ -834,7 +828,7 @@ WorldMap::update(float delta)
               break;
             }
 
-          sound_manager->play_music(song);
+          sound_manager->play_music(std::string("music/") + music);
           Menu::set_current(0);
           if (!savegame_file.empty())
             savegame(savegame_file);
@@ -843,11 +837,15 @@ WorldMap::update(float delta)
          the level (in case there is one), don't show anything */
       if(level_finished) {
         if (level->extro_script != "") {
-          ScriptInterpreter* interpreter = new ScriptInterpreter(levels_path);
-          std::istringstream in(level->extro_script);
-          interpreter->load_script(in, "level-extro-script");
-          interpreter->start_script();
-          add_object(interpreter);
+          try {
+            std::auto_ptr<ScriptInterpreter> interpreter 
+              (new ScriptInterpreter(levels_path));
+            std::istringstream in(level->extro_script);
+            interpreter->run_script(in, "level-extro-script");
+            add_object(interpreter.release());
+          } catch(std::exception& e) {
+            std::cerr << "Couldn't run level-extro-script:" << e.what() << "\n";
+          }
         }
 
         if (!level->next_worldmap.empty())
@@ -972,7 +970,7 @@ WorldMap::draw_status(DrawingContext& context)
         }
     }
   /* Display a passive message in the map, if needed */
-  if(passive_message_timer.check())
+  if(passive_message_timer.started())
     context.draw_text(gold_text, passive_message, 
             Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT - white_text->get_height() - 60),
             CENTER_ALLIGN, LAYER_FOREGROUND1);
@@ -987,15 +985,19 @@ WorldMap::display()
 
   quit = false;
 
-  song = sound_manager->load_music(datadir +  "/music/" + music);
-  sound_manager->play_music(song);
+  sound_manager->play_music(std::string("music/") + music);
 
   if(!intro_displayed && intro_script != "") {
-    ScriptInterpreter* interpreter = new ScriptInterpreter(levels_path);
-    std::istringstream in(intro_script);
-    interpreter->load_script(in, "worldmap-intro-script");
-    interpreter->start_script();
-    add_object(interpreter);
+    try {
+      std::auto_ptr<ScriptInterpreter> interpreter 
+        (new ScriptInterpreter(levels_path));
+      std::istringstream in(intro_script);
+      interpreter->run_script(in, "worldmap-intro-script");
+      add_object(interpreter.release());
+    } catch(std::exception& e) {
+      std::cerr << "Couldn't execute worldmap-intro-script: "
+        << e.what() << "\n";
+    }
                                            
     intro_displayed = true;
   }
@@ -1032,6 +1034,7 @@ WorldMap::display()
     context.pop_transform();
     get_input();
     update(elapsed_time);
+    sound_manager->update();
       
     if(Menu::current()) {
       Menu::current()->draw(context);
@@ -1047,8 +1050,7 @@ WorldMap::savegame(const std::string& filename)
   if(filename == "")
     return;
 
-  std::ofstream file(filename.c_str(), std::ios::out);
-  lisp::Writer writer(file);
+  lisp::Writer writer(filename);
 
   int nb_solved_levels = 0, total_levels = 0;
   for(Levels::iterator i = levels.begin(); i != levels.end(); ++i) {