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
FlyByWire Class Reference

#include <flybywire.h>

Inheritance diagram for FlyByWire:
Orders::MatchVelocity Orders::MatchAngularVelocity Order AImissionScript EvadeLeftRightC FlyByKeyboard AIFlyToJumppoint AIFlyToWaypoint AIFlyToWaypointDefend AIOrderList AIPatrol AIPatrolDefend AISuperiority FlyByJoystick

Public Member Functions

 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...
 
void Execute ()
 The function that gets called and executes all queued suborders. 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...
 
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...
 
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 ()
 

Protected Attributes

Vector DesiredShiftVelocity
 
Vector DirectThrust
 
bool sheltonslide
 If shelton slide, do not have the computer match linear. More...
 
bool controltype
 
bool inertial_flight_model
 
bool inertial_flight_enable
 
bool stolen_setspeed
 
float stolen_setspeed_value
 
- Protected Attributes inherited from Orders::MatchVelocity
Vector desired_velocity
 werld space... generally r*speed or local space More...
 
bool LocalVelocity
 Is the above in world space? More...
 
bool afterburn
 
- Protected Attributes inherited from Orders::MatchAngularVelocity
Vector desired_ang_velocity
 werld space or local space (pitch = 1 on the x axis) More...
 
bool LocalAng
 specified in Local or World coordinates More...
 
bool willfinish
 Whether this script should terminate upon reaching desired angular velocity. More...
 
- Protected Attributes inherited from Order
Unitparent
 The unit this order is attached to. More...
 
unsigned int type
 The bit code (from ORDERTYPES) that this order is (for parallel execution) More...
 
unsigned int subtype
 
bool done
 Whether or not this order is done. More...
 
UnitContainer group
 If this order applies to a group of units (as in form up with this group) More...
 
QVector targetlocation
 If this order applies to a physical location in world space. More...
 
std::vector< Order * > suborders
 The queue of suborders that will be executed in parallel according to bit code. More...
 
std::list< class
CommunicationMessage * > 
messagequeue
 a bunch of communications that have not been answered CommunicationMessages are actually containing reference to a nice Finite State Machine that can allow a player to have a reasonable conversation with an AI More...
 
std::string actionstring
 

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 }
 
- Protected Member Functions inherited from Order
virtual ~Order ()
 
virtual void Destructor ()
 changes the local relation of this unit to another...may inform superiors about "good" or bad! behavior depending on the AI More...
 

Detailed Description

This class uses a parent's computer struct to set the appropriate desired linear and angular velocity based on what the user input may be

Definition at line 152 of file flybywire.h.

Constructor & Destructor Documentation

FlyByWire::FlyByWire ( )

Definition at line 155 of file flybywire.cpp.

References DesiredShiftVelocity, DirectThrust, VegaConfig::getVariable(), inertial_flight_enable, inertial_flight_model, XMLSupport::parse_bool(), stolen_setspeed, stolen_setspeed_value, Vector, and vs_config.

155  : MatchVelocity( Vector( 0, 0, 0 ), Vector( 0, 0, 0 ), true, false, false )
156  , sheltonslide( false )
158 {
159  DesiredShiftVelocity = Vector( 0, 0, 0 );
160  DirectThrust = Vector( 0, 0, 0 );
161  stolen_setspeed = false;
163 
164  static bool static_inertial_flight_model =
165  XMLSupport::parse_bool( vs_config->getVariable( "flight", "inertial::initial", "false" ) );
166  static bool static_inertial_flight_enable =
167  XMLSupport::parse_bool( vs_config->getVariable( "flight", "inertial::enable", "true" ) );
168  inertial_flight_model = static_inertial_flight_model;
169  inertial_flight_enable = static_inertial_flight_enable;
170 }
FlyByWire::~FlyByWire ( )

Definition at line 354 of file flybywire.cpp.

References VSFileSystem::vs_fprintf().

355 {
356 #ifdef ORDERDEBUG
357  VSFileSystem::vs_fprintf( stderr, "fbw%x", this );
358  fflush( stderr );
359 #endif
360 }

Member Function Documentation

void FlyByWire::Accel ( float  percentage)

negative is decel... 0 = nothing

Definition at line 245 of file flybywire.cpp.

References Orders::MatchVelocity::afterburn, Orders::MatchVelocity::desired_velocity, Unit::GetComputerData(), VegaConfig::getVariable(), Unit::Computer::max_speed(), Order::parent, XMLSupport::parse_float(), Unit::Computer::set_speed, SIMULATION_ATOM, Vector, and vs_config.

Referenced by FlyByKeyboard::Execute().

246 {
248 
249  cpu->set_speed += per*cpu->max_speed()*SIMULATION_ATOM;
250  if ( cpu->set_speed > cpu->max_speed() )
251  cpu->set_speed = cpu->max_speed();
252  static float reverse_speed_limit = XMLSupport::parse_float( vs_config->getVariable( "physics", "reverse_speed_limit", "1.0" ) );
253  if (cpu->set_speed < -cpu->max_speed()*reverse_speed_limit)
254  cpu->set_speed = -cpu->max_speed()*reverse_speed_limit;
255  afterburn = false;
256 
257  desired_velocity = Vector( 0, 0, cpu->set_speed );
258 }
void FlyByWire::Afterburn ( float  percentage)

Specifies match speed to use afterbuner and gives in higher velocity.

Definition at line 215 of file flybywire.cpp.

References _Universe, Universe::AccessCockpit(), Orders::MatchVelocity::afterburn, Unit::Limits::afterburn, Orders::MatchVelocity::desired_velocity, DirectThrust, Unit::GetComputerData(), Cockpit::GetParent(), inertial_flight_model, Unit::Limits(), Unit::Computer::max_ab_speed(), Order::parent, Unit::Computer::set_speed, sheltonslide, and Vector.

Referenced by BarrelRoll(), EvadeWavy(), and FlyByKeyboard::Execute().

216 {
218 
219  afterburn = (per > .1);
221  desired_velocity = Vector( 0, 0, cpu->set_speed+per*(cpu->max_ab_speed()-cpu->set_speed) );
222  else if (inertial_flight_model)
223  DirectThrust += Vector( 0, 0, parent->Limits().afterburn*per );
224  if ( parent == _Universe->AccessCockpit()->GetParent() ) {
225  //printf("afterburn is %d\n",afterburn); // DELETEME WTF all this force feedback code and its unused.
226  //COMMENTED BECAUSE OF SERVER -- NEED TO REINTEGRATE IT IN ANOTHER WAY
227  //forcefeedback->playAfterburner(afterburn);
228  }
229 }
void FlyByWire::DirectThrustFront ( float  percent)

Definition at line 287 of file flybywire.cpp.

References DirectThrust, Unit::Limits::forward, Unit::Limits(), Order::parent, and Unit::Limits::retro.

Referenced by FlyByJoystick::Execute(), and FlyByKeyboard::Execute().

288 {
289  if (percent > 0)
290  DirectThrust.k = parent->Limits().forward*percent;
291  else
292  DirectThrust.k = parent->Limits().retro*percent;
293 }
void FlyByWire::DirectThrustRight ( float  percent)

Definition at line 277 of file flybywire.cpp.

References DirectThrust, Unit::Limits::lateral, Unit::Limits(), and Order::parent.

Referenced by FlyByJoystick::Execute(), and FlyByKeyboard::Execute().

278 {
279  DirectThrust.i = parent->Limits().lateral*percent;
280 }
void FlyByWire::DirectThrustUp ( float  percent)

Definition at line 282 of file flybywire.cpp.

References DirectThrust, Unit::Limits(), Order::parent, and Unit::Limits::vertical.

Referenced by FlyByJoystick::Execute(), and FlyByKeyboard::Execute().

283 {
284  DirectThrust.j = parent->Limits().vertical*percent;
285 }
void FlyByWire::Execute ( )
virtual

The function that gets called and executes all queued suborders.

Reimplemented from Orders::MatchVelocity.

Reimplemented in EvadeLeftRightC, FlyByKeyboard, AImissionScript, and FlyByJoystick.

Definition at line 295 of file flybywire.cpp.

References _Universe, Orders::MatchVelocity::afterburn, controltype, Orders::MatchVelocity::desired_velocity, DesiredShiftVelocity, DirectThrust, Unit::Limits::forward, Unit::GetComputerData(), getNewTime(), VegaConfig::getVariable(), inertial_flight_model, Universe::isPlayerStarship(), Unit::Limits::lateral, Unit::Limits(), Unit::Computer::max_speed(), Network, Order::parent, XMLSupport::parse_float(), Unit::Limits::retro, Unit::Computer::set_speed, sheltonslide, stolen_setspeed, stolen_setspeed_value, Unit::Thrust(), Vector, Unit::Limits::vertical, and vs_config.

Referenced by AImissionScript::Execute(), FlyByKeyboard::Execute(), and EvadeLeftRightC::Execute().

296 {
297  bool desireThrust = false;
298  Vector des_vel_bak( desired_velocity );
299  if (!inertial_flight_model) {
300  //Must translate the thrust values to velocities, which is somewhat cumbersome.
301  Vector Limit(
303  ( (DirectThrust.k > 0) ? parent->Limits().forward : parent->Limits().retro )
304  );
305  if (Limit.i <= 1) Limit.i = 1;
306  if (Limit.j <= 1) Limit.j = 1;
307  if (Limit.k <= 1) Limit.k = 1;
308  Vector DesiredDrift(
309  DirectThrust.i/Limit.i,
310  DirectThrust.j/Limit.j,
311  DirectThrust.k/Limit.k
312  );
313  //Now, scale so that maximum shift velocity is max_speed
314  DesiredDrift *= parent->GetComputerData().max_speed();
315  //And apply
316  DesiredShiftVelocity += DesiredDrift;
317  }
319  if (!stolen_setspeed) {
320  stolen_setspeed = true;
322  }
325 
326  desireThrust = true;
327  if (!controltype) {
328  if (desired_velocity.k < 0) {
329  desired_velocity.k = 0;
331  }
332  }
333  } else if (stolen_setspeed) {
335  stolen_setspeed = false;
336  }
337  static double collidepanic = XMLSupport::parse_float( vs_config->getVariable( "physics", "collision_inertial_time", "1.25" ) );
340  || !controltype)
341  && (!desireThrust) )
342  || ( tempcp && Network == NULL && ( (getNewTime()-tempcp->TimeOfLastCollision) < collidepanic ) ) ) {
343  MatchAngularVelocity::Execute(); //only match turning
346  } else {
347  MatchVelocity::Execute();
348  }
349  DesiredShiftVelocity.Set( 0, 0, 0 );
350  DirectThrust.Set( 0, 0, 0 );
351  desired_velocity = des_vel_bak;
352 }
virtual std::string FlyByWire::getOrderDescription ( )
inlinevirtual

Reimplemented from Orders::MatchVelocity.

Reimplemented in AImissionScript.

Definition at line 195 of file flybywire.h.

196  {
197  return "wire";
198  }
void FlyByWire::InertialFlight ( bool  onoff)

Definition at line 362 of file flybywire.cpp.

References inertial_flight_model, Unit::inertialmode, and Order::parent.

363 {
364  inertial_flight_model = onoff;
365  parent->inertialmode = onoff;
366 }
bool FlyByWire::InertialFlight ( ) const

Definition at line 368 of file flybywire.cpp.

References inertial_flight_model.

Referenced by FlyByKeyboard::Execute().

369 {
370  return inertial_flight_model;
371 }
bool FlyByWire::InertialFlightEnable ( ) const

Definition at line 373 of file flybywire.cpp.

References inertial_flight_enable.

374 {
375  return inertial_flight_enable;
376 }
void FlyByWire::MatchSpeed ( const Vector velocity)

matches set_speed to this velocity's magnitude

Definition at line 236 of file flybywire.cpp.

References Unit::GetComputerData(), Magnitude(), Unit::Computer::max_speed(), Order::parent, and Unit::Computer::set_speed.

Referenced by BarrelRoll(), EvadeWavy(), and FlyByKeyboard::Execute().

237 {
239 
240  cpu->set_speed = (vec).Magnitude();
241  if ( cpu->set_speed > cpu->max_speed() )
242  cpu->set_speed = cpu->max_speed();
243 }
void FlyByWire::Right ( float  percentage)

pass in the percentage of the turn they were turnin right. -age indicates left

Definition at line 179 of file flybywire.cpp.

References Orders::MatchAngularVelocity::desired_ang_velocity, Unit::GetComputerData(), getTimeCompression(), Unit::Computer::max_yaw_left, Unit::Computer::max_yaw_right, Order::parent, and Vector.

Referenced by BarrelRoll(), FlyByJoystick::Execute(), and FlyByKeyboard::KeyboardRight().

180 {
182  ( -per
183  *(per
186  0,
187  1,
188  0 );
189 }
void FlyByWire::SheltonSlide ( bool  onoff)

Definition at line 231 of file flybywire.cpp.

References sheltonslide.

Referenced by FlyByKeyboard::Execute().

232 {
233  sheltonslide = onoff;
234 }
void FlyByWire::Stop ( float  percentage)

Stops... sets desired velocity to 0.

Definition at line 172 of file flybywire.cpp.

References Unit::GetComputerData(), Unit::Computer::max_speed(), Order::parent, Unit::Computer::set_speed, Orders::MatchVelocity::SetDesiredVelocity(), and Vector.

Referenced by FlyByKeyboard::Execute().

173 {
174  SetDesiredVelocity( Vector( 0, 0, per*parent->GetComputerData().max_speed() ), true );
175 
177 }
void FlyByWire::SwitchFlightMode ( )
inline

Definition at line 166 of file flybywire.h.

References controltype.

Referenced by FlyByKeyboard::Execute().

167  {
169  }
void FlyByWire::ThrustFront ( float  percent)
void FlyByWire::ThrustRight ( float  percent)

Turns on or off velocity resolution.

Definition at line 262 of file flybywire.cpp.

References DesiredShiftVelocity, Unit::GetComputerData(), Unit::Computer::max_speed(), and Order::parent.

263 {
265 }
void FlyByWire::ThrustUp ( float  percent)
void FlyByWire::Up ( float  percentage)

pass in the percentage of the turn they were turning up

Definition at line 191 of file flybywire.cpp.

References Orders::MatchAngularVelocity::desired_ang_velocity, Unit::GetComputerData(), getTimeCompression(), Unit::Computer::max_pitch_down, Unit::Computer::max_pitch_up, Order::parent, and Vector.

Referenced by BarrelRoll(), FlyByJoystick::Execute(), and FlyByKeyboard::KeyboardUp().

192 {
194  ( -per
195  *(per
198  1,
199  0,
200  0 );
201 }

Member Data Documentation

bool FlyByWire::controltype
protected

Definition at line 159 of file flybywire.h.

Referenced by Execute(), and SwitchFlightMode().

Vector FlyByWire::DesiredShiftVelocity
protected

Definition at line 155 of file flybywire.h.

Referenced by Execute(), FlyByWire(), ThrustFront(), ThrustRight(), and ThrustUp().

Vector FlyByWire::DirectThrust
protected
bool FlyByWire::inertial_flight_enable
protected

Definition at line 161 of file flybywire.h.

Referenced by FlyByWire(), and InertialFlightEnable().

bool FlyByWire::inertial_flight_model
protected

Definition at line 160 of file flybywire.h.

Referenced by Afterburn(), Execute(), FlyByWire(), and InertialFlight().

bool FlyByWire::sheltonslide
protected

If shelton slide, do not have the computer match linear.

Definition at line 158 of file flybywire.h.

Referenced by Afterburn(), Execute(), and SheltonSlide().

bool FlyByWire::stolen_setspeed
protected

Definition at line 162 of file flybywire.h.

Referenced by Execute(), and FlyByWire().

float FlyByWire::stolen_setspeed_value
protected

Definition at line 163 of file flybywire.h.

Referenced by Execute(), and FlyByWire().


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