Let's Rock
[supertux.git] / src / game_session.cpp
index 4495343..fe24f25 100644 (file)
@@ -179,11 +179,30 @@ GameSession::record_demo(const std::string& filename)
   capture_file = filename;
 
   char buf[30];                            // save the seed in the demo file
-  snprintf(buf, sizeof(buf), "random_seed=%010d", config->random_seed);
+  snprintf(buf, sizeof(buf), "random_seed=%10d", config->random_seed);
   for (int i=0; i==0 || buf[i-1]; i++)
     capture_demo_stream->put(buf[i]);
 }
 
+int
+GameSession::get_demo_random_seed(const std::string& filename)
+{
+  std::istream* test_stream = new std::ifstream(filename.c_str());
+  if(test_stream->good()) {
+    char buf[30];                     // recall the seed from the demo file
+    int seed;
+    for (int i=0; i<30 && (i==0 || buf[i-1]); i++)
+      test_stream->get(buf[i]);
+    if (sscanf(buf, "random_seed=%10d", &seed) == 1) {
+      log_info << "Random seed " << seed << " from demo file" << std::endl;
+         return seed;
+    }
+    else
+      log_info << "Demo file contains no random number" << std::endl;
+  }
+  return 0;
+}
+
 void
 GameSession::play_demo(const std::string& filename)
 {
@@ -201,34 +220,18 @@ GameSession::play_demo(const std::string& filename)
   demo_controller = new CodeController();
   tux.set_controller(demo_controller);
 
-  char buf[30];                            // recall the seed from the demo file
+  // skip over random seed, if it exists in the file
+  char buf[30];                            // ascii decimal seed
   int seed;
   for (int i=0; i<30 && (i==0 || buf[i-1]); i++)
     playback_demo_stream->get(buf[i]);
-  if (sscanf(buf, "random_seed=%010d", &seed) == 1) {
-    config->random_seed = seed;            // save where it will be used
-    log_info << "Taking random seed " << seed << " from demo file" <<std::endl;
-  }
-  else {
+  if (sscanf(buf, "random_seed=%010d", &seed) != 1)
     playback_demo_stream->seekg(0);     // old style w/o seed, restart at beg
-    log_info << "Demo file contains no random number" << std::endl;
-  }
-}
-
-namespace {
-  inline const char* chain(const char* c1, const char* c2) {
-    return (std::string(c1) + std::string(c2)).c_str();
-  }
-  inline const char* chain(const char* c1, const char* c2, const char* c3) {
-    return (std::string(c1) + std::string(c2) + std::string(c3)).c_str();
-  }
 }
 
 void
 GameSession::levelintro()
 {
-  char str[60];
-
   sound_manager->stop_music();
 
   DrawingContext context;
@@ -249,8 +252,9 @@ GameSession::levelintro()
   context.draw_center_text(gold_text, level->get_name(), Vector(0, 160),
       LAYER_FOREGROUND1);
 
-  snprintf(str, sizeof(str), chain(_("Coins"), ": %d"), player_status->coins);
-  context.draw_text(white_text, str, Vector(SCREEN_WIDTH/2, 210),
+  std::stringstream ss_coins;
+  ss_coins << _("Coins") << ": " << player_status->coins;
+  context.draw_text(white_text, ss_coins.str(), Vector(SCREEN_WIDTH/2, 210),
       CENTER_ALLIGN, LAYER_FOREGROUND1);
 
   if((level->get_author().size()) && (level->get_author() != "SuperTux Team"))