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
hard_coded_scripts.cpp File Reference
#include <boost/version.hpp>
#include "python/python_class.h"
#include "script.h"
#include "cmd/unit_generic.h"
#include "hard_coded_scripts.h"
#include "flybywire.h"
#include "navigation.h"
#include "tactics.h"
#include "fire.h"
#include "order.h"
#include "vs_random.h"
#include "cmd/unit_util.h"

Go to the source code of this file.

Classes

class  EvadeLeftRightC
 
class  Orders::LoopAround
 
class  Orders::LoopAroundAgro
 
class  Orders::FacePerpendicular
 

Namespaces

 Orders
 

Constant Groups

 Orders
 

Functions

BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE
BOOST_PYTHON_END_CONVERSION_NAMESPACE
bool 
useAfterburner ()
 
bool useAfterburnerToRun ()
 
bool useAfterburnerToFollow ()
 
void AddOrd (Order *aisc, Unit *un, Order *ord)
 
void ReplaceOrd (Order *aisc, Unit *un, Order *ord)
 
void AfterburnTurnTowards (Order *aisc, Unit *un)
 
void AfterburnTurnTowardsITTS (Order *aisc, Unit *un)
 
void BarrelRoll (Order *aisc, Unit *un)
 
static void EvadeWavy (Order *aisc, Unit *un, bool updown, bool ab)
 
void AfterburnEvadeLeftRight (Order *aisc, Unit *un)
 
void AfterburnEvadeUpDown (Order *aisc, Unit *un)
 
void EvadeLeftRight (Order *aisc, Unit *un)
 
void EvadeUpDown (Order *aisc, Unit *un)
 
void LoopAround (Order *aisc, Unit *un)
 
void AggressiveLoopAround (Order *aisc, Unit *un)
 
void RollLeft (Order *aisc, Unit *un)
 
void RollRight (Order *aisc, Unit *un)
 
void RollLeftHard (Order *aisc, Unit *un)
 
void RollRightHard (Order *aisc, Unit *un)
 
void LoopAroundFast (Order *aisc, Unit *un)
 
void FacePerpendicularFast (Order *aisc, Unit *un)
 
void FacePerpendicular (Order *aisc, Unit *un)
 
void FacePerpendicularSlow (Order *aisc, Unit *un)
 
void RollFacePerpendicularFast (Order *aisc, Unit *un)
 
void RollFacePerpendicular (Order *aisc, Unit *un)
 
void RollFacePerpendicularSlow (Order *aisc, Unit *un)
 
void AggressiveLoopAroundFast (Order *aisc, Unit *un)
 
void LoopAroundSlow (Order *aisc, Unit *un)
 
void SelfDestruct (Order *aisc, Unit *un)
 
void AggressiveLoopAroundSlow (Order *aisc, Unit *un)
 
void MoveTo (Order *aisc, Unit *un)
 
void KickstopBase (Order *aisc, Unit *un, bool match)
 
void Kickstop (Order *aisc, Unit *un)
 
void CoastToStop (Order *aisc, Unit *un)
 
void DoNothing (Order *aisc, Unit *un)
 
void MatchVelocity (Order *aisc, Unit *un)
 
static Vector VectorThrustHelper (Order *aisc, Unit *un, bool ab=false)
 
void VeerAway (Order *aisc, Unit *un)
 
void VeerAwayITTS (Order *aisc, Unit *un)
 
void VeerAndVectorAway (Order *aisc, Unit *un)
 
void AfterburnVeerAndVectorAway (Order *aisc, Unit *un)
 
void AfterburnVeerAndTurnAway (Order *aisc, Unit *un)
 
static void SetupVAndTargetV (QVector &targetv, QVector &targetpos, Unit *un)
 
void SheltonSlide (Order *aisc, Unit *un)
 
void AfterburnerSlide (Order *aisc, Unit *un)
 
void SkilledABSlide (Order *aisc, Unit *un)
 
void Stop (Order *aisc, Unit *un)
 
void AfterburnTurnAway (Order *aisc, Unit *un)
 
void TurnAway (Order *aisc, Unit *un)
 
void TurnTowards (Order *aisc, Unit *un)
 
void FlyStraight (Order *aisc, Unit *un)
 
void FlyStraightAfterburner (Order *aisc, Unit *un)
 
void Takeoff (Order *aisc, Unit *un)
 
void TakeoffEveryZig (Order *aisc, Unit *un)
 
void CloakForScript (Order *aisc, Unit *un)
 
void TurnTowardsITTS (Order *aisc, Unit *un)
 
void DropCargo (Order *aisc, Unit *un)
 
void DropHalfCargo (Order *aisc, Unit *un)
 
void DropOneCargo (Order *aisc, Unit *un)
 

Variables

static OrderlastOrder = NULL
 

Function Documentation

void AfterburnerSlide ( Order aisc,
Unit un 
)

Definition at line 755 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), Unit::Position(), QVector, SetupVAndTargetV(), and useAfterburner().

756 {
757  QVector def = un->Position()+QVector( 1, 0, 0 );
758  QVector targetv( def );
759  QVector targetpos( def );
760  SetupVAndTargetV( targetpos, targetv, un );
761 
762  QVector difference = targetpos-un->Position();
763  QVector perp = targetv.Cross( -difference );
764  perp.Normalize();
765  perp = perp*( targetv.Dot( difference* -1./( difference.Magnitude() ) ) );
766  perp = (perp+difference)*1000;
767  bool afterburn = useAfterburner();
768  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( perp.Cast(), afterburn ), false, afterburn, true );
769  AddOrd( aisc, un, ord );
770  ord = new Orders::ExecuteFor( new Orders::ChangeHeading( perp+un->Position(), 3 ), 1.5 );
771  AddOrd( aisc, un, ord );
772  ord = ( new Orders::FaceTargetITTS( false, 3 ) );
773  AddOrd( aisc, un, ord );
774 }
void AfterburnEvadeLeftRight ( Order aisc,
Unit un 
)

Definition at line 219 of file hard_coded_scripts.cpp.

References EvadeWavy().

220 {
221  EvadeWavy( aisc, un, false, true );
222 }
void AfterburnEvadeUpDown ( Order aisc,
Unit un 
)

Definition at line 223 of file hard_coded_scripts.cpp.

References EvadeWavy().

224 {
225  EvadeWavy( aisc, un, true, true );
226 }
void AfterburnTurnAway ( Order aisc,
Unit un 
)

Definition at line 805 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), Unit::Position(), QVector, Unit::Target(), useAfterburner(), useAfterburnerToRun(), and v.

806 {
807  QVector v( un->Position() );
808  QVector u( v );
809  Unit *targ = un->Target();
810  if (targ)
811  u = targ->Position();
812  bool afterburn = useAfterburner() || useAfterburnerToRun();
813  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( 200*(v-u).Cast(), afterburn ), false, afterburn, false );
814  AddOrd( aisc, un, ord );
815  ord = new Orders::ChangeHeading( ( 200*(v-u) )+v, 3 );
816  AddOrd( aisc, un, ord );
817 }
void AfterburnTurnTowards ( Order aisc,
Unit un 
)

Definition at line 168 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), FaceTarget(), useAfterburnerToFollow(), and Vector.

169 {
170  Vector vec( 0, 0, 10000 );
171  bool afterburn = useAfterburnerToFollow();
172  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, afterburn ), true, afterburn, false );
173  AddOrd( aisc, un, ord );
174  ord = ( new Orders::FaceTarget( false, 3 ) );
175  AddOrd( aisc, un, ord );
176 }
void AfterburnTurnTowardsITTS ( Order aisc,
Unit un 
)

Definition at line 177 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), useAfterburnerToFollow(), and Vector.

178 {
179  Vector vec( 0, 0, 10000 );
180 
181  bool afterburn = useAfterburnerToFollow();
182  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, afterburn ), true, afterburn, false );
183  AddOrd( aisc, un, ord );
184  ord = ( new Orders::FaceTargetITTS( false, 3 ) );
185  AddOrd( aisc, un, ord );
186 }
void AfterburnVeerAndTurnAway ( Order aisc,
Unit un 
)

Definition at line 709 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), Order::EnqueueOrder(), Unit::Position(), Unit::Target(), and Vector.

710 {
711  Vector vec = Vector( 0, 0, 1 );
712  bool ab = true;
713  Vector tpos = un->Position().Cast();
714  if ( un->Target() ) {
715  tpos = un->Target()->Position().Cast();
716  Vector relpos = tpos-un->Position().Cast();
717  CrossProduct( relpos, Vector( 1, 0, 0 ), vec );
718  }
719  Order *ord = new Orders::ExecuteFor( new Orders::MatchLinearVelocity( Vector( 0, 0, 0 ), true, ab, true ), .5 );
720 
721  AddOrd( aisc, un, ord );
722  ord = new Orders::MatchLinearVelocity( un->ClampVelocity( Vector( 0, 0, 100000 ), ab ), true, ab, true );
723  aisc->EnqueueOrder( ord );
724  ord = new Orders::ChangeHeading( tpos+vec, 3, 1 );
725  AddOrd( aisc, un, ord );
726 }
void AfterburnVeerAndVectorAway ( Order aisc,
Unit un 
)

Definition at line 703 of file hard_coded_scripts.cpp.

References AddOrd(), Vector, and VectorThrustHelper().

704 {
705  Vector retval = VectorThrustHelper( aisc, un, true );
706  Order *ord = new Orders::ChangeHeading( retval, 3, 1 );
707  AddOrd( aisc, un, ord );
708 }
void AggressiveLoopAround ( Order aisc,
Unit un 
)

Definition at line 503 of file hard_coded_scripts.cpp.

References AddOrd().

504 {
505  Order *broll = new Orders::LoopAroundAgro( true, true, false, (int) (size_t) un );
506  AddOrd( aisc, un, broll );
507 }
void AggressiveLoopAroundFast ( Order aisc,
Unit un 
)

Definition at line 568 of file hard_coded_scripts.cpp.

References AddOrd().

569 {
570  Order *broll = new Orders::LoopAroundAgro( true, true, true, (int) (size_t) un );
571  AddOrd( aisc, un, broll );
572 }
void AggressiveLoopAroundSlow ( Order aisc,
Unit un 
)

Definition at line 595 of file hard_coded_scripts.cpp.

References AddOrd().

596 {
597  Order *broll = new Orders::LoopAroundAgro( true, false, false, (int) (size_t) un );
598  AddOrd( aisc, un, broll );
599 }
void BarrelRoll ( Order aisc,
Unit un 
)

Definition at line 188 of file hard_coded_scripts.cpp.

References AddOrd(), FlyByWire::Afterburn(), float, Unit::GetComputerData(), FlyByWire::MatchSpeed(), Unit::Computer::max_ab_speed(), Unit::Computer::max_speed(), FlyByWire::Right(), FlyByWire::RollRight(), FlyByWire::Up(), useAfterburner(), and Vector.

189 {
190  FlyByWire *broll = new FlyByWire;
191  AddOrd( aisc, un, broll );
192  broll->RollRight( rand() > RAND_MAX/2 ? 1 : -1 );
193  float per;
194  if (rand() < RAND_MAX/2) {
195  per = ( (float) rand() )/RAND_MAX;
196  if (per < .5)
197  per -= 1;
198  broll->Up( per );
199  } else {
200  per = ( (float) rand() )/RAND_MAX;
201  if (per < .5)
202  per -= 1;
203  broll->Right( per );
204  }
205  bool afterburn = useAfterburner();
206  broll->MatchSpeed( Vector( 0, 0, afterburn ? un->GetComputerData().max_ab_speed() : un->GetComputerData().max_speed() ) );
207  broll->Afterburn( afterburn );
208 }
void CloakForScript ( Order aisc,
Unit un 
)

Definition at line 927 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), and Vector.

928 {
929  Vector vec( 0, 0, 10000 );
930  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, false ), true, false, false );
931  AddOrd( aisc, un, ord );
932  ord = ( new Orders::FaceTargetITTS( 0, 3 ) );
933  AddOrd( aisc, un, ord );
934  ord = new Orders::ExecuteFor( new CloakFor( 1, 8 ), 32 );
935  AddOrd( aisc, un, ord );
936 }
void CoastToStop ( Order aisc,
Unit un 
)

Definition at line 644 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), Unit::GetVelocity(), and Vector.

645 {
646  Vector vec( 0, 0, 0 );
647  vec = un->GetVelocity();
648 
649  vec.i = vec.i*0.1;
650  vec.j = vec.j*0.1;
651  vec.k = vec.k*0.1;
652 
653  Order *ord = new Orders::ExecuteFor( new Orders::MatchLinearVelocity( un->ClampVelocity( vec, false ), true, false, true ), 1 );
654  AddOrd( aisc, un, ord );
655 }
void DoNothing ( Order aisc,
Unit un 
)

Definition at line 657 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::GetVelocity(), and Vector.

658 {
659  Vector vec( 0, 0, 0 );
660  vec = un->GetVelocity();
661 
662  Order *ord = new Orders::ExecuteFor( new Orders::MatchLinearVelocity( vec, true, false, true ), 1 );
663  AddOrd( aisc, un, ord );
664 }
void DropCargo ( Order aisc,
Unit un 
)

Definition at line 946 of file hard_coded_scripts.cpp.

References Unit::EjectCargo(), i, Unit::numCargo(), Stop, and TurnAway.

947 {
948  if (un->numCargo() > 0) {
949  int dropcount = un->numCargo();
950 
951  {
952  for (int i = 0; i < dropcount; i++)
953  un->EjectCargo( 0 );
954  }
955  Stop( aisc, un );
956  } else {
957  TurnAway( aisc, un );
958  }
959 }
void DropHalfCargo ( Order aisc,
Unit un 
)

Definition at line 961 of file hard_coded_scripts.cpp.

References Unit::EjectCargo(), i, Unit::numCargo(), Stop, and TurnAway.

962 {
963  if (un->numCargo() > 0) {
964  int dropcount = (un->numCargo()/2)+1;
965 
966  {
967  for (int i = 0; i < dropcount; i++)
968  un->EjectCargo( 0 );
969  }
970  Stop( aisc, un );
971  } else {
972  TurnAway( aisc, un );
973  }
974 }
void DropOneCargo ( Order aisc,
Unit un 
)

Definition at line 976 of file hard_coded_scripts.cpp.

References Unit::EjectCargo(), Unit::numCargo(), Stop, and TurnAway.

977 {
978  if (un->numCargo() > 0) {
979  un->EjectCargo( 0 );
980  Stop( aisc, un );
981  } else {
982  TurnAway( aisc, un );
983  }
984 }
void EvadeLeftRight ( Order aisc,
Unit un 
)

Definition at line 227 of file hard_coded_scripts.cpp.

References EvadeWavy().

228 {
229  EvadeWavy( aisc, un, false, false );
230 }
void EvadeUpDown ( Order aisc,
Unit un 
)

Definition at line 231 of file hard_coded_scripts.cpp.

References EvadeWavy().

232 {
233  EvadeWavy( aisc, un, true, false );
234 }
static void EvadeWavy ( Order aisc,
Unit un,
bool  updown,
bool  ab 
)
static

Definition at line 210 of file hard_coded_scripts.cpp.

References AddOrd(), FlyByWire::Afterburn(), Unit::GetComputerData(), FlyByWire::MatchSpeed(), Unit::Computer::max_ab_speed(), Unit::Computer::max_speed(), useAfterburner(), and Vector.

Referenced by AfterburnEvadeLeftRight(), AfterburnEvadeUpDown(), EvadeLeftRight(), and EvadeUpDown().

211 {
212  EvadeLeftRightC *broll = NULL;
213  broll = new EvadeLeftRightC( updown );
214  AddOrd( aisc, un, broll );
215  bool afterburn = ab && useAfterburner();
216  broll->MatchSpeed( Vector( 0, 0, afterburn ? un->GetComputerData().max_ab_speed() : un->GetComputerData().max_speed() ) );
217  broll->Afterburn( afterburn );
218 }
void FacePerpendicular ( Order aisc,
Unit un 
)

Definition at line 541 of file hard_coded_scripts.cpp.

References AddOrd(), and FacePerpendicular.

542 {
543  Order *broll = new Orders::FacePerpendicular( false, true, false, (int) (size_t) un );
544  AddOrd( aisc, un, broll );
545 }
void FacePerpendicularFast ( Order aisc,
Unit un 
)

Definition at line 536 of file hard_coded_scripts.cpp.

References AddOrd(), and FacePerpendicular.

537 {
538  Order *broll = new Orders::FacePerpendicular( false, true, true, (int) (size_t) un );
539  AddOrd( aisc, un, broll );
540 }
void FacePerpendicularSlow ( Order aisc,
Unit un 
)

Definition at line 546 of file hard_coded_scripts.cpp.

References AddOrd(), and FacePerpendicular.

547 {
548  Order *broll = new Orders::FacePerpendicular( false, false, false, (int) (size_t) un );
549  AddOrd( aisc, un, broll );
550 }
void FlyStraight ( Order aisc,
Unit un 
)

Definition at line 840 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), MatchVelocity, and Vector.

841 {
842  Vector vec( 0, 0, 10000 );
843  Order *ord = new Orders::MatchVelocity( un->ClampVelocity( vec, false ), Vector( 0, 0, 0 ), true, false, false );
844  AddOrd( aisc, un, ord );
845  ord = new Orders::MatchAngularVelocity( Vector( 0, 0, 0 ), 1, false );
846  AddOrd( aisc, un, ord );
847 }
void FlyStraightAfterburner ( Order aisc,
Unit un 
)

Definition at line 848 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), MatchVelocity, useAfterburner(), and Vector.

849 {
850  Vector vec( 0, 0, 10000 );
851  bool afterburn = useAfterburner();
852  Order *ord = new Orders::MatchVelocity( un->ClampVelocity( vec, afterburn ), Vector( 0, 0, 0 ), true, afterburn, false );
853  AddOrd( aisc, un, ord );
854  ord = new Orders::MatchAngularVelocity( Vector( 0, 0, 0 ), 1, false );
855  AddOrd( aisc, un, ord );
856 }
void Kickstop ( Order aisc,
Unit un 
)

Definition at line 639 of file hard_coded_scripts.cpp.

References KickstopBase().

640 {
641  KickstopBase( aisc, un, false );
642 }
void KickstopBase ( Order aisc,
Unit un,
bool  match 
)

Definition at line 629 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), Unit::GetVelocity(), Unit::Target(), and Vector.

Referenced by Kickstop(), and MatchVelocity().

630 {
631  Vector vec( 0, 0, 0 );
632  if ( match && un->Target() )
633  vec = un->Target()->GetVelocity();
634  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, false ), true, false, true );
635  AddOrd( aisc, un, ord );
636  ord = ( new Orders::FaceTargetITTS( false, 3 ) );
637  AddOrd( aisc, un, ord );
638 }
void LoopAround ( Order aisc,
Unit un 
)

Definition at line 498 of file hard_coded_scripts.cpp.

References AddOrd(), and LoopAround.

499 {
500  Order *broll = new Orders::LoopAround( false, true, false, (int) (size_t) un );
501  AddOrd( aisc, un, broll );
502 }
void LoopAroundFast ( Order aisc,
Unit un 
)

Definition at line 530 of file hard_coded_scripts.cpp.

References AddOrd(), and LoopAround.

531 {
532  Order *broll = new Orders::LoopAround( false, true, true, (int) (size_t) un );
533  AddOrd( aisc, un, broll );
534 }
void LoopAroundSlow ( Order aisc,
Unit un 
)

Definition at line 573 of file hard_coded_scripts.cpp.

References AddOrd(), and LoopAround.

574 {
575  Order *broll = new Orders::LoopAround( false, false, false, (int) (size_t) un );
576  AddOrd( aisc, un, broll );
577 }
void MatchVelocity ( Order aisc,
Unit un 
)

Definition at line 666 of file hard_coded_scripts.cpp.

References KickstopBase().

667 {
668  KickstopBase( aisc, un, true );
669 }
void MoveTo ( Order aisc,
Unit un 
)

Definition at line 619 of file hard_coded_scripts.cpp.

References AddOrd(), MoveTo, Unit::Position(), QVector, and Unit::Target().

620 {
621  QVector Targ( un->Position() );
622  Unit *untarg = un->Target();
623  if (untarg)
624  Targ = untarg->Position();
625  Order *ord = new Orders::MoveTo( Targ, false, 3 );
626  AddOrd( aisc, un, ord );
627 }
void ReplaceOrd ( Order aisc,
Unit un,
Order ord 
)

Definition at line 42 of file hard_coded_scripts.cpp.

References Order::ReplaceOrder(), and Order::SetParent().

Referenced by Orders::FireAt::AddReplaceLastOrder().

43 {
44  ord->SetParent( un );
45  aisc->ReplaceOrder( ord );
46 }
void RollFacePerpendicular ( Order aisc,
Unit un 
)

Definition at line 557 of file hard_coded_scripts.cpp.

References AddOrd(), and FacePerpendicular.

558 {
559  Order *broll = new Orders::FacePerpendicular( true, true, false, (int) (size_t) un );
560  AddOrd( aisc, un, broll );
561 }
void RollFacePerpendicularFast ( Order aisc,
Unit un 
)

Definition at line 552 of file hard_coded_scripts.cpp.

References AddOrd(), and FacePerpendicular.

553 {
554  Order *broll = new Orders::FacePerpendicular( true, true, true, (int) (size_t) un );
555  AddOrd( aisc, un, broll );
556 }
void RollFacePerpendicularSlow ( Order aisc,
Unit un 
)

Definition at line 562 of file hard_coded_scripts.cpp.

References AddOrd(), and FacePerpendicular.

563 {
564  Order *broll = new Orders::FacePerpendicular( true, false, false, (int) (size_t) un );
565  AddOrd( aisc, un, broll );
566 }
void RollLeft ( Order aisc,
Unit un 
)

Definition at line 508 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::aistate, f, Unit::GetComputerData(), and Unit::Computer::max_roll_right.

509 {
510  if (un->aistate)
511  AddOrd( un->aistate, un, new Orders::ExecuteFor( new Orders::MatchRoll( un->GetComputerData().max_roll_right, false ), 1.0f ) );
512 }
void RollLeftHard ( Order aisc,
Unit un 
)

Definition at line 518 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::aistate, Unit::GetComputerData(), VegaConfig::getVariable(), Unit::Computer::max_roll_right, XMLSupport::parse_float(), and vs_config.

519 {
520  static float durvar = XMLSupport::parse_float( vs_config->getVariable( "AI", "roll_order_duration", "5.0" ) );
521  if (un->aistate)
522  AddOrd( un->aistate, un, new Orders::ExecuteFor( new Orders::MatchRoll( un->GetComputerData().max_roll_right, false ), durvar ) );
523 }
void RollRight ( Order aisc,
Unit un 
)

Definition at line 513 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::aistate, f, Unit::GetComputerData(), and Unit::Computer::max_roll_left.

514 {
515  if (un->aistate)
516  AddOrd( un->aistate, un, new Orders::ExecuteFor( new Orders::MatchRoll( -un->GetComputerData().max_roll_left, false ), 1.0f ) );
517 }
void RollRightHard ( Order aisc,
Unit un 
)

Definition at line 524 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::aistate, Unit::GetComputerData(), VegaConfig::getVariable(), Unit::Computer::max_roll_left, XMLSupport::parse_float(), and vs_config.

525 {
526  static float durvar = XMLSupport::parse_float( vs_config->getVariable( "AI", "roll_order_duration", "5.0" ) );
527  if (un->aistate)
528  AddOrd( un->aistate, un, new Orders::ExecuteFor( new Orders::MatchRoll( -un->GetComputerData().max_roll_left, false ), durvar ) );
529 }
void SelfDestruct ( Order aisc,
Unit un 
)

Definition at line 579 of file hard_coded_scripts.cpp.

References Unit::armor, Armor::backleftbottom, Armor::backlefttop, Armor::backrightbottom, Armor::backrighttop, Unit::Explode(), Armor::frontleftbottom, Armor::frontlefttop, Armor::frontrightbottom, Armor::frontrighttop, Unit::hull, Unit::RemoveFromSystem(), and Unit::Split().

580 {
581  un->armor.frontrighttop = -1;
582  un->armor.backrighttop = -1;
583  un->armor.frontlefttop = -1;
584  un->armor.backlefttop = -1;
585  un->armor.frontrightbottom = -1;
586  un->armor.backrightbottom = -1;
587  un->armor.frontleftbottom = -1;
588  un->armor.backleftbottom = -1;
589  un->hull = -1; //hull goes to zero but no kill, same for armor. strangely enough, all of them together work.
590  un->Split( rand()%3+1 );
591  un->Explode( true, 0 ); //displays explosion, unit continues
592  un->RemoveFromSystem(); //has no effect
593 }
static void SetupVAndTargetV ( QVector targetv,
QVector targetpos,
Unit un 
)
static

Definition at line 727 of file hard_coded_scripts.cpp.

References Unit::GetVelocity(), Unit::Position(), and Unit::Target().

Referenced by AfterburnerSlide(), SheltonSlide(), and SkilledABSlide().

728 {
729  Unit *targ;
730  if ( ( targ = un->Target() ) ) {
731  targetv = targ->GetVelocity().Cast();
732  targetpos = targ->Position();
733  }
734 }
void SheltonSlide ( Order aisc,
Unit un 
)

Definition at line 736 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), Unit::Position(), QVector, SetupVAndTargetV(), and useAfterburner().

737 {
738  QVector def( un->Position()+QVector( 1, 0, 0 ) );
739  QVector targetv( def );
740  QVector targetpos( def );
741  SetupVAndTargetV( targetpos, targetv, un );
742  QVector difference = targetpos-un->Position();
743  QVector perp = targetv.Cross( -difference );
744  perp.Normalize();
745  perp = perp*( targetv.Dot( difference* -1./( difference.Magnitude() ) ) );
746  perp = (perp+difference)*10000.;
747 
748  bool afterburn = useAfterburner();
749  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( perp.Cast(), afterburn ), false, afterburn, true );
750  AddOrd( aisc, un, ord );
751  ord = ( new Orders::FaceTargetITTS( false, 3 ) );
752  AddOrd( aisc, un, ord );
753 }
void SkilledABSlide ( Order aisc,
Unit un 
)

Definition at line 775 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), Unit::Position(), QVector, SetupVAndTargetV(), and useAfterburner().

776 {
777  QVector def = un->Position()+QVector( 1, 0, 0 );
778  QVector targetv( def );
779  QVector targetpos( def );
780  SetupVAndTargetV( targetpos, targetv, un );
781 
782  QVector difference = targetpos-un->Position();
783  QVector ndifference = difference;
784  ndifference.Normalize();
785  QVector Perp;
786  ScaledCrossProduct( ndifference, targetv, Perp );
787  Perp = Perp+.5*ndifference;
788  Perp = Perp*10000;
789 
790  bool afterburn = useAfterburner();
791 
792  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( Perp.Cast(), afterburn ), false, afterburn, true );
793  AddOrd( aisc, un, ord );
794  ord = new Orders::ExecuteFor( new Orders::ChangeHeading( Perp+un->Position(), 3 ), .5 );
795  AddOrd( aisc, un, ord );
796  ord = ( new Orders::FaceTargetITTS( false, 3 ) );
797  AddOrd( aisc, un, ord );
798 }
void Stop ( Order aisc,
Unit un 
)

Definition at line 799 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), and Vector.

800 {
801  Vector vec( 0, 0, 0000 );
802  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, false ), true, false, false );
803  AddOrd( aisc, un, ord ); //<!-- should we fini? -->
804 }
void Takeoff ( Order aisc,
Unit un 
)

Definition at line 860 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), f, Unit::Fire(), firsttime, weapon_info::LIGHT, MatchVelocity, weapon_info::MEDIUM, Unit::SelectAllWeapon(), TurnTowards, Unit::UnFire(), and Vector.

861 {
862  Vector vec( 0, 0, 10000 );
863  static bool firsttime = true;
864  Order *ord;
865  if (firsttime) {
866  un->UnFire();
867  ord = new Orders::MatchVelocity( un->ClampVelocity( vec, true ), Vector( 0, 0, 0 ), true, true, false );
868  AddOrd( aisc, un, ord );
869  ord = new Orders::MatchAngularVelocity( Vector( 0, 0, 0 ), 1, false );
870  AddOrd( aisc, un, ord );
871  ord = new Orders::ExecuteFor( new Orders::MatchVelocity( un->ClampVelocity( vec, true ), Vector( 0,
872  0,
873  0 ), true, true, false ), 1.5f );
874  AddOrd( aisc, un, ord );
875  ord = new Orders::ExecuteFor( new Orders::MatchAngularVelocity( Vector( 0, 0, 0 ), 1, false ), 1.5f );
876  AddOrd( aisc, un, ord );
877  ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, false ), true, false, false );
878  AddOrd( aisc, un, ord );
879  ord = ( new Orders::FaceTargetITTS( 0, 3 ) );
880  AddOrd( aisc, un, ord );
881  un->UnFire();
882  firsttime = false;
883  } else {
884  firsttime = false;
885  ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, false ), true, false, false );
886  AddOrd( aisc, un, ord );
887  ord = ( new Orders::FaceTargetITTS( 0, 3 ) );
888  AddOrd( aisc, un, ord );
889  }
890  ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, false ), true, false, false );
891  AddOrd( aisc, un, ord );
892  ord = ( new Orders::FaceTargetITTS( 0, 3 ) );
893  AddOrd( aisc, un, ord );
894  un->SelectAllWeapon( false );
895  un->Fire( (weapon_info::LIGHT || weapon_info::MEDIUM), false );
896  TurnTowards( aisc, un );
897 }
void TakeoffEveryZig ( Order aisc,
Unit un 
)

Definition at line 899 of file hard_coded_scripts.cpp.

References AddOrd(), weapon_info::CAPSHIPHEAVY, Unit::ClampVelocity(), f, Unit::Fire(), MatchVelocity, Unit::SelectAllWeapon(), Unit::UnFire(), and Vector.

900 {
901  Vector vec( 0, 0, 10000 );
902 
903  Order *ord;
904  un->UnFire();
905  un->Fire( weapon_info::CAPSHIPHEAVY, false );
906  un->UnFire();
907  ord = new Orders::MatchVelocity( un->ClampVelocity( vec, true ), Vector( 0, 0, 0 ), true, true, false );
908  AddOrd( aisc, un, ord );
909  ord = new Orders::MatchAngularVelocity( Vector( 0, 0, 0 ), 1, false );
910  AddOrd( aisc, un, ord );
911  ord = new Orders::ExecuteFor( new Orders::MatchAngularVelocity( Vector( 0, 0, 0 ), 1, false ), 3.4f );
912  AddOrd( aisc, un, ord );
913  ord = new Orders::ExecuteFor( new Orders::MatchVelocity( un->ClampVelocity( vec, true ), Vector( 0,
914  0,
915  0 ), true, true, false ), 0.1f );
916  AddOrd( aisc, un, ord );
917  ord = new Orders::ExecuteFor( new Orders::FaceTarget( 0, 3 ), 1.0f );
918  AddOrd( aisc, un, ord );
919  ord = new Orders::MatchVelocity( un->ClampVelocity( vec, true ), Vector( 0, 0, 0 ), true, true, false );
920  AddOrd( aisc, un, ord );
921  ord = new Orders::MatchAngularVelocity( Vector( 0, 0, 0 ), 1, false );
922  AddOrd( aisc, un, ord );
923  un->Fire( weapon_info::CAPSHIPHEAVY, false ); //doesn't have time to happen anyway
924  un->SelectAllWeapon( false );
925 }
void TurnAway ( Order aisc,
Unit un 
)

Definition at line 818 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), Unit::Position(), QVector, Unit::Target(), and v.

819 {
820  QVector v( un->Position() );
821  QVector u( v );
822  Unit *targ = un->Target();
823  if (targ)
824  u = targ->Position();
825  bool afterburn = false;
826  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( 200*(v-u).Cast(), afterburn ), false, afterburn, false );
827  AddOrd( aisc, un, ord );
828  ord = new Orders::ChangeHeading( ( 200*(v-u) )+v, 3 );
829  AddOrd( aisc, un, ord );
830 }
void TurnTowards ( Order aisc,
Unit un 
)

Definition at line 831 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), FaceTarget(), and Vector.

832 {
833  Vector vec( 0, 0, 10000 );
834  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, false ), true, false, false );
835  AddOrd( aisc, un, ord );
836 
837  ord = new Orders::FaceTarget( 0, 3 );
838  AddOrd( aisc, un, ord );
839 }
void TurnTowardsITTS ( Order aisc,
Unit un 
)

Definition at line 937 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), and Vector.

938 {
939  Vector vec( 0, 0, 10000 );
940  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, false ), true, false, false );
941  AddOrd( aisc, un, ord );
942  ord = ( new Orders::FaceTargetITTS( 0, 3 ) );
943  AddOrd( aisc, un, ord );
944 }
BOOST_PYTHON_BEGIN_CONVERSION_NAMESPACE BOOST_PYTHON_END_CONVERSION_NAMESPACE bool useAfterburner ( )
bool useAfterburnerToFollow ( )

Definition at line 32 of file hard_coded_scripts.cpp.

References VegaConfig::getVariable(), XMLSupport::parse_bool(), and vs_config.

Referenced by AfterburnTurnTowards(), and AfterburnTurnTowardsITTS().

33 {
34  static bool useafterburner = XMLSupport::parse_bool( vs_config->getVariable( "AI", "use_afterburner_to_follow", "true" ) );
35  return useafterburner;
36 }
bool useAfterburnerToRun ( )

Definition at line 27 of file hard_coded_scripts.cpp.

References VegaConfig::getVariable(), XMLSupport::parse_bool(), and vs_config.

Referenced by AfterburnTurnAway().

28 {
29  static bool useafterburner = XMLSupport::parse_bool( vs_config->getVariable( "AI", "use_afterburner_to_run", "true" ) );
30  return useafterburner;
31 }
static Vector VectorThrustHelper ( Order aisc,
Unit un,
bool  ab = false 
)
static

Definition at line 671 of file hard_coded_scripts.cpp.

References AddOrd(), Unit::ClampVelocity(), Unit::Position(), Unit::Target(), and Vector.

Referenced by AfterburnVeerAndVectorAway(), VeerAndVectorAway(), VeerAway(), and VeerAwayITTS().

672 {
673  Vector vec( 0, 0, 0 );
674  Vector retval( 0, 0, 0 );
675  if ( un->Target() ) {
676  Vector tpos = un->Target()->Position().Cast();
677  Vector relpos = tpos-un->Position().Cast();
678  CrossProduct( relpos, Vector( 1, 0, 0 ), vec );
679  retval += tpos;
680  }
681  Order *ord = new Orders::MatchLinearVelocity( un->ClampVelocity( vec, ab ), false, ab, true );
682  AddOrd( aisc, un, ord );
683  return retval;
684 }
void VeerAndVectorAway ( Order aisc,
Unit un 
)

Definition at line 697 of file hard_coded_scripts.cpp.

References AddOrd(), Vector, and VectorThrustHelper().

698 {
699  Vector retval = VectorThrustHelper( aisc, un );
700  Order *ord = new Orders::ChangeHeading( retval, 3, 1 );
701  AddOrd( aisc, un, ord );
702 }
void VeerAway ( Order aisc,
Unit un 
)

Definition at line 685 of file hard_coded_scripts.cpp.

References AddOrd(), FaceTarget(), and VectorThrustHelper().

686 {
687  VectorThrustHelper( aisc, un );
688  Order *ord = ( new Orders::FaceTarget( false, 3 ) );
689  AddOrd( aisc, un, ord );
690 }
void VeerAwayITTS ( Order aisc,
Unit un 
)

Definition at line 691 of file hard_coded_scripts.cpp.

References AddOrd(), and VectorThrustHelper().

692 {
693  VectorThrustHelper( aisc, un );
694  Order *ord = ( new Orders::FaceTargetITTS( false, 3 ) );
695  AddOrd( aisc, un, ord );
696 }

Variable Documentation

Order* lastOrder = NULL
static

Definition at line 47 of file hard_coded_scripts.cpp.