<MatzeB> my patch fixes another leak in the levelsubset code and cleans that up a...
authorIngo Ruhnke <grumbel@gmx.de>
Wed, 28 Apr 2004 18:45:26 +0000 (18:45 +0000)
committerIngo Ruhnke <grumbel@gmx.de>
Wed, 28 Apr 2004 18:45:26 +0000 (18:45 +0000)
<MatzeB> it also removes the code for the bsod badguy, since that was a duplication of the snowball code anyway

SVN-Revision: 814

src/badguy.cpp
src/badguy.h
src/level.cpp
src/level.h
src/leveleditor.cpp
src/title.cpp

index 4649386..4181a2d 100644 (file)
 #include "resources.h"
 #include "sprite_manager.h"
 
-Sprite* img_bsod_squished_left;
-Sprite* img_bsod_squished_right;
-Sprite* img_bsod_falling_left;
-Sprite* img_bsod_falling_right;
 Sprite* img_mriceblock_flat_left;
 Sprite* img_mriceblock_flat_right;
 Sprite* img_mriceblock_falling_left;
 Sprite* img_mriceblock_falling_right;
-Sprite* img_bsod_left;
-Sprite* img_bsod_right;
 Sprite* img_mriceblock_left;
 Sprite* img_mriceblock_right;
 Sprite* img_jumpy_left_up;
@@ -78,8 +72,6 @@ BadGuyKind  badguykind_from_string(const std::string& str)
     return BAD_JUMPY;
   else if (str == "laptop" || str == "mriceblock") // was laptop in old maps
     return BAD_MRICEBLOCK;
-  else if (str == "bsod")
-    return BAD_BSOD;
   else if (str == "mrbomb")
     return BAD_MRBOMB;
   else if (str == "stalactite")
@@ -94,12 +86,12 @@ BadGuyKind  badguykind_from_string(const std::string& str)
     return BAD_FLYINGSNOWBALL;
   else if (str == "spiky")
     return BAD_SPIKY;
-  else if (str == "snowball")
+  else if (str == "snowball" || str == "bsod") // was bsod in old maps
     return BAD_SNOWBALL;
   else
     {
       printf("Couldn't convert badguy: '%s'\n", str.c_str());
-      return BAD_BSOD;
+      return BAD_SNOWBALL;
     }
 }
 
@@ -113,9 +105,6 @@ std::string badguykind_to_string(BadGuyKind kind)
     case BAD_MRICEBLOCK:
       return "mriceblock";
       break;
-    case BAD_BSOD:
-      return "bsod";
-      break;
     case BAD_MRBOMB:
       return "mrbomb";
       break;
@@ -141,7 +130,7 @@ std::string badguykind_to_string(BadGuyKind kind)
       return "snowball";
       break;
     default:
-      return "bsod";
+      return "snowball";
     }
 }
 
@@ -167,10 +156,7 @@ BadGuy::BadGuy(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
   physic.reset();
   timer.init(true);
 
-  if(kind == BAD_BSOD) {
-    physic.set_velocity(-BADGUY_WALK_SPEED, 0);
-    set_sprite(img_bsod_left, img_bsod_right);
-  } else if(kind == BAD_MRBOMB) {
+  if(kind == BAD_MRBOMB) {
     physic.set_velocity(-BADGUY_WALK_SPEED, 0);
     set_sprite(img_mrbomb_left, img_mrbomb_right);
   } else if (kind == BAD_MRICEBLOCK) {
@@ -215,38 +201,6 @@ BadGuy::BadGuy(float x, float y, BadGuyKind kind_, bool stay_on_platform_)
 }
 
 void
-BadGuy::action_bsod(float frame_ratio)
-{
-  static const float BSODJUMP = 2;
-    
-  if (dying == DYING_NOT)
-    check_horizontal_bump();
-
-  fall();
-
-  // jump when we're about to fall
-  if (physic.get_velocity_y() == 0 && 
-      !issolid(base.x+base.width/2, base.y + base.height)) 
-    {
-      physic.enable_gravity(true);
-      physic.set_velocity(physic.get_velocity_x(), BSODJUMP);
-    }
-
-  // Handle dying timer:
-  if (dying == DYING_SQUISHED && !timer.check())
-    {
-      /* Remove it if time's up: */
-      remove_me();
-      return;
-    }
-
-  // move
-  physic.apply(frame_ratio, base.x, base.y);
-  if(dying != DYING_FALLING)
-    collision_swept_object_map(&old_base, &base);
-}
-
-void
 BadGuy::action_mriceblock(float frame_ratio)
 {
   Player& tux = *World::current()->get_tux();
@@ -721,10 +675,6 @@ BadGuy::action(float frame_ratio)
 
   switch (kind)
     {
-    case BAD_BSOD:
-      action_bsod(frame_ratio);
-      break;
-
     case BAD_MRICEBLOCK:
       action_mriceblock(frame_ratio);
       break;
@@ -872,12 +822,6 @@ BadGuy::squish(Player* player)
     remove_me();
     return;
 
-  } else if(kind == BAD_BSOD) {
-    squish_me(player);
-    set_sprite(img_bsod_squished_left, img_bsod_squished_right);
-    physic.set_velocity_x(0);
-    return;
-      
   } else if (kind == BAD_MRICEBLOCK) {
     if (mode == NORMAL || mode == KICK)
       {
@@ -958,20 +902,14 @@ BadGuy::kill_me(int score)
       Player& tux = *World::current()->get_tux();  
       tux.holding_something = false;
     }
-  } else if(kind == BAD_BSOD) {
-    set_sprite(img_bsod_falling_left, img_bsod_falling_right);
   }
   
   physic.enable_gravity(true);
   physic.set_velocity_y(0);
 
   /* Gain some points: */
-//  if (kind == BAD_BSOD)
     World::current()->add_score(base.x - scroll_x, base.y,
                     score * player_status.score_multiplier);
-/*  else 
-    World::current()->add_score(base.x - scroll_x, base.y,                                 
-                    25 * player_status.score_multiplier);*/
 
   /* Play death sound: */
   play_sound(sounds[SND_FALL], SOUND_CENTER_SPEAKER);
@@ -1109,16 +1047,10 @@ BadGuy::collision(void *p_c_object, int c_object, CollisionType type)
 
 void load_badguy_gfx()
 {
-  img_bsod_squished_left = sprite_manager->load("bsod-squished-left");
-  img_bsod_squished_right = sprite_manager->load("bsod-squished-right");
-  img_bsod_falling_left = sprite_manager->load("bsod-falling-left");
-  img_bsod_falling_right = sprite_manager->load("bsod-falling-right");
   img_mriceblock_flat_left = sprite_manager->load("mriceblock-flat-left");
   img_mriceblock_flat_right = sprite_manager->load("mriceblock-flat-right");
   img_mriceblock_falling_left = sprite_manager->load("mriceblock-falling-left");
   img_mriceblock_falling_right = sprite_manager->load("mriceblock-falling-right");
-  img_bsod_left = sprite_manager->load("bsod-left");
-  img_bsod_right = sprite_manager->load("bsod-right");
   img_mriceblock_left = sprite_manager->load("mriceblock-left");
   img_mriceblock_right = sprite_manager->load("mriceblock-right");
   img_jumpy_left_up = sprite_manager->load("jumpy-left-up");
index 09a8080..1511e6b 100644 (file)
@@ -35,7 +35,6 @@
 
 /* Bad guy kinds: */
 enum BadGuyKind {
-  BAD_BSOD,
   BAD_MRICEBLOCK,
   BAD_JUMPY,
   BAD_MRBOMB,
@@ -65,7 +64,7 @@ struct BadGuyData
     : kind(kind_), x(x_), y(y_), stay_on_platform(stay_on_platform_) {}
 
   BadGuyData()
-    : kind(BAD_BSOD), x(0), y(0), stay_on_platform(false) {}
+    : kind(BAD_SNOWBALL), x(0), y(0), stay_on_platform(false) {}
 };
 
 class Player;
@@ -142,7 +141,6 @@ public:
   bool is_removable() const { return removable; }
  
 private:
-  void action_bsod(float frame_ratio);
   void action_mriceblock(float frame_ratio);
   void action_jumpy(float frame_ratio); 
   void action_bomb(float frame_ratio);
index 9a12740..34a914a 100644 (file)
 
 using namespace std;
 
-st_subset::st_subset()
+LevelSubset::LevelSubset()
+    : image(0), levels(0)
 {
-  levels = 0;
 }
 
-void st_subset::create(const std::string& subset_name)
+LevelSubset::~LevelSubset()
+{
+    delete image;
+}
+
+void LevelSubset::create(const std::string& subset_name)
 {
   Level new_lev;
-  st_subset new_subset;
+  LevelSubset new_subset;
   new_subset.name = subset_name;
   new_subset.title = "Unknown Title";
   new_subset.description = "No description so far.";
@@ -53,7 +58,7 @@ void st_subset::create(const std::string& subset_name)
   new_lev.save(subset_name.c_str(),1);
 }
 
-void st_subset::parse (lisp_object_t* cursor)
+void LevelSubset::parse (lisp_object_t* cursor)
 {
   while(!lisp_nil_p(cursor))
     {
@@ -85,7 +90,7 @@ void st_subset::parse (lisp_object_t* cursor)
     }
 }
 
-void st_subset::load(char *subset)
+void LevelSubset::load(char *subset)
 {
   FILE* fi;
   char filename[1024];
@@ -156,7 +161,7 @@ void st_subset::load(char *subset)
   levels = --i;
 }
 
-void st_subset::save()
+void LevelSubset::save()
 {
   FILE* fi;
   string filename;
@@ -192,15 +197,6 @@ void st_subset::save()
     }
 }
 
-void st_subset::free()
-{
-  title.clear();
-  description.clear();
-  name.clear();
-  delete image;
-  levels = 0;
-}
-
 Level::Level()
   : img_bkgd(0)
 {
index 11d8181..2da2c36 100644 (file)
@@ -31,14 +31,15 @@ class Tile;
 
 /** This type holds meta-information about a level-subset. 
     It could be extended to handle manipulation of subsets. */
-class st_subset
+class LevelSubset
   {
   public:
-    st_subset();
+    LevelSubset();
+    ~LevelSubset();
+
     static void create(const std::string& subset_name);
     void load(char *subset);
     void save();
-    void free();
 
     std::string name;
     std::string title;
index 6c18ed3..05b6f34 100644 (file)
@@ -113,7 +113,7 @@ static bool le_level_changed;  /* if changes, ask for saving, when quiting*/
 static int pos_x, cursor_x, cursor_y, fire;
 static int le_level;
 static LevelEditorWorld le_world;
-static st_subset le_level_subset;
+static LevelSubset le_level_subset;
 static int le_show_grid;
 static int le_frame;
 static Surface* le_selection;
@@ -303,7 +303,7 @@ int leveleditor(int levelnb)
                   switch (i = subset_new_menu->check())
                     {
                     case 3:
-                      st_subset::create(subset_new_menu->item[2].input);
+                      LevelSubset::create(subset_new_menu->item[2].input);
                       le_level_subset.load(subset_new_menu->item[2].input);
                       leveleditor_menu->item[3].kind = MN_GOTO;
                       le_level = 1;
@@ -1158,7 +1158,7 @@ void le_change(float x, float y, int tm, unsigned int c)
               le_world.bad_guys.erase(le_world.bad_guys.begin() + i);
 
           if(c == '0')  /* if it's a bad guy */
-            le_world.add_bad_guy(xx*32, yy*32, BAD_BSOD);
+            le_world.add_bad_guy(xx*32, yy*32, BAD_SNOWBALL);
           else if(c == '1')
             le_world.add_bad_guy(xx*32, yy*32, BAD_MRICEBLOCK);
           else if(c == '2')
@@ -1204,7 +1204,7 @@ void le_change(float x, float y, int tm, unsigned int c)
                 le_current_level->change(xx*32, yy*32, tm, c);
 
                 if(c == '0')  // if it's a bad guy
-                  le_world.add_bad_guy(xx*32, yy*32, BAD_BSOD);
+                  le_world.add_bad_guy(xx*32, yy*32, BAD_SNOWBALL);
                 else if(c == '1')
                   le_world.add_bad_guy(xx*32, yy*32, BAD_MRICEBLOCK);
                 else if(c == '2')
index d30a3bc..d3416c5 100644 (file)
@@ -62,22 +62,33 @@ static int frame;
 static unsigned int last_update_time;
 static unsigned int update_time;
 
-std::vector<st_subset> contrib_subsets;
+std::vector<LevelSubset*> contrib_subsets;
 std::string current_contrib_subset;
 
+void free_contrib_menu()
+{
+  for(std::vector<LevelSubset*>::iterator i = contrib_subsets.begin();
+      i != contrib_subsets.end(); ++i)
+    delete *i;
+
+  contrib_subsets.clear();
+  contrib_menu->clear();
+}
+
 void generate_contrib_menu()
 {
   string_list_type level_subsets = dsubdirs("/levels", "info");
 
-  contrib_menu->clear();
+  free_contrib_menu();
+
   contrib_menu->additem(MN_LABEL,"Contrib Levels",0,0);
   contrib_menu->additem(MN_HL,"",0,0);
 
   for (int i = 0; i < level_subsets.num_items; ++i)
     {
-      st_subset subset;
-      subset.load(level_subsets.item[i]);
-      contrib_menu->additem(MN_GOTO, subset.title.c_str(), i,
+      LevelSubset* subset = new LevelSubset();
+      subset->load(level_subsets.item[i]);
+      contrib_menu->additem(MN_GOTO, subset->title.c_str(), i,
           contrib_subset_menu, i+1);
       contrib_subsets.push_back(subset);
     }
@@ -102,7 +113,7 @@ void check_contrib_menu()
             {
               current_subset = index;
               // FIXME: This shouln't be busy looping
-              st_subset& subset = contrib_subsets[index];
+              LevelSubset& subset = * (contrib_subsets[index]);
           
               current_contrib_subset = subset.name;
 
@@ -222,7 +233,6 @@ void draw_demo(GameSession* session, double frame_ratio)
 /* --- TITLE SCREEN --- */
 void title(void)
 {
-  st_subset subset;
   random_timer.init(true);
 
   walking = true;
@@ -360,6 +370,7 @@ void title(void)
     }
   /* Free surfaces: */
 
+  free_contrib_menu();
   delete bkg_title;
   delete logo;
   delete img_choose_subset;