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
aggressive.cpp File Reference
#include "config.h"
#include "aggressive.h"
#include "event_xml.h"
#include "script.h"
#include <list>
#include <vector>
#include "vs_globals.h"
#include "config_xml.h"
#include "xml_support.h"
#include "cmd/unit_generic.h"
#include "communication.h"
#include "cmd/script/flightgroup.h"
#include "flybywire.h"
#include "hard_coded_scripts.h"
#include "cmd/script/mission.h"
#include "gfx/cockpit_generic.h"
#include "lin_time.h"
#include "faction_generic.h"
#include "cmd/role_bitmask.h"
#include "cmd/unit_util.h"
#include "warpto.h"
#include "cmd/csv.h"
#include "universe_util.h"
#include "vs_random.h"
#include "python/python_compile.h"
#include "cmd/unit_find.h"
#include "docking.h"

Go to the source code of this file.

Classes

class  FlyTo
 

Functions

bool CheckAccessory (Unit *tur)
 
static void TurretFAW (Unit *parent)
 
static vsUMap< string, string > getAITypes ()
 
static string select_from_space_list (string inp, unsigned int seed)
 
static AIEvents::ElemAttrMapgetLogicOrInterrupt (string name, int faction, string unittype, vsUMap< string, AIEvents::ElemAttrMap * > &mymap, int personalityseed)
 
static AIEvents::ElemAttrMapgetProperLogicOrInterruptScript (string name, int faction, string unittype, bool interrupt, int personalityseed)
 
static AIEvents::ElemAttrMapgetProperScript (Unit *me, Unit *targ, bool interrupt, int personalityseed)
 
std::string GetRelationshipColor (float rel)
 
unsigned int DoSpeech (Unit *un, Unit *player_un, const FSM::Node &node)
 
void LeadMe (Unit *un, string directive, string speech, bool changetarget)
 
UnitGetThreat (Unit *parent, Unit *leader)
 
static bool overridable (const std::string &s)
 
static UnitGetRandomNav (vector< UnitContainer >navs[3], unsigned int randnum)
 
static std::string insysString ("Insys")
 
static std::string arrowString ("->")
 
static UnitChooseNavPoint (Unit *parent, Unit **otherdest, float *lurk_on_arrival)
 
static UnitChooseNearNavPoint (Unit *parent, Unit *suggestion, QVector location, float locradius)
 
bool CloseEnoughToNavOrDest (Unit *parent, Unit *navUnit, QVector nav)
 
static Vector randVector ()
 
static void GoTo (AggressiveAI *ai, Unit *parent, const QVector &nav, float creationtime, bool boonies=false, Unit *destUnit=NULL)
 

Variables

double aggfire
 
const EnumMap::Pair element_names []
 
const EnumMap AggressiveAIel_map (element_names, 25)
 
vsUMap< string,
AIEvents::ElemAttrMap * > 
logic
 
static float aggressivity = 2.01
 
static int randomtemp
 
volatile Unituoif
 
volatile Unituoi
 
AggressiveAIDONOTUSEAG = NULL
 

Function Documentation

static std::string arrowString ( "->"  )
static

Referenced by ChooseNavPoint().

bool CheckAccessory ( Unit tur)

Definition at line 1348 of file unit_generic.cpp.

Referenced by AddSubUnits(), Unit::LoadRow(), Unit::SetTurretAI(), TurretFAW(), and Unit::TurretFAW().

1349 {
1350  bool accessory = tur->name.get().find( "accessory" ) != string::npos;
1351  if (accessory) {
1354  tur->GetComputerData().max_roll_right ) ) );
1355  }
1356  return accessory;
1357 }
static Unit* ChooseNavPoint ( Unit parent,
Unit **  otherdest,
float lurk_on_arrival 
)
static

Definition at line 1240 of file aggressive.cpp.

References _Universe, a, Universe::activeStarSystem(), arrowString(), b, CompileRunPython(), Unit::UnitJump::drive, StarSystem::Statistics::enemycount, Unit::faction, float, StarSystem::Statistics::friendlycount, VSRandom::genrand_int31(), Unit::GetComputerData(), UnitUtil::getDistance(), StarSystem::getFileName(), UnitUtil::getFlightgroupName(), Unit::GetJumpStatus(), getNewTime(), GetRandomNav(), UnitUtil::getRelationFromFaction(), UniverseUtil::getScratchUnit(), VegaConfig::getVariable(), i, insysString(), int, FactionUtil::isCitizenInt(), StarSystem::Statistics::jumpPoints, k, Unit::Computer::RADARLIM::maxrange, StarSystem::Statistics::navs, XMLSupport::parse_bool(), XMLSupport::parse_float(), XMLSupport::parse_int(), Unit::Computer::radar, UniverseUtil::setScratchUnit(), start, StarSystem::stats, StarSystem::Statistics::system_faction, VSRandom::uniformExc(), vs_config, and vsrandom.

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

1241 {
1242  static string script = vs_config->getVariable( "AI", "ChooseDestinationScript", "" );
1243  *lurk_on_arrival = 0;
1244  if (script.length() > 0) {
1245  Unit *ret = NULL;
1246  UniverseUtil::setScratchUnit( parent );
1247  CompileRunPython( script );
1250  if (ret != NULL && ret != parent)
1251  return ret;
1252  }
1254  StarSystem::Statistics *stats = &ss->stats;
1255 
1256  float sysrel = UnitUtil::getRelationFromFaction( parent, stats->system_faction );
1257  static float lurk_time = XMLSupport::parse_float( vs_config->getVariable( "AI", "lurk_time", "600" ) );
1258  static float select_time = XMLSupport::parse_float( vs_config->getVariable( "AI", "fg_nav_select_time", "120" ) );
1259  static float hostile_select_time = XMLSupport::parse_float( vs_config->getVariable( "AI", "pirate_nav_select_time", "400" ) );
1260  static int num_ships_per_roid =
1261  XMLSupport::parse_int( vs_config->getVariable( "AI", "num_pirates_per_asteroid_field", "12" ) );
1262  bool civilian = FactionUtil::isCitizenInt( parent->faction );
1263 
1264  bool hostile = sysrel < 0;
1265  bool anarchy = stats->enemycount > stats->friendlycount;
1266  float timehash = select_time;
1267  if (hostile && !anarchy)
1268  timehash = hostile_select_time;
1269  unsigned int firstRand, thirdRand;
1270  float secondRand;
1271  const unsigned int maxrand = 5;
1272  unsigned int additionalrand[maxrand];
1273  if (civilian) {
1274  firstRand = vsrandom.genrand_int31();
1275  secondRand = vsrandom.uniformExc( 0, 1 );
1276  thirdRand = vsrandom.genrand_int31();
1277  for (unsigned int i = 0; i < maxrand; ++i)
1278  additionalrand[i] = thirdRand+i;
1279  } else {
1280  int k = (int) (getNewTime()/timehash); //two minutes
1281  string key = UnitUtil::getFlightgroupName( parent );
1282  std::string::const_iterator start = key.begin();
1283  for (; start != key.end(); start++)
1284  k += (k*128)+*start;
1285  VSRandom choosePlace( k );
1286  firstRand = choosePlace.genrand_int31();
1287  secondRand = choosePlace.uniformExc( 0, 1 );
1288  thirdRand = choosePlace.genrand_int31();
1289  for (unsigned int i = 0; i < maxrand; ++i)
1290  additionalrand[i] = choosePlace.genrand_int31();
1291  }
1292  bool asteroidhide = false;
1293  if (stats->friendlycount > 0 && stats->enemycount > 0)
1294  asteroidhide = (secondRand < stats->enemycount/(float) stats->friendlycount)
1295  && (secondRand < num_ships_per_roid*stats->navs[2].size()/(float) stats->enemycount);
1296  bool siege = stats->enemycount > 2*stats->friendlycount; //rough approx
1297  int whichlist = 1; //friendly
1298  std::string fgname = UnitUtil::getFlightgroupName( parent );
1299 
1300  bool insys = (parent->GetJumpStatus().drive == -2) || fgname.find( insysString ) != std::string::npos;
1301  std::string::size_type whereconvoy = fgname.find( arrowString );
1302  bool convoy = (whereconvoy != std::string::npos);
1303  size_t total_size = stats->navs[0].size()+stats->navs[whichlist].size(); //friendly and neutral
1304  static bool bad_units_lurk = XMLSupport::parse_bool( vs_config->getVariable( "AI", "hostile_lurk", "true" ) );
1305  if (hostile && bad_units_lurk) {
1306  if (anarchy && !siege) {
1307  whichlist = 2;
1308  total_size = stats->navs[0].size()+stats->navs[whichlist].size(); //asteroids and neutrals
1309  } else {
1310  whichlist = 2;
1311  total_size = stats->navs[whichlist].size(); //just asteroids
1312  }
1313  } else if (civilian) {
1314  if (anarchy || siege) {
1315  whichlist = 0;
1316  total_size = stats->navs[0].size();
1317  } else if (insys || convoy) {
1318  whichlist = 1;
1319  total_size = stats->navs[1].size(); //don't go to jump point
1320  }
1321  }
1322  if (hostile && ( (anarchy == false && asteroidhide == false) || total_size == 0 ) && civilian == false && bad_units_lurk) {
1323  //hit and run
1324  Unit *a = GetRandomNav( stats->navs, firstRand );
1325  Unit *b = GetRandomNav( stats->navs, thirdRand );
1326  if (a == b)
1327  b = GetRandomNav( stats->navs, thirdRand+1 );
1328  if (a != b) {
1329  int retrycount = maxrand;
1330  while ( --retrycount > 0 && (UnitUtil::getDistance( a, b ) < parent->GetComputerData().radar.maxrange*4 || a == b) )
1331  b = GetRandomNav( stats->navs, additionalrand[retrycount] );
1332  if (retrycount != 0) {
1333  *otherdest = b;
1334  *lurk_on_arrival = lurk_time;
1335  }
1336  }
1337  return a;
1338  } else {
1339  if (convoy) {
1340  std::string srcdst[2] = {fgname.substr( 0, whereconvoy ), fgname.substr( whereconvoy+2 )};
1341  if ( srcdst[0] == ss->getFileName() )
1342  srcdst[0] = srcdst[1];
1343  if ( srcdst[1] == ss->getFileName() )
1344  srcdst[1] = srcdst[0];
1345  if (thirdRand < 2) {
1346  vsUMap< std::string, UnitContainer >::iterator i = stats->jumpPoints.find( srcdst[thirdRand] );
1347  if ( i != stats->jumpPoints.end() ) {
1348  Unit *un = i->second.GetUnit();
1349  if (un)
1350  return un;
1351  } else {
1352  total_size = stats->navs[whichlist].size()+stats->navs[0].size(); //no such jump point--have to random-walk it
1353  //maybe one day we can incorporate some sort of route planning
1354  }
1355  }
1356  }
1357  if (total_size > 0) {
1358  firstRand %= total_size;
1359  if ( firstRand >= stats->navs[whichlist].size() ) {
1360  firstRand -= stats->navs[whichlist].size();
1361  whichlist = 0; //allows you to look for both neutral and ally lists
1362  }
1363  return stats->navs[whichlist][firstRand].GetUnit();
1364  }
1365  }
1366  return NULL;
1367 }
static Unit* ChooseNearNavPoint ( Unit parent,
Unit suggestion,
QVector  location,
float  locradius 
)
static

Definition at line 1369 of file aggressive.cpp.

References _Universe, Universe::activeStarSystem(), StarSystem::collidemap, UnitCollection::createIterator(), findObjects(), StarSystem::getUnitList(), i, UnitUtil::isSignificant(), Unit::location, Magnitude(), Unit::Position(), NearestUnitLocator::retval, Unit::rSize(), Collidable::CollideRef::unit, and Unit::UNIT_ONLY.

Referenced by FlyTo::Execute(), and Orders::AggressiveAI::ExecuteNoEnemies().

1370 {
1371  if (suggestion) return suggestion;
1372  Unit *candidate = NULL;
1373  float dist = FLT_MAX;
1374  Unit *un;
1377  parent->location[Unit::UNIT_ONLY],
1378  &nnl );
1379  return nnl.retval.unit;
1380  //DEAD CODE
1382  (un = *i) != NULL;
1383  ++i)
1384  if (UnitUtil::isSignificant( un ) && un != parent) {
1385  float newdist = ( location-un->Position() ).Magnitude()-un->rSize()-locradius;
1386  if (candidate == NULL || newdist <= dist) {
1387  candidate = un;
1388  dist = newdist;
1389  }
1390  }
1391  return candidate;
1392  //END DEAD CODE
1393 }
bool CloseEnoughToNavOrDest ( Unit parent,
Unit navUnit,
QVector  nav 
)

Definition at line 1395 of file aggressive.cpp.

References UnitUtil::getDistance(), VegaConfig::getVariable(), Unit::isUnit(), XMLSupport::parse_float(), PLANETPTR, Unit::Position(), Unit::predicted_priority, Unit::rSize(), and vs_config.

Referenced by FlyTo::Execute(), and Orders::AggressiveAI::ExecuteNoEnemies().

1396 {
1397  static float how_far_to_stop_moving =
1398  XMLSupport::parse_float( vs_config->getVariable( "AI", "how_far_to_stop_navigating", "100" ) );
1399  if (navUnit && navUnit->isUnit() != PLANETPTR) {
1400  float dist = UnitUtil::getDistance( navUnit, parent );
1401  if (dist < SIMULATION_ATOM*parent->Velocity.Magnitude()*parent->predicted_priority*how_far_to_stop_moving)
1402  return true;
1403  }
1404  return ( nav-parent->Position() ).MagnitudeSquared() < 4*parent->rSize()*parent->rSize();
1405 }
unsigned int DoSpeech ( Unit un,
Unit player_un,
const FSM::Node node 
)

Definition at line 199 of file aggressive.cpp.

References MessageCenter::add(), Unit::getFgSubnumber(), Unit::getFlightgroup(), Unit::getFullname(), FSM::Node::GetMessage(), Unit::getRelation(), GetRelationshipColor(), Unit::isUnit(), FSM::Node::messagedelta, mission, Mission::msgcenter, Flightgroup::name, Unit::name, PLANETPTR, and XMLSupport::tostring().

Referenced by FireKeyboard::DoSpeechAndAni(), FireKeyboard::Execute(), HelpOut(), LeadMe(), and FireKeyboard::ProcessCommMessage().

200 {
201  unsigned int dummy = 0;
202  string speech = node.GetMessage( dummy );
203  string myname( "[Static]" );
204  if (un != NULL) {
205  myname = un->isUnit() == PLANETPTR ? un->name : un->getFullname();
206  Flightgroup *fg = un->getFlightgroup();
207  if (fg && fg->name != "base" && fg->name != "Base")
208  myname = fg->name+" "+XMLSupport::tostring( un->getFgSubnumber() )+", "+un->getFullname();
209  else if (myname.length() == 0)
210  myname = un->name;
211  if (player_un != NULL) {
212  if (player_un == un) {
213  myname = std::string( "#0033FF" )+myname+"#000000";
214  } else {
215  float rel = un->getRelation( player_un );
216  myname = GetRelationshipColor( rel )+myname+"#000000";
217  }
218  }
219  }
220  mission->msgcenter->add( myname, "all", GetRelationshipColor( node.messagedelta*10 )+speech+"#000000" ); //multiply by 2 so colors are easier to tell
221  return dummy;
222 }
static vsUMap< string, string > getAITypes ( )
static

Definition at line 83 of file aggressive.cpp.

References VSFileSystem::AiFile, VSFileSystem::VSFile::Close(), f, VSFileSystem::VSFile::GetRoot(), i, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), and CSVTable::rows.

Referenced by getLogicOrInterrupt().

84 {
85  vsUMap< string, string >ret;
87  VSError err = f.OpenReadOnly( "VegaPersonalities.csv", AiFile );
88  if (err <= Ok) {
89  CSVTable table( f, f.GetRoot() );
90  vsUMap< std::string, int >::iterator browser = table.rows.begin();
91  for (; browser != table.rows.end(); ++browser) {
92  string rowname = (*browser).first;
93  CSVRow row( &table, rowname );
94  for (unsigned int i = 1; i < table.key.size(); ++i) {
95  string hasher = rowname;
96  if (i != 1)
97  hasher = rowname+"%"+table.key[i];
98  string rawrow = row[i];
99  if (rawrow.length() > 0)
100  ret[hasher] = rawrow;
101  }
102  }
103  f.Close();
104  }
105  return ret;
106 }
static AIEvents::ElemAttrMap* getLogicOrInterrupt ( string  name,
int  faction,
string  unittype,
vsUMap< string, AIEvents::ElemAttrMap * > &  mymap,
int  personalityseed 
)
static

Definition at line 134 of file aggressive.cpp.

References AggressiveAIel_map, getAITypes(), FactionUtil::GetFaction(), i, AIEvents::LoadAI(), and select_from_space_list().

Referenced by getProperLogicOrInterruptScript().

139 {
140  string append = "agg";
141  static vsUMap< string, string >myappend = getAITypes();
142  vsUMap< string, string >::iterator iter;
143  string factionname = FactionUtil::GetFaction( faction );
144  if ( ( iter = myappend.find( factionname+"%"+unittype ) ) != myappend.end() )
145  append = select_from_space_list( (*iter).second, personalityseed );
146  else if ( ( iter = myappend.find( factionname ) ) != myappend.end() )
147  append = select_from_space_list( (*iter).second, personalityseed );
148  if (append.length() == 0) append = "agg";
149  string hashname = name+"."+append;
150  vsUMap< string, AIEvents::ElemAttrMap* >::iterator i = mymap.find( hashname );
151  if ( i == mymap.end() ) {
153  string filename( name+"."+append+".xml" );
154  AIEvents::LoadAI( filename.c_str(), *attr, FactionUtil::GetFaction( faction ) );
155  mymap.insert( pair< string, AIEvents::ElemAttrMap* > ( hashname, attr ) );
156  return attr;
157  }
158  return i->second;
159 }
static AIEvents::ElemAttrMap* getProperLogicOrInterruptScript ( string  name,
int  faction,
string  unittype,
bool  interrupt,
int  personalityseed 
)
static

Definition at line 161 of file aggressive.cpp.

References getLogicOrInterrupt(), and logic.

Referenced by getProperScript().

166 {
167  return getLogicOrInterrupt( name, faction, unittype, logic, personalityseed );
168 }
static AIEvents::ElemAttrMap* getProperScript ( Unit me,
Unit targ,
bool  interrupt,
int  personalityseed 
)
static

Definition at line 170 of file aggressive.cpp.

References Unit::attackPreference(), Unit::faction, getProperLogicOrInterruptScript(), ROLES::getRoleEvents(), Unit::name, and Unit::unitRole().

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

171 {
172  if (!me || !targ) {
173  string nam = "eject";
174  int fac = 0;
175  if (me) {
176  fac = me->faction;
177  nam = me->name;
178  }
179  return getProperLogicOrInterruptScript( "default", fac, nam, interrupt, personalityseed );
180  }
182  targ->unitRole() ), me->faction, me->name, interrupt,
183  personalityseed );
184 }
static Unit* GetRandomNav ( vector< UnitContainer navs[3],
unsigned int  randnum 
)
static

Definition at line 1220 of file aggressive.cpp.

References size.

Referenced by ChooseNavPoint().

1221 {
1222  size_t total_size = navs[0].size()+navs[1].size()+navs[2].size();
1223  if (total_size == 0) return NULL;
1224  randnum %= total_size;
1225  if ( randnum >= navs[0].size() ) {
1226  randnum -= navs[0].size();
1227  if ( randnum >= navs[1].size() ) {
1228  randnum -= navs[1].size();
1229  return navs[2][randnum].GetUnit();
1230  }
1231  return navs[1][randnum].GetUnit();
1232  }
1233  return navs[0][randnum].GetUnit();
1234 }
std::string GetRelationshipColor ( float  rel)
inline

Definition at line 186 of file aggressive.cpp.

Referenced by DoSpeech().

187 {
188  if (rel >= 1)
189  return "#00FF00";
190  if (rel <= -1)
191  return "#FF0000";
192  rel += 1.;
193  rel /= 2.;
194  char str[20]; //Just in case all 8 digits of both #s end up inside the string for some reason.
195  sprintf( str, "#%2X%2X00", (int) ( (1-rel)*256 ), (int) (rel*256) );
196  return str;
197 }
Unit* GetThreat ( Unit parent,
Unit leader 
)

Definition at line 574 of file aggressive.cpp.

References _Universe, Universe::activeStarSystem(), UnitCollection::createIterator(), d, Unit::getRelation(), StarSystem::getUnitList(), Magnitude(), Unit::Position(), and Unit::Target().

Referenced by HelpOut(), and Orders::AggressiveAI::ProcessCurrentFgDirective().

575 {
576  Unit *th = NULL;
577  Unit *un = NULL;
578  bool targetted = false;
579  float mindist = FLT_MAX;
581  (un = *ui);
582  ++ui)
583  if (parent->getRelation( un ) < 0) {
584  float d = ( un->Position()-leader->Position() ).Magnitude();
585  bool thistargetted = (un->Target() == leader);
586  if ( !th || (thistargetted && !targetted) || ( ( thistargetted || (!targetted) ) && d < mindist ) ) {
587  th = un;
588  targetted = thistargetted;
589  mindist = d;
590  }
591  }
592  return th;
593 }
static void GoTo ( AggressiveAI ai,
Unit parent,
const QVector nav,
float  creationtime,
bool  boonies = false,
Unit destUnit = NULL 
)
static

Definition at line 1452 of file aggressive.cpp.

References Order::EnqueueOrder(), Order::eraseType(), f, Order::FACING, VegaConfig::getVariable(), Order::MOVEMENT, XMLSupport::parse_bool(), Order::ReplaceOrder(), Order::SetParent(), and vs_config.

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

1458 {
1459  static bool can_afterburn = XMLSupport::parse_bool( vs_config->getVariable( "AI", "afterburn_to_no_enemies", "true" ) );
1460  Order *mt = new FlyTo( nav, can_afterburn, true, creationtime, boonies ? 16 : 6, destUnit );
1461  Order *ch = new Orders::ChangeHeading( nav, 32, .25f, false );
1462  ai->eraseType( Order::FACING );
1463  ai->eraseType( Order::MOVEMENT );
1464  mt->SetParent( parent );
1465  ch->SetParent( parent );
1466  ai->ReplaceOrder( mt );
1467  ai->EnqueueOrder( ch );
1468 }
static std::string insysString ( "Insys"  )
static
void LeadMe ( Unit un,
string  directive,
string  speech,
bool  changetarget 
)

Definition at line 224 of file aggressive.cpp.

References _Universe, Universe::AccessCockpit(), Flightgroup::directive, DoSpeech(), Unit::getFlightgroup(), Cockpit::GetParent(), UnitContainer::GetUnit(), i, Universe::isPlayerStarship(), Flightgroup::leader, FSM::Node::MakeNode(), Universe::numPlayers(), UnitContainer::SetUnit(), Flightgroup::target, and Unit::Target().

Referenced by FireKeyboard::AttackTarget(), FireKeyboard::BreakFormation(), FireKeyboard::DefendTarget(), FireKeyboard::DockTarget(), FireKeyboard::DockWithMe(), FireKeyboard::EjectKey(), FireKeyboard::FormUp(), FireKeyboard::HelpMeOut(), FireKeyboard::HoldPosition(), LeadMe(), and Orders::AggressiveAI::ReCommandWing().

225 {
226  if (un != NULL) {
227  for (unsigned int i = 0; i < _Universe->numPlayers(); i++) {
228  Unit *pun = _Universe->AccessCockpit( i )->GetParent();
229  if (pun)
230  if ( pun->getFlightgroup() == un->getFlightgroup() )
231  DoSpeech( un, pun, FSM::Node::MakeNode( speech, .1 ) );
232  }
233  Flightgroup *fg = un->getFlightgroup();
234  if (fg) {
235  if (fg->leader.GetUnit() != un)
236  if ( ( !_Universe->isPlayerStarship( fg->leader.GetUnit() ) ) || _Universe->isPlayerStarship( un ) )
237  fg->leader.SetUnit( un );
238  fg->directive = directive;
239  if (changetarget)
240  fg->target.SetUnit( un->Target() );
241  if ( (directive == "") )
242  fg->target.SetUnit( NULL );
243  }
244  }
245 }
static bool overridable ( const std::string &  s)
static

Definition at line 1183 of file aggressive.cpp.

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

1184 {
1185  if ( s.empty() )
1186  return true;
1187  return ( *s.begin() ) != toupper( *s.begin() );
1188 }
static Vector randVector ( )
static

Definition at line 1447 of file aggressive.cpp.

References Vector.

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

1448 {
1449  return Vector( (rand()/(float) RAND_MAX)*2-1, (rand()/(float) RAND_MAX)*2-1, (rand()/(float) RAND_MAX)*2-1 );
1450 }
static string select_from_space_list ( string  inp,
unsigned int  seed 
)
static

Definition at line 108 of file aggressive.cpp.

References i, and j.

Referenced by getLogicOrInterrupt().

109 {
110  if (inp.length() == 0)
111  return "";
112  int count = 1;
113  string::size_type len = inp.length();
114  for (unsigned int i = 0; i < len; ++i)
115  if (inp[i] == ' ')
116  count++;
117  count = seed%count;
118  int ncount = 0;
119  unsigned int j;
120  for (j = 0; j < len; ++j) {
121  if (inp[j] == ' ')
122  ncount++;
123  if (ncount >= count)
124  break;
125  }
126  if (inp[j] == ' ')
127  j++;
128  inp = inp.substr( j );
129  if ( ( len = inp.find( " " ) ) != string::npos )
130  inp = inp.substr( 0, len );
131  return inp;
132 }
static void TurretFAW ( Unit parent)
static

Definition at line 69 of file aggressive.cpp.

References CheckAccessory(), Unit::EnqueueAIFirst(), f, and Unit::getSubUnits().

Referenced by Unit::EjectCargo(), and Orders::AggressiveAI::ProcessCurrentFgDirective().

70 {
71  un_iter iter = parent->getSubUnits();
72  Unit *un;
73  while ( NULL != (un = *iter) ) {
74  if ( !CheckAccessory( un ) ) {
75  un->EnqueueAIFirst( new Orders::FireAt( 15.0f ) );
76  un->EnqueueAIFirst( new Orders::FaceTarget( false, 3 ) );
77  }
78  TurretFAW( un );
79  ++iter;
80  }
81 }

Variable Documentation

double aggfire
const EnumMap AggressiveAIel_map(element_names, 25)

Referenced by getLogicOrInterrupt().

float aggressivity = 2.01
static

Definition at line 247 of file aggressive.cpp.

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

AggressiveAI* DONOTUSEAG = NULL

Definition at line 1712 of file aggressive.cpp.

const EnumMap::Pair element_names[]
Initial value:
= {
EnumMap::Pair( "AggressiveAI", AggressiveAI::AGGAI ),
EnumMap::Pair( "MeterDistance", AggressiveAI::METERDISTANCE ),
EnumMap::Pair( "Threat", AggressiveAI::THREAT ),
EnumMap::Pair( "FShield", AggressiveAI::FSHIELD ),
EnumMap::Pair( "LShield", AggressiveAI::LSHIELD ),
EnumMap::Pair( "RShield", AggressiveAI::RSHIELD ),
EnumMap::Pair( "BShield", AggressiveAI::BSHIELD ),
EnumMap::Pair( "Facing", AggressiveAI::FACING ),
EnumMap::Pair( "Movement", AggressiveAI::MOVEMENT ),
EnumMap::Pair( "FShield_Heal_Rate", AggressiveAI::FSHIELD_HEAL_RATE ),
EnumMap::Pair( "BShield_Heal_Rate", AggressiveAI::BSHIELD_HEAL_RATE ),
EnumMap::Pair( "LShield_Heal_Rate", AggressiveAI::LSHIELD_HEAL_RATE ),
EnumMap::Pair( "RShield_Heal_Rate", AggressiveAI::RSHIELD_HEAL_RATE ),
EnumMap::Pair( "FArmor_Heal_Rate", AggressiveAI::FARMOR_HEAL_RATE ),
EnumMap::Pair( "BArmor_Heal_Rate", AggressiveAI::BARMOR_HEAL_RATE ),
EnumMap::Pair( "LArmor_Heal_Rate", AggressiveAI::LARMOR_HEAL_RATE ),
EnumMap::Pair( "RArmor_Heal_Rate", AggressiveAI::RARMOR_HEAL_RATE ),
EnumMap::Pair( "Hull_Heal_Rate", AggressiveAI::HULL_HEAL_RATE ),
EnumMap::Pair( "Target_Faces_You", AggressiveAI::TARGET_FACES_YOU ),
EnumMap::Pair( "Target_In_Front_Of_You", AggressiveAI::TARGET_IN_FRONT_OF_YOU ),
EnumMap::Pair( "Rand", AggressiveAI::RANDOMIZ ),
EnumMap::Pair( "Target_Going_Your_Direction", AggressiveAI::TARGET_GOING_YOUR_DIRECTION )
}

Definition at line 34 of file aggressive.cpp.

vsUMap< string, AIEvents::ElemAttrMap* > logic

Definition at line 65 of file aggressive.cpp.

Referenced by getProperLogicOrInterruptScript().

int randomtemp
static

Definition at line 248 of file aggressive.cpp.

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

volatile Unit* uoi

Definition at line 1582 of file aggressive.cpp.

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

volatile Unit* uoif

Definition at line 1407 of file aggressive.cpp.

Referenced by FlyTo::Execute().