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
Orders::ChangeHeading Class Reference

#include <navigation.h>

Inheritance diagram for Orders::ChangeHeading:
Order Orders::AutoLongHaul Orders::FaceDirection Orders::FaceTarget Orders::FaceTargetITTS Orders::FacePerpendicular Orders::LoopAround Orders::LoopAroundAgro Orders::TurretAI

Public Member Functions

 ChangeHeading (const QVector &final_heading, int switchback, float turning_speed=1, bool term=false)
 takes in the destination target, and the ammount of accuracy (how many times it should miss destination and come back) should be used More...
 
void SetDest (const QVector &)
 
virtual void Execute ()
 The function that gets called and executes all queued suborders. More...
 
virtual string getOrderDescription ()
 
virtual ~ChangeHeading ()
 
- 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 Member Functions

void ResetDone ()
 
- 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...
 

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 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
 

Detailed Description

This AI script attempts to change headings to face a given direction again it is inaccurate to within 1 physics frame, though calculating thrust at 1/3 the way through a physics frame has made this effect of wobbling all but subside! switchbacks keep track of how many times it has almost but passed over target destination

Definition at line 80 of file navigation.h.

Constructor & Destructor Documentation

Orders::ChangeHeading::ChangeHeading ( const QVector final_heading,
int  switchback,
float  turning_speed = 1,
bool  term = false 
)
inline

takes in the destination target, and the ammount of accuracy (how many times it should miss destination and come back) should be used

Definition at line 101 of file navigation.h.

101  : Order( FACING,
102  SLOCATION )
103  , turningspeed( turning_speed )
104  , switchbacks( switchback )
105  , terminatingX( 0 )
106  , terminatingY( 0 )
107  , last_velocity( 0, 0, 0 )
108  , final_heading( final_heading )
109  , terminating( term ) {}
ChangeHeading::~ChangeHeading ( )
virtual

Definition at line 363 of file navigation.cpp.

References VSFileSystem::vs_fprintf().

364 {
365 #ifdef ORDERDEBUG
366  VSFileSystem::vs_fprintf( stderr, "ch%x", this );
367  fflush( stderr );
368 #endif
369 }

Member Function Documentation

void ChangeHeading::Execute ( )
virtual

The function that gets called and executes all queued suborders.

Reimplemented from Order.

Reimplemented in Orders::FacePerpendicular, Orders::LoopAroundAgro, Orders::LoopAround, Orders::FaceDirection, Orders::FaceTargetITTS, Orders::AutoLongHaul, Orders::FaceTarget, and Orders::TurretAI.

Definition at line 281 of file navigation.cpp.

References Unit::ApplyLocalTorque(), Order::done, Order::Done(), Order::Execute(), Unit::GetAngularVelocity(), Unit::GetComputerData(), Unit::GetMass(), Unit::GetMoment(), Unit::GetOrientation(), VegaConfig::getVariable(), Unit::isSubUnit(), Unit::Limits(), Unit::Computer::max_pitch_down, Unit::Computer::max_pitch_up, Unit::Computer::max_yaw_left, Unit::Computer::max_yaw_right, XMLSupport::parse_bool(), XMLSupport::parse_float(), PI, Unit::Limits::pitch, Unit::Position(), R, Unit::SetAngularVelocity(), Unit::SetOrientation(), SIMULATION_ATOM, Unit::ToLocalCoordinates(), Unit::UpCoordinateLevel(), Vector, vs_config, and Unit::Limits::yaw.

Referenced by Orders::FaceTarget::Execute(), Orders::AutoLongHaul::Execute(), Orders::FaceTargetITTS::Execute(), Orders::FaceDirection::Execute(), Orders::LoopAround::Execute(), Orders::LoopAroundAgro::Execute(), and Orders::FacePerpendicular::Execute().

282 {
283  bool temp = done;
284  Order::Execute();
285  done = temp;
286  Vector ang_vel = parent->GetAngularVelocity();
287  Vector local_velocity( parent->UpCoordinateLevel( ang_vel ) );
288  Vector local_heading( parent->ToLocalCoordinates( ( final_heading-parent->Position() ).Cast() ) );
289  char xswitch =
290  ( (local_heading.i > 0) != (last_velocity.i > 0) || (!local_heading.i) ) && last_velocity.i != 0 ? 1 : 0;
291  char yswitch =
292  ( (local_heading.j > 0) != (last_velocity.j > 0) || (!local_heading.j) ) && last_velocity.j != 0 ? 1 : 0;
293  static bool AICheat = XMLSupport::parse_bool( vs_config->getVariable( "AI", "turn_cheat", "true" ) );
294  bool cheater = false;
295  static float min_for_no_oversteer = XMLSupport::parse_float( vs_config->getVariable( "AI", "min_angular_accel_cheat", "50" ) );
296  if ( AICheat && ( (parent->Limits().yaw+parent->Limits().pitch)*180/( PI*parent->GetMass() ) > min_for_no_oversteer )
297  && !parent->isSubUnit() ) {
298  if (xswitch || yswitch) {
299  Vector P, Q, R;
300  parent->GetOrientation( P, Q, R );
301  Vector desiredR = ( final_heading-parent->Position() ).Cast();
302  desiredR.Normalize();
303  static float cheatpercent = XMLSupport::parse_float( vs_config->getVariable( "AI", "ai_cheat_dot", ".99" ) );
304  if (desiredR.Dot( R ) > cheatpercent) {
305  P = Q.Cross( desiredR );
306  Q = desiredR.Cross( P );
307  parent->SetOrientation( Q, desiredR );
308  xswitch = yswitch = 1;
309  if (xswitch) {
310  if (yswitch) {
311  local_velocity.j = .0f;
312  local_velocity.i = .0f;
313  ang_vel.i = .0f;
314  ang_vel.j = .0f;
315  } else {
316  local_velocity.i = .0f;
317  ang_vel.i = .0f;
318  }
319  } else if (yswitch) {
320  local_velocity.j = .0f;
321  ang_vel.j = .0f;
322  }
323  cheater = true;
324  ang_vel.k = local_velocity.k = 0;
325  parent->SetAngularVelocity( ang_vel );
326  }
327  }
328  }
329  terminatingX += xswitch;
330  terminatingY += yswitch;
331  last_velocity = local_velocity;
332  if (done /*||(xswitch&&yswitch)*/)
333  return;
334  Vector torque( parent->Limits().pitch, parent->Limits().yaw, 0 ); //set torque to max accel in any direction
335  if (terminatingX > switchbacks && terminatingY > switchbacks) {
336  if ( Done( local_velocity ) ) {
337  if (this->terminating) {
338  done = true;
339  } else {
340  terminatingX = 0;
341  terminatingY = 0;
342  }
343  return;
344  }
345  torque = (-parent->GetMoment()/SIMULATION_ATOM)*local_velocity;
346  } else {
347  TurnToward( atan2( local_heading.j, local_heading.k ), local_velocity.i, torque.i ); //find angle away from axis 0,0,1 in yz plane
348  OptimizeAngSpeed( turningspeed*parent->GetComputerData().max_pitch_down,
349  turningspeed*parent->GetComputerData().max_pitch_up,
350  local_velocity.i,
351  torque.i );
352  TurnToward( atan2( local_heading.i, local_heading.k ), -local_velocity.j, torque.j );
353  torque.j = -torque.j;
354  OptimizeAngSpeed( turningspeed*parent->GetComputerData().max_yaw_left,
355  turningspeed*parent->GetComputerData().max_yaw_right,
356  local_velocity.j,
357  torque.j );
358  torque.k = -parent->GetMoment()*local_velocity.k/SIMULATION_ATOM; //try to counteract roll;
359  }
360  if (!cheater)
361  parent->ApplyLocalTorque( torque );
362 }
virtual string Orders::ChangeHeading::getOrderDescription ( )
inlinevirtual

Reimplemented from Order.

Reimplemented in Orders::FaceDirection, Orders::FaceTargetITTS, Orders::AutoLongHaul, and Orders::FaceTarget.

Definition at line 112 of file navigation.h.

113  {
114  return "chhead";
115  }
void Orders::ChangeHeading::ResetDone ( )
inlineprotected

Definition at line 93 of file navigation.h.

References Order::done.

Referenced by Orders::FaceTarget::Execute(), Orders::AutoLongHaul::Execute(), Orders::FaceTargetITTS::Execute(), Orders::FaceDirection::Execute(), and SetDest().

94  {
95  done = false;
96  terminatingX = terminatingY = 0;
97  }
void ChangeHeading::SetDest ( const QVector target)

Definition at line 265 of file navigation.cpp.

References ResetDone().

Referenced by Orders::FaceTarget::Execute(), Orders::AutoLongHaul::Execute(), Orders::FaceTargetITTS::Execute(), and Orders::FaceDirection::Execute().

266 {
267  final_heading = target;
268  ResetDone();
269 }

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