25 extern bool isWeapon( std::string name );
30 if (name.length() < 8)
return false;
31 return (name[0] ==
'A' || name[0] ==
'a')
46 template <
typename T >
49 return (a < b) ? a :
b;
52 template <
typename T >
55 return (a > b) ? a :
b;
62 if (!my_unit)
return false;
68 if (!my_unit)
return false;
70 return ( ( 1<<(
unsigned int) my_unit->
unitRole() )&capitaltypes ) != 0;
75 if (!my_unit)
return false;
94 float rad = un->
rSize();
96 float cpdist = FLT_MAX;
100 static float fixed_system_orbit_priorities =
105 bool force_system_installation_priority =
false;
106 if (system_installation && un->
Velocity.MagnitudeSquared() > fixed_system_orbit_priorities*fixed_system_orbit_priorities)
107 force_system_installation_priority =
true;
108 for (
unsigned int i = 0;
i < np; ++
i) {
112 return SYSTEM_INSTALLATION_PRIORITY;
113 if ( un == player->
Target() )
114 return PLAYER_PRIORITY;
116 if (tmpdist < cpdist) {
122 if (relpos.Dot( relvel ) >= 0) {
126 +relvel.Magnitude()*lowest_priority_time;
135 double dist = relpos.Magnitude()-rad;
140 if (relpos.Dot( relvel ) >= 0)
144 +relvel.Magnitude()*lowest_priority_time;
150 return PLAYER_PRIORITY;
153 return MISSILE_PRIORITY;
155 return DOCKABLE_PRIORITY;
185 vs_config->
getVariable(
"physics",
"priorities",
"dynamic_throttle.mindistancefactor",
"0.25" ) );
190 static const float DYNAMIC_THROTTLE_TARGETELAPSEDTIME = 1.f/DYNAMIC_THROTTLE_TARGETFPS;
191 static float DYNAMIC_THROTTLE_FACTOR = 1.f;
192 static float lastThrottleAdjust = 0;
195 float newfactor = DYNAMIC_THROTTLE_FACTOR*DYNAMIC_THROTTLE_TARGETELAPSEDTIME/
GetElapsedTime();
196 newfactor =
mymax( DYNAMIC_THROTTLE_MINFACTOR,
mymin( DYNAMIC_THROTTLE_MAXFACTOR, newfactor ) );
199 const float PLAYERTHREAT_DISTANCE_FACTOR = _PLAYERTHREAT_DISTANCE_FACTOR*DYNAMIC_THROTTLE_FACTOR;
200 const float THREAT_DISTANCE_FACTOR = _THREAT_DISTANCE_FACTOR*DYNAMIC_THROTTLE_FACTOR;
203 float missile_range = 0;
222 return ASTEROID_PARENT_PRIORITY;
226 return ASTEROID_HIGH_PRIORITY;
228 return ASTEROID_LOW_PRIORITY;
235 if (dist < too_close_asteroid)
236 return ASTEROID_HIGH_PRIORITY;
238 return ASTEROID_LOW_PRIORITY;
243 return un->
isJumppoint() ? PLAYER_PRIORITY : HIGH_PRIORITY;
245 return MEDIUMHIGH_PRIORITY;
248 static float compwarprampuptime =
257 return MEDIUM_PRIORITY;
258 if (dist < gun_range)
259 return MEDIUM_PRIORITY;
260 if (time_ramped < lowest_priority_time*2)
264 if (system_installation || un->
faction == cargofac || un->
faction == upfac || un->
faction == neutral) {
265 if (dist < tooclose) {
266 return MEDIUM_PRIORITY;
268 if (system_installation)
270 return INERT_PRIORITY;
274 if ( !( obj.length() == 0 || (obj.length() >= 1 && obj[0] ==
'b') ) )
275 return MEDIUM_PRIORITY;
276 if ( dist < 2*PLAYERTHREAT_DISTANCE_FACTOR*
mymax( missile_range, gun_range ) ) {
277 if (dist < tooclose*PLAYERTHREAT_DISTANCE_FACTOR)
278 return MEDIUMHIGH_PRIORITY;
279 else if (dist < 2*gun_range*PLAYERTHREAT_DISTANCE_FACTOR)
280 return MEDIUM_PRIORITY;
288 if (distance <= 2*gun_range*THREAT_DISTANCE_FACTOR)
289 return NOT_VISIBLE_COMBAT_HIGH;
290 if (distance < 2*missile_range*THREAT_DISTANCE_FACTOR)
291 return NOT_VISIBLE_COMBAT_MEDIUM;
292 return NOT_VISIBLE_COMBAT_LOW;
294 if (dist < tooclose*THREAT_DISTANCE_FACTOR)
295 return MEDIUMHIGH_PRIORITY;
319 if (!my_unit)
return "";
325 if (!my_unit)
return 0;
331 if (!my_unit)
return;
337 if (!my_unit)
return;
348 else if (their_cp != -1)
373 if (!my_unit)
return "";
374 return my_unit->
name;
379 if (!my_unit)
return;
380 my_unit->
name = name;
385 if (!my_unit)
return;
386 my_unit->
hull = newhull;
391 if (!my_unit)
return 0;
401 if (!my_unit)
return;
412 static const string empty_string;
413 if (!my_unit)
return empty_string;
429 if (!my_unit)
return 0;
439 if (!my_unit || !un)
return false;
455 static string emptystr;
456 static string fgdirdef(
"b" );
468 if (!my_unit)
return false;
478 if (!my_unit)
return -1;
484 if (!my_unit)
return 0;
486 if ( my_unit->
GetCargo( s, index ) )
487 quantity = my_unit->
RemoveCargo( index, quantity, erasezero );
495 if (un == NULL)
return;
499 for (i = 0; i < un->
numCargo(); ++i) {
507 for (i = 0; i < un->
numCargo(); ++i) {
515 for (i = 0; i < un->
numCargo(); ++i) {
532 float upgrade(
Unit *my_unit,
string file,
int mountoffset,
int subunitoffset,
bool force,
bool loop_through_mounts )
534 if (!my_unit)
return 0;
535 double percentage = 0;
536 percentage = my_unit->
Upgrade( file, mountoffset, subunitoffset, force, loop_through_mounts );
543 if (!my_unit)
return -1;
544 int maxmount = my_unit->
mounts.size();
545 int max = maxmount+mountoffset;
546 for (
int loopi = mountoffset; loopi <
max; ++loopi) {
547 int i = loopi%maxmount;
548 if ( my_unit->
mounts[i].type->weapon_name == weapon_name
559 if (!my_unit)
return 0;
574 if (!my_unit)
return 0;
581 if (!my_unit)
return 0;
607 if (!my_unit)
return false;
612 c.quantity = quantity;
626 if (!my_unit)
return false;
640 if ( index >= 0 && (
unsigned int) index < my_unit->numCargo() )
650 unsigned int indx = 0;
652 if (cargptr && indx >= 0)
662 if (!my_unit)
return false;
683 if ( dis < un->rSize() )
690 if (my_unit == NULL || un == NULL)
697 if (un == NULL || sig == NULL)
703 dist = dist-(sig->
rSize()*planetpct);
705 dist = dist-(un->
rSize()*planetpct);
711 if (!my_unit)
return false;
717 res = ( (
Planet*) my_unit )->hasLights();
723 if (!my_unit)
return false;
728 return res && !
isSun( my_unit );
777 if ( un != par &&
ishere( un, look ) )
788 if ( tmp == un ||
ishere( tmp, un ) ) {
797 if (un && unitToDockWith) {
810 if (!upgrade)
return 1.0f;
812 static std::string loadfailed(
"LOAD_FAILED" );
816 for (
unsigned int i = 0;
i < nummounts; ++
i)
820 if (un->
mounts[
i].functionality < 1.0f)
821 return un->
mounts[
i].functionality;
824 }
else if (name.find(
"add_" ) != 0 && name.find(
"mult_" ) != 0) {
827 if (upgrade->
GetHull() > 1 || armor[0] || armor[1] || armor[2] || armor[3] || armor[4] || armor[5] || armor[6]
829 if (countHullAndArmorAsFull)
833 if (percent > 0 && percent < 1)
835 else if (percent >= 1)
838 }
else if (percent > 0) {