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::LoopAround Class Reference
Inheritance diagram for Orders::LoopAround:
Orders::FaceTargetITTS Orders::ChangeHeading Order

Public Member Functions

void SetParent (Unit *parent1)
 Sets the parent of this Unit. Any virtual functions must call this one. More...
 
 LoopAround (bool aggressive, bool afterburn, bool force_afterburn, int seed)
 
void Execute ()
 The function that gets called and executes all queued suborders. More...
 
- Public Member Functions inherited from Orders::FaceTargetITTS
 FaceTargetITTS (bool fini=false, int accuracy=3)
 
virtual string getOrderDescription ()
 
virtual ~FaceTargetITTS ()
 
- Public Member Functions inherited from Orders::ChangeHeading
 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 ~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 ()
 
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 ()
 

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 Orders::ChangeHeading
void ResetDone ()
 
- 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

Definition at line 238 of file hard_coded_scripts.cpp.

Constructor & Destructor Documentation

Orders::LoopAround::LoopAround ( bool  aggressive,
bool  afterburn,
bool  force_afterburn,
int  seed 
)
inline

Definition at line 253 of file hard_coded_scripts.cpp.

References VegaConfig::getVariable(), XMLSupport::parse_float(), VSRandom::rand(), VSRandom::uniformInc(), vs_config, and VS_RAND_MAX.

253  : FaceTargetITTS( false, 3 )
254  , m( Vector( 0, 0, 1000 ), true, afterburn, false )
255  {
256  VSRandom vsr( seed );
257  this->aggressive = aggressive;
258  this->afterburn = afterburn;
259  this->force_afterburn = force_afterburn;
260 
261  static float loopdis = XMLSupport::parse_float( vs_config->getVariable( "AI", "loop_around_distance", "1" ) );
262  qq = pp = 0;
263  static float loopdisd =
264  XMLSupport::parse_float( vs_config->getVariable( "AI", "loop_around_destination_distance", "20.0" ) );
265  static float loopdisv =
266  XMLSupport::parse_float( vs_config->getVariable( "AI", "loop_around_destination_vertical", "4.0" ) );
267  static float loopdisl = XMLSupport::parse_float( vs_config->getVariable( "AI", "loop_around_destination_lateral", "4.0" ) );
268  rr.Set( loopdisl*vsr.uniformInc( -1, 1 ), loopdisv*vsr.uniformInc( -1, 1 ), 1.0+loopdisd*vsr.uniformInc( 0, 1 ) );
269  if (vsr.rand() < VS_RAND_MAX/2) {
270  qq = vsr.uniformInc( -1, 1 );
271  rr.j = qq;
272  if (qq > 0)
273  qq += loopdis;
274  if (qq < 0)
275  qq -= loopdis;
276  } else {
277  pp = vsr.uniformInc( -1, 1 );
278  rr.i = pp;
279  if (pp > 0)
280  pp += loopdis;
281  if (pp < 0)
282  pp -= loopdis;
283  }
284  }

Member Function Documentation

void Orders::LoopAround::Execute ( )
inlinevirtual

The function that gets called and executes all queued suborders.

Reimplemented from Orders::FaceTargetITTS.

Definition at line 285 of file hard_coded_scripts.cpp.

References Unit::cumulative_transformation_matrix, Unit::cumulative_velocity, done, Orders::ChangeHeading::Execute(), Orders::FaceTargetITTS::Execute(), UnitUtil::getDistance(), Matrix::getP(), Matrix::getQ(), Matrix::getR(), VegaConfig::getVariable(), Unit::GetVelocity(), XMLSupport::parse_float(), Unit::Position(), QVector, Unit::rSize(), Unit::Target(), useAfterburner(), Vector, and vs_config.

286  {
287  Unit *targ = parent->Target();
288  if (targ) {
289  Vector relloc = parent->Position()-targ->Position();
291  bool afterburn = useAfterburner() && this->afterburn;
292  bool ab_needed = force_afterburn || targ->GetVelocity().MagnitudeSquared() > parent->GetComputerData().max_speed();
293  m.SetDesiredVelocity( Vector( 0, 0, afterburn
294  && ab_needed ? parent->GetComputerData().max_ab_speed() : parent->GetComputerData().
295  max_speed() ), true );
296  float spseed, grange = 0, mrange = 0;
297  parent->getAverageGunSpeed( spseed, grange, mrange );
298  if (r.Dot( relloc ) < 0) {
299  static float gun_range_pct =
300  XMLSupport::parse_float( vs_config->getVariable( "AI", "gun_range_percent_ok", ".66" ) );
302  float dist = UnitUtil::getDistance( parent, targ );
303  if ( dist < grange*gun_range_pct || (grange == 0 && dist < mrange) ) {
304  static float velocity_adjustment_pct =
305  XMLSupport::parse_float( vs_config->getVariable( "AI", "loop_around_pursuit_velocity_percent", ".9" ) );
306  m.SetDesiredVelocity( Vector( 0, 0, targ->cumulative_velocity.Magnitude()*velocity_adjustment_pct ), true );
307  }
308  m.SetAfterburn( afterburn && ab_needed );
309  m.Execute();
310  } else {
311  done = false;
312  if (afterburn)
313  m.SetAfterburn( ab_needed );
314  else
315  m.SetAfterburn( 0 );
316  Vector scala =
317  targ->cumulative_transformation_matrix.getQ().Scale( qq
318  *( parent->rSize()
319  +targ->rSize() ) )
320  +targ->cumulative_transformation_matrix.getP().Scale( pp*( parent->rSize()+targ->rSize() ) );
321  QVector dest = targ->Position()+scala;
322  SetDest( dest );
324  m.Execute();
325  }
326  }
327  }
void Orders::LoopAround::SetParent ( Unit parent1)
inlinevirtual

Sets the parent of this Unit. Any virtual functions must call this one.

Reimplemented from Order.

Definition at line 248 of file hard_coded_scripts.cpp.

References Order::SetParent().

249  {
250  FaceTargetITTS::SetParent( parent1 );
251  m.SetParent( parent1 );
252  }

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