Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FlyByJoystick Class Reference

#include <flyjoystick.h>

Inheritance diagram for FlyByJoystick:
FlyByKeyboard FlyByWire Orders::MatchVelocity Orders::MatchAngularVelocity Order

Public Member Functions

 FlyByJoystick (unsigned int whichplayer)
 
void Execute ()
 The function that gets called and executes all queued suborders. More...
 
virtual ~FlyByJoystick ()
 
- Public Member Functions inherited from FlyByKeyboard
 FlyByKeyboard (unsigned int whichplayer)
 
virtual void Destroy ()
 The virutal function that unrefs all memory then calls Destruct () which takes care of unreffing this or calling delete on this. More...
 
virtual ~FlyByKeyboard ()
 
void Execute (bool)
 
void Execute ()
 The function that gets called and executes all queued suborders. More...
 
- Public Member Functions inherited from FlyByWire
 FlyByWire ()
 
 ~FlyByWire ()
 
void SwitchFlightMode ()
 
void ThrustRight (float percent)
 Turns on or off velocity resolution. More...
 
void ThrustUp (float percent)
 
void ThrustFront (float percent)
 
void DirectThrustRight (float percent)
 
void DirectThrustUp (float percent)
 
void DirectThrustFront (float percent)
 
void SheltonSlide (bool onoff)
 
void InertialFlight (bool onoff)
 
bool InertialFlight () const
 
bool InertialFlightEnable () const
 
void Stop (float percentage)
 Stops... sets desired velocity to 0. More...
 
void Right (float percentage)
 pass in the percentage of the turn they were turnin right. -age indicates left More...
 
void Up (float percentage)
 pass in the percentage of the turn they were turning up More...
 
void RollRight (float percentage)
 
void Afterburn (float percentage)
 Specifies match speed to use afterbuner and gives in higher velocity. More...
 
void MatchSpeed (const Vector &velocity)
 matches set_speed to this velocity's magnitude More...
 
void Accel (float percentage)
 negative is decel... 0 = nothing More...
 
virtual std::string getOrderDescription ()
 
- Public Member Functions inherited from Orders::MatchVelocity
 MatchVelocity (const Vector &desired, const Vector &desired_ang, const bool Local, const bool afterburner, const bool fini=true)
 
void SetDesiredVelocity (const Vector &desired, const bool Local)
 
void SetAfterburn (bool use_afterburn)
 
virtual ~MatchVelocity ()
 
- Public Member Functions inherited from Orders::MatchAngularVelocity
 MatchAngularVelocity (const Vector &desired, bool Local, bool fini=true)
 
void SetDesiredAngularVelocity (const Vector &desired, bool Local)
 
virtual ~MatchAngularVelocity ()
 
- Public Member Functions inherited from Order
virtual void ChooseTarget ()
 this function calls the destructor (needs to be overridden for python; More...
 
virtual bool PursueTarget (Unit *, bool isleader)
 
void ClearMessages ()
 clears the messasges of this order More...
 
 Order ()
 The default constructor setting everything to NULL and no dependency on order. More...
 
 Order (int type, int subtype)
 The constructor that specifies what order dependencies this order has. More...
 
OrderqueryType (unsigned int type)
 returns a pointer to the first order that may be bitwised ored with that type More...
 
OrderqueryAny (unsigned int type)
 returns a pointer to the first order that may be bitwise ored with any type More...
 
void eraseType (unsigned int type)
 Erases all orders that bitwise OR with that type. More...
 
bool AttachOrder (Unit *targets)
 Attaches a group of targets to this order (used for strategery-type games) More...
 
bool AttachOrder (QVector target)
 Attaches a navigation point to this order. More...
 
bool AttachSelfOrder (Unit *targets)
 Attaches a group (form up) to this order. More...
 
OrderEnqueueOrder (Order *ord)
 Enqueues another order that will be executed (in parallel perhaps) when next void Execute() is called. More...
 
OrderReplaceOrder (Order *ord)
 Replaces the first order of that type in the order queue. More...
 
bool Done ()
 
int getType ()
 
int getSubType ()
 
virtual void SetParent (Unit *parent1)
 Sets the parent of this Unit. Any virtual functions must call this one. More...
 
UnitGetParent () const
 
virtual void Communicate (const class CommunicationMessage &c)
 Sends a communication message from the Unit (encapulated in c) to this unit. More...
 
virtual void ProcessCommMessage (class CommunicationMessage &c)
 processes a single message...generally called by the Messages() func More...
 
virtual void ProcessCommunicationMessages (float CommRepsonseTime, bool RemoveMessageProcessed)
 responds (or does not) to certain messages in the message queue More...
 
OrderfindOrder (Order *ord)
 return pointer to order or NULL if not found More...
 
void eraseOrder (Order *ord)
 erase that order from the list More...
 
OrderEnqueueOrderFirst (Order *ord)
 enqueue order as first order More...
 
virtual olist_tgetOrderList ()
 returns the orderlist (NULL for orders that haven't got any) More...
 
virtual void AdjustRelationTo (Unit *un, float factor)
 
OrderfindOrderList ()
 searches the suborders recursively for the first order that has an orderlist More...
 
std::string createFullOrderDescription (int level=0)
 
void setActionString (std::string astring)
 
std::string getActionString ()
 
virtual float getMood ()
 

Static Public Member Functions

static void JAccelKey (KBSTATE, float, float, int)
 
static void JDecelKey (KBSTATE, float, float, int)
 
static void JShelt (KBSTATE, float, float, int)
 
static void JAB (KBSTATE, float, float, int)
 
- Static Public Member Functions inherited from FlyByKeyboard
static void SwitchWebcam (const KBData &, KBSTATE)
 
static void SwitchSecured (const KBData &, KBSTATE)
 
static void ChangeCommStatus (const KBData &, KBSTATE)
 
static void DownFreq (const KBData &, KBSTATE)
 
static void UpFreq (const KBData &, KBSTATE)
 
static void KSwitchFlightMode (const KBData &, KBSTATE)
 
static void KThrustRight (const KBData &, KBSTATE)
 
static void KThrustLeft (const KBData &, KBSTATE)
 
static void KThrustUp (const KBData &, KBSTATE)
 
static void KThrustDown (const KBData &, KBSTATE)
 
static void KThrustFront (const KBData &, KBSTATE)
 
static void KThrustBack (const KBData &, KBSTATE)
 
static void SheltonKey (const KBData &, KBSTATE)
 
static void InertialToggleKey (const KBData &, KBSTATE)
 
static void InertialPulsorKey (const KBData &, KBSTATE)
 
static void JoyInertialXYPulsorKey (const KBData &, KBSTATE)
 
static void JoyInertialXZPulsorKey (const KBData &, KBSTATE)
 
static void JoyInertialXYToggleKey (const KBData &, KBSTATE)
 
static void JoyInertialXZToggleKey (const KBData &, KBSTATE)
 
static void JoyRollPulsorKey (const KBData &, KBSTATE)
 
static void JoyRollToggleKey (const KBData &, KBSTATE)
 
static void JoyBankPulsorKey (const KBData &, KBSTATE)
 
static void JoyBankToggleKey (const KBData &, KBSTATE)
 
static void StartKey (const KBData &, KBSTATE)
 
static void StopKey (const KBData &, KBSTATE)
 
static void UpKey (const KBData &, KBSTATE)
 
static void DownKey (const KBData &, KBSTATE)
 
static void LeftKey (const KBData &, KBSTATE)
 
static void RightKey (const KBData &, KBSTATE)
 
static void ABKey (const KBData &, KBSTATE)
 
static void AccelKey (const KBData &, KBSTATE)
 
static void DecelKey (const KBData &, KBSTATE)
 
static void RollLeftKey (const KBData &, KBSTATE)
 
static void RollRightKey (const KBData &, KBSTATE)
 
static void MatchSpeedKey (const KBData &, KBSTATE)
 
static void JumpKey (const KBData &, KBSTATE)
 
static void AutoKey (const KBData &, KBSTATE)
 
static void SwitchCombatModeKey (const KBData &, KBSTATE)
 
static void EngageSpecAuto (const KBData &, KBSTATE)
 
static void StopAutoKey (const KBData &, KBSTATE)
 
static void SetVelocityRefKey (const KBData &, KBSTATE)
 
static void SetNullVelocityRefKey (const KBData &, KBSTATE)
 

Additional Inherited Members

- Public Types inherited from Order
enum  ORDERTYPES {
  MOVEMENT =1, FACING =2, WEAPON =4, CLOAKING =8,
  ALLTYPES =(1|2|4|8)
}
 The varieties of order types MOVEMENT,FACING, and WEAPON orders may not be mutually executed (lest one engine goes left, the other right) More...
 
enum  SUBORDERTYPES { SLOCATION =1, STARGET =2, SSELF =4 }
 
- Public Attributes inherited from FlyByKeyboard
int whichplayer
 
bool inauto
 
- Protected Types inherited from FlyByKeyboard
enum  joy_mode_enum {
  joyModeNormal =0, joyModeInertialXY =1, joyModeInertialXZ =2, joyModeRoll =4,
  joyModeBank =8
}
 
- Protected Member Functions inherited from FlyByKeyboard
void KeyboardUp (float val)
 
void KeyboardRight (float val)
 
void KeyboardRollRight (float val)
 
float clamp_axis (float v)
 
float reduce_axis (float v)
 
- Protected Attributes inherited from FlyByKeyboard
char joy_mode
 

Detailed Description

Definition at line 3 of file flyjoystick.h.

Constructor & Destructor Documentation

FlyByJoystick::FlyByJoystick ( unsigned int  whichplayer)

Definition at line 10 of file flyjoystick.cpp.

References FireKeyboard::FireKey(), i, joystick, MAX_JOYSTICKS, and FireKeyboard::MissileKey().

10  : FlyByKeyboard( configfile )
11 {
12  for (int i = 0; i < MAX_JOYSTICKS; i++)
13  if ( (unsigned int) joystick[i]->player == configfile )
14  whichjoystick.push_back( i );
15  //remember keybindings from config file?
16 
17  //this below is outdated
18 #if 0
19  //why does the compiler not allow this?//check out my queued events section in firekeyboard.cpp
20  BindButton( 0, FireKeyboard::FireKey );
21  BindButton( 1, FireKeyboard::MissileKey );
22 #endif
23 }
FlyByJoystick::~FlyByJoystick ( )
virtual

Definition at line 194 of file flyjoystick.cpp.

194 {}

Member Function Documentation

void FlyByJoystick::Execute ( )
virtual

The function that gets called and executes all queued suborders.

Reimplemented from FlyByWire.

Definition at line 56 of file flyjoystick.cpp.

References JoyStick::axis_axis, JoyStick::axis_inverse, VegaConfig::axis_joy, AXIS_THROTTLE, AXIS_X, AXIS_Y, AXIS_Z, Unit::Computer::combat_mode, Orders::MatchAngularVelocity::desired_ang_velocity, Orders::MatchVelocity::desired_velocity, FlyByWire::DirectThrustFront(), FlyByWire::DirectThrustRight(), FlyByWire::DirectThrustUp(), FlyByKeyboard::Execute(), UniverseUtil::exp(), float, Unit::GetComputerData(), VegaConfig::getVariable(), i, JoyStick::joy_axis, FlyByKeyboard::joy_mode, FlyByKeyboard::joyModeBank, FlyByKeyboard::joyModeInertialXY, FlyByKeyboard::joyModeInertialXZ, FlyByKeyboard::joyModeNormal, FlyByKeyboard::joyModeRoll, joystick, MAX_JOYSTICKS, Unit::Computer::max_speed(), Order::parent, XMLSupport::parse_bool(), XMLSupport::parse_float(), FlyByWire::Right(), FlyByWire::RollRight(), Unit::Computer::set_speed, FlyByWire::Up(), Vector, and vs_config.

57 {
58  static bool clamp_joystick_axes = XMLSupport::parse_bool( vs_config->getVariable( "joystick", "clamp_axes", "true" ) );
59  static bool nonlinear_throttle_nav =
60  XMLSupport::parse_bool( vs_config->getVariable( "joystick", "nonlinear_throttle_nav", "true" ) );
61  static bool nonlinear_throttle_combat =
62  XMLSupport::parse_bool( vs_config->getVariable( "joystick", "nonlinear_throttle_combat", "false" ) );
63  static float expfactorn = XMLSupport::parse_float( vs_config->getVariable( "joystick", "nonlinear_expfactor_nav", "6.0" ) );
64  static float pfactorn = XMLSupport::parse_float( vs_config->getVariable( "joystick", "nonlinear_pfactor_nav", "2.0" ) );
65  static float expamountn = XMLSupport::parse_float( vs_config->getVariable( "joystick", "nonlinear_expamount_nav", "1.0" ) );
66  static float pamountn = XMLSupport::parse_float( vs_config->getVariable( "joystick", "nonlinear_pamount_nav", "0.0" ) );
67  static float expfactorc = XMLSupport::parse_float( vs_config->getVariable( "joystick", "nonlinear_expfactor_combat", "6.0" ) );
68  static float pfactorc = XMLSupport::parse_float( vs_config->getVariable( "joystick", "nonlinear_pfactor_combat", "2.0" ) );
69  static float expamountc = XMLSupport::parse_float( vs_config->getVariable( "joystick", "nonlinear_expamount_combat", "1.0" ) );
70  static float pamountc = XMLSupport::parse_float( vs_config->getVariable( "joystick", "nonlinear_pamount_combat", "0.0" ) );
71  desired_ang_velocity = Vector( 0, 0, 0 );
72  for (unsigned int i = 0; i < this->whichjoystick.size(); i++) {
73  int which_joystick = this->whichjoystick[i];
74  if (which_joystick < MAX_JOYSTICKS) {
75  int joy_nr;
76 
77  joy_nr = vs_config->axis_joy[AXIS_Y];
78  if (joy_nr != -1)
79  joy_nr = which_joystick;
80  if ( joy_nr != -1 && joystick[joy_nr]->isAvailable() ) {
81  int config_axis = joystick[joy_nr]->axis_axis[AXIS_Y];
82  if (config_axis != -1) {
83  bool inverse = joystick[joy_nr]->axis_inverse[AXIS_Y];
84  float axis_value = -joystick[joy_nr]->joy_axis[config_axis];
85  if (inverse) axis_value = -axis_value;
86  if (clamp_joystick_axes) {
87  if (axis_value < -1)
88  axis_value = -1;
89  if (axis_value > 1)
90  axis_value = 1;
91  }
93  Up( axis_value );
94 
95  else if (joy_mode&joyModeInertialXY)
96  DirectThrustUp( axis_value );
97 
98  else if (joy_mode&joyModeInertialXZ)
99  DirectThrustFront( -axis_value );
100  }
101  }
102  joy_nr = vs_config->axis_joy[AXIS_X];
103  if (joy_nr != -1)
104  joy_nr = which_joystick;
105  if ( joy_nr != -1 && joystick[joy_nr]->isAvailable() ) {
106  int config_axis = joystick[joy_nr]->axis_axis[AXIS_X];
107  if (config_axis != -1) {
108  bool inverse = joystick[joy_nr]->axis_inverse[AXIS_X];
109  float axis_value = -joystick[joy_nr]->joy_axis[config_axis];
110  if (inverse) axis_value = -axis_value;
111  if (clamp_joystick_axes) {
112  if (axis_value < -1)
113  axis_value = -1;
114  if (axis_value > 1)
115  axis_value = 1;
116  }
117  if (joy_mode == joyModeNormal)
118  Right( axis_value );
119 
120  else if (joy_mode&joyModeRoll)
121  RollRight( -axis_value );
122 
124  DirectThrustRight( axis_value );
125 
126  else if (joy_mode&joyModeBank)
127  Right( axis_value ), RollRight( -axis_value );
128  }
129  }
130  joy_nr = vs_config->axis_joy[AXIS_Z];
131  if (joy_nr != -1)
132  joy_nr = which_joystick;
133  if ( joy_nr != -1 && joystick[joy_nr]->isAvailable() ) {
134  int config_axis = joystick[joy_nr]->axis_axis[AXIS_Z];
135  if (config_axis != -1) {
136  bool inverse = joystick[joy_nr]->axis_inverse[AXIS_Z];
137  float axis_value = -joystick[joy_nr]->joy_axis[config_axis];
138  if (inverse) axis_value = -axis_value;
139  if (clamp_joystick_axes) {
140  if (axis_value < -1)
141  axis_value = -1;
142  if (axis_value > 1)
143  axis_value = 1;
144  }
145  if ( (joy_mode == joyModeNormal) || (joy_mode&joyModeBank) )
146  RollRight( axis_value );
147 
148  else if (joy_mode&joyModeRoll)
149  Right( axis_value );
150 
151  else if (joy_mode&joyModeInertialXY)
152  DirectThrustFront( axis_value );
153 
154  else if (joy_mode&joyModeInertialXZ)
155  DirectThrustUp( axis_value );
156  }
157  }
158  joy_nr = vs_config->axis_joy[AXIS_THROTTLE];
159  if (joy_nr != -1)
160  joy_nr = which_joystick;
161  if ( joy_nr != -1 && joystick[joy_nr]->isAvailable() ) {
162  int config_axis = joystick[joy_nr]->axis_axis[AXIS_THROTTLE];
163  if (config_axis != -1) {
164  bool inverse = joystick[joy_nr]->axis_inverse[AXIS_THROTTLE];
165  float axis_value = -joystick[joy_nr]->joy_axis[config_axis];
166  if (inverse) axis_value = -axis_value;
168  if (axis_value > 1)
169  axis_value = 1;
170  if (axis_value < -1)
171  axis_value = -1; //this code due to paolodinca
172 
173  //put axis from 0 to 2
174  axis_value++;
175  //put axis from 0 to 1
176  axis_value = axis_value/2; //thanks!
177  if (nonlinear_throttle_nav && !cpu->combat_mode) {
178  static float norm = float(exp( expfactorn )-1);
179  axis_value =
180  float( expamountn*(exp( expfactorn*axis_value )-1)/norm+pamountn*pow( axis_value, pfactorn ) );
181  } else if (nonlinear_throttle_combat && cpu->combat_mode) {
182  static float norm = float(exp( expfactorc )-1);
183  axis_value =
184  float( expamountc*(exp( expfactorc*axis_value )-1)/norm+pamountc*pow( axis_value, pfactorc ) );
185  }
186  cpu->set_speed = axis_value*cpu->max_speed();
187  desired_velocity = Vector( 0, 0, cpu->set_speed );
188  }
189  }
190  }
191  }
192  FlyByKeyboard::Execute( false );
193 }
static void FlyByJoystick::JAB ( KBSTATE  ,
float  ,
float  ,
int   
)
static
static void FlyByJoystick::JAccelKey ( KBSTATE  ,
float  ,
float  ,
int   
)
static
static void FlyByJoystick::JDecelKey ( KBSTATE  ,
float  ,
float  ,
int   
)
static
static void FlyByJoystick::JShelt ( KBSTATE  ,
float  ,
float  ,
int   
)
static

The documentation for this class was generated from the following files: