---
 lib/wormux/include/WORMUX_action.h |    9 +++++
 src/include/action_handler.cpp     |   48 ++++++++++++++++++++++++++
 src/weapon/weapon.cpp              |   65 ++++++++++++++++++++++++++++++++++++
 src/weapon/weapon.h                |   24 +++++++++++++
 4 files changed, 146 insertions(+), 0 deletions(-)

diff --git a/lib/wormux/include/WORMUX_action.h 
b/lib/wormux/include/WORMUX_action.h
index 78edd13..19d0e06 100644
--- a/lib/wormux/include/WORMUX_action.h
+++ b/lib/wormux/include/WORMUX_action.h
@@ -90,6 +90,15 @@ public:
     // Quite standard weapon options
     ACTION_WEAPON_SET_TIMEOUT,
     ACTION_WEAPON_SET_TARGET,
+    ACTION_WEAPON_START_MOVING_LEFT,
+    ACTION_WEAPON_STOP_MOVING_LEFT,
+    ACTION_WEAPON_START_MOVING_RIGHT,
+    ACTION_WEAPON_STOP_MOVING_RIGHT,
+    ACTION_WEAPON_START_MOVING_UP,
+    ACTION_WEAPON_STOP_MOVING_UP,
+    ACTION_WEAPON_START_MOVING_DOWN,
+    ACTION_WEAPON_STOP_MOVING_DOWN,
+
 
     // Special weapon options
     ACTION_WEAPON_CONSTRUCTION,
diff --git a/src/include/action_handler.cpp b/src/include/action_handler.cpp
index 65ef7ab..24f5360 100644
--- a/src/include/action_handler.cpp
+++ b/src/include/action_handler.cpp
@@ -650,6 +650,46 @@ static void Action_Weapon_SetTimeout (Action *a)
   launcher->GetProjectile()->m_timeout_modifier = a->PopInt();
 }
 
+static void Action_Weapon_StartMovingLeft(Action */*a*/)
+{
+  ActiveTeam().AccessWeapon().StartMovingLeft();
+}
+
+static void Action_Weapon_StopMovingLeft(Action */*a*/)
+{
+  ActiveTeam().AccessWeapon().StopMovingLeft();
+}
+
+static void Action_Weapon_StartMovingRight(Action */*a*/)
+{
+  ActiveTeam().AccessWeapon().StartMovingRight();
+}
+
+static void Action_Weapon_StopMovingRight(Action */*a*/)
+{
+  ActiveTeam().AccessWeapon().StopMovingRight();
+}
+
+static void Action_Weapon_StartMovingUp(Action */*a*/)
+{
+  ActiveTeam().AccessWeapon().StartMovingUp();
+}
+
+static void Action_Weapon_StopMovingUp(Action */*a*/)
+{
+  ActiveTeam().AccessWeapon().StopMovingUp();
+}
+
+static void Action_Weapon_StartMovingDown(Action */*a*/)
+{
+  ActiveTeam().AccessWeapon().StartMovingDown();
+}
+
+static void Action_Weapon_StopMovingDown(Action */*a*/)
+{
+  ActiveTeam().AccessWeapon().StopMovingDown();
+}
+
 static void Action_Weapon_Construction (Action *a)
 {
   Construct* construct_weapon = 
dynamic_cast<Construct*>(&(ActiveTeam().AccessWeapon()));
@@ -980,6 +1020,14 @@ void Action_Handler_Init()
   // Quite standard weapon options
   ActionHandler::GetInstance()->Register (Action::ACTION_WEAPON_SET_TIMEOUT, 
"WEAPON_set_timeout", &Action_Weapon_SetTimeout);
   ActionHandler::GetInstance()->Register (Action::ACTION_WEAPON_SET_TARGET, 
"WEAPON_set_target", &Action_Weapon_SetTarget);
+  ActionHandler::GetInstance()->Register 
(Action::ACTION_WEAPON_START_MOVING_LEFT, "WEAPON_start_moving_left", 
&Action_Weapon_StartMovingLeft);
+  ActionHandler::GetInstance()->Register 
(Action::ACTION_WEAPON_STOP_MOVING_LEFT, "WEAPON_stop_moving_left", 
&Action_Weapon_StopMovingLeft);
+  ActionHandler::GetInstance()->Register 
(Action::ACTION_WEAPON_START_MOVING_RIGHT, "WEAPON_start_moving_right", 
&Action_Weapon_StartMovingRight);
+  ActionHandler::GetInstance()->Register 
(Action::ACTION_WEAPON_STOP_MOVING_RIGHT, "WEAPON_stop_moving_right", 
&Action_Weapon_StopMovingRight);
+  ActionHandler::GetInstance()->Register 
(Action::ACTION_WEAPON_START_MOVING_UP, "WEAPON_start_moving_up", 
&Action_Weapon_StartMovingUp);
+  ActionHandler::GetInstance()->Register 
(Action::ACTION_WEAPON_STOP_MOVING_UP, "WEAPON_stop_moving_up", 
&Action_Weapon_StopMovingUp);
+  ActionHandler::GetInstance()->Register 
(Action::ACTION_WEAPON_START_MOVING_DOWN, "WEAPON_start_moving_down", 
&Action_Weapon_StartMovingDown);
+  ActionHandler::GetInstance()->Register 
(Action::ACTION_WEAPON_STOP_MOVING_DOWN, "WEAPON_stop_moving_down", 
&Action_Weapon_StopMovingDown);
 
   // Special weapon options
   ActionHandler::GetInstance()->Register (Action::ACTION_WEAPON_CONSTRUCTION, 
"WEAPON_construction", &Action_Weapon_Construction);
diff --git a/src/weapon/weapon.cpp b/src/weapon/weapon.cpp
index 75d4e8f..fcf70c5 100644
--- a/src/weapon/weapon.cpp
+++ b/src/weapon/weapon.cpp
@@ -34,6 +34,7 @@
 #include "include/app.h"
 #include "include/action_handler.h"
 #include "map/camera.h"
+#include "network/network.h"
 #include "team/macro.h"
 #include "team/team.h"
 #include "tool/math_tools.h"
@@ -345,6 +346,70 @@ void Weapon::RepeatShoot()
   }
 }
 
+void Weapon::StartMovingLeftForAllPlayers()
+{
+  Action a(Action::ACTION_WEAPON_START_MOVING_LEFT);
+  Network::GetInstance()->SendActionToAll(a);
+
+  StartMovingLeft();
+}
+
+void Weapon::StopMovingLeftForAllPlayers()
+{
+  Action a(Action::ACTION_WEAPON_STOP_MOVING_LEFT);
+  Network::GetInstance()->SendActionToAll(a);
+
+  StopMovingLeft();
+}
+
+void Weapon::StartMovingRightForAllPlayers()
+{
+  Action a(Action::ACTION_WEAPON_START_MOVING_RIGHT);
+  Network::GetInstance()->SendActionToAll(a);
+
+  StartMovingRight();
+}
+
+void Weapon::StopMovingRightForAllPlayers()
+{
+  Action a(Action::ACTION_WEAPON_STOP_MOVING_RIGHT);
+  Network::GetInstance()->SendActionToAll(a);
+
+  StopMovingRight();
+}
+
+void Weapon::StartMovingUpForAllPlayers()
+{
+  Action a(Action::ACTION_WEAPON_START_MOVING_UP);
+  Network::GetInstance()->SendActionToAll(a);
+
+  StartMovingUp();
+}
+
+void Weapon::StopMovingUpForAllPlayers()
+{
+  Action a(Action::ACTION_WEAPON_STOP_MOVING_UP);
+  Network::GetInstance()->SendActionToAll(a);
+
+  StopMovingUp();
+}
+
+void Weapon::StartMovingDownForAllPlayers()
+{
+  Action a(Action::ACTION_WEAPON_START_MOVING_DOWN);
+  Network::GetInstance()->SendActionToAll(a);
+
+  StartMovingDown();
+}
+
+void Weapon::StopMovingDownForAllPlayers()
+{
+  Action a(Action::ACTION_WEAPON_STOP_MOVING_DOWN);
+  Network::GetInstance()->SendActionToAll(a);
+
+  StopMovingDown();
+}
+
 // Compute position of weapon's image
 void Weapon::PosXY (int &x, int &y) const
 {
diff --git a/src/weapon/weapon.h b/src/weapon/weapon.h
index 42cdb8b..2b4f2a5 100644
--- a/src/weapon/weapon.h
+++ b/src/weapon/weapon.h
@@ -158,6 +158,18 @@ protected:
   void DrawAmmoUnits() const;
 
   void RepeatShoot();
+
+  void StartMovingLeftForAllPlayers();
+  void StopMovingLeftForAllPlayers();
+
+  void StartMovingRightForAllPlayers();
+  void StopMovingRightForAllPlayers();
+
+  void StartMovingUpForAllPlayers();
+  void StopMovingUpForAllPlayers();
+
+  void StartMovingDownForAllPlayers();
+  void StopMovingDownForAllPlayers();
 public:
   Weapon(Weapon_type type,
          const std::string &id,
@@ -326,6 +338,18 @@ public:
   inline const double &GetMinAngle() const {return min_angle;}
   inline void SetMaxAngle(double max) {max_angle = max;}
   inline const double &GetMaxAngle() const {return max_angle;}
+
+  virtual void StartMovingLeft() {};
+  virtual void StopMovingLeft() {};
+
+  virtual void StartMovingRight() {};
+  virtual void StopMovingRight() {};
+
+  virtual void StartMovingUp() {};
+  virtual void StopMovingUp() {};
+
+  virtual void StartMovingDown() {};
+  virtual void StopMovingDown() {};
 private:
   // Angle in radian between -PI to PI
   double min_angle, max_angle;
-- 
1.6.0.4


_______________________________________________
Wormux-dev mailing list
Wormux-dev@gna.org
https://mail.gna.org/listinfo/wormux-dev

Répondre à