implemented an install target in scons
[supertux.git] / src / worldmap.cpp
index 65d45d4..655710d 100644 (file)
@@ -17,6 +17,8 @@
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
+#include <config.h>
+
 #include <iostream>
 #include <fstream>
 #include <vector>
@@ -38,8 +40,9 @@
 #include "resources.h"
 #include "app/gettext.h"
 #include "misc.h"
+#include "scene.h"
 
-#define map_message_TIME 2800
+#define map_message_TIME 2.8
 
 Menu* worldmap_menu  = 0;
 
@@ -115,13 +118,12 @@ TileManager::TileManager()
           if (strcmp(lisp_symbol(lisp_car(element)), "tile") == 0)
             {
               int id = 0;
-              std::string filename = "<invalid>";
 
               Tile* tile = new Tile;             
               tile->north = tile->east = tile->south = tile->west = true;
               tile->stop  = true;
               tile->auto_walk = false;
-  
+
               LispReader reader(lisp_cdr(element));
               reader.read_int("id", id);
 
@@ -148,7 +150,6 @@ TileManager::TileManager()
 
               reader.read_bool("stop",  tile->stop);
               reader.read_bool("auto-walk",  tile->auto_walk);
-              reader.read_string("image", filename);
 
               reader.read_string("one-way", temp);
               tile->one_way = BOTH_WAYS;
@@ -164,9 +165,23 @@ TileManager::TileManager()
                   tile->one_way = WEST_EAST_WAY;
                 }
 
-              tile->sprite = new Surface(
-                           datadir +  "/images/worldmap/" + filename, 
-                           true);
+              std::vector<std::string> filenames;
+              reader.read_string_vector("image", filenames);
+
+              if(filenames.size() == 0)
+                std::cerr << "Warning: no image specified for tile " << id
+                          << ".\nIgnoring...\n" << std::endl;
+
+              for(int i = 0; static_cast<unsigned int>(i) < filenames.size(); i++)
+                {
+                Surface* image = new Surface(
+                         datadir +  "/images/worldmap/" + filenames[i], true);
+                tile->images.push_back(image);
+                }
+
+              tile->anim_speed = 25;
+              reader.read_int("anim-speed", tile->anim_speed);
+
 
               if (id >= int(tiles.size()))
                 tiles.resize(id+1);
@@ -297,11 +312,11 @@ Tux::action(float delta)
     {
       if (input_direction != D_NONE)
         { 
-          WorldMap::SpecialTile* special_tile = worldmap->at_special_tile();
+          WorldMap::Level* level = worldmap->at_level();
 
           // We got a new direction, so lets start walking when possible
           Vector next_tile;
-          if ((!special_tile || special_tile->solved || special_tile->level_name.empty())
+          if ((!level || level->solved)
               && worldmap->path_ok(input_direction, tile_pos, &next_tile))
             {
               tile_pos = next_tile;
@@ -341,12 +356,13 @@ Tux::action(float delta)
               }
             }
 
-          if (worldmap->at(tile_pos)->stop || (special_tile && 
-              !special_tile->passive_message))
+          if (worldmap->at(tile_pos)->stop ||
+             (special_tile && !special_tile->passive_message) ||
+              worldmap->at_level())
             {
               if(special_tile && !special_tile->map_message.empty() &&
                 !special_tile->passive_message)
-                worldmap->passive_message_timer.stop();
+                worldmap->passive_message_timer.start(0);
               stop();
             }
           else
@@ -423,7 +439,30 @@ Tile::Tile()
 
 Tile::~Tile()
 {
-  delete sprite;
+  for(std::vector<Surface*>::iterator i = images.begin(); i != images.end(); i++)
+    delete *i;
+}
+
+
+void
+Tile::draw(DrawingContext& context, Vector pos)
+{
+  // same code as from tile_manager.cpp draw_tile()
+
+  if(!images.size())
+    return;
+
+  if(images.size() > 1)
+    {
+    size_t frame 
+      = ((global_frame_counter*25) / anim_speed) % images.size();
+
+    context.draw_surface(images[frame], pos, LAYER_TILES);
+    }
+  else if (images.size() == 1)
+    {
+    context.draw_surface(images[0], pos, LAYER_TILES);
+    }
 }
 
 //---------------------------------------------------------------------------
@@ -438,6 +477,8 @@ WorldMap::WorldMap()
   
   start_x = 4;
   start_y = 5;
+
+  tux = new Tux(this);
   
   leveldot_green = new Surface(datadir +  "/images/worldmap/leveldot_green.png", true);
   leveldot_red = new Surface(datadir +  "/images/worldmap/leveldot_red.png", true);
@@ -447,7 +488,11 @@ WorldMap::WorldMap()
   enter_level = false;
 
   name = "<no title>";
-  music = "SALCON.MOD";
+  music = "salcon.mod";
+
+  global_frame_counter = 0;
+
+  total_stats.reset();
 }
 
 WorldMap::~WorldMap()
@@ -461,6 +506,7 @@ WorldMap::~WorldMap()
   delete teleporterdot;
 }
 
+// Don't forget to set map_filename before calling this
 void
 WorldMap::load_map()
 {
@@ -504,28 +550,18 @@ WorldMap::load_map()
                     {
                       SpecialTile special_tile;
                       LispReader reader(lisp_cdr(element));
-                      special_tile.solved = false;
                       
-                      special_tile.north = true;
-                      special_tile.east  = true;
-                      special_tile.south = true;
-                      special_tile.west  = true;
-
-                      reader.read_int("x", special_tile.x);
-                      reader.read_int("y", special_tile.y);
-                      reader.read_string("level", special_tile.level_name, false);
-
-                      special_tile.vertical_flip = false;
-                      reader.read_bool("vertical-flip", special_tile.vertical_flip);
+                      reader.read_float("x", special_tile.pos.x);
+                      reader.read_float("y", special_tile.pos.y);
 
                       special_tile.map_message.erase();
                       reader.read_string("map-message", special_tile.map_message);
                       special_tile.passive_message = false;
                       reader.read_bool("passive-message", special_tile.passive_message);
 
-                      special_tile.teleport_dest_x = special_tile.teleport_dest_y = -1;
-                      reader.read_int("teleport-to-x", special_tile.teleport_dest_x);
-                      reader.read_int("teleport-to-y", special_tile.teleport_dest_y);
+                      special_tile.teleport_dest = Vector(-1,-1);
+                      reader.read_float("teleport-to-x", special_tile.teleport_dest.x);
+                      reader.read_float("teleport-to-y", special_tile.teleport_dest.y);
 
                       special_tile.invisible = false;
                       reader.read_bool("invisible-tile", special_tile.invisible);
@@ -533,6 +569,7 @@ WorldMap::load_map()
                       special_tile.apply_action_north = special_tile.apply_action_south =
                           special_tile.apply_action_east = special_tile.apply_action_west =
                           true;
+
                       std::string apply_direction;
                       reader.read_string("apply-to-direction", apply_direction);
                       if(!apply_direction.empty())
@@ -550,46 +587,37 @@ WorldMap::load_map()
                           special_tile.apply_action_west = true;
                         }
 
-                      reader.read_string("extro-filename", special_tile.extro_filename);
-                      reader.read_string("next-world", special_tile.next_worldmap);
-                      special_tile.quit_worldmap = false;
-                      reader.read_bool("exit-game", special_tile.quit_worldmap);
-
-                      special_tile.auto_path = true;
-                      reader.read_bool("auto-path", special_tile.auto_path);
-
                       special_tiles.push_back(special_tile);
                     }
 
-                  /* Kept for backward compability */
                   else if (strcmp(lisp_symbol(lisp_car(element)), "level") == 0)
                     {
-                      SpecialTile special_tile;
+                      Level level;
                       LispReader reader(lisp_cdr(element));
-                      special_tile.solved = false;
+                      level.solved = false;
                       
-                      special_tile.north = true;
-                      special_tile.east  = true;
-                      special_tile.south = true;
-                      special_tile.west  = true;
+                      level.north = true;
+                      level.east  = true;
+                      level.south = true;
+                      level.west  = true;
 
-                      special_tile.invisible = false;
+                      reader.read_string("extro-filename", level.extro_filename);
+                      reader.read_string("next-worldmap", level.next_worldmap);
 
-                      special_tile.apply_action_north = special_tile.apply_action_south =
-                          special_tile.apply_action_east = special_tile.apply_action_west =
-                          true;
-                      special_tile.vertical_flip = false;
-                      special_tile.teleport_dest_x = special_tile.teleport_dest_y = -1;
+                      level.quit_worldmap = false;
+                      reader.read_bool("quit-worldmap", level.quit_worldmap);
 
-                      reader.read_string("extro-filename", special_tile.extro_filename);
-                      if(!special_tile.extro_filename.empty())
-                        special_tile.quit_worldmap = true;
-                      reader.read_string("name", special_tile.level_name, true);
-                      reader.read_int("x", special_tile.x);
-                      reader.read_int("y", special_tile.y);
+                      reader.read_string("name", level.name, true);
+                      reader.read_float("x", level.pos.x);
+                      reader.read_float("y", level.pos.y);
 
+                      level.auto_path = true;
+                      reader.read_bool("auto-path", level.auto_path);
 
-                      special_tiles.push_back(special_tile);
+                      level.vertical_flip = false;
+                      reader.read_bool("vertical-flip", level.vertical_flip);
+
+                      levels.push_back(level);
                     }
                   
                   cur = lisp_cdr(cur);      
@@ -605,31 +633,33 @@ WorldMap::load_map()
     }
 
     lisp_free(root_obj);
+
+    delete tux;
     tux = new Tux(this);
 }
 
-void WorldMap::get_level_title(SpecialTile& special_tile)
+void WorldMap::get_level_title(Level& level)
 {
   /** get special_tile's title */
-  special_tile.title = "<no title>";
+  level.title = "<no title>";
 
-  LispReader* reader = LispReader::load(datadir + "/levels/" + special_tile.level_name, "supertux-level");
+  LispReader* reader = LispReader::load(datadir + "/levels/" + level.name, "supertux-level");
   if(!reader)
     {
     std::cerr << "Error: Could not open level file. Ignoring...\n";
     return;
     }
 
-  reader->read_string("name", special_tile.title, true);
+  reader->read_string("name", level.title, true);
   delete reader;
 }
 
 void WorldMap::calculate_total_stats()
 {
   total_stats.reset();
-  for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i)
+  for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
     {
-    if (!i->level_name.empty() && i->solved)
+    if (i->solved)
       {
       total_stats += i->statistics;
       }
@@ -653,7 +683,8 @@ void
 WorldMap::get_input()
 {
   enter_level = false;
-   
+  SDLKey key;
+
   SDL_Event event;
   while (SDL_PollEvent(&event))
     {
@@ -670,32 +701,22 @@ WorldMap::get_input()
               break;
           
             case SDL_KEYDOWN:
-              switch(event.key.keysym.sym)
-                {
-                case SDLK_ESCAPE:
-                  on_escape_press();
-                  break;
-                case SDLK_LCTRL:
-                case SDLK_RETURN:
-                  enter_level = true;
-                  break;
+              key = event.key.keysym.sym;
 
-                case SDLK_LEFT:
-                  tux->set_direction(D_WEST);
-                  break;
-                case SDLK_RIGHT:
-                  tux->set_direction(D_EAST);
-                  break;
-                case SDLK_UP:
-                  tux->set_direction(D_NORTH);
-                  break;
-                case SDLK_DOWN:
-                  tux->set_direction(D_SOUTH);
-                  break;
-
-                default:
-                  break;
-                }
+              if(key == SDLK_ESCAPE)
+                on_escape_press();
+              else if(key == SDLK_RETURN || key == keymap.power)
+                enter_level = true;
+              else if(key == SDLK_LEFT || key == keymap.power)
+                tux->set_direction(D_WEST);
+              else if(key == SDLK_RIGHT || key == keymap.right)
+                tux->set_direction(D_EAST);
+              else if(key == SDLK_UP || key == keymap.up ||
+                key == keymap.jump)
+                  // there might be ppl that use jump as up key
+                tux->set_direction(D_NORTH);
+              else if(key == SDLK_DOWN || key == keymap.down)
+                tux->set_direction(D_SOUTH);
               break;
 
             case SDL_JOYHATMOTION:
@@ -810,42 +831,59 @@ std::cerr << "one way only\n";
 void
 WorldMap::update(float delta)
 {
+  if(!frame_timer.check()) {
+    global_frame_counter++;
+  }
+
   if (enter_level && !tux->is_moving())
     {
-      bool level_finished = true;
+      /* Check special tile action */
       SpecialTile* special_tile = at_special_tile();
-      if (!special_tile)
+      if(special_tile)
         {
-        std::cout << "Nothing to enter at: "
+        if (special_tile->teleport_dest != Vector(-1,-1))
+          {
+          // TODO: an animation, camera scrolling or a fading would be a nice touch
+          SoundManager::get()->play_sound(IDToSound(SND_WARP));
+          tux->back_direction = D_NONE;
+          tux->set_tile_pos(special_tile->teleport_dest);
+          SDL_Delay(1000);
+          }
+        }
+
+      /* Check level action */
+      bool level_finished = true;
+      Level* level = at_level();
+      if (!level)
+        {
+        std::cout << "No level to enter at: "
           << tux->get_tile_pos().x << ", " << tux->get_tile_pos().y << std::endl;
         return;
         }
 
 
-      if(!special_tile->level_name.empty())
-        {
-          if (special_tile->x == tux->get_tile_pos().x && 
-              special_tile->y == tux->get_tile_pos().y)
+          if (level->pos == tux->get_tile_pos())
             {
               PlayerStatus old_player_status = player_status;
 
-              std::cout << "Enter the current level: " << special_tile->level_name << std::endl;
-              // do a shriking fade to the special_tile
-              shrink_fade(Vector((special_tile->x*32 + 16 + offset.x),(special_tile->y*32 + 16
+              std::cout << "Enter the current level: " << level->name << std::endl;
+              // 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(datadir +  "/levels/" + special_tile->level_name,
-                                  ST_GL_LOAD_LEVEL_FILE, special_tile->vertical_flip);
+              GameSession session(level->name,
+                                  ST_GL_LOAD_LEVEL_FILE, level->vertical_flip,
+                                  &level->statistics);
 
               switch (session.run())
                 {
                 case GameSession::ES_LEVEL_FINISHED:
                   {
                     level_finished = true;
-                    bool old_level_state = special_tile->solved;
-                    special_tile->solved = true;
+                    bool old_level_state = level->solved;
+                    level->solved = true;
 
                     // deal with statistics
-                    special_tile->statistics.merge(global_stats);
+                    level->statistics.merge(global_stats);
                     calculate_total_stats();
 
                     if (session.get_current_sector()->player->got_power !=
@@ -856,7 +894,7 @@ WorldMap::update(float delta)
                     else
                       player_status.bonus = PlayerStatus::NO_BONUS;
 
-                    if (old_level_state != special_tile->solved && special_tile->auto_path)
+                    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;
@@ -885,7 +923,7 @@ WorldMap::update(float delta)
                   break;
                 case GameSession::ES_LEVEL_ABORT:
                   level_finished = false;
-                  /* In case the player's abort the special_tile, keep it using the old
+                  /* In case the player's abort the level, keep it using the old
                       status. But the minimum lives and no bonus. */
                   player_status.distros = old_player_status.distros;
                   player_status.lives = std::min(old_player_status.lives, player_status.lives);
@@ -905,21 +943,19 @@ WorldMap::update(float delta)
                   context.draw_gradient(Color (200,240,220), Color(200,200,220),
                       LAYER_BACKGROUND0);
 
-                  context.draw_text_center(blue_text, _("GAMEOVER"), 
-                      Vector(0, 200), LAYER_FOREGROUND1);
-
-                  sprintf(str, _("SCORE: %d"), total_stats.get_points(SCORE_STAT));
-                  context.draw_text_center(gold_text, str,
-                      Vector(0, 230), LAYER_FOREGROUND1);
+                  context.draw_text(blue_text, _("GAMEOVER"), 
+                      Vector(screen->w/2, 200), CENTER_ALLIGN, LAYER_FOREGROUND1);
 
                   sprintf(str, _("COINS: %d"), player_status.distros);
-                  context.draw_text_center(gold_text, str,
-                      Vector(0, screen->w - 32), LAYER_FOREGROUND1);
+                  context.draw_text(gold_text, str,
+                      Vector(screen->w/2, screen->w - 32), CENTER_ALLIGN, LAYER_FOREGROUND1);
+
+                  total_stats.draw_message_info(context, _("Total Statistics"));
 
                   context.do_drawing();
   
                   SDL_Event event;
-                  wait_for_event(event,2000,5000,true);
+                  wait_for_event(event,2000,6000,true);
 
                   quit = true;
                   player_status.reset();
@@ -936,30 +972,22 @@ WorldMap::update(float delta)
               if (!savegame_file.empty())
                 savegame(savegame_file);
             }
-        }
       /* The porpose of the next checking is that if the player lost
-         the special_tile (in case there is one), don't show anything */
+         the level (in case there is one), don't show anything */
       if(level_finished)
         {
-        if (!special_tile->extro_filename.empty())
+        if (!level->extro_filename.empty())
           {
           // Display a text file
-          display_text_file(special_tile->extro_filename, SCROLL_SPEED_MESSAGE, white_big_text , white_text, white_small_text, blue_text );
+          display_text_file(level->extro_filename, SCROLL_SPEED_MESSAGE, white_big_text , white_text, white_small_text, blue_text );
           }
-        if (special_tile->teleport_dest_x != -1 && special_tile->teleport_dest_y != -1)
-          {
-          // TODO: an animation, camera scrolling or a fading would be a nice touch
-          SoundManager::get()->play_sound(IDToSound(SND_WARP));
-          tux->back_direction = D_NONE;
-          tux->set_tile_pos(Vector(special_tile->teleport_dest_x, special_tile->teleport_dest_y));
-          SDL_Delay(1000);
-          }
-        if (!special_tile->next_worldmap.empty())
+
+        if (!level->next_worldmap.empty())
           {
           // Load given worldmap
-          loadmap(special_tile->next_worldmap);
+          loadmap(level->next_worldmap);
           }
-        if (special_tile->quit_worldmap)
+        if (level->quit_worldmap)
           quit = true;
         }
     }
@@ -1005,13 +1033,24 @@ WorldMap::at(Vector p)
   return tile_manager->get(tilemap[width * y + x]);
 }
 
+WorldMap::Level*
+WorldMap::at_level()
+{
+  for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+    {
+      if (i->pos == tux->get_tile_pos())
+        return &*i; 
+    }
+
+  return 0;
+}
+
 WorldMap::SpecialTile*
 WorldMap::at_special_tile()
 {
   for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i)
     {
-      if (i->x == tux->get_tile_pos().x && 
-          i->y == tux->get_tile_pos().y)
+      if (i->pos == tux->get_tile_pos())
         return &*i; 
     }
 
@@ -1026,33 +1065,31 @@ WorldMap::draw(DrawingContext& context, const Vector& offset)
     for(int x = 0; x < width; ++x)
       {
         Tile* tile = at(Vector(x, y));
-        context.draw_surface(tile->sprite,
-            Vector(x*32 + offset.x, y*32 + offset.y), LAYER_TILES);
+        tile->draw(context, Vector(x*32 + offset.x, y*32 + offset.y));
       }
-  
+
+  for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
+    {
+      if (i->solved)
+        context.draw_surface(leveldot_green,
+            Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1);
+      else
+        context.draw_surface(leveldot_red,
+            Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1);
+    }
+
   for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i)
     {
       if(i->invisible)
         continue;
-      if(i->level_name.empty())
-        {
-        if (i->teleport_dest_x != -1 && i->teleport_dest_y != -1)
-          context.draw_surface(teleporterdot,
-              Vector(i->x*32 + offset.x, i->y*32 + offset.y), LAYER_TILES+1);
 
-        else if (!i->map_message.empty() && !i->passive_message)
-          context.draw_surface(messagedot,
-              Vector(i->x*32 + offset.x, i->y*32 + offset.y), LAYER_TILES+1);
+      if (i->teleport_dest != Vector(-1, -1))
+        context.draw_surface(teleporterdot,
+                Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1);
 
-        continue;
-        }
-
-      if (i->solved)
-        context.draw_surface(leveldot_green,
-            Vector(i->x*32 + offset.x, i->y*32 + offset.y), LAYER_TILES+1);
-      else
-        context.draw_surface(leveldot_red,
-            Vector(i->x*32 + offset.x, i->y*32 + offset.y), LAYER_TILES+1);
+      else if (!i->map_message.empty() && !i->passive_message)
+        context.draw_surface(messagedot,
+                Vector(i->pos.x*32 + offset.x, i->pos.y*32 + offset.y), LAYER_TILES+1);
     }
 
   tux->draw(context, offset);
@@ -1065,23 +1102,23 @@ WorldMap::draw_status(DrawingContext& context)
   char str[80];
   sprintf(str, " %d", total_stats.get_points(SCORE_STAT));
 
-  context.draw_text(white_text, _("SCORE"), Vector(0, 0), LAYER_FOREGROUND1);
-  context.draw_text(gold_text, str, Vector(96, 0), LAYER_FOREGROUND1);
+  context.draw_text(white_text, _("SCORE"), Vector(0, 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
+  context.draw_text(gold_text, str, Vector(96, 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   sprintf(str, "%d", player_status.distros);
   context.draw_text(white_text, _("COINS"), Vector(screen->w/2 - 16*5, 0),
-      LAYER_FOREGROUND1);
+      LEFT_ALLIGN, LAYER_FOREGROUND1);
   context.draw_text(gold_text, str, Vector(screen->w/2 + (16*5)/2, 0),
-        LAYER_FOREGROUND1);
+        LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   if (player_status.lives >= 5)
     {
       sprintf(str, "%dx", player_status.lives);
       context.draw_text(gold_text, str, 
           Vector(screen->w - gold_text->get_text_width(str) - tux_life->w, 0),
-          LAYER_FOREGROUND1);
+          LEFT_ALLIGN, LAYER_FOREGROUND1);
       context.draw_surface(tux_life, Vector(screen->w -
-            gold_text->get_text_width("9"), 0), LAYER_FOREGROUND1);
+            gold_text->get_text_width("9"), 0), LEFT_ALLIGN, LAYER_FOREGROUND1);
     }
   else
     {
@@ -1092,41 +1129,45 @@ WorldMap::draw_status(DrawingContext& context)
     }
   context.draw_text(white_text, _("LIVES"),
       Vector(screen->w - white_text->get_text_width(_("LIVES")) - white_text->get_text_width("   99"), 0),
-      LAYER_FOREGROUND1);
+      LEFT_ALLIGN, LAYER_FOREGROUND1);
 
   if (!tux->is_moving())
     {
-      for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i)
+      for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
         {
-          if (i->x == tux->get_tile_pos().x && 
-              i->y == tux->get_tile_pos().y)
+          if (i->pos == tux->get_tile_pos())
             {
-              if(!i->level_name.empty())
-                {
-                if(i->title == "")
-                  get_level_title(*i);
-
-                context.draw_text_center(white_text, i->title, 
-                    Vector(0, screen->h - white_text->get_height() - 30),
-                    LAYER_FOREGROUND1);
+              if(i->title == "")
+                get_level_title(*i);
 
-                i->statistics.draw_worldmap_info(context);
-                }
+              context.draw_text(white_text, i->title, 
+                  Vector(screen->w/2,
+                         screen->h - white_text->get_height() - 30),
+                  CENTER_ALLIGN, LAYER_FOREGROUND1);
 
-              /* Display an in-map message in the map, if any as been selected */
+              i->statistics.draw_worldmap_info(context);
+              break;
+            }
+        }
+      for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i)
+        {
+          if (i->pos == tux->get_tile_pos())
+            {
+               /* Display an in-map message in the map, if any as been selected */
               if(!i->map_message.empty() && !i->passive_message)
-                context.draw_text_center(gold_text, i->map_message, 
-                    Vector(0, screen->h - white_text->get_height() - 60),
-                    LAYER_FOREGROUND1);
+                context.draw_text(gold_text, i->map_message, 
+                    Vector(screen->w/2,
+                           screen->h - white_text->get_height() - 60),
+                    CENTER_ALLIGN, LAYER_FOREGROUND1);
               break;
             }
         }
     }
   /* Display a passive message in the map, if needed */
   if(passive_message_timer.check())
-    context.draw_text_center(gold_text, passive_message, 
-            Vector(0, screen->h - white_text->get_height() - 60),
-            LAYER_FOREGROUND1);
+    context.draw_text(gold_text, passive_message, 
+            Vector(screen->w/2, screen->h - white_text->get_height() - 60),
+            CENTER_ALLIGN, LAYER_FOREGROUND1);
 }
 
 void
@@ -1143,6 +1184,7 @@ WorldMap::display()
   frame_rate.set_frame_limit(false);
 
   frame_rate.start();
+  frame_timer.start(.25, true);
 
   DrawingContext context;
   while(!quit)
@@ -1197,10 +1239,9 @@ WorldMap::savegame(const std::string& filename)
    LispWriter* writer = new LispWriter(file);
 
   int nb_solved_levels = 0, total_levels = 0;
-  for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i)
+  for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
     {
-      if(!i->level_name.empty())
-        ++total_levels;
+      ++total_levels;
       if (i->solved)
         ++nb_solved_levels;
     }
@@ -1217,6 +1258,7 @@ WorldMap::savegame(const std::string& filename)
   writer->write_string("map", map_filename);
   writer->write_int("lives", player_status.lives);
   writer->write_int("distros", player_status.lives);
+  writer->write_int("max-score-multiplier", player_status.max_score_multiplier);
 
   writer->start_list("tux");
 
@@ -1229,13 +1271,13 @@ WorldMap::savegame(const std::string& filename)
 
   writer->start_list("levels");
 
-  for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i)
+  for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
     {
-      if (i->solved && !i->level_name.empty())
+      if (i->solved)
         {
         writer->start_list("level");
 
-        writer->write_string("name", i->level_name);
+        writer->write_string("name", i->name);
         writer->write_bool("solved", true);
         i->statistics.write(*writer);
 
@@ -1253,11 +1295,13 @@ WorldMap::loadgame(const std::string& filename)
 {
   std::cout << "loadgame: " << filename << std::endl;
   savegame_file = filename;
-  map_filename = "icyisland.stwm";
 
   if (access(filename.c_str(), F_OK) != 0)
     {
     load_map();
+
+    player_status.reset();
+
     return;
     }
   
@@ -1280,12 +1324,15 @@ WorldMap::loadgame(const std::string& filename)
   cur = lisp_cdr(cur);
   LispReader reader(cur);
 
-  /* Get the Map filename and then load it before setting special_tile settings */
+  /* Get the Map filename and then load it before setting level settings */
+  std::string cur_map_filename = map_filename;
   reader.read_string("map", map_filename);
-  load_map(); 
+//  if(cur_map_filename != map_filename)
+    load_map(); 
 
   reader.read_int("lives", player_status.lives);
   reader.read_int("distros", player_status.distros);
+  reader.read_int("max-score-multiplier", player_status.max_score_multiplier);
 
   if (player_status.lives < 0)
     player_status.lives = START_LIVES;
@@ -1325,9 +1372,9 @@ WorldMap::loadgame(const std::string& filename)
               level_reader.read_string("name", name);
               level_reader.read_bool("solved", solved);
 
-              for(SpecialTiles::iterator i = special_tiles.begin(); i != special_tiles.end(); ++i)
+              for(Levels::iterator i = levels.begin(); i != levels.end(); ++i)
                 {
-                  if (name == i->level_name)
+                  if (name == i->name)
                     {
                     i->solved = solved;
                     i->statistics.parse(level_reader);