Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7862


Ignore:
Timestamp:
Feb 12, 2011, 11:57:28 AM (13 years ago)
Author:
landauf
Message:

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.

Location:
code/trunk/src/orxonox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/controllers/HumanController.cc

    r7533 r7862  
    4040namespace orxonox
    4141{
     42    extern const std::string __CC_fire_name = "fire";
     43
    4244    SetConsoleCommand("HumanController", "moveFrontBack",          &HumanController::moveFrontBack ).addShortcut().setAsInputCommand();
    4345    SetConsoleCommand("HumanController", "moveRightLeft",          &HumanController::moveRightLeft ).addShortcut().setAsInputCommand();
     
    4648    SetConsoleCommand("HumanController", "rotatePitch",            &HumanController::rotatePitch   ).addShortcut().setAsInputCommand();
    4749    SetConsoleCommand("HumanController", "rotateRoll",             &HumanController::rotateRoll    ).addShortcut().setAsInputCommand();
    48     SetConsoleCommand("HumanController", "fire",                   &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
     50    SetConsoleCommand("HumanController", __CC_fire_name,           &HumanController::fire          ).addShortcut().keybindMode(KeybindMode::OnHold);
    4951    SetConsoleCommand("HumanController", "reload",                 &HumanController::reload        ).addShortcut();
    5052    SetConsoleCommand("HumanController", "boost",                  &HumanController::boost         ).addShortcut().keybindMode(KeybindMode::OnHold);
  • code/trunk/src/orxonox/worldentities/pawns/Spectator.cc

    r6417 r7862  
    2929#include "Spectator.h"
    3030
     31#include "util/Convert.h"
    3132#include "core/CoreIncludes.h"
    3233#include "core/ConfigValueIncludes.h"
    3334#include "core/GameMode.h"
     35#include "core/command/CommandExecutor.h"
     36#include "core/command/ConsoleCommand.h"
    3437
    3538#include "tools/BillboardSet.h"
     
    3942namespace orxonox
    4043{
     44    extern const std::string __CC_fire_name;
     45
    4146    CreateFactory(Spectator);
    4247
     
    148153    }
    149154
     155    /**
     156        @brief Changes the keybind mode of the fire command to OnPress.
     157    */
    150158    void Spectator::startLocalHumanControl()
    151159    {
    152160        ControllableEntity::startLocalHumanControl();
     161
     162        // change keybind mode of fire command to OnPress to avoid firing after respawn
     163        ModifyConsoleCommand(__CC_fire_name).keybindMode(KeybindMode::OnPress);
     164    }
     165
     166    /**
     167        @brief Changes the keybind mode of the fire command back to OnHold.
     168    */
     169    void Spectator::stopLocalHumanControl()
     170    {
     171        ControllableEntity::stopLocalHumanControl();
     172
     173        // change fire command to a helper function and change keybind mode to OnPress
     174        // 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
     175        ModifyConsoleCommand(__CC_fire_name).pushFunction(&Spectator::resetFireCommand).keybindMode(KeybindMode::OnPress);
     176    }
     177
     178    /**
     179        @brief Helper function which changes the fire command back to the original function and keybind mode to OnHold.
     180    */
     181    void Spectator::resetFireCommand(unsigned int firemode)
     182    {
     183        ModifyConsoleCommand(__CC_fire_name).popFunction().keybindMode(KeybindMode::OnHold); // pop this helper function and change keybind mode
     184
     185        CommandExecutor::execute(__CC_fire_name + " " + multi_cast<std::string>(firemode)); // call the fire command again, this time with the real function
    153186    }
    154187
  • code/trunk/src/orxonox/worldentities/pawns/Spectator.h

    r7857 r7862  
    6161            virtual void setPlayer(PlayerInfo* player);
    6262            virtual void startLocalHumanControl();
     63            virtual void stopLocalHumanControl();
    6364
    6465        private:
     
    6667            void changedGreeting();
    6768            void changedFlareVisibility();
     69
     70            static void resetFireCommand(unsigned int firemode);
    6871
    6972            BillboardSet* greetingFlare_;
Note: See TracChangeset for help on using the changeset viewer.