Moved some console commands' implementations nearer to target classes
[supertux.git] / src / game_session.cpp
index b502668..bad7bfd 100644 (file)
@@ -80,11 +80,6 @@ namespace {
          "foo",
          "whereami",
          "camera",
-         "grow", 
-         "fire", 
-         "ice",
-         "coins",
-         "numberofthebeast",
          "grease",
          "invincible",
          "mortal",
@@ -119,6 +114,8 @@ GameSession::GameSession(const std::string& levelfile_, GameSessionMode mode,
     Console::registerCommand(consoleCommands[i], this);
   }
 
+  statistics_backdrop = new Surface("images/engine/menu/score-backdrop.png");
+
   restart_level(true);
 }
 
@@ -191,9 +188,8 @@ GameSession::~GameSession()
 
   delete end_sequence_controller;
   delete level;
-  for (uint16_t i=0; i < sizeof(::consoleCommands)/sizeof(typeof(consoleCommands[0])); i++) {
-    Console::unregisterCommand(consoleCommands[i], this);
-  }
+
+  delete statistics_backdrop;
 
   current_ = NULL;
 }
@@ -347,7 +343,7 @@ GameSession::process_events()
 }
 
 bool
-GameSession::consoleCommand(std::string command, std::vector<std::string> arguments)
+GameSession::consoleCommand(std::string command, std::vector<std::string>)
 {
   if (command == "foo") {
     msg_info << "bar" << std::endl;
@@ -359,30 +355,6 @@ GameSession::consoleCommand(std::string command, std::vector<std::string> argume
   
   // Cheating words (the goal of this is really for debugging,
   // but could be used for some cheating, nothing wrong with that)
-  if (command == "grow") {
-    tux.set_bonus(GROWUP_BONUS, false);
-    return true;
-  }
-  if (command == "fire") {
-    tux.set_bonus(FIRE_BONUS, false);
-    return true;
-  }
-  if (command == "ice") {
-    tux.set_bonus(ICE_BONUS, false);
-    return true;
-  }
-  if (command == "coins") {
-    if ((arguments.size() < 1) || (!Console::string_is<int>(arguments[0]))) {
-      msg_info << "Usage: coins <number>" << std::endl;
-    } else {
-      player_status->coins = Console::string_to<int>(arguments[0]);
-    }
-    return true;
-  }
-  if (command == "numberofthebeast") {
-    player_status->coins += 55;
-    return true;
-  }
   if (command == "grease") {
     tux.physic.set_velocity_x(tux.physic.get_velocity_x()*3);
     return true;
@@ -451,28 +423,6 @@ GameSession::check_end_conditions()
   /* End of level? */
   if(end_sequence && endsequence_timer.check()) {
     finish(true);
-    
-    // add time spent to statistics
-    int tottime = 0, remtime = 0;
-    for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
-    {
-      Sector* sec = *i;
-
-      for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
-          j != sec->gameobjects.end(); ++j)
-      {
-        GameObject* obj = *j;
-
-        LevelTime* lt = dynamic_cast<LevelTime*> (obj);
-        if(lt)
-        {
-          tottime += int(lt->get_level_time());
-          remtime += int(lt->get_remaining_time());
-        }
-      }
-    }
-    global_stats.set_points(TIME_NEEDED_STAT, (tottime == 0 ? -1 : (tottime-remtime)));
-
     return;
   } else if (!end_sequence && tux->is_dead()) {
     if (player_status->coins < 0) { 
@@ -796,6 +746,27 @@ GameSession::start_sequence(const std::string& sequencename)
         lt->stop();
     }
 
+    // add time spent to statistics
+    int tottime = 0, remtime = 0;
+    for(std::vector<Sector*>::iterator i = level->sectors.begin(); i != level->sectors.end(); ++i)
+    {
+      Sector* sec = *i;
+
+      for(std::vector<GameObject*>::iterator j = sec->gameobjects.begin();
+          j != sec->gameobjects.end(); ++j)
+      {
+        GameObject* obj = *j;
+
+        LevelTime* lt = dynamic_cast<LevelTime*> (obj);
+        if(lt)
+        {
+          tottime += int(lt->get_level_time());
+          remtime += int(lt->get_remaining_time());
+        }
+      }
+    }
+    global_stats.set_points(TIME_NEEDED_STAT, (tottime == 0 ? -1 : (tottime-remtime)));
+
     if(sequencename == "fireworks") {
       currentsector->add_object(new Fireworks());
     }
@@ -823,5 +794,10 @@ GameSession::drawstatus(DrawingContext& context)
     context.draw_text(white_text, fpstext, Vector(SCREEN_WIDTH - white_text->get_text_width(fpstext) - gold_text->get_text_width(" 99999") - BORDER_X, BORDER_Y + 20), LEFT_ALLIGN, LAYER_FOREGROUND1);
     context.draw_text(gold_text, str, Vector(SCREEN_WIDTH - BORDER_X, BORDER_Y + 20), RIGHT_ALLIGN, LAYER_FOREGROUND1);
   }
+
+  // draw level stats while end_sequence is running
+  if (end_sequence) {
+    global_stats.draw_endseq_panel(context, best_level_statistics, statistics_backdrop);
+  }
 }