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::FireAt Class Reference

#include <fire.h>

Inheritance diagram for Orders::FireAt:
CommunicatingAI Order Orders::AggressiveAI Orders::Ikarus

Public Member Functions

virtual void ChooseTarget ()
 this function calls the destructor (needs to be overridden for python; More...
 
void PossiblySwitchTarget (bool istargetjumpableplanet)
 
virtual bool PursueTarget (Unit *, bool leader)
 
void AddReplaceLastOrder (bool replace)
 
void ExecuteLastScriptFor (float time)
 
void FaceTarget (bool end)
 
void FaceTargetITTS (bool end)
 
void MatchLinearVelocity (bool terminate, Vector vec, bool afterburn, bool local)
 
void MatchAngularVelocity (bool terminate, Vector vec, bool local)
 
void ChangeHeading (QVector vec)
 
void ChangeLocalDirection (Vector vec)
 
void MoveTo (QVector, bool afterburn)
 
void MatchVelocity (bool terminate, Vector vec, Vector angvel, bool afterburn, bool local)
 
void Cloak (bool enable, float seconds)
 
void FormUp (QVector pos)
 
void FormUpToOwner (QVector pos)
 
void FaceDirection (float distToMatchFacing, bool finish)
 
void XMLScript (std::string script)
 
void LastPythonScript ()
 
virtual void SetParent (Unit *parent)
 Sets the parent of this Unit. Any virtual functions must call this one. More...
 
UnitGetParent ()
 
 FireAt (float aggressivitylevel)
 
 FireAt ()
 
virtual void Execute ()
 The function that gets called and executes all queued suborders. More...
 
virtual std::string Pickle ()
 
virtual void UnPickle (std::string)
 
virtual ~FireAt ()
 
- Public Member Functions inherited from CommunicatingAI
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 float getMood ()
 
UnitGetRandomUnit (float PlayerProbability, float TargetProbability)
 
void RandomInitiateCommunication (float PlayerProbability, float TargetProbability)
 
void TerminateContrabandSearch (bool foundcontraband)
 
void InitiateContrabandSearch (float PlayerProbability, float TargetProbability)
 
void UpdateContrabandSearch ()
 
 CommunicatingAI (int ttype, int stype, float mood=0, float anger=-666, float appeasement=666, float moodswingyness=666, float randomnessresponse=666)
 
virtual void ProcessCommMessage (class CommunicationMessage &c)
 processes a single message...generally called by the Messages() func More...
 
virtual void AdjustRelationTo (Unit *un, float factor)
 
virtual ~CommunicatingAI ()
 
virtual int selectCommunicationMessage (class CommunicationMessage &c, Unit *)
 
virtual int selectCommunicationMessageMood (CommunicationMessage &c, float mood)
 
- Public Member Functions inherited from Order
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 ()
 
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 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 std::string getOrderDescription ()
 
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 ()
 

Protected Member Functions

bool ShouldFire (Unit *targ, bool &missilelock)
 
void FireWeapons (bool shouldfire, bool lockmissile)
 
virtual void ChooseTargets (int num, bool force=false)
 
bool isJumpablePlanet (Unit *)
 
void ReInit (float agglevel)
 
virtual void SignalChosenTarget ()
 
- Protected Member Functions inherited from CommunicatingAI
void GetMadAt (Unit *which, int howMad)
 
- 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...
 

Protected Attributes

float missileprobability
 
float lastmissiletime
 
float delay
 
float agg
 
float distance
 
float lastchangedtarg
 
bool had_target
 
- Protected Attributes inherited from CommunicatingAI
float anger
 
float appease
 
float moodswingyness
 
float randomresponse
 
float mood
 
UnitContainer contraband_searchee
 
Vector SpeedAndCourse
 
int which_cargo_item
 
- 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 }
 

Detailed Description

Definition at line 10 of file fire.h.

Constructor & Destructor Documentation

FireAt::FireAt ( float  aggressivitylevel)

Definition at line 114 of file fire.cpp.

References ReInit().

115 {
116  ReInit( aggressivitylevel );
117 }
FireAt::FireAt ( )

Definition at line 119 of file fire.cpp.

References VegaConfig::getVariable(), XMLSupport::parse_float(), ReInit(), and vs_config.

120 {
121  static float aggr = XMLSupport::parse_float( vs_config->getVariable( "AI", "Firing", "Aggressivity", "15" ) );
122  ReInit( aggr );
123 }
FireAt::~FireAt ( )
virtual

Definition at line 631 of file fire.cpp.

References VSFileSystem::vs_fprintf().

632 {
633 #ifdef ORDERDEBUG
634  VSFileSystem::vs_fprintf( stderr, "fire%x\n", this );
635  fflush( stderr );
636 #endif
637 }

Member Function Documentation

void FireAt::AddReplaceLastOrder ( bool  replace)

Definition at line 48 of file hard_coded_scripts.cpp.

References AddOrd(), Order::parent, and ReplaceOrd().

49 {
50  if (lastOrder) {
51  if (replace)
52  ReplaceOrd( this, parent, lastOrder );
53  else
54  AddOrd( this, parent, lastOrder );
55  lastOrder = NULL;
56  }
57 }
void FireAt::ChangeHeading ( QVector  vec)

Definition at line 80 of file hard_coded_scripts.cpp.

81 {
82  lastOrder = new Orders::ChangeHeading( vec, 3 );
83 }
void FireAt::ChangeLocalDirection ( Vector  vec)

Definition at line 84 of file hard_coded_scripts.cpp.

References Order::parent, Unit::Position(), and Unit::ToWorldCoordinates().

85 {
86  lastOrder = new Orders::ChangeHeading( ( ( parent->Position().Cast() )+parent->ToWorldCoordinates( vec ) ).Cast(), 3 );
87 }
virtual void Orders::FireAt::ChooseTarget ( )
inlinevirtual

this function calls the destructor (needs to be overridden for python;

Reimplemented from Order.

Definition at line 28 of file fire.h.

References ChooseTargets().

29  {
30  ChooseTargets( 1, true );
31  }
void FireAt::ChooseTargets ( int  num,
bool  force = false 
)
protectedvirtual

Definition at line 424 of file fire.cpp.

References _Universe, Universe::AccessCockpit(), Universe::activeStarSystem(), AssignTBin(), Unit::attackPreference(), StarSystem::collidemap, Flightgroup::directive, findObjects(), float_to_int(), UnitUtil::getDistance(), UnitUtil::getFlightgroupLeader(), UniverseUtil::GetGameTime(), Cockpit::GetParent(), ROLES::getRole(), Unit::getSubUnits(), VegaConfig::getVariable(), i, k, Universe::numPlayers(), numpolled, numprocessed, XMLSupport::parse_bool(), XMLSupport::parse_float(), XMLSupport::parse_int(), pollindex, prevpollindex, queryTime(), Unit::Target(), targetpick, targrand, Unit::Threat(), VSRandom::uniformInc(), Unit::UNIT_ONLY, and vs_config.

Referenced by ChooseTarget().

425 {
426  float gunspeed, gunrange, missilerange;
427  parent->getAverageGunSpeed( gunspeed, gunrange, missilerange );
428  static float targettimer = UniverseUtil::GetGameTime(); //timer used to determine passage of physics frames
429  static float mintimetoswitch =
430  XMLSupport::parse_float( vs_config->getVariable( "AI", "Targetting", "MinTimeToSwitchTargets", "3" ) );
431  static float minnulltimetoswitch =
432  XMLSupport::parse_float( vs_config->getVariable( "AI", "Targetting", "MinNullTimeToSwitchTargets", "5" ) );
433  static int minnumpollers =
434  float_to_int( XMLSupport::parse_float( vs_config->getVariable( "AI", "Targetting", "MinNumberofpollersperframe", "5" ) ) ); //maximum number of vessels allowed to search for a target in a given physics frame
435  static int maxnumpollers =
436  float_to_int( XMLSupport::parse_float( vs_config->getVariable( "AI", "Targetting", "MaxNumberofpollersperframe", "49" ) ) ); //maximum number of vessels allowed to search for a target in a given physics frame
437  static int numpollers[2] = {maxnumpollers, maxnumpollers};
438 
439  static float nextframenumpollers[2] = {maxnumpollers, maxnumpollers};
440  if (lastchangedtarg+mintimetoswitch > 0)
441  return; //don't switch if switching too soon
442 
443  Unit *curtarg = parent->Target();
444  int hastarg = (curtarg == NULL) ? 0 : 1;
445  //Following code exists to limit the number of craft polling for a target in a given frame - this is an expensive operation, and needs to be spread out, or there will be pauses.
446  static float simatom = XMLSupport::parse_float( vs_config->getVariable( "general", "simulation_atom", "0.1" ) );
447  if ( ( UniverseUtil::GetGameTime() )-targettimer >= simatom*.99 ) {
448  //Check if one or more physics frames have passed
449  numpolled[0] = numpolled[1] = 0; //reset counters
450  prevpollindex[0] = pollindex[0];
451  prevpollindex[1] = pollindex[1];
452  pollindex[hastarg] = 0;
453  targettimer = UniverseUtil::GetGameTime();
454  numpollers[0] = float_to_int( nextframenumpollers[0] );
455  numpollers[1] = float_to_int( nextframenumpollers[1] );
456  }
457  pollindex[hastarg]++; //count number of craft touched - will use in the next physics frame to spread out the vessels actually chosen to be processed among all of the vessels being touched
458  if (numpolled[hastarg] > numpollers[hastarg]) //over quota, wait until next physics frame
459  return;
460  if ( !( pollindex[hastarg]%( (prevpollindex[hastarg]/numpollers[hastarg])+1 ) ) ) //spread out, in modulo fashion, the possibility of changing one's target. Use previous physics frame count of craft to estimate current number of craft
461  numpolled[hastarg]++; //if a more likely candidate, we're going to search for a target.
462  else
463  return; //skipped to achieve better fairness - see comment on modulo distribution above
464  if (curtarg)
465  if ( isJumpablePlanet( curtarg ) )
466  return;
467  bool wasnull = (curtarg == NULL);
469  lastchangedtarg = 0+targrand.uniformInc( 0, 1 )*mintimetoswitch; //spread out next valid time to switch targets - helps to ease per-frame loads.
470  if (fg) {
471  if ( !fg->directive.empty() )
472  if ( curtarg != NULL && ( *fg->directive.begin() ) == toupper( *fg->directive.begin() ) )
473  return;
474  }
475  //not allowed to switch targets
476  numprocessed++;
477  vector< TurretBin >tbin;
478  Unit *su = NULL;
479  un_iter subun = parent->getSubUnits();
480  for (; (su = *subun) != NULL; ++subun) {
481  static unsigned int inert = ROLES::getRole( "INERT" );
482  static unsigned int pointdef = ROLES::getRole( "POINTDEF" );
483  static bool assignpointdef =
484  XMLSupport::parse_bool( vs_config->getVariable( "AI", "Targetting", "AssignPointDef", "true" ) );
485  if ( (su->attackPreference() != pointdef) || assignpointdef ) {
486  if (su->attackPreference() != inert) {
487  AssignTBin( su, tbin );
488  } else {
489  Unit *ssu = NULL;
490  for (un_iter subturret = su->getSubUnits(); ( ssu = (*subturret) ); ++subturret)
491  AssignTBin( ssu, tbin );
492  }
493  }
494  }
495  std::sort( tbin.begin(), tbin.end() );
496  float efrel = 0;
497  float mytargrange = FLT_MAX;
498  static float unitRad =
499  XMLSupport::parse_float( vs_config->getVariable( "AI", "Targetting", "search_extra_radius", "1000" ) ); //Maximum target radius that is guaranteed to be detected
500  static char maxrolepriority =
501  XMLSupport::parse_int( vs_config->getVariable( "AI", "Targetting", "search_max_role_priority", "16" ) );
502  static int maxtargets = XMLSupport::parse_int( vs_config->getVariable( "AI", "Targetting", "search_max_candidates", "64" ) ); //Cutoff candidate count (if that many hostiles found, stop search - performance/quality tradeoff, 0=no cutoff)
504  StaticTuple< float, 2 >maxranges;
505 
506  maxranges[0] = gunrange;
507  maxranges[1] = missilerange;
508  if ( tbin.size() )
509  maxranges[0] = (tbin[0].maxrange > gunrange ? tbin[0].maxrange : gunrange);
510  double pretable = queryTime();
511  unitLocator.action.init( this, parent, gunrange, &tbin, maxranges, maxrolepriority, maxtargets );
512  static int gcounter = 0;
513  static int min_rechoose_interval = XMLSupport::parse_int( vs_config->getVariable( "AI", "min_rechoose_interval", "128" ) );
514  if (curtarg) {
515  if (gcounter++ < min_rechoose_interval || rand()/8 < RAND_MAX/9) {
516  //in this case only look at potentially *interesting* units rather than huge swaths of nearby units...including target, threat, players, and leader's target
517  unitLocator.action.ShouldTargetUnit( curtarg, UnitUtil::getDistance( parent, curtarg ) );
518  unsigned int np = _Universe->numPlayers();
519  for (unsigned int i = 0; i < np; ++i) {
520  Unit *playa = _Universe->AccessCockpit( i )->GetParent();
521  if (playa)
522  unitLocator.action.ShouldTargetUnit( playa, UnitUtil::getDistance( parent, playa ) );
523  }
525  if (lead != NULL && lead != parent && ( lead = lead->Target() ) != NULL)
526  unitLocator.action.ShouldTargetUnit( lead, UnitUtil::getDistance( parent, lead ) );
527  Unit *threat = parent->Threat();
528  if (threat)
529  unitLocator.action.ShouldTargetUnit( threat, UnitUtil::getDistance( parent, threat ) );
530  } else {
531  gcounter = 0;
532  }
533  }
534  if (unitLocator.action.mytarg == NULL) //decided to rechoose or did not have initial target
535  findObjects(
537  Unit *mytarg = unitLocator.action.mytarg;
538  targetpick += queryTime()-pretable;
539  if (mytarg) {
540  efrel = parent->getRelation( mytarg );
541  mytargrange = UnitUtil::getDistance( parent, mytarg );
542  }
543  TargetAndRange my_target( mytarg, mytargrange, efrel );
544  for (vector< TurretBin >::iterator k = tbin.begin(); k != tbin.end(); ++k)
545  k->AssignTargets( my_target, parent->cumulative_transformation_matrix );
546  parent->LockTarget( false );
547  if (wasnull) {
548  if (mytarg) {
549  nextframenumpollers[hastarg] += 2;
550  if (nextframenumpollers[hastarg] > maxnumpollers)
551  nextframenumpollers[hastarg] = maxnumpollers;
552  } else {
553  lastchangedtarg += targrand.uniformInc( 0, 1 )*minnulltimetoswitch;
554  nextframenumpollers[hastarg] -= .05;
555  if (nextframenumpollers[hastarg] < minnumpollers)
556  nextframenumpollers[hastarg] = minnumpollers;
557  }
558  } else {
559  if (parent->Target() != mytarg) {
560  nextframenumpollers[hastarg] += 2;
561  if (nextframenumpollers[hastarg] > maxnumpollers)
562  nextframenumpollers[hastarg] = maxnumpollers;
563  } else {
564  nextframenumpollers[hastarg] -= .01;
565  if (nextframenumpollers[hastarg] < minnumpollers)
566  nextframenumpollers[hastarg] = minnumpollers;
567  }
568  }
569  parent->Target( mytarg );
570  parent->LockTarget( true );
572 }
void FireAt::Cloak ( bool  enable,
float  seconds 
)

Definition at line 99 of file hard_coded_scripts.cpp.

100 {
101  lastOrder = new CloakFor( enable, seconds );
102 }
void FireAt::Execute ( )
virtual

The function that gets called and executes all queued suborders.

Reimplemented from Order.

Reimplemented in Orders::AggressiveAI, and Orders::Ikarus.

Definition at line 700 of file fire.cpp.

References Unit::CloakVisible(), done, Order::Execute(), float, Unit::GetHull(), VegaConfig::getVariable(), int, XMLSupport::parse_float(), SIMULATION_ATOM, Unit::Target(), UNITPTR, and vs_config.

Referenced by Orders::AggressiveAI::Execute().

701 {
703  bool missilelock = false;
704  bool tmp = done;
705  Order::Execute();
706  done = tmp;
707  Unit *targ;
708  if (parent->isUnit() == UNITPTR) {
709  static float cont_update_time = XMLSupport::parse_float( vs_config->getVariable( "AI", "ContrabandUpdateTime", "1" ) );
710  if (rand() < RAND_MAX*SIMULATION_ATOM/cont_update_time)
712  static float cont_initiate_time = XMLSupport::parse_float( vs_config->getVariable( "AI", "CommInitiateTime", "300" ) );
713  if ( (float) rand() < ( (float) RAND_MAX*(SIMULATION_ATOM/cont_initiate_time) ) ) {
714  static float contraband_initiate_time =
715  XMLSupport::parse_float( vs_config->getVariable( "AI", "ContrabandInitiateTime", "3000" ) );
716  static float comm_to_player = XMLSupport::parse_float( vs_config->getVariable( "AI", "CommToPlayerPercent", ".05" ) );
717  static float comm_to_target = XMLSupport::parse_float( vs_config->getVariable( "AI", "CommToTargetPercent", ".25" ) );
718  static float contraband_to_player =
719  XMLSupport::parse_float( vs_config->getVariable( "AI", "ContrabandToPlayerPercent", ".98" ) );
720  static float contraband_to_target =
721  XMLSupport::parse_float( vs_config->getVariable( "AI", "ContrabandToTargetPercent", "0.001" ) );
722 
723  unsigned int modulo = ( (unsigned int) (contraband_initiate_time/cont_initiate_time) );
724  if (modulo < 1)
725  modulo = 1;
726  if (rand()%modulo)
727  RandomInitiateCommunication( comm_to_player, comm_to_target );
728  else
729  InitiateContrabandSearch( contraband_to_player, contraband_to_target );
730  }
731  }
732  bool shouldfire = false;
733  bool istargetjumpableplanet = false;
734  if ( ( targ = parent->Target() ) ) {
735  istargetjumpableplanet = isJumpablePlanet( targ );
736  if (targ->CloakVisible() > .8 && targ->GetHull() >= 0) {
737  had_target = true;
738  if (parent->GetNumMounts() > 0)
739  if (!istargetjumpableplanet)
740  shouldfire |= ShouldFire( targ, missilelock );
741  } else {
742  if (had_target) {
743  had_target = false;
744  lastchangedtarg = -100000;
745  }
746  ChooseTarget();
747  }
748  } else if (had_target) {
749  had_target = false;
750  lastchangedtarg = -100000;
751  }
752  PossiblySwitchTarget( istargetjumpableplanet );
753  if ( (!istargetjumpableplanet) && parent->GetNumMounts() > 0 )
754  FireWeapons( shouldfire, missilelock );
755 }
void FireAt::ExecuteLastScriptFor ( float  time)

Definition at line 58 of file hard_coded_scripts.cpp.

59 {
60  if (lastOrder)
61  lastOrder = new ExecuteFor( lastOrder, time );
62 }
void FireAt::FaceDirection ( float  distToMatchFacing,
bool  finish 
)

Definition at line 111 of file hard_coded_scripts.cpp.

112 {
113  lastOrder = new Orders::FaceDirection( distToMatchFacing, finish, 3 );
114 }
void FireAt::FaceTarget ( bool  end)

Definition at line 63 of file hard_coded_scripts.cpp.

References FaceTarget().

64 {
65  lastOrder = new Orders::FaceTarget( end, 4 );
66 }
void FireAt::FaceTargetITTS ( bool  end)

Definition at line 67 of file hard_coded_scripts.cpp.

68 {
69  lastOrder = new Orders::FaceTargetITTS( end, 4 );
70 }
void FireAt::FireWeapons ( bool  shouldfire,
bool  lockmissile 
)
protected

Definition at line 660 of file fire.cpp.

References FireBitmask(), UniverseUtil::GetGameTime(), VegaConfig::getVariable(), XMLSupport::parse_float(), SIMULATION_ATOM, and vs_config.

661 {
662  static float missiledelay = XMLSupport::parse_float( vs_config->getVariable( "AI", "MissileGunDelay", "4" ) );
663  bool fire_missile = lockmissile && rand() < RAND_MAX*missileprobability*SIMULATION_ATOM;
665  if ( shouldfire && delay < parent->pilot->getReactionTime() )
666  return;
667  else if (!shouldfire)
668  delay = 0;
669  if (fire_missile)
671  else if (UniverseUtil::GetGameTime()-lastmissiletime < missiledelay && !fire_missile)
672  return;
673  parent->Fire( FireBitmask( parent, shouldfire, fire_missile ), true );
674 }
void FireAt::FormUp ( QVector  pos)

Definition at line 103 of file hard_coded_scripts.cpp.

104 {
105  lastOrder = new Orders::FormUp( pos );
106 }
void FireAt::FormUpToOwner ( QVector  pos)

Definition at line 107 of file hard_coded_scripts.cpp.

108 {
109  lastOrder = new Orders::FormUpToOwner( pos );
110 }
Unit* Orders::FireAt::GetParent ( )
inline

Definition at line 55 of file fire.h.

References Order::GetParent().

56  {
58  }
bool FireAt::isJumpablePlanet ( Unit targ)
protected

Definition at line 676 of file fire.cpp.

References Unit::isUnit(), and PLANETPTR.

Referenced by Orders::AggressiveAI::ProcessCurrentFgDirective().

677 {
678  bool istargetjumpableplanet = targ->isUnit() == PLANETPTR;
679  if (istargetjumpableplanet) {
680  istargetjumpableplanet = ( !( (Planet*) targ )->GetDestinations().empty() ) && (parent->GetJumpStatus().drive >= 0);
681  }
682  return istargetjumpableplanet;
683 }
void FireAt::LastPythonScript ( )
void FireAt::MatchAngularVelocity ( bool  terminate,
Vector  vec,
bool  local 
)

Definition at line 76 of file hard_coded_scripts.cpp.

References Unit::ClampAngVel(), Order::parent, and BriefingUtil::terminate().

77 {
79 }
void FireAt::MatchLinearVelocity ( bool  terminate,
Vector  vec,
bool  afterburn,
bool  local 
)

Definition at line 71 of file hard_coded_scripts.cpp.

References Unit::ClampVelocity(), Order::parent, BriefingUtil::terminate(), and useAfterburner().

72 {
73  afterburn = afterburn && useAfterburner();
74  lastOrder = new Orders::MatchLinearVelocity( parent->ClampVelocity( vec, afterburn ), local, afterburn, terminate );
75 }
void FireAt::MatchVelocity ( bool  terminate,
Vector  vec,
Vector  angvel,
bool  afterburn,
bool  local 
)

Definition at line 93 of file hard_coded_scripts.cpp.

References Unit::ClampAngVel(), Unit::ClampVelocity(), MatchVelocity, Order::parent, BriefingUtil::terminate(), and useAfterburner().

94 {
95  afterburn = afterburn && useAfterburner();
97  angvel ), local, afterburn, terminate );
98 }
void FireAt::MoveTo ( QVector  vec,
bool  afterburn 
)

Definition at line 88 of file hard_coded_scripts.cpp.

References MoveTo, and useAfterburner().

89 {
90  afterburn = afterburn && useAfterburner();
91  lastOrder = new Orders::MoveTo( vec, afterburn, 3 );
92 }
virtual std::string Orders::FireAt::Pickle ( )
inlinevirtual

Definition at line 62 of file fire.h.

63  {
64  return std::string();
65  } //these are to serialize this AI
void FireAt::PossiblySwitchTarget ( bool  istargetjumpableplanet)

Definition at line 686 of file fire.cpp.

References Flightgroup::directive, VegaConfig::getVariable(), XMLSupport::parse_float(), SIMULATION_ATOM, VSRandom::uniformInc(), vs_config, and vsrandom.

687 {
688  static float targettime = XMLSupport::parse_float( vs_config->getVariable( "AI", "Targetting", "TimeUntilSwitch", "20" ) );
689  if ( (targettime <= 0) || (vsrandom.uniformInc( 0, 1 ) < SIMULATION_ATOM/targettime) ) {
690  bool ct = true;
691  Flightgroup *fg;
692  if ( ( fg = parent->getFlightgroup() ) )
693  if (fg->directive.find( "." ) != string::npos)
694  ct = (parent->Target() == NULL);
695  if (ct)
696  ChooseTarget();
697  }
698 }
bool FireAt::PursueTarget ( Unit un,
bool  leader 
)
virtual

Reimplemented from Order.

Definition at line 66 of file fire.cpp.

References Unit::getRelation(), Order::parent, and Unit::Target().

67 {
68  if (leader)
69  return true;
70  if ( un == parent->Target() )
71  return rand() < .9*RAND_MAX;
72  if (parent->getRelation( un ) < 0)
73  return rand() < .2*RAND_MAX;
74  return false;
75 }
void FireAt::ReInit ( float  agglevel)
protected

Definition at line 99 of file fire.cpp.

References agg, delay, distance, UniverseUtil::GetGameTime(), VegaConfig::getVariable(), had_target, lastchangedtarg, lastmissiletime, missileprobability, XMLSupport::parse_float(), targrand, VSRandom::uniformInc(), and vs_config.

Referenced by FireAt().

100 {
101  static float missileprob = XMLSupport::parse_float( vs_config->getVariable( "AI", "Firing", "MissileProbability", ".01" ) );
102  static float mintimetoswitch =
103  XMLSupport::parse_float( vs_config->getVariable( "AI", "Targetting", "MinTimeToSwitchTargets", "3" ) );
105  missileprobability = missileprob;
106  delay = 0;
107  agg = aggressivitylevel;
108  distance = 1;
109  //JS --- spreading target switch times
110  lastchangedtarg = 0.0-targrand.uniformInc( 0, 1 )*mintimetoswitch;
111  had_target = false;
112 }
virtual void Orders::FireAt::SetParent ( Unit parent1)
inlinevirtual

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

Reimplemented from Order.

Reimplemented in Orders::AggressiveAI.

Definition at line 51 of file fire.h.

References Order::SetParent().

Referenced by Orders::AggressiveAI::SetParent().

52  {
54  }
bool FireAt::ShouldFire ( Unit targ,
bool missilelock 
)
protected

Definition at line 574 of file fire.cpp.

References _Universe, UniverseUtil::cos(), f, float, VSRandom::genrand_int31(), Unit::GetComputerData(), UniverseUtil::GetGameTime(), VegaConfig::getVariable(), VSRandom::init_genrand(), int, Universe::isPlayerStarship(), Unit::isUnit(), Unit::Computer::itts, M_PI, Cockpit::number_of_attackers, XMLSupport::parse_float(), XMLSupport::parse_int(), PLANETPTR, Unit::Target(), test, Unit::Threaten(), Cockpit::tooManyAttackers(), vs_config, and VSFileSystem::vs_fprintf().

575 {
576  float dist;
577  if (!targ) {
578  return false;
579 
580  static int test = 0;
581  if (test++%1000 == 1)
582  VSFileSystem::vs_fprintf( stderr, "lost target" );
583  }
584  float gunspeed, gunrange, missilerange;
585  parent->getAverageGunSpeed( gunspeed, gunrange, missilerange );
586  float angle = parent->cosAngleTo( targ, dist, parent->GetComputerData().itts ? gunspeed : FLT_MAX, gunrange, false );
587  missilelock = false;
588  targ->Threaten( parent, angle/(dist < .8 ? .8 : dist) );
589  if ( targ == parent->Target() )
590  distance = dist;
591  static float firewhen = XMLSupport::parse_float( vs_config->getVariable( "AI", "Firing", "InWeaponRange", "1.2" ) );
592  static float fireangle_minagg =
594  "Firing",
595  "MaximumFiringAngle.minagg",
596  "10" ) )/180. ); //Roughly 10 degrees
597  static float fireangle_maxagg =
599  "Firing",
600  "MaximumFiringAngle.maxagg",
601  "18" ) )/180. ); //Roughly 18 degrees
602  float temp = parent->TrackingGuns( missilelock );
603  bool isjumppoint = targ->isUnit() == PLANETPTR && ( (Planet*) targ )->GetDestinations().empty() == false;
604  float fangle = (fireangle_minagg+fireangle_maxagg*agg)/(1.0f+agg);
605  bool retval =
606  ( (dist < firewhen)
607  && ( (angle > fangle) || ( temp && (angle > temp) ) || ( missilelock && (angle > 0) ) ) ) && !isjumppoint;
608  if (retval) {
609  if ( Cockpit::tooManyAttackers() ) {
610  Cockpit *player = _Universe->isPlayerStarship( targ );
611  if (player) {
612  static int max_attackers = XMLSupport::parse_int( vs_config->getVariable( "AI", "max_player_attackers", "0" ) );
613  int attackers = player->number_of_attackers;
614  if (attackers > max_attackers && max_attackers > 0) {
615  static float attacker_switch_time =
616  XMLSupport::parse_float( vs_config->getVariable( "AI", "attacker_switch_time", "15" ) );
617  int curtime = (int) fmod( floor( UniverseUtil::GetGameTime()/attacker_switch_time ), (float) (1<<24) );
618  int seed = ( ( ( (size_t) parent )&0xffffffff )^curtime );
619  static VSRandom decide( seed );
620  decide.init_genrand( seed );
621  if (decide.genrand_int31()%attackers >= max_attackers) {
622  return false;
623  }
624  }
625  }
626  }
627  }
628  return retval;
629 }
void FireAt::SignalChosenTarget ( )
protectedvirtual

Reimplemented in Orders::AggressiveAI.

Definition at line 125 of file fire.cpp.

Referenced by Orders::AggressiveAI::SignalChosenTarget().

125 {}
virtual void Orders::FireAt::UnPickle ( std::string  )
inlinevirtual

Definition at line 66 of file fire.h.

66 {}
void FireAt::XMLScript ( std::string  script)

Definition at line 115 of file hard_coded_scripts.cpp.

116 {
117  lastOrder = new AIScript( script.c_str() );
118 }

Member Data Documentation

float Orders::FireAt::agg
protected

Definition at line 17 of file fire.h.

Referenced by ReInit().

float Orders::FireAt::delay
protected

Definition at line 16 of file fire.h.

Referenced by ReInit().

float Orders::FireAt::distance
protected

Definition at line 18 of file fire.h.

Referenced by Orders::AggressiveAI::ProcessLogicItem(), and ReInit().

bool Orders::FireAt::had_target
protected

Definition at line 20 of file fire.h.

Referenced by ReInit().

float Orders::FireAt::lastchangedtarg
protected

Definition at line 19 of file fire.h.

Referenced by ReInit().

float Orders::FireAt::lastmissiletime
protected

Definition at line 15 of file fire.h.

Referenced by ReInit().

float Orders::FireAt::missileprobability
protected

Definition at line 14 of file fire.h.

Referenced by ReInit().


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