Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.