[Orxonox-commit 3169] r7862 - in code/trunk/src/orxonox: controllers worldentities/pawns

landauf at orxonox.net landauf at orxonox.net
Sat Feb 12 11:57:28 CET 2011


Author: landauf
Date: 2011-02-12 11:57:28 +0100 (Sat, 12 Feb 2011)
New Revision: 7862

Modified:
   code/trunk/src/orxonox/controllers/HumanController.cc
   code/trunk/src/orxonox/worldentities/pawns/Spectator.cc
   code/trunk/src/orxonox/worldentities/pawns/Spectator.h
Log:
added feature to Spectator which changes the keybind mode of the fire command to OnPress if the player controls a Spectator. changes mode back to OnHold if the player stops control of the Spectator (e.g. spawns) by using a helper function.

This avoids accidentally firing the weapons right after spawn.


Modified: code/trunk/src/orxonox/controllers/HumanController.cc
===================================================================
--- code/trunk/src/orxonox/controllers/HumanController.cc	2011-02-12 10:54:07 UTC (rev 7861)
+++ code/trunk/src/orxonox/controllers/HumanController.cc	2011-02-12 10:57:28 UTC (rev 7862)
@@ -39,13 +39,15 @@
 
 namespace orxonox
 {
+    extern const std::string __CC_fire_name = "fire";
+
     SetConsoleCommand("HumanController", "moveFrontBack",          &HumanController::moveFrontBack ).addShortcut().setAsInputCommand();
     SetConsoleCommand("HumanController", "moveRightLeft",          &HumanController::moveRightLeft ).addShortcut().setAsInputCommand();
     SetConsoleCommand("HumanController", "moveUpDown",             &HumanController::moveUpDown    ).addShortcut().setAsInputCommand();
     SetConsoleCommand("HumanController", "rotateYaw",              &HumanController::rotateYaw     ).addShortcut().setAsInputCommand();
     SetConsoleCommand("HumanController", "rotatePitch",            &HumanController::rotatePitch   ).addShortcut().setAsInputCommand();
     SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
-    SetConsoleCommand("HumanController", "fire",                   &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
+    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
     SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
     SetConsoleCommand("HumanController", "boost",                  &HumanController::boost         ).addShortcut().keybindMode(KeybindMode::OnHold);
     SetConsoleCommand("HumanController", "greet",                  &HumanController::greet         ).addShortcut();

Modified: code/trunk/src/orxonox/worldentities/pawns/Spectator.cc
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/Spectator.cc	2011-02-12 10:54:07 UTC (rev 7861)
+++ code/trunk/src/orxonox/worldentities/pawns/Spectator.cc	2011-02-12 10:57:28 UTC (rev 7862)
@@ -28,9 +28,12 @@
 
 #include "Spectator.h"
 
+#include "util/Convert.h"
 #include "core/CoreIncludes.h"
 #include "core/ConfigValueIncludes.h"
 #include "core/GameMode.h"
+#include "core/command/CommandExecutor.h"
+#include "core/command/ConsoleCommand.h"
 
 #include "tools/BillboardSet.h"
 #include "Scene.h"
@@ -38,6 +41,8 @@
 
 namespace orxonox
 {
+    extern const std::string __CC_fire_name;
+
     CreateFactory(Spectator);
 
     Spectator::Spectator(BaseObject* creator) : ControllableEntity(creator)
@@ -147,11 +152,39 @@
 //        this->setSyncMode(ObjectDirection::ToClient);
     }
 
+    /**
+        @brief Changes the keybind mode of the fire command to OnPress.
+    */
     void Spectator::startLocalHumanControl()
     {
         ControllableEntity::startLocalHumanControl();
+
+        // change keybind mode of fire command to OnPress to avoid firing after respawn
+        ModifyConsoleCommand(__CC_fire_name).keybindMode(KeybindMode::OnPress);
     }
 
+    /**
+        @brief Changes the keybind mode of the fire command back to OnHold.
+    */
+    void Spectator::stopLocalHumanControl()
+    {
+        ControllableEntity::stopLocalHumanControl();
+
+        // change fire command to a helper function and change keybind mode to OnPress
+        // as soon as the player releases and presses the button again, the helper function will be called which changes the keybind mode back to OnHold
+        ModifyConsoleCommand(__CC_fire_name).pushFunction(&Spectator::resetFireCommand).keybindMode(KeybindMode::OnPress);
+    }
+
+    /**
+        @brief Helper function which changes the fire command back to the original function and keybind mode to OnHold.
+    */
+    void Spectator::resetFireCommand(unsigned int firemode)
+    {
+        ModifyConsoleCommand(__CC_fire_name).popFunction().keybindMode(KeybindMode::OnHold); // pop this helper function and change keybind mode
+
+        CommandExecutor::execute(__CC_fire_name + " " + multi_cast<std::string>(firemode)); // call the fire command again, this time with the real function
+    }
+
     void Spectator::moveFrontBack(const Vector2& value)
     {
         this->localVelocity_.z -= value.x;

Modified: code/trunk/src/orxonox/worldentities/pawns/Spectator.h
===================================================================
--- code/trunk/src/orxonox/worldentities/pawns/Spectator.h	2011-02-12 10:54:07 UTC (rev 7861)
+++ code/trunk/src/orxonox/worldentities/pawns/Spectator.h	2011-02-12 10:57:28 UTC (rev 7862)
@@ -60,12 +60,15 @@
         protected:
             virtual void setPlayer(PlayerInfo* player);
             virtual void startLocalHumanControl();
+            virtual void stopLocalHumanControl();
 
         private:
             void registerVariables();
             void changedGreeting();
             void changedFlareVisibility();
 
+            static void resetFireCommand(unsigned int firemode);
+
             BillboardSet* greetingFlare_;
             bool bGreetingFlareVisible_;
             bool bGreeting_;




More information about the Orxonox-commit mailing list