Statisticts now also count secret areas found
authorChristoph Sommer <mail@christoph-sommer.de>
Tue, 18 Apr 2006 22:14:59 +0000 (22:14 +0000)
committerChristoph Sommer <mail@christoph-sommer.de>
Tue, 18 Apr 2006 22:14:59 +0000 (22:14 +0000)
SVN-Revision: 3362

src/badguy/badguy.cpp
src/game_session.cpp
src/level.cpp
src/level.hpp
src/object/coin.cpp
src/sector.hpp
src/statistics.cpp
src/statistics.hpp
src/trigger/secretarea_trigger.cpp

index 1f1d597..88827a5 100644 (file)
@@ -26,6 +26,7 @@
 #include "statistics.hpp"
 #include "game_session.hpp"
 #include "log.hpp"
+#include "level.hpp"
 
 static const float SQUISH_TIME = 2;
 static const float X_OFFSCREEN_DISTANCE = 1600;
index b650253..0e817de 100644 (file)
@@ -66,6 +66,7 @@
 #include "gettext.hpp"
 #include "console.hpp"
 #include "flip_level_transformer.hpp"
+#include "trigger/secretarea_trigger.hpp"
 
 // the engine will be run with a logical framerate of 64fps.
 // We chose 64fps here because it is a power of 2, so 1/64 gives an "even"
@@ -118,6 +119,7 @@ GameSession::restart_level(bool fromBeginning)
   level->load(levelfile);
   level->stats.total_coins = level->get_total_coins();
   level->stats.total_badguys = level->get_total_badguys();
+  level->stats.total_secrets = level->get_total_count<SecretAreaTrigger>();
   level->stats.reset();
 
   if (fromBeginning) reset_sector="";
index 0517c6a..1ba57a4 100644 (file)
@@ -182,15 +182,6 @@ Level::get_sector(size_t num)
 }
 
 int
-Level::get_total_badguys()
-{
-  int total_badguys = 0;
-  for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
-    total_badguys += (*i)->get_total_badguys();
-  return total_badguys;
-}
-
-int
 Level::get_total_coins()
 {
   // FIXME not really correct as coins can also be inside blocks...
@@ -207,3 +198,11 @@ Level::get_total_coins()
   return total_coins;
 }
 
+int
+Level::get_total_badguys()
+{
+  int total_badguys = 0;
+  for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i)
+    total_badguys += (*i)->get_total_badguys();
+  return total_badguys;
+}
index f91ab3c..7e0aba7 100644 (file)
@@ -24,8 +24,7 @@
 #include <vector>
 #include <string>
 #include "statistics.hpp"
-
-class Sector;
+#include "sector.hpp"
 
 namespace lisp {
 class Lisp;
@@ -61,8 +60,18 @@ public:
   size_t get_sector_count();
   Sector* get_sector(size_t num);
 
-  int get_total_badguys();
   int get_total_coins();
+  int get_total_badguys();
+
+  /** Get total number of GameObjects of given type */
+  template<class T> int get_total_count()
+  {
+    int total = 0;
+    for(Sectors::iterator i = sectors.begin(); i != sectors.end(); ++i) {
+      total += (*i)->get_total_count<T>();
+    }
+    return total;
+  }
 
 private:
   void load_old_format(const lisp::Lisp& reader);
index c7cf940..b89f200 100644 (file)
@@ -29,6 +29,7 @@
 #include "gameobjs.hpp"
 #include "statistics.hpp"
 #include "object_factory.hpp"
+#include "level.hpp"
 
 Coin::Coin(const Vector& pos)
 {
index 12a1682..d291c0a 100644 (file)
@@ -28,7 +28,6 @@
 #include "script_manager.hpp"
 #include "math/vector.hpp"
 #include "video/drawing_context.hpp"
-#include "level.hpp"
 
 namespace lisp {
 class Lisp;
@@ -47,6 +46,7 @@ class ScriptInterpreter;
 class SpawnPoint;
 class MovingObject;
 class CollisionHit;
+class Level;
 
 enum MusicType {
   LEVEL_MUSIC,
@@ -117,6 +117,16 @@ public:
   /** Get total number of badguys */
   int get_total_badguys();
 
+  /** Get total number of GameObjects of given type */
+  template<class T> int get_total_count()
+  {
+    int total = 0;
+    for(GameObjects::iterator i = gameobjects.begin(); i != gameobjects.end(); ++i) {
+      if (dynamic_cast<T*>(*i)) total++;
+    }
+    return total;
+  }
+
   void collision_tilemap(const Rect& dest, const Vector& movement, CollisionHit& hit) const;
 
   /** Checks if at the specified rectangle are gameobjects with STATIC flag set
index 1642312..d08f7b0 100644 (file)
@@ -34,9 +34,10 @@ namespace {
   const int nv_coins = std::numeric_limits<int>::min();
   const int nv_badguys = std::numeric_limits<int>::min();
   const float nv_time = std::numeric_limits<float>::max();
+  const int nv_secrets = std::numeric_limits<int>::min();
 }
 
-Statistics::Statistics() : coins(nv_coins), total_coins(nv_coins), badguys(nv_badguys), total_badguys(nv_badguys), time(nv_time), display_stat(0)
+Statistics::Statistics() : coins(nv_coins), total_coins(nv_coins), badguys(nv_badguys), total_badguys(nv_badguys), time(nv_time), secrets(nv_secrets), total_secrets(nv_secrets), display_stat(0)
 {
 }
 
@@ -52,6 +53,8 @@ Statistics::parse(const lisp::Lisp& reader)
   reader.get("badguys-killed", badguys);
   reader.get("badguys-killed-total", total_badguys);
   reader.get("time-needed", time);
+  reader.get("secrets-found", secrets);
+  reader.get("secrets-found-total", total_secrets);
 }
 
 void
@@ -62,6 +65,8 @@ Statistics::write(lisp::Writer& writer)
   writer.write_int("badguys-killed", badguys);
   writer.write_int("badguys-killed-total", total_badguys);
   writer.write_float("time-needed", time);
+  writer.write_int("secrets-found", secrets);
+  writer.write_int("secrets-found-total", total_secrets);
 }
 
 //define TOTAL_DISPLAY_TIME  3400
@@ -113,6 +118,9 @@ Statistics::draw_worldmap_info(DrawingContext& context)
        sprintf(stat_buf, "%02d:%02d", mins,secs); 
       }
       break;
+    case 3:
+      sprintf(caption_buf, _("Max secrets found:"));
+      sprintf(stat_buf, "%d/%d", secrets, total_secrets);
     default:
       log_debug << "Invalid stat requested to be drawn" << std::endl;
       break;
@@ -122,7 +130,7 @@ Statistics::draw_worldmap_info(DrawingContext& context)
   {
     timer.start(TOTAL_DISPLAY_TIME);
     display_stat++;
-    if (display_stat > 2) display_stat = 0;
+    if (display_stat > 3) display_stat = 0;
   }
 
   context.draw_text(white_small_text, caption_buf, Vector(WMAP_INFO_LEFT_X, 490), LEFT_ALLIGN, LAYER_GUI);
@@ -155,6 +163,11 @@ Statistics::draw_message_info(DrawingContext& context, std::string title)
   int secs = (csecs % 6000) / 100;
   sprintf(str, _("Min time needed:       %02d:%02d"), mins,secs);
   context.draw_text(white_small_text, str, Vector(SCREEN_WIDTH/2, py), CENTER_ALLIGN, LAYER_GUI); 
+  py+=18;
+  
+  sprintf(str, _("Max secrets found:     %d / %d"), secrets, total_secrets);
+  context.draw_text(white_small_text, str, Vector(SCREEN_WIDTH/2, py), CENTER_ALLIGN, LAYER_GUI); 
+  py+=18;
 }
 
 void 
@@ -200,11 +213,11 @@ Statistics::draw_endseq_panel(DrawingContext& context, Statistics* best_stats, S
   }
   context.draw_text(gold_text, buf, Vector(col3_x, row2_y), LEFT_ALLIGN, LAYER_GUI);
 
-  context.draw_text(white_text, "Badguys", Vector(col1_x, row4_y), LEFT_ALLIGN, LAYER_GUI);
-  snprintf(buf, 128, "%d/%d", badguys, total_badguys);
+  context.draw_text(white_text, "Secrets", Vector(col1_x, row4_y), LEFT_ALLIGN, LAYER_GUI);
+  snprintf(buf, 128, "%d/%d", secrets, total_secrets);
   context.draw_text(gold_text, buf, Vector(col2_x, row4_y), LEFT_ALLIGN, LAYER_GUI);
-  if (best_stats && (best_stats->badguys > badguys)) {
-    snprintf(buf, 128, "%d/%d", best_stats->badguys, best_stats->total_badguys);
+  if (best_stats && (best_stats->secrets > secrets)) {
+    snprintf(buf, 128, "%d/%d", best_stats->secrets, best_stats->total_secrets);
   }
   context.draw_text(gold_text, buf, Vector(col3_x, row4_y), LEFT_ALLIGN, LAYER_GUI);
 
@@ -229,6 +242,7 @@ Statistics::reset()
   coins = 0; 
   badguys = 0; 
   time = 0; 
+  secrets = 0; 
 }
 
 void
@@ -239,6 +253,8 @@ Statistics::merge(Statistics& s2)
   badguys = std::max(badguys, s2.badguys);
   total_badguys = s2.total_badguys;
   time = std::min(time, s2.time);
+  secrets = std::max(secrets, s2.secrets);
+  total_secrets = s2.total_secrets;
 }
 
 void
@@ -249,4 +265,6 @@ Statistics::operator+=(const Statistics& s2)
   if (s2.badguys != nv_badguys) badguys += s2.badguys;
   if (s2.total_badguys != nv_badguys) total_badguys += s2.total_badguys;
   if (s2.time != nv_time) time += s2.time;
+  if (s2.secrets != nv_secrets) secrets += s2.secrets;
+  if (s2.total_secrets != nv_secrets) total_secrets += s2.total_secrets;
 }
index d2655eb..0883e36 100644 (file)
@@ -39,6 +39,8 @@ public:
   int badguys; /**< badguys actively killed */
   int total_badguys; /**< (vincible) badguys in level */
   float time; /**< seconds needed */
+  int secrets; /**< secret areas found */
+  int total_secrets; /**< secret areas in level */
 
 public:
   Statistics(); /**< Creates new statistics, call reset() before counting */
index e7a0770..9beca7b 100644 (file)
@@ -25,6 +25,8 @@
 #include "lisp/writer.hpp"
 #include "object_factory.hpp"
 #include "main.hpp"
+#include "sector.hpp"
+#include "level.hpp"
 
 static const float MESSAGE_TIME=3.5;
 
@@ -45,7 +47,7 @@ SecretAreaTrigger::SecretAreaTrigger(const lisp::Lisp& reader)
 SecretAreaTrigger::SecretAreaTrigger(const Rect& area)
 {
   bbox = area;
-  message = "You found a secret area!";
+  message = "You found a secret area!"; //FIXME: translation missing
   message_displayed = false;
 }
 
@@ -89,6 +91,7 @@ SecretAreaTrigger::event(Player& , EventType type)
     if (!message_displayed) {
       message_timer.start(MESSAGE_TIME);
       message_displayed = true;
+      Sector::current()->get_level()->stats.secrets++;
     }
   }
 }