Replaced more lisp::Lisp/lisp::Writer with Reader/Writer
[supertux.git] / src / badguy / yeti.cpp
index 1c03906..08631e5 100644 (file)
@@ -1,13 +1,11 @@
-//  $Id$
-//
 //  SuperTux - Boss "Yeti"
 //  Copyright (C) 2005 Matthias Braun <matze@braunis.de>
 //  Copyright (C) 2006 Christoph Sommer <christoph.sommer@2006.expires.deltadevelopment.de>
 //
-//  This program is free software; you can redistribute it and/or
-//  modify it under the terms of the GNU General Public License
-//  as published by the Free Software Foundation; either version 2
-//  of the License, or (at your option) any later version.
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
 //
 //  This program is distributed in the hope that it will be useful,
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  GNU General Public License for more details.
 //
 //  You should have received a copy of the GNU General Public License
-//  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>
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-#include <float.h>
-#include <sstream>
-#include <memory>
-#include "yeti.hpp"
+#include "badguy/yeti.hpp"
+
+#include "audio/sound_manager.hpp"
+#include "badguy/bouncing_snowball.hpp"
+#include "badguy/yeti_stalactite.hpp"
 #include "object/camera.hpp"
-#include "yeti_stalactite.hpp"
-#include "bouncing_snowball.hpp"
-#include "game_session.hpp"
-#include "level.hpp"
+#include "object/player.hpp"
+#include "sprite/sprite.hpp"
+#include "supertux/object_factory.hpp"
+#include "supertux/sector.hpp"
+
+#include <float.h>
+#include <math.h>
 
 namespace {
-  const float JUMP_DOWN_VX = 250; /**< horizontal speed while jumping off the dais */
-  const float JUMP_DOWN_VY = -250; /**< vertical speed while jumping off the dais */
+const float JUMP_DOWN_VX = 250; /**< horizontal speed while jumping off the dais */
+const float JUMP_DOWN_VY = -250; /**< vertical speed while jumping off the dais */
 
-  const float RUN_VX = 350; /**< horizontal speed while running */
+const float RUN_VX = 350; /**< horizontal speed while running */
 
-  const float JUMP_UP_VX = 350; /**< horizontal speed while jumping on the dais */
-  const float JUMP_UP_VY = -800; /**< vertical speed while jumping on the dais */
+const float JUMP_UP_VX = 350; /**< horizontal speed while jumping on the dais */
+const float JUMP_UP_VY = -800; /**< vertical speed while jumping on the dais */
 
-  const float STOMP_VY = -250; /** vertical speed while stomping on the dais */
+const float STOMP_VY = -250; /** vertical speed while stomping on the dais */
 
-  const float LEFT_STAND_X = 16; /**< x-coordinate of left dais' end position */
-  const float RIGHT_STAND_X = 800-60-16; /**< x-coordinate of right dais' end position */
-  const float LEFT_JUMP_X = LEFT_STAND_X+224; /**< x-coordinate of from where to jump on the left dais */
-  const float RIGHT_JUMP_X = RIGHT_STAND_X-224; /**< x-coordinate of from where to jump on the right dais */
-  const float STOMP_WAIT = .5; /**< time we stay on the dais before jumping again */
-  const float SAFE_TIME = .5; /**< the time we are safe when tux just hit us */
-  const int INITIAL_HITPOINTS = 3; /**< number of hits we can take */
+const float LEFT_STAND_X = 16; /**< x-coordinate of left dais' end position */
+const float RIGHT_STAND_X = 800-60-16; /**< x-coordinate of right dais' end position */
+const float LEFT_JUMP_X = LEFT_STAND_X+224; /**< x-coordinate of from where to jump on the left dais */
+const float RIGHT_JUMP_X = RIGHT_STAND_X-224; /**< x-coordinate of from where to jump on the right dais */
+const float STOMP_WAIT = .5; /**< time we stay on the dais before jumping again */
+const float SAFE_TIME = .5; /**< the time we are safe when tux just hit us */
+const int INITIAL_HITPOINTS = 3; /**< number of hits we can take */
 
-  const float SQUISH_TIME = 5;
+const float SQUISH_TIME = 5;
 }
 
-Yeti::Yeti(const lisp::Lisp& reader)
-       : BadGuy(reader, "images/creatures/yeti/yeti.sprite")
+Yeti::Yeti(const Reader& reader) :
+  BadGuy(reader, "images/creatures/yeti/yeti.sprite"),
+  state(),
+  state_timer(),
+  safe_timer(),
+  stomp_count(),
+  hit_points(),
+  hud_head()
 {
   hit_points = INITIAL_HITPOINTS;
   countMe = false;
@@ -222,12 +227,7 @@ void Yeti::take_hit(Player& )
     set_colgroup_active(COLGROUP_MOVING_ONLY_STATIC);
     sprite->set_action("dead");
 
-    if (countMe) Sector::current()->get_level()->stats.badguys++;
-
-    if(dead_script != "") {
-      std::istringstream stream(dead_script);
-      Sector::current()->run_script(stream, "Yeti - dead-script");
-    }
+    run_dead_script();
   }
   else {
     safe_timer.start(SAFE_TIME);
@@ -242,17 +242,6 @@ Yeti::kill_fall()
 }
 
 void
-Yeti::write(lisp::Writer& writer)
-{
-  writer.start_list("yeti");
-
-  writer.write_float("x", start_position.x);
-  writer.write_float("y", start_position.y);
-
-  writer.end_list("yeti");
-}
-
-void
 Yeti::drop_stalactite()
 {
   // make a stalactite falling down and shake camera a bit
@@ -290,28 +279,28 @@ Yeti::collision_solid(const CollisionHit& hit)
     physic.set_velocity_y(0);
     switch (state) {
       case JUMP_DOWN:
-       run();
-       break;
+        run();
+        break;
       case RUN:
-       break;
+        break;
       case JUMP_UP:
-       break;
+        break;
       case BE_ANGRY:
-       // we just landed
-       if(!state_timer.started()) {
-         sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
-         stomp_count++;
-         drop_stalactite();
-
-         // go to other side after 3 jumps
-         if(stomp_count == 3) {
-           jump_down();
-         } else {
-           // jump again
-           state_timer.start(STOMP_WAIT);
-         }
-       }
-       break;
+        // we just landed
+        if(!state_timer.started()) {
+          sprite->set_action((dir==RIGHT)?"stand-right":"stand-left");
+          stomp_count++;
+          drop_stalactite();
+
+          // go to other side after 3 jumps
+          if(stomp_count == 3) {
+            jump_down();
+          } else {
+            // jump again
+            state_timer.start(STOMP_WAIT);
+          }
+        }
+        break;
       case SQUISHED:
         break;
     }
@@ -321,4 +310,6 @@ Yeti::collision_solid(const CollisionHit& hit)
   }
 }
 
-IMPLEMENT_FACTORY(Yeti, "yeti")
+IMPLEMENT_FACTORY(Yeti, "yeti");
+
+/* EOF */