pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] CVS: Games/Pingus/src action_button.cxx,1.2,1.3 action_butt


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src action_button.cxx,1.2,1.3 action_button.hxx,1.2,1.3 action_data.hxx,1.2,1.3 action_holder.cxx,1.2,1.3 action_holder.hxx,1.2,1.3 button_panel.cxx,1.4,1.5 button_panel.hxx,1.3,1.4 capture_rectangle.cxx,1.3,1.4 exit.cxx,1.2,1.3 multiplayer_client_child.cxx,1.2,1.3 pingu.cxx,1.15,1.16 pingu.hxx,1.7,1.8 pingu_action.cxx,1.4,1.5 pingu_action.hxx,1.5,1.6 pingu_action_factory.cxx,1.3,1.4 pingu_action_factory.hxx,1.2,1.3 pingu_enums.hxx,1.3,1.4 playfield.cxx,1.6,1.7 plf_plf.cxx,1.3,1.4 server.cxx,1.7,1.8 world.cxx,1.12,1.13 xml_plf.cxx,1.4,1.5
Date: 28 Jun 2002 15:12:24 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv7425

Modified Files:
        action_button.cxx action_button.hxx action_data.hxx 
        action_holder.cxx action_holder.hxx button_panel.cxx 
        button_panel.hxx capture_rectangle.cxx exit.cxx 
        multiplayer_client_child.cxx pingu.cxx pingu.hxx 
        pingu_action.cxx pingu_action.hxx pingu_action_factory.cxx 
        pingu_action_factory.hxx pingu_enums.hxx playfield.cxx 
        plf_plf.cxx server.cxx world.cxx xml_plf.cxx 
Log Message:
- changed action names from string to enum
- implemented actions slots for wall and fall case
- some cleanup


Index: action_button.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/action_button.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- action_button.cxx   13 Jun 2002 14:25:12 -0000      1.2
+++ action_button.cxx   28 Jun 2002 15:12:22 -0000      1.3
@@ -27,6 +27,8 @@
 #include "server.hxx"
 #include "string_converter.hxx"
 
+using namespace Pingus::Actions;
+
 Button::Button()
 {
 }
@@ -77,15 +79,15 @@
 ActionButton::~ActionButton() {}
 
 void
-ActionButton::init(int x, int y, std::string str, int owner_id)
+ActionButton::init(int x, int y, ActionName name_, int owner_id)
 {
   //  make_action = func;
   x_pos = x;
   y_pos = y;
-  name = str;
+  name = name_;
  
-  if (name == "digger" || name == "bomber" 
-      || name == "floater" || name == "blocker")
+  if (name == Digger || name == Bomber
+      || name == Floater || name == Blocker)
     {
       is_multi_direct = false;
     }
@@ -100,25 +102,21 @@
   font_b = PingusResource::load_font("Fonts/pingus","fonts");
   */
 
-  font = PingusResource::load_font("Fonts/pingus_small", "fonts");
-  font_h = PingusResource::load_font("Fonts/pingus_small","fonts");
-  font_b = PingusResource::load_font("Fonts/pingus","fonts");
+  font   = PingusResource::load_font("Fonts/pingus_small", "fonts");
+  font_h = PingusResource::load_font("Fonts/pingus_small", "fonts");
+  font_b = PingusResource::load_font("Fonts/pingus",       "fonts");
 
-  if (str != "empty") 
+  surface   = PingusResource::load_surface("Pingus/" + action_to_string(name) 
+ to_string(owner_id), "pingus");
+  if (is_multi_direct)
     {
-      surface   = PingusResource::load_surface("Pingus/" + str + 
to_string(owner_id),
-                                              "pingus");
-      if (is_multi_direct)
-       {
-         action_c.set_size(surface.get_num_frames()/2);
-       }
-      else
-       {
-         action_c.set_size(surface.get_num_frames());
-       }
-
-      action_c.set_speed(50);
+      action_c.set_size(surface.get_num_frames()/2);
     }
+  else
+    {
+      action_c.set_size(surface.get_num_frames());
+    }
+
+  action_c.set_speed(50);
 }
 
 bool
@@ -133,7 +131,7 @@
   ++action_c;
 }
 
-std::string
+ActionName
 ActionButton::get_action_name()
 {
   return name;
@@ -145,11 +143,11 @@
   action_holder = h;
 }
 
-VerticalActionButton::VerticalActionButton(int x, int y, std::string str, int 
owner_id) :
+VerticalActionButton::VerticalActionButton(int x, int y, ActionName name, int 
owner_id) :
     background (PingusResource::load_surface("buttons/buttonbackground", 
"core")),
     backgroundhl (PingusResource::load_surface("buttons/buttonbackgroundhl", 
"core"))
 {
-  init(x, y, str, owner_id);
+  init(x, y, name, owner_id);
 }
 
 VerticalActionButton::~VerticalActionButton() {}
@@ -212,7 +210,7 @@
      && CL_Mouse::get_x() > x_pos && CL_Mouse::get_x() < x_pos + 60
      && CL_Mouse::get_y() < y_pos + 35 && CL_Mouse::get_y() > y_pos) 
   {
-       font_b->print_left (x_pos + 65, y_pos, name.c_str());
+       font_b->print_left (x_pos + 65, y_pos, action_to_string(name).c_str());
   }
 
   surface.put_screen(x_pos + 20 - surface.get_width ()/2,

Index: action_button.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/action_button.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- action_button.hxx   24 Jun 2002 22:52:53 -0000      1.2
+++ action_button.hxx   28 Jun 2002 15:12:22 -0000      1.3
@@ -23,6 +23,9 @@
 #include <ClanLib/Display/Display/surface.h>
 #include <string>
 #include "anim_counter.hxx"
+#include "pingu_enums.hxx"
+
+using Pingus::Actions::ActionName;
 
 class Server;
 class ActionHolder;
@@ -142,8 +145,7 @@
   // Added for printing action names next to the button.
   CL_Font*    font_b;
 
-  /// The x and y position of the button
-  std::string name;
+  ActionName name;
   ///
   int available;
   ///
@@ -163,7 +165,7 @@
   virtual ~ActionButton();
 
   ///
-  void init(int x, int y, std::string str, int owner_id);
+  void init(int x, int y, ActionName name_, int owner_id);
 
   /// Draws the button and increase the animation counter.
   virtual void   draw() = 0;
@@ -172,7 +174,7 @@
   void   update(float delta);
 
   /// Returns the name of the action the button represents.
-  std::string get_action_name();
+  ActionName get_action_name();
 
   /// Returns true if the button is pressed.
   bool   is_pressed();
@@ -193,7 +195,7 @@
   CL_Surface backgroundhl;
 
 public:
-  VerticalActionButton(int x, int y, std::string str, int owner_id);
+  VerticalActionButton(int x, int y, ActionName name, int owner_id);
   virtual ~VerticalActionButton();
 
   void draw();

Index: action_data.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/action_data.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- action_data.hxx     24 Jun 2002 22:52:53 -0000      1.2
+++ action_data.hxx     28 Jun 2002 15:12:22 -0000      1.3
@@ -21,6 +21,9 @@
 #define HEADER_PINGUS_ACTION_DATA_HXX
 
 #include <string>
+#include "pingu_enums.hxx"
+
+using Pingus::Actions::ActionName;
 
 ///
 class ActionData
@@ -30,12 +33,12 @@
   ActionData() {}
 
   ///
-  ActionData(const std::string& str, int i) : name(str), number_of(i)
+  ActionData(ActionName name_, int i) : name(name_), number_of(i)
   {
   }
 
   ///
-  std::string   name;
+  ActionName   name;
   ///
   int number_of;
 };

Index: action_holder.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/action_holder.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- action_holder.cxx   13 Jun 2002 14:25:12 -0000      1.2
+++ action_holder.cxx   28 Jun 2002 15:12:22 -0000      1.3
@@ -23,8 +23,6 @@
 #include "pingu_action_factory.hxx"
 #include "action_holder.hxx"
 
-using namespace boost;
-
 ActionHolder::ActionHolder (PLF* plf)
 {
   std::vector<ActionData> action_data = plf->get_actions ();
@@ -43,25 +41,25 @@
 }
 
 void
-ActionHolder::set_actions(const std::string& name, int available)
+ActionHolder::set_actions(ActionName name, int available)
 {
   available_actions[name] = available;
 }
 
 void
-ActionHolder::push_action(const std::string& name)
+ActionHolder::push_action(ActionName name)
 {
   available_actions[name]++;
 }
 
 int
-ActionHolder::get_available(const std::string& name)
+ActionHolder::get_available(ActionName name)
 {
   return available_actions[name];
 }
 
 PinguAction*
-ActionHolder::get_action(const std::string& name)
+ActionHolder::get_action(ActionName name)
 {
   if (unlimited_actions) // runtime option; defined in global.hh
     {    

Index: action_holder.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/action_holder.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- action_holder.hxx   24 Jun 2002 22:52:53 -0000      1.2
+++ action_holder.hxx   28 Jun 2002 15:12:22 -0000      1.3
@@ -22,6 +22,9 @@
 
 #include <string>
 #include <map>
+#include "pingu_enums.hxx"
+
+using Pingus::Actions::ActionName;
 
 class PLF;
 class PinguAction;
@@ -40,7 +43,7 @@
    *  where the integer <i>n</i> indicates how much more actions 
    *  called <i>name</i> can be created.
    */
-  std::map<std::string, int> available_actions;
+  std::map<ActionName, int> available_actions;
 
 public:
   ActionHolder (PLF* plf);
@@ -50,31 +53,25 @@
    * @param name the name of the action
    * @param available the number of actions available
    */
-  void set_actions(const std::string& name, int available);
+  void set_actions(ActionName name, int available);
   
   /** Adds an action to the pool of actions, making one more action available
    * @param name the name of the action
    */
-  void push_action(const std::string& name);
-
-  /** Sets a given number of actions to the pool.
-   * @deprecated This method does the same as 'set_actions', there is no
-   *  implementation and no-one uses it anyways.
-   */
-  void set_action(const std::string& name, int available);
+  void push_action(ActionName name);
 
   /** Returns the number of actions of the specified name which are available 
    *  thru get_action() 
    * @return 0 if the name is unknown
    */
-  int  get_available(const std::string&);
+  int  get_available(ActionName);
 
   /** Returns a newly allocated or cached action by a given name. It
    *  returns it from the action pool and decreases the number of available
    *  actions if necessary. If the actions are out, it returns 0. 
    *  The deletion of the action is handled by this class.  
    */
-  PinguAction* get_action(const std::string&);
+  PinguAction* get_action(ActionName);
 };
 
 #endif

Index: button_panel.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/button_panel.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- button_panel.cxx    19 Jun 2002 15:19:26 -0000      1.4
+++ button_panel.cxx    28 Jun 2002 15:12:22 -0000      1.5
@@ -28,6 +28,8 @@
 #include "world.hxx"
 #include "plf.hxx"
 
+using namespace Pingus::Actions;
+
 CL_Surface ButtonPanel::button_cap;
 
 ButtonPanel::ButtonPanel(PLF* plf, Controller* arg_controller,
@@ -47,10 +49,10 @@
   if (buttons_data.size() == 0)
     {
       std::cout << "ButtonPanel: No actions given in this level, fall back to 
default" << std::endl;
-      buttons_data.push_back(ActionData("bridger", 20));
-      buttons_data.push_back(ActionData("basher", 20));
-      buttons_data.push_back(ActionData("digger", 20));
-      buttons_data.push_back(ActionData("miner", 20));
+      buttons_data.push_back(ActionData(Bridger, 20));
+      buttons_data.push_back(ActionData(Basher, 20));
+      buttons_data.push_back(ActionData(Digger, 20));
+      buttons_data.push_back(ActionData(Miner, 20));
     }
 
   for(std::vector<ActionData>::size_type i = 0; i < buttons_data.size(); i++)
@@ -95,7 +97,7 @@
     } 
 }
 
-std::string
+ActionName
 ButtonPanel::get_action_name()
 {
   return (*pressed_button)->get_action_name();

Index: button_panel.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/button_panel.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- button_panel.hxx    24 Jun 2002 22:52:54 -0000      1.3
+++ button_panel.hxx    28 Jun 2002 15:12:22 -0000      1.4
@@ -62,7 +62,7 @@
   void on_button_press(const CL_Key& key);
   void on_button_release(const CL_Key& key);
 
-  std::string get_action_name();
+  ActionName get_action_name();
   void   update(float delta);
   void   draw();
   void   set_server(Server*);

Index: capture_rectangle.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/capture_rectangle.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- capture_rectangle.cxx       24 Jun 2002 14:25:03 -0000      1.3
+++ capture_rectangle.cxx       28 Jun 2002 15:12:22 -0000      1.4
@@ -64,18 +64,21 @@
        {
          std::string action_str = pingu->get_action()->get_name();
 
-         std::vector<PinguAction*>* persitant = pingu->get_persistent_actions 
();
-         // FIXME: This needs to get changed if we want to use action slots
-         if (persitant->size() > 0)
-           {
-             action_str += " [";
-             for (std::vector<PinguAction*>::iterator i = persitant->begin ();
-                  i != persitant->end (); ++i)
-               {
-                 action_str += (*i)->get_persistent_char ();
-               }
-             action_str += "]";
-           }
+          PinguAction * wall_action = pingu->get_wall_action();
+          PinguAction * fall_action = pingu->get_fall_action();
+          
+          if (wall_action || fall_action) {
+          
+            action_str += " [";
+            
+            if (wall_action)
+              action_str += wall_action->get_persistent_char();
+              
+            if (fall_action)
+              action_str += fall_action->get_persistent_char();
+              
+            action_str += "]";
+          }
 
          // Draw the caputure rectangle
          sur->put_screen(pingu->get_center_pos() + 
CL_Vector(x_offset,y_offset));

Index: exit.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/exit.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- exit.cxx    13 Jun 2002 14:25:12 -0000      1.2
+++ exit.cxx    28 Jun 2002 15:12:22 -0000      1.3
@@ -25,6 +25,8 @@
 #include "string_converter.hxx"
 #include "pingu.hxx"
 
+using namespace Pingus::Actions;
+
 Exit::Exit(const ExitData& data)
   : sprite (data.desc, 10.0f),
     flag ("misc/flag" + to_string (data.owner_id), "core")
@@ -87,7 +89,7 @@
          if ((*pingu)->get_status() != PS_EXITED
              && (*pingu)->get_status() != PS_DEAD)
            {
-             (*pingu)->set_action("exiter");
+             (*pingu)->set_action(Exiter);
            }
        }
     }

Index: multiplayer_client_child.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/multiplayer_client_child.cxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- multiplayer_client_child.cxx        20 Jun 2002 12:22:51 -0000      1.2
+++ multiplayer_client_child.cxx        28 Jun 2002 15:12:22 -0000      1.3
@@ -96,7 +96,7 @@
   if (pingu && pingu->get_owner () == controller->get_owner ())
     {
       char str[256];
-      sprintf(str, "Pingu: %d:%s", pingu->get_id(), 
button_panel->get_action_name().c_str());
+      sprintf(str, "Pingu: %d:%s", pingu->get_id(), 
action_to_string(button_panel->get_action_name()).c_str());
       server->send_event(str);
     }
 }

Index: pingu.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu.cxx,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- pingu.cxx   26 Jun 2002 19:13:13 -0000      1.15
+++ pingu.cxx   28 Jun 2002 15:12:22 -0000      1.16
@@ -33,6 +33,8 @@
 #include "debug.hxx"
 #include "string_converter.hxx"
 
+using namespace Pingus::Actions;
+
 const float deadly_velocity = 20.0;
 int   Pingu::id_counter = 0;
 
@@ -40,6 +42,8 @@
 Pingu::Pingu(const CL_Vector& arg_pos, int owner)
   : action(0),
     countdown_action (0),
+    wall_action(0),
+    fall_action(0),
     id (++id_counter),
     font (PingusResource::load_font("Fonts/numbers", "fonts")),
     owner_id (owner),
@@ -54,7 +58,7 @@
   velocity.x = 0;
   velocity.y = 0;
 
-  set_action("faller");
+  set_action(Faller);
 }
 
 Pingu::~Pingu()
@@ -82,7 +86,7 @@
 }
 
 bool
-Pingu::change_allowed (const std::string& new_action)
+Pingu::change_allowed (ActionName new_action)
 {
   assert (action);
   return action->change_allowed (new_action);
@@ -116,69 +120,76 @@
       pout(PINGUS_DEBUG_ACTIONS) << _("Setting action to a dead pingu") << 
std::endl;
       return false;
     }
-  act->set_pingu(this);
+    
+  switch (act->get_activation_mode()) {
+  
+    case INSTANT:
+    
+      if (act->get_type() == action->get_type()) 
+        {
+          pout(PINGUS_DEBUG_ACTIONS) << "Pingu: Already have action" << 
std::endl;
+          return false;
+        }
+                    
+        if (action->change_allowed(act->get_type()))
+          {
+            act->set_pingu(this);
+            set_action(act);
+            return true;
+          }
+                    
+      return false;
+                  
+    case WALL_TRIGGERED:
+    
+      if (wall_action && wall_action->get_type() == act->get_type())
+        {
+          pout(PINGUS_DEBUG_ACTIONS) << "Not using wall action, we have 
already" << std::endl;
+          return false;
+        }
 
-  // check for persistent actions
-  if (act->get_type() != (ActionType)ONCE) // action is persistent
-    {
-      pout(PINGUS_DEBUG_ACTIONS) << "Pingu: Found some persistant action" << 
std::endl
-                                << "Pingu: Action is " 
-                                << (act->get_type() == FALL) ? "FALL" : "WALL";
+      wall_action = act;
+      return true;
       
-      for(std::vector<PinguAction*>::iterator i = persist.begin(); i != 
persist.end(); i++)
-       {
-         if ((*i)->get_name() == act->get_name()) 
-           {
-             pout(PINGUS_DEBUG_ACTIONS) << "Not using action, we have already" 
<< std::endl;
-             return false;
-           }
-       }
-
-      persist.push_back(act);
+    case FALL_TRIGGERED:
+    
+      if (fall_action && fall_action->get_type() == act->get_type())
+        {
+          pout(PINGUS_DEBUG_ACTIONS) << "Not using fall action, we have 
already" << std::endl;
+          return false;
+        }
+      
+      fall_action = act;
       return true;
-    }
-  else 
-    {  
-      if (act->activation_time() == -1)
-       { // Immediately activate the action
-         if (action && (action->get_name() == act->get_name()))
-           {
-             pout(PINGUS_DEBUG_ACTIONS) << "Pingu: Already have action" << 
std::endl;
-             return false;
-           }
 
-         if (act->change_allowed (string_downcase(action->get_name ()))) 
//FIXME: ugly
-           {
-             set_action (act);
-             return true;
-           }
-         else
-           {
-             return false;         
-           }
-       }
-      else // timed action
-       {
-         if (countdown_action && countdown_action->get_name() == 
act->get_name())
-           { // We skip the action, since it is already set
-             return false;
-           }
-         // We set the action and start the countdown
-         action_time = act->activation_time();
-         countdown_action = act;
-         return true;
-       }
-    }
+    case COUNTDOWN_TRIGGERED:
+    
+      if (countdown_action && countdown_action->get_type() == act->get_type())
+        {
+          pout(PINGUS_DEBUG_ACTIONS) << "Not using countdown action, we have 
already" << std::endl;
+          return false;
+        }
+        
+      // We set the action and start the countdown
+      action_time = act->activation_time();
+      countdown_action = act;
+      return true;
+      
+   default:
+     
+     assert(0);
+     return false;
+  }
 }
 
 bool 
-Pingu::request_set_action (const std::string& action_name)
+Pingu::request_set_action (ActionName action_name)
 {
   return request_set_action (PinguActionFactory::instance ()->create 
(action_name));
 }
 
 void
-Pingu::set_action(const std::string& action_name) 
+Pingu::set_action(ActionName action_name) 
 {
   set_action (PinguActionFactory::instance ()->create (action_name));
 }
@@ -192,6 +203,30 @@
   action->set_pingu(this);
 }
 
+bool
+Pingu::set_fall_action ()
+{
+  if (fall_action)
+    {
+      set_action(fall_action);
+      return true;
+    }
+    
+  return false;
+}
+
+bool
+Pingu::set_wall_action ()
+{
+  if (wall_action)
+    {
+      set_action(wall_action);
+      return true;
+    }
+
+  return false;
+}
+
 PinguStatus
 Pingu::get_status(void) const
 {
@@ -235,8 +270,6 @@
 }
 
 // Let the pingu do his job (i.e. walk his way)
-// FIXME: This function is *much* too large, it needs a real cut down
-// into smaller pieces.  
 void
 Pingu::update(float delta)
 {
@@ -259,7 +292,7 @@
 
   if (action_time == 0 && countdown_action) 
     {
-      std::cout << "COUNTDOWNACTIAN SET: " << countdown_action->get_name () << 
std::endl;
+      std::cout << "COUNTDOWNACTION SET: " << countdown_action->get_name () << 
std::endl;
 
       set_action(countdown_action);
       // Reset the countdown action handlers 
@@ -268,23 +301,7 @@
       return;
     }
   
-  if ( !action || action->is_finished) 
-    {
-      update_action(delta);
-    }
-
   action->update(delta);
-}
-
-// Check if the pingu is on ground and then do something.
-void 
-Pingu::update_action(float /*delta*/)
-{
-  pout(PINGUS_DEBUG_ACTIONS) << "Pingu: No action set, setting action." << 
std::endl;
-  if (rel_getpixel(0,-1) == GroundpieceData::GP_NOTHING)
-    set_action("faller");
-  else
-    set_action("walker");
 }
 
 // Draws the pingu on the screen with the given offset

Index: pingu.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu.hxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- pingu.hxx   26 Jun 2002 19:13:13 -0000      1.7
+++ pingu.hxx   28 Jun 2002 15:12:22 -0000      1.8
@@ -27,6 +27,9 @@
 #include "direction.hxx"
 #include "pingu_enums.hxx"
 #include "worldobj.hxx"
+#include "pingu_enums.hxx"
+
+using Pingus::Actions::ActionName;
 
 // Forward declarations
 class CL_Font;
@@ -65,23 +68,21 @@
   int owner_id;
 
 public:
-  /** A list of action with are activated on-demand, so when the pingu
-      is in the air a floater will get activated, if he needs to climb
-      a climber gets active. 
-      
-      FIXME: This will get obsolete sooner or later
-  */
-  std::vector<PinguAction*> persist;
-
 
-  // The stat of the pingu, these can be modified by PinguActions
-  
+  /// The stat of the pingu, these can be modified by PinguActions
   PinguStatus status;
+  
   /// The postion of the pingu (CL_Vector::z is always zero)
   CL_Vector pos;
   Direction direction;
   CL_Vector velocity; 
 
+
+public:
+  bool request_set_action (PinguAction*);
+  
+  void  set_action (PinguAction*);
+
 public:
   /** Creates a new Pingu at the given coordinates
       @param pos The start position of the pingu
@@ -110,7 +111,7 @@
   int  get_y(void);
 
   /** Checks if this action allows to be overwritten with the given new action 
*/
-  bool change_allowed (const std::string&);
+  bool change_allowed (ActionName new_action);
 
   /// Check if the pingu is still alive
   bool is_alive(void);
@@ -121,6 +122,8 @@
   ///
   PinguStatus set_status(PinguStatus);
 
+  PinguAction* get_action();
+
   /// Returns the unique id of the pingu
   int  get_id(void); 
   
@@ -140,18 +143,21 @@
       action, it will be hold back for later execution, same with a
       timed action, normal action will be applied if the current
       action allows that. */
-  bool request_set_action (PinguAction*);
-  bool request_set_action (const std::string& action_name);
+  bool request_set_action (ActionName action_name);
 
   /** Set an action without any checking, the action will take
       instantly control. */
-  void  set_action (PinguAction*);
-  void  set_action (const std::string& action_name);
-
-  ///
-  PinguAction* get_action();
+  void set_action (ActionName action_name);
+  
+  /// set the wall action if we have one
+  bool set_wall_action ();
+  
+  /// set the fall action if we have one
+  bool set_fall_action ();
 
-  std::vector<PinguAction*>* get_persistent_actions () { return &persist; } 
+  PinguAction* get_wall_action() { return wall_action; }
+  
+  PinguAction* get_fall_action() { return fall_action; }
 
   /** Returns the `color' of the colmap in the walking direction 
       Examples: 
@@ -172,7 +178,6 @@
   void apply_force(CL_Vector);
   
   void update(float delta);
-  void update_action(float delta);
   
   /** Indicate if the pingu's speed is above the deadly velocity */
   //bool is_tumbling () const;
@@ -199,7 +204,4 @@
 #endif /* PINGU_HH */
 
 /* EOF */
-
-
-
 

Index: pingu_action.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu_action.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- pingu_action.cxx    25 Jun 2002 18:15:18 -0000      1.4
+++ pingu_action.cxx    28 Jun 2002 15:12:22 -0000      1.5
@@ -29,7 +29,6 @@
 PinguAction::PinguAction()
   : pingu (0)
 {
-  is_finished = false;
 }
 
 PinguAction::~PinguAction()
@@ -61,9 +60,9 @@
 }
 
 ActionType
-PinguAction::get_type(void)
+PinguAction::get_activation_mode() const
 {
-  return (ActionType)ONCE;
+  return INSTANT;
 }
 
 char

Index: pingu_action.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu_action.hxx,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- pingu_action.hxx    26 Jun 2002 19:13:13 -0000      1.5
+++ pingu_action.hxx    28 Jun 2002 15:12:22 -0000      1.6
@@ -22,16 +22,18 @@
 
 #include "worldobj.hxx"
 #include "pingu_enums.hxx"
+#include "pingu.hxx"
+
+using namespace Pingus::Actions;
 
-///
-class Pingu;
 class ActionHolder;
 
 enum ActionType
 {
-  ONCE = 1<<1,
-  WALL = 1<<2,
-  FALL = 1<<3
+  INSTANT             = 1<<1,
+  WALL_TRIGGERED      = 1<<2,
+  FALL_TRIGGERED      = 1<<3,
+  COUNTDOWN_TRIGGERED = 1<<4
 };
 
 // This class provides an abstract interface for pingu actions. It is 
@@ -48,9 +50,6 @@
   static const int pingu_height;
 
 public:
-  /** Indicate if the action should be canceled at the next possible
-      point. FIXME: Only keeped public for lazyness. */
-  bool is_finished;
 
   PinguAction();
   virtual ~PinguAction();
@@ -68,25 +67,28 @@
   int  rel_getpixel(int x, int y);
 
   /** Checks if this action allows to be overwritten with the given new action 
*/
-  virtual bool change_allowed (const std::string&) { return true; }
+  virtual bool change_allowed (ActionName) { return true; }
   
   /** Used to load all data, which is needed by the action, its
       seperated and called in set_pingu(), because some data will be
       only valid if set_pingu() is called. */
   virtual void  init(void) {};
 
-  /// The "AI" of the pingu. The walker and faller is in class Pingu
+  /// The "AI" of the pingu.
   virtual void  update(float delta) = 0;
 
   /** Draws the surfaced defined by the action, can be overwritten if
       the action needs a more complicated way of drawing. */
   virtual void  draw_offset(int x, int y, float s) =0;
 
-  /// Returns the action type
-  virtual ActionType get_type(void);
+  /// Returns the activation mode
+  virtual ActionType get_activation_mode(void) const;
 
-  /// The name of the action, used in pingu_info.hxx
+  /// The name of the action
   virtual std::string get_name(void) const =0;
+  
+  /// The type of the action
+  virtual ActionName get_type() const =0;
   
   /** Return the character that is shown when a persitent action is
       activated in the CaptureRectangle. */

Index: pingu_action_factory.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu_action_factory.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pingu_action_factory.cxx    18 Jun 2002 10:04:11 -0000      1.3
+++ pingu_action_factory.cxx    28 Jun 2002 15:12:22 -0000      1.4
@@ -66,36 +66,35 @@
 void 
 PinguActionFactory::register_core_actions ()
 {
-  new PinguActionFactoryImpl<RocketLauncher> ("rocketlauncher");
-  new PinguActionFactoryImpl<Boarder> ("boarder");
-  new PinguActionFactoryImpl<Superman> ("superman");
-  new PinguActionFactoryImpl<Angel> ("angel");
-  new PinguActionFactoryImpl<Basher> ("basher");
-  new PinguActionFactoryImpl<Blocker> ("blocker");
-  new PinguActionFactoryImpl<Bomber> ("bomber");
-  new PinguActionFactoryImpl<Bridger> ("bridger");
-  new PinguActionFactoryImpl<Climber> ("climber");
-  new PinguActionFactoryImpl<Digger> ("digger");
-  new PinguActionFactoryImpl<Exiter> ("exiter");
-  new PinguActionFactoryImpl<Floater> ("floater");
-  new PinguActionFactoryImpl<Miner> ("miner");
-  new PinguActionFactoryImpl<Jumper> ("jumper");
-  new PinguActionFactoryImpl<Slider> ("slider");
-  new PinguActionFactoryImpl<Teleported> ("teleporter");
-  new PinguActionFactoryImpl<Exiter> ("exiter");
-  new PinguActionFactoryImpl<Smashed> ("smashed");
-  new PinguActionFactoryImpl<LaserKill> ("laserkill");
-  new PinguActionFactoryImpl<Splashed> ("splashed");
-  new PinguActionFactoryImpl<Waiter> ("waiter");
-  new PinguActionFactoryImpl<Drown> ("drown");
-  new PinguActionFactoryImpl<Faller> ("faller");
-  new PinguActionFactoryImpl<Walker> ("walker");
+  new PinguActionFactoryImpl<class Angel>          (Pingus::Actions::Angel);
+  new PinguActionFactoryImpl<class Basher>         (Pingus::Actions::Basher);
+  new PinguActionFactoryImpl<class Blocker>        (Pingus::Actions::Blocker);
+  new PinguActionFactoryImpl<class Boarder>        (Pingus::Actions::Boarder);
+  new PinguActionFactoryImpl<class Bomber>         (Pingus::Actions::Bomber);
+  new PinguActionFactoryImpl<class Bridger>        (Pingus::Actions::Bridger);
+  new PinguActionFactoryImpl<class Climber>        (Pingus::Actions::Climber);
+  new PinguActionFactoryImpl<class Digger>         (Pingus::Actions::Digger);
+  new PinguActionFactoryImpl<class Drown>          (Pingus::Actions::Drown);
+  new PinguActionFactoryImpl<class Exiter>         (Pingus::Actions::Exiter);
+  new PinguActionFactoryImpl<class Faller>         (Pingus::Actions::Faller);
+  new PinguActionFactoryImpl<class Floater>        (Pingus::Actions::Floater);
+  new PinguActionFactoryImpl<class Jumper>         (Pingus::Actions::Jumper);
+  new PinguActionFactoryImpl<class LaserKill>      
(Pingus::Actions::Laserkill);
+  new PinguActionFactoryImpl<class Miner>          (Pingus::Actions::Miner);
+  new PinguActionFactoryImpl<class RocketLauncher> 
(Pingus::Actions::Rocketlauncher);
+  new PinguActionFactoryImpl<class Slider>         (Pingus::Actions::Slider);
+  new PinguActionFactoryImpl<class Smashed>        (Pingus::Actions::Smashed);
+  new PinguActionFactoryImpl<class Splashed>       (Pingus::Actions::Splashed);
+  new PinguActionFactoryImpl<class Superman>       (Pingus::Actions::Superman);
+  new PinguActionFactoryImpl<class Teleported>     
(Pingus::Actions::Teleported);
+  new PinguActionFactoryImpl<class Waiter>         (Pingus::Actions::Waiter);
+  new PinguActionFactoryImpl<class Walker>         (Pingus::Actions::Walker);
 }
 
 PinguAction* 
-PinguActionFactory::create (const std::string& id)
+PinguActionFactory::create (ActionName id)
 {
-  std::map<std::string, PinguActionAbstractFactory*>::iterator it = 
factories.find(id);
+  std::map<ActionName, PinguActionAbstractFactory*>::iterator it = 
factories.find(id);
   
   if (it == factories.end())
     throw PingusError("PinguActionFactory: Invalid id: " + id);
@@ -121,7 +120,7 @@
 }
 
 void 
-PinguActionFactory::register_factory (const std::string& id, 
PinguActionAbstractFactory* factory)
+PinguActionFactory::register_factory (ActionName id, 
PinguActionAbstractFactory* factory)
 {
   // FIXME: Could need some more error checking
   factories[id] = factory;

Index: pingu_action_factory.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu_action_factory.hxx,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- pingu_action_factory.hxx    24 Jun 2002 22:52:55 -0000      1.2
+++ pingu_action_factory.hxx    28 Jun 2002 15:12:22 -0000      1.3
@@ -22,13 +22,9 @@
 
 #include <map>
 #include <string>
+#include "pingu.hxx"
 
 class PinguActionAbstractFactory;
-class PinguAction;
-
-namespace boost {
-  template <class T> class shared_ptr;
-}
 
 class PinguActionFactory
 {
@@ -36,14 +32,15 @@
   /** This vector saves all allocated actions to delete them at a later point 
*/
   std::vector<PinguAction*> all_actions;
 
-  std::map<std::string, PinguActionAbstractFactory*> factories;
+  std::map<ActionName, PinguActionAbstractFactory*> factories;
   static PinguActionFactory* instance_;
   
   PinguActionFactory ();
   void register_core_actions ();
+  
 public:
   static PinguActionFactory* instance ();
-  void register_factory (const std::string& id, PinguActionAbstractFactory*);
+  void register_factory (ActionName id, PinguActionAbstractFactory*);
 
   /** Delete all actions which this class has allocated. This needs to
       be called seperatly from the constructor, due to the used
@@ -51,13 +48,13 @@
   void delete_actions ();
 
   /** Allocate the given action */
-  PinguAction* create (const std::string& id);
+  PinguAction* create (ActionName id);
 };
 
 class PinguActionAbstractFactory
 {
 public:
-  PinguActionAbstractFactory (const std::string& id) {
+  PinguActionAbstractFactory (ActionName id) {
     PinguActionFactory::instance ()-> register_factory (id, this);
   }
   
@@ -68,7 +65,7 @@
 class PinguActionFactoryImpl : public PinguActionAbstractFactory
 {
 public:
-  PinguActionFactoryImpl (const std::string& id)
+  PinguActionFactoryImpl (ActionName id)
     : PinguActionAbstractFactory (id)
   {
   }

Index: pingu_enums.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/pingu_enums.hxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- pingu_enums.hxx     26 Jun 2002 19:13:13 -0000      1.3
+++ pingu_enums.hxx     28 Jun 2002 15:12:22 -0000      1.4
@@ -20,6 +20,8 @@
 #ifndef HEADER_PINGUS_PINGU_ENUMS_HXX
 #define HEADER_PINGUS_PINGU_ENUMS_HXX
 
+#include <string>
+
 /** Haven't yet experimented much with pingu status, but maybe it is a
     good idea. Maybe that should be changed to a bitmask. */
 enum PinguStatus { PS_ALIVE, PS_EXITED, PS_DEAD };
@@ -30,6 +32,41 @@
   DEMO_MODE 
 };
 
+namespace Pingus {
+
+  namespace Actions {
+    
+     enum ActionName { Angel,
+                       Basher,
+                       Blocker,
+                       Boarder,
+                       Bomber,
+                       Bridger,
+                       Climber,
+                       Digger,
+                       Drown,
+                       Exiter,
+                       Faller,
+                       Floater,
+                       Jumper,
+                       Laserkill,
+                       Miner,
+                       Rocketlauncher,
+                       Slider,
+                       Smashed,
+                       Splashed,
+                       Superman,
+                       Teleported,
+                       Waiter,
+                       Walker
+                  };
+     
+     std::string action_to_string(ActionName action);
+     ActionName  action_from_string(const std::string& action);
+   }
+}
+
 #endif
+
 
 /* EOF */

Index: playfield.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/playfield.cxx,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- playfield.cxx       24 Jun 2002 14:25:03 -0000      1.6
+++ playfield.cxx       28 Jun 2002 15:12:22 -0000      1.7
@@ -219,7 +219,7 @@
     {
       char str[256];
       sprintf(str, "Pingu: %d:%s", current_pingu->get_id(), 
-             buttons->get_action_name().c_str());
+             action_to_string(buttons->get_action_name()).c_str());
       server->send_event(str);
       return true;
     }

Index: plf_plf.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/plf_plf.cxx,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -d -r1.3 -r1.4
--- plf_plf.cxx 20 Jun 2002 11:23:53 -0000      1.3
+++ plf_plf.cxx 28 Jun 2002 15:12:22 -0000      1.4
@@ -22,8 +22,10 @@
 #include "pingus_error.hxx"
 #include "psm_parser.hxx"
 #include "plf_plf.hxx"
+#include "pingu_enums.hxx"
 
 using namespace std;
+using Pingus::Actions::action_from_string;
 
 int    str_to_int(const string& str);
 float str_to_float(const string& str);
@@ -263,7 +265,7 @@
   case PLFPLF::BUTTONS:
     {
       ActionData temp;
-      temp.name = valueid;
+      temp.name = action_from_string(valueid);
       sscanf(value.c_str(), "%d", &temp.number_of);
       actions.push_back(temp);
     }

Index: server.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/server.cxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- server.cxx  28 Jun 2002 09:51:46 -0000      1.7
+++ server.cxx  28 Jun 2002 15:12:22 -0000      1.8
@@ -30,6 +30,7 @@
 #include "world.hxx"
 
 using namespace std;
+using Pingus::Actions::action_from_string;
 
 PingusEvent::PingusEvent()
 {
@@ -161,13 +162,13 @@
 
       if (pingu != pingus->end()) 
        {
-         PinguAction* tmp_action = action_holder.get_action(action);
+         PinguAction* tmp_action = 
action_holder.get_action(action_from_string(action));
          
          if (tmp_action)
            {
              if (!(*pingu)->request_set_action(tmp_action))
                {
-                 action_holder.push_action(action);
+                 action_holder.push_action(action_from_string(action));
                }
            }
        } 

Index: world.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/world.cxx,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- world.cxx   28 Jun 2002 09:51:46 -0000      1.12
+++ world.cxx   28 Jun 2002 15:12:22 -0000      1.13
@@ -34,6 +34,7 @@
 
 using namespace std;
 using boost::shared_ptr;
+using Pingus::Actions::Bomber;
 
 typedef std::list<WorldObj*>::iterator WorldObjIter;
 
@@ -136,7 +137,7 @@
   if (do_armageddon && armageddon_count != pingus->end())
     {
       // The iterator here might be invalid
-      (*armageddon_count)->request_set_action("bomber");
+      (*armageddon_count)->request_set_action(Bomber);
       armageddon_count++;
     }
     

Index: xml_plf.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/xml_plf.cxx,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- xml_plf.cxx 24 Jun 2002 18:53:14 -0000      1.4
+++ xml_plf.cxx 28 Jun 2002 15:12:22 -0000      1.5
@@ -32,6 +32,7 @@
 #include "liquid_data.hxx"
 
 using namespace std;
+using Pingus::Actions::action_from_string;
 
 XMLPLF::XMLPLF(const std::string& filename)
 {
@@ -306,7 +307,7 @@
        }
  
       ActionData button;
-      button.name = (char*)cur->name;
+      button.name = action_from_string((const char*) cur->name);
 
       char* count = (char*)xmlGetProp(cur, (xmlChar*)"count");
       if (count)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]