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
unit_generic.cpp File Reference
#include "config.h"
#include <set>
#include "configxml.h"
#include "audiolib.h"
#include "unit_generic.h"
#include "beam.h"
#include "lin_time.h"
#include "xml_serializer.h"
#include "vsfilesystem.h"
#include "file_main.h"
#include "universe_util.h"
#include "unit_util.h"
#include "script/mission.h"
#include "script/flightgroup.h"
#include "cmd/ai/fire.h"
#include "cmd/ai/turretai.h"
#include "cmd/ai/communication.h"
#include "cmd/ai/navigation.h"
#include "cmd/ai/script.h"
#include "cmd/ai/missionscript.h"
#include "cmd/ai/flybywire.h"
#include "cmd/ai/aggressive.h"
#include "python/python_class.h"
#include "cmd/unit_factory.h"
#include "missile_generic.h"
#include "gfx/cockpit_generic.h"
#include "gfx/vsbox.h"
#include <algorithm>
#include "cmd/ai/ikarus.h"
#include "role_bitmask.h"
#include "unit_const_cache.h"
#include "gfx/warptrail.h"
#include "networking/netserver.h"
#include "networking/netclient.h"
#include "universe_generic.h"
#include "csv.h"
#include "vs_random.h"
#include "galaxy_xml.h"
#include "gfx/camera.h"
#include "unit_find.h"
#include "pilot.h"
#include <iostream>

Go to the source code of this file.

Classes

class  WeaponComparator< FORWARD >
 
class  VCString
 
class  DoubleName
 
class  CatCompare
 

Macros

#define DEBUG_MESH_ANI
 
#define damagelevel   hullpercent
 
#define INVERSEFORCEDISTANCE   5400
 
#define PARANOIA   (0.4f)
 
#define MM(A, B)   m.r[B*3+A]
 
#define MM(A, B)   ( (cumulative_transformation_matrix.r[B*3+A]) )
 
#define UPGRADEOK   (1)
 
#define NOTTHERE   (0)
 
#define CAUSESDOWNGRADE   (-1)
 
#define LIMITEDBYTEMPLATE   (-2)
 
#define STDUPGRADE_SPECIFY_DEFAULTS(my, oth, temp, noth, dgradelimer, dgradelimerdefault, clamp, value_to_lookat)
 
#define STDUPGRADE(my, oth, temp, noth)
 
#define STDUPGRADECLAMP(my, oth, temp, noth)
 
#define REPAIRINTEGRATED(functionality, max_functionality)
 

Typedefs

typedef std::set< intWeaponGroup
 
typedef double(* adder )(double a, double b)
 
typedef double(* percenter )(double a, double b, double c)
 
typedef bool(* comparer )(double a, double b)
 
typedef vsUMap< const char
*, bool
UnitHasRecursiveData
 
typedef vsUMap< std::string,
UnitHasRecursiveData
FactionHasRecursiveData
 
typedef std::vector
< FactionHasRecursiveData
HasRecursiveData
 

Functions

static float mymax (float a, float b)
 
static float mymin (float a, float b)
 
void DestroyMount (Mount *)
 
bool isMissile (const weapon_info *weap)
 
bool flickerDamage (Unit *un, float hullpercent)
 
Vector ReflectNormal (const Vector &vel, const Vector &norm)
 
void abletodock (int dock)
 
bool CrashForceDock (Unit *thus, Unit *dockingUn, bool force)
 
float copysign (float x, float y)
 
float rand01 ()
 
unsigned int apply_float_to_unsigned_int (float tmp)
 
std::string accelStarHandler (const XMLType &input, void *mythis)
 
std::string speedStarHandler (const XMLType &input, void *mythis)
 
void CheckUnit (Unit *un)
 
void UncheckUnit (Unit *un)
 
string GetUnitDir (string filename)
 
char * GetUnitDir (const char *filename)
 
std::string lookupMountSize (int s)
 
void update_ani_cache ()
 
std::string getMasterPartListUnitName ()
 
std::string GetReadPlayerSaveGame (int)
 
CSVRow GetUnitRow (string filename, bool subu, int faction, bool readLast, bool &read)
 
static float tmpmax (float a, float b)
 
bool CheckAccessory (Unit *tur)
 
bool preEmptiveClientFire (const weapon_info *wi)
 
static float tmpsqr (float x)
 
float CloseEnoughCone (Unit *me)
 
bool CloseEnoughToAutotrack (Unit *me, Unit *targ, float &cone)
 
static float safeacos (float mycos)
 
void disableSubUnits (Unit *uhn)
 
signed char ComputeAutoGuarantee (Unit *un)
 
float getAutoRSize (Unit *orig, Unit *un, bool ignore_friend=false)
 
void SetShieldZero (Unit *)
 
double howFarToJump ()
 
QVector SystemLocation (std::string system)
 
static std::string NearestSystem (std::string currentsystem, QVector pos)
 
float CalculateNearestWarpUnit (const Unit *thus, float minmultiplier, Unit **nearest_unit, bool count_negative_warp_units)
 
static QVector RealPosition (Unit *un)
 
static QVector AutoSafeEntrancePoint (const QVector start, float rsize, Unit *goal)
 
float globQueryShell (QVector pos, QVector dir, float rad)
 
std::string GenerateAutoError (Unit *me, Unit *targ)
 
void ActivateAnimation (Unit *jp)
 
void TurnJumpOKLightOn (Unit *un, Cockpit *cp)
 
float GetFuelUsage (bool afterburner)
 
float WARPENERGYMULTIPLIER (Unit *un)
 
static bool applyto (float &shield, const float max, const float amt)
 
float totalShieldVal (const Shield &shield)
 
float currentTotalShieldVal (const Shield &shield)
 
float totalShieldEnergyCapacitance (const Shield &shield)
 
UnitfindUnitInStarsystem (void *unitDoNotDereference)
 
void ScoreKill (Cockpit *cp, Unit *killer, Unit *killedUnit)
 
void AllUnitsCloseAndEngage (Unit *, int faction)
 
UnitmakeBlankUpgrade (string templnam, int faction)
 
const UnitmakeFinalBlankUpgrade (string name, int faction)
 
const UnitmakeTemplateUpgrade (string name, int faction)
 
const UnitloadUnitByCache (std::string name, int faction)
 
bool DestroySystem (float hull, float maxhull, float numhits)
 
bool DestroyPlayerSystem (float hull, float maxhull, float numhits)
 
bool withinShield (const ShieldFacing &facing, float theta, float rho)
 
void WarpPursuit (Unit *un, StarSystem *sourcess, std::string destination)
 
static Transformation HoldPositionWithRespectTo (Transformation holder, const Transformation &changeold, const Transformation &changenew)
 
void ExecuteDirector ()
 
void SwitchUnits (Unit *, Unit *)
 
void UpdateMasterPartList (Unit *)
 
bool insideDock (const DockingPorts &dock, const QVector &pos, float radius)
 
const UnitgetUnitFromUpgradeName (const string &upgradeName, int myUnitFaction=0)
 
bool GreaterZero (double a, double b)
 
double AddUp (double a, double b)
 
double MultUp (double a, double b)
 
double GetsB (double a, double b)
 
bool AGreaterB (double a, double b)
 
double SubtractUp (double a, double b)
 
double SubtractClamp (double a, double b)
 
bool ALessB (double a, double b)
 
double computePercent (double old, double upgrade, double newb)
 
double computeWorsePercent (double old, double upgrade, double isnew)
 
double computeAdderPercent (double a, double b, double c)
 
double computeMultPercent (double a, double b, double c)
 
double computeDowngradePercent (double old, double upgrade, double isnew)
 
static int UpgradeFloat (double &result, double tobeupgraded, double upgrador, double templatelimit, double(*myadd)(double, double), bool(*betterthan)(double a, double b), double nothing, double completeminimum, double(*computepercentage)(double oldvar, double upgrador, double newvar), double &percentage, bool forcedowngrade, bool usetemplate, double at_least_this, bool(*atLeastthiscompare)(double a, double b)=AGreaterB, bool clamp=false, bool force_nothing=false)
 
int UpgradeBoolval (int a, int upga, bool touchme, bool downgrade, int &numave, double &percentage, bool force_nothing)
 
void YoinkNewlines (char *input_buffer)
 
bool Quit (const char *input_buffer)
 
void Tokenize (const string &str, vector< string > &tokens, const string &delimiters=" ")
 
std::string CheckBasicSizes (const std::string tokens)
 
std::map< VCString, VCStringparseTurretSizes ()
 
std::string getTurretSize (const std::string &size)
 
UnitCreateGenericTurret (std::string tur, int faction)
 
static void GCCBugCheckFloat (float *f, int offset)
 
double ComputeMinDowngradePercent ()
 
int GetModeFromName (const char *)
 
UnitCreateGameTurret (std::string tur, int faction)
 
bool AddToDowngradeMap (std::string name, double value, int unitoffset, vsUMap< int, DoubleName > &tempdowngrademap)
 
void ClearDowngradeMap ()
 
std::set< std::string > GetListOfDowngrades ()
 
static std::string upgradeString ("Upgrades")
 
static bool cell_has_recursive_data (const string &name, unsigned int fac, const char *key)
 
float RepairPrice (float operational, float price)
 
bool isWeapon (std::string name)
 
float uniformrand (float min, float max)
 
QVector randVector (float min, float max)
 
int SelectDockPort (Unit *, Unit *parent)
 
bool cargoIsUpgrade (const Cargo &c)
 
UnitGetUnitMasterPartList ()
 
bool myless (const Cargo &a, const Cargo &b)
 
CargoGetMasterPartList (const char *input_buffer)
 
std::string CargoToString (const Cargo &cargo)
 
string toLowerCase (string in)
 

Variables

float capship_size = 500
 
static list< Unit * > Unitdeletequeue
 
static Hashtable< long, Unit, 2095 > deletedUn
 
int deathofvs = 1
 
static const string LOAD_FAILED = "LOAD_FAILED"
 
const char * DamagedCategory = "upgrades/Damaged/"
 
vector< Vectorperplines
 
vector< intturretcontrol
 
std::set< Unit * > arrested_list_do_not_dereference
 
vector< intswitchunit
 
vsUMap< int, DoubleNamedowngrademap
 
int curdowngrademapoffset = 5*sizeof (Unit)
 
static HasRecursiveData has_recursive_data
 
static const GFXColor disable (1, 0, 0, 1)
 

Macro Definition Documentation

#define CAUSESDOWNGRADE   (-1)

Definition at line 6075 of file unit_generic.cpp.

Referenced by UpgradeFloat().

#define damagelevel   hullpercent
#define DEBUG_MESH_ANI

Definition at line 53 of file unit_generic.cpp.

#define INVERSEFORCEDISTANCE   5400

Definition at line 362 of file unit_generic.cpp.

#define LIMITEDBYTEMPLATE   (-2)

Definition at line 6076 of file unit_generic.cpp.

Referenced by UpgradeFloat().

#define MM (   A,
 
)    m.r[B*3+A]

Definition at line 4046 of file unit_generic.cpp.

Referenced by Unit::ToLocalCoordinates(), and Unit::UpCoordinateLevel().

#define MM (   A,
 
)    ( (cumulative_transformation_matrix.r[B*3+A]) )

Definition at line 4046 of file unit_generic.cpp.

#define NOTTHERE   (0)

Definition at line 6074 of file unit_generic.cpp.

Referenced by UpgradeFloat().

#define PARANOIA   (0.4f)

Definition at line 1796 of file unit_generic.cpp.

Referenced by Unit::Threaten().

#define REPAIRINTEGRATED (   functionality,
  max_functionality 
)
Value:
do { \
if (functionality < max_functionality) \
{ \
(functionality) += ammt_repair; \
if ( (functionality) > (max_functionality) ) \
(functionality) = (max_functionality); \
} \
} \
while (0)

Definition at line 8826 of file unit_generic.cpp.

Referenced by Unit::Repair().

#define STDUPGRADE (   my,
  oth,
  temp,
  noth 
)
Value:
oth, \
temp, \
noth, \
downgradelimit->my, \
blankship->my, \
false, \
this->my ); } \
while (0)

Definition at line 6901 of file unit_generic.cpp.

Referenced by Unit::UpAndDownGrade().

#define STDUPGRADE_SPECIFY_DEFAULTS (   my,
  oth,
  temp,
  noth,
  dgradelimer,
  dgradelimerdefault,
  clamp,
  value_to_lookat 
)

Definition at line 6862 of file unit_generic.cpp.

Referenced by Unit::UpAndDownGrade().

#define STDUPGRADECLAMP (   my,
  oth,
  temp,
  noth 
)
Value:
oth, \
temp, \
noth, \
downgradelimit->my, \
blankship->my, \
!force_change_on_nothing, \
this->my ); } \
while (0)

Definition at line 6912 of file unit_generic.cpp.

Referenced by Unit::UpAndDownGrade().

#define UPGRADEOK   (1)

Definition at line 6073 of file unit_generic.cpp.

Referenced by Unit::UpAndDownGrade(), and UpgradeFloat().

Typedef Documentation

typedef double(* adder)(double a, double b)

Definition at line 6080 of file unit_generic.cpp.

typedef bool(* comparer)(double a, double b)

Definition at line 6082 of file unit_generic.cpp.

Definition at line 6813 of file unit_generic.cpp.

typedef std::vector< FactionHasRecursiveData > HasRecursiveData

Definition at line 6814 of file unit_generic.cpp.

typedef double(* percenter)(double a, double b, double c)

Definition at line 6081 of file unit_generic.cpp.

typedef vsUMap< const char*, bool > UnitHasRecursiveData

Definition at line 6812 of file unit_generic.cpp.

typedef std::set< int > WeaponGroup

Definition at line 5426 of file unit_generic.cpp.

Function Documentation

void abletodock ( int  dock)

Definition at line 1247 of file firekeyboard.cpp.

References AUDCreateSoundWAV(), AUDPlay(), VegaConfig::getVariable(), soundContainer::loadsound(), XMLSupport::parse_bool(), soundContainer::playsound(), QVector, soundContainer::sound, Vector, and vs_config.

Referenced by BaseInterface::Room::Launch::Click(), BaseInterface::Room::Eject::Click(), CrashForceDock(), DoDockingOps(), Unit::EjectCargo(), and TryDock().

1248 {
1249  static bool play_anim = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "docking_comm_anim", "false" ) );
1250  switch (dock)
1251  {
1252  case 5:
1253  {
1254  static soundContainer reqsound;
1255  if (reqsound.sound == -2) {
1256  static string str = vs_config->getVariable( "cockpitaudio", "undocking_complete", "undocking_complete" );
1257  reqsound.loadsound( str );
1258  }
1259  reqsound.playsound();
1260  break;
1261  }
1262  case 4:
1263  {
1264  static soundContainer reqsound;
1265  if (reqsound.sound == -2) {
1266  static string str = vs_config->getVariable( "cockpitaudio", "undocking_failed", "undocking_failed" );
1267  reqsound.loadsound( str );
1268  }
1269  reqsound.playsound();
1270  break;
1271  }
1272  case 3:
1273  {
1274  static soundContainer reqsound;
1275  static string otherstr = vs_config->getVariable( "audio", "automatic_docking_zone", "automatic_landing_zone.wav" );
1276  if (otherstr != "" && rand() < RAND_MAX/2) {
1277  static int s = AUDCreateSoundWAV( otherstr, false );
1278  AUDPlay( s, QVector( 0, 0, 0 ), Vector( 0, 0, 0 ), 1 );
1279  } else {
1280  if (reqsound.sound == -2) {
1281  static string str = vs_config->getVariable( "cockpitaudio", "docking_complete", "docking_complete" );
1282  reqsound.loadsound( str );
1283  }
1284  reqsound.playsound();
1285  }
1286  break;
1287  }
1288  case 2:
1289  {
1290  static soundContainer reqsound;
1291  if (reqsound.sound == -2) {
1292  static string str = vs_config->getVariable( "cockpitaudio", "docking_failed", "docking_failed" );
1293  reqsound.loadsound( str );
1294  }
1295  reqsound.playsound();
1296  break;
1297  }
1298  case 1:
1299  {
1300  static soundContainer reqsound;
1301  if (reqsound.sound == -2) {
1302  static string str = vs_config->getVariable( "cockpitaudio", "docking_granted", "request_granted" );
1303  reqsound.loadsound( str );
1304  }
1305  reqsound.playsound();
1306  break;
1307  }
1308  case 0:
1309  {
1310  static soundContainer reqsound;
1311  if (reqsound.sound == -2) {
1312  static string str = vs_config->getVariable( "cockpitaudio", "docking_denied", "request_denied" );
1313  reqsound.loadsound( str );
1314  }
1315  reqsound.playsound();
1316  break;
1317  }
1318  }
1319 }
std::string accelStarHandler ( const XMLType input,
void *  mythis 
)

Definition at line 661 of file unit_generic.cpp.

References XMLType::wordlength::f, VegaConfig::getVariable(), XMLSupport::parse_float(), XMLSupport::tostring(), vs_config, and XMLType::w.

662 {
663  static float game_speed = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
664  static float game_accel = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_accel", "1" ) );
665  return XMLSupport::tostring( *input.w.f/(game_speed*game_accel) );
666 }
void ActivateAnimation ( Unit jp)

Definition at line 893 of file star_system_generic.cpp.

Referenced by ActivateAnimation(), StarSystem::JumpTo(), and GameUnit< UnitType >::TransferUnitToSystem().

894 {
895  jumppoint->graphicOptions.Animating = 1;
896  Unit *un;
897  for (un_iter i = jumppoint->getSubUnits(); NULL != (un = *i); ++i)
898  ActivateAnimation( un );
899 }
bool AddToDowngradeMap ( std::string  name,
double  value,
int  unitoffset,
vsUMap< int, DoubleName > &  tempdowngrademap 
)

Definition at line 6781 of file unit_generic.cpp.

References vsUMap.

Referenced by Unit::UpAndDownGrade().

6782 {
6783  using vsUMap;
6784  vsUMap< int, DoubleName >::iterator i = downgrademap.find( unitoffset );
6785  if ( i != downgrademap.end() ) {
6786  if ( (*i).second.d <= value ) {
6787  tempdowngrademap[unitoffset] = DoubleName( name, value );
6788  return true;
6789  }
6790  } else {
6791  tempdowngrademap[unitoffset] = DoubleName( name, value );
6792  return true;
6793  }
6794  return false;
6795 }
double AddUp ( double  a,
double  b 
)

Definition at line 6089 of file unit_generic.cpp.

References b.

Referenced by Unit::UpAndDownGrade().

6090 {
6091  return a+b;
6092 }
bool AGreaterB ( double  a,
double  b 
)

Definition at line 6104 of file unit_generic.cpp.

References b.

Referenced by Unit::UpAndDownGrade().

6105 {
6106  return a > b;
6107 }
bool ALessB ( double  a,
double  b 
)

Definition at line 6119 of file unit_generic.cpp.

References b.

6120 {
6121  return a < b;
6122 }
void AllUnitsCloseAndEngage ( Unit ,
int  faction 
)

Definition at line 98 of file comm_ai.cpp.

References _Universe, Universe::activeStarSystem(), UniverseUtil::adjustRelationModifierInt(), UnitCollection::createIterator(), Flightgroup::directive, Unit::faction, Unit::getFlightgroup(), GetMadAt(), UnitUtil::getRelationFromFaction(), StarSystem::getUnitList(), VegaConfig::getVariable(), i, Magnitude(), XMLSupport::parse_float(), Unit::Position(), Unit::Target(), Unit::TargetTurret(), vs_config, and Universe::whichPlayerStarship().

Referenced by Unit::ApplyDamage(), and CommunicatingAI::TerminateContrabandSearch().

99 {
100  Unit *ally;
101  static float contraband_assist_range =
102  XMLSupport::parse_float( vs_config->getVariable( "physics", "contraband_assist_range", "50000" ) );
103  float relation = 0;
104  static float minrel = XMLSupport::parse_float( vs_config->getVariable( "AI", "max_faction_contraband_relation", "-.05" ) );
105  static float adj = XMLSupport::parse_float( vs_config->getVariable( "AI", "faction_contraband_relation_adjust", "-.025" ) );
106  float delta;
107  int cp = _Universe->whichPlayerStarship( un );
108  if (cp != -1) {
109  if ( ( relation = UnitUtil::getRelationFromFaction( un, faction ) ) > minrel )
110  delta = minrel-relation;
111  else
112  delta = adj;
114  }
116  (ally = *i) != NULL;
117  ++i)
118  //Vector loc;
119  if (ally->faction == faction) {
120  if ( ( ally->Position()-un->Position() ).Magnitude() < contraband_assist_range ) {
121  GetMadAt( un, ally );
122  Flightgroup *fg = ally->getFlightgroup();
123  if (fg) {
124  if ( fg->directive.empty() ? true : toupper( *fg->directive.begin() ) != *fg->directive.begin() ) {
125  ally->Target( un );
126  ally->TargetTurret( un );
127  } else {
128  ally->Target( un );
129  ally->TargetTurret( un );
130  }
131  }
132  }
133  }
134  //}
135 }
unsigned int apply_float_to_unsigned_int ( float  tmp)

Definition at line 649 of file unit_generic.cpp.

References int.

Referenced by Unit::DealDamageToHullReturnArmor().

650 {
651  static unsigned long int seed = 2531011;
652  seed += 214013;
653  seed %= 4294967295u;
654  unsigned int ans = (unsigned int) tmp;
655  tmp -= ans; //now we have decimal;
656  if ( seed < (unsigned long int) (4294967295u*tmp) )
657  ans += 1;
658  return ans;
659 }
static bool applyto ( float shield,
const float  max,
const float  amt 
)
static

Definition at line 3564 of file unit_generic.cpp.

References max().

Referenced by Unit::RegenShields().

3565 {
3566  shield += amt; //short fix
3567  if (shield > max)
3568  shield = max;
3569  return (shield >= max) ? 1 : 0;
3570 }
static QVector AutoSafeEntrancePoint ( const QVector  start,
float  rsize,
Unit goal 
)
static

Definition at line 2797 of file unit_generic.cpp.

References j, k, QVector, RealPosition(), Unit::rSize(), and UniverseUtil::SafeEntrancePoint().

Referenced by Unit::AutoPilotToErrorMessage().

2798 {
2800  float bdis = ( def-RealPosition( goal ) ).MagnitudeSquared();
2801  for (int i = -1; i <= 1; ++i)
2802  for (int j = -1; j <= 1; ++j)
2803  for (int k = -1; k <= 1; k += 2) {
2804  QVector delta( i, j, k );
2805  delta.Normalize();
2806  QVector tmp = RealPosition( goal )+delta*(goal->rSize()+rsize);
2807  tmp = UniverseUtil::SafeEntrancePoint( tmp, rsize );
2808  float tmag = ( tmp-RealPosition( goal ) ).MagnitudeSquared();
2809  if (tmag < bdis) {
2810  bdis = tmag;
2811  def = tmp;
2812  }
2813  }
2814  return def;
2815 }
float CalculateNearestWarpUnit ( const Unit thus,
float  minmultiplier,
Unit **  nearest_unit,
bool  count_negative_warp_units 
)

Definition at line 2595 of file unit_generic.cpp.

References _Universe, Universe::activeStarSystem(), StarSystem::collidemap, UnitCollection::fastIterator(), findObjects(), UniverseUtil::getPlanetRadiusPercent(), UnitUtil::getSignificantDistance(), VegaConfig::getVariable(), Unit::graphicOptions, StarSystem::gravitationalUnits(), Unit::location, XMLSupport::parse_float(), PLANETPTR, Unit::Position(), QVector, NearestUnitLocator::retval, Unit::rSize(), Unit::specInterdiction, Unit::graphic_options::specInterdictionOnline, Collidable::CollideRef::unit, Unit::UNIT_ONLY, and vs_config.

Referenced by Unit::AddVelocity(), and Orders::AutoLongHaul::Execute().

2596 {
2597  static float smallwarphack = XMLSupport::parse_float( vs_config->getVariable( "physics", "minwarpeffectsize", "100" ) );
2598  static float bigwarphack =
2599  XMLSupport::parse_float( vs_config->getVariable( "physics", "maxwarpeffectsize", "10000000" ) );
2600  //Boundary between multiplier regions 1&2. 2 is "high" mult
2601  static double warpregion1 = XMLSupport::parse_float( vs_config->getVariable( "physics", "warpregion1", "5000000" ) );
2602  //Boundary between multiplier regions 0&1 0 is mult=1
2603  static double warpregion0 = XMLSupport::parse_float( vs_config->getVariable( "physics", "warpregion0", "5000" ) );
2604  //Mult at 1-2 boundary
2605  static double warpcruisemult = XMLSupport::parse_float( vs_config->getVariable( "physics", "warpcruisemult", "5000" ) );
2606  //degree of curve
2607  static double curvedegree = XMLSupport::parse_float( vs_config->getVariable( "physics", "warpcurvedegree", "1.5" ) );
2608  //coefficient so as to agree with above
2609  static double upcurvek = warpcruisemult/pow( (warpregion1-warpregion0), curvedegree );
2610  //inverse fractional effect of ship vs real big object
2611  static float def_inv_interdiction = 1.
2612  /XMLSupport::parse_float( vs_config->getVariable( "physics", "default_interdiction",
2613  ".125" ) );
2614  Unit *planet;
2615  Unit *testthis = NULL;
2616  {
2617  NearestUnitLocator locatespec;
2619  testthis = locatespec.retval.unit;
2620  }
2622  (planet = *iter) || testthis;
2623  ++iter) {
2624  if ( !planet || !planet->Killed() ) {
2625  if (planet == NULL) {
2626  planet = testthis;
2627  testthis = NULL;
2628  }
2629  if (planet == thus)
2630  continue;
2631  float shiphack = 1;
2632  if (planet->isUnit() != PLANETPTR) {
2633  shiphack = def_inv_interdiction;
2634  if ( planet->specInterdiction != 0 && planet->graphicOptions.specInterdictionOnline != 0
2635  && (planet->specInterdiction > 0 || count_negative_warp_units) ) {
2636  shiphack = 1/fabs( planet->specInterdiction );
2637  if (thus->specInterdiction != 0 && thus->graphicOptions.specInterdictionOnline != 0)
2638  //only counters artificial interdiction ... or maybe it cheap ones shouldn't counter expensive ones!? or
2639  // expensive ones should counter planets...this is safe now, for gameplay
2640  shiphack *= fabs( thus->specInterdiction );
2641  }
2642  }
2643  float multipliertemp = 1;
2644  float minsizeeffect = (planet->rSize() > smallwarphack) ? planet->rSize() : smallwarphack;
2645  float effectiverad = minsizeeffect*( 1.0f+UniverseUtil::getPlanetRadiusPercent() )+thus->rSize();
2646  if (effectiverad > bigwarphack)
2647  effectiverad = bigwarphack;
2648  QVector dir = thus->Position()-planet->Position();
2649  double udist = dir.Magnitude();
2650  float sigdist = UnitUtil::getSignificantDistance( thus, planet );
2651  if ( planet->isPlanet() && udist < (1<<28) ) //If distance is viable as a float approximation and it's an actual celestial body
2652  udist = sigdist;
2653  do {
2654  double dist = udist;
2655  if (dist < 0) dist = 0;
2656  dist *= shiphack;
2657  if ( dist > (effectiverad+warpregion0) )
2658  multipliertemp = pow( (dist-effectiverad-warpregion0), curvedegree )*upcurvek;
2659  else
2660  multipliertemp = 1;
2661  if (multipliertemp < minmultiplier) {
2662  minmultiplier = multipliertemp;
2663  *nearest_unit = planet;
2664  //eventually use new multiplier to compute
2665  } else {break; }
2666  } while (0);
2667  if (!testthis)
2668  break; //don't want the ++
2669  }
2670  }
2671  return minmultiplier;
2672 }
bool cargoIsUpgrade ( const Cargo c)

Definition at line 8255 of file unit_generic.cpp.

References Cargo::GetCategory().

Referenced by Unit::CanAddCargo(), Unit::getCargoVolume(), and Unit::getUpgradeVolume().

8256 {
8257  return c.GetCategory().find( "upgrades" ) == 0;
8258 }
std::string CargoToString ( const Cargo cargo)

Definition at line 8740 of file unit_generic.cpp.

References Cargo::GetContent(), Cargo::mass, Cargo::mission, Cargo::price, Cargo::quantity, XMLSupport::tostring(), and Cargo::volume.

Referenced by Unit::cargoSerializer().

8741 {
8742  string missioncargo;
8743  if (cargo.mission)
8744  missioncargo = string( "\" missioncargo=\"" )+XMLSupport::tostring( cargo.mission );
8745  return string( "\t\t\t<Cargo mass=\"" )+XMLSupport::tostring( (float) cargo.mass )+string( "\" price=\"" )
8746  +XMLSupport::tostring( (float) cargo.price )+string( "\" volume=\"" )+XMLSupport::tostring( (float) cargo.volume )
8747  +string(
8748  "\" quantity=\"" )+XMLSupport::tostring( (int) cargo.quantity )+string( "\" file=\"" )+cargo.GetContent()
8749  +missioncargo
8750  +string( "\"/>\n" );
8751 }
static bool cell_has_recursive_data ( const string &  name,
unsigned int  fac,
const char *  key 
)
static

Definition at line 6819 of file unit_generic.cpp.

References FactionUtil::GetFactionName(), UniverseUtil::LookupUnitStat(), UnitUtil::upgrade(), and upgradeString().

Referenced by Unit::UpAndDownGrade().

6820 {
6821  if ( fac < has_recursive_data.size() ) {
6822  FactionHasRecursiveData::const_iterator iter = has_recursive_data[fac].find( name );
6823  if ( iter != has_recursive_data[fac].end() ) {
6824  UnitHasRecursiveData::const_iterator iter2 = iter->second.find( key );
6825  if ( iter2 != iter->second.end() )
6826  return iter2->second;
6827  }
6828  } else {
6829  has_recursive_data.resize( fac+1 );
6830  }
6831  bool retval = false;
6832  string faction = FactionUtil::GetFactionName( fac );
6833  string lkey = key;
6834  string::size_type lkstart = 0;
6835  string::size_type lkend = lkey.find( '|' );
6836  //Big short circuit - avoids recursion
6837  while ( !retval && (lkstart != string::npos) ) {
6838  string skey = lkey.substr( lkstart, (lkend == string::npos) ? string::npos : lkend-lkstart );
6839  string lus = UniverseUtil::LookupUnitStat( name, faction, skey );
6840 
6841  retval = (lus.length() != 0);
6842 
6843  lkstart = (lkend != string::npos) ? lkend+1 : string::npos;
6844  lkend = lkey.find( '|', lkstart );
6845  }
6846  if (!retval) {
6847  //Big short circuit - avoids recursion
6848  string::size_type when;
6849  string upgrades = UniverseUtil::LookupUnitStat( name, faction, upgradeString );
6850  string::size_type ofs = 0;
6851  while ( !retval && ( ( when = upgrades.find( '{', ofs ) ) != string::npos ) ) {
6852  string::size_type where = upgrades.find( '}', when+1 );
6853  string upgrade = upgrades.substr( when+1, ( (where != string::npos) ? where-when-1 : string::npos ) );
6854  retval = cell_has_recursive_data( upgrade, fac, key );
6855  ofs = where+1;
6856  }
6857  }
6858  has_recursive_data[fac][name][key] = retval;
6859  return retval;
6860 }
bool CheckAccessory ( Unit tur)

Definition at line 1348 of file unit_generic.cpp.

References Unit::DownCoordinateLevel(), Unit::GetComputerData(), Unit::Computer::max_pitch_up, Unit::Computer::max_roll_right, Unit::Computer::max_yaw_right, Unit::name, Unit::SetAngularVelocity(), and Vector.

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 }
std::string CheckBasicSizes ( const std::string  tokens)

Definition at line 6261 of file unit_generic.cpp.

Referenced by getTurretSize().

6262 {
6263  if (tokens.find( "small" ) != string::npos)
6264  return "small";
6265  if (tokens.find( "medium" ) != string::npos)
6266  return "medium";
6267  if (tokens.find( "large" ) != string::npos)
6268  return "large";
6269  if (tokens.find( "cargo" ) != string::npos)
6270  return "cargo";
6271  if (tokens.find( "LR" ) != string::npos || tokens.find( "massive" ) != string::npos)
6272  return "massive";
6273  return "";
6274 }
void CheckUnit ( Unit un)

Definition at line 677 of file unit_generic.cpp.

References deathofvs, and deletedUn.

Referenced by UnitContainer::GetUnit().

678 {
679  if (deletedUn.Get( (long) un ) != NULL)
680  while (deathofvs)
681  printf( "%ld died", (long) un );
682 }
void ClearDowngradeMap ( )

Definition at line 6797 of file unit_generic.cpp.

Referenced by BaseComputer::loadSellUpgradeControls().

6798 {
6799  downgrademap.clear();
6800 }
float CloseEnoughCone ( Unit me)

Definition at line 1695 of file unit_generic.cpp.

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

Referenced by CloseEnoughToAutotrack().

1696 {
1697  static float close_autotrack_cone = XMLSupport::parse_float( vs_config->getVariable( "physics", "near_autotrack_cone", ".9" ) );
1698  return close_autotrack_cone;
1699 }
bool CloseEnoughToAutotrack ( Unit me,
Unit targ,
float cone 
)

Definition at line 1701 of file unit_generic.cpp.

References CloseEnoughCone(), Unit::curr_physical_state, VegaConfig::getVariable(), XMLSupport::parse_float(), Transformation::position, Unit::prev_physical_state, tmpsqr(), and vs_config.

Referenced by Unit::UpdatePhysics().

1702 {
1703  if (targ) {
1704  static float close_enough_to_autotrack =
1705  tmpsqr( XMLSupport::parse_float( vs_config->getVariable( "physics", "close_enough_to_autotrack", "4" ) ) );
1706  float dissqr = ( me->curr_physical_state.position.Cast()-targ->curr_physical_state.position.Cast() ).MagnitudeSquared();
1707  float movesqr = close_enough_to_autotrack
1708  *( me->prev_physical_state.position.Cast()-me->curr_physical_state.position.Cast() ).MagnitudeSquared();
1709  if (dissqr < movesqr && movesqr > 0) {
1710  cone = CloseEnoughCone( me )*(movesqr-dissqr)/movesqr+1*dissqr/movesqr;
1711  return true;
1712  }
1713  }
1714  return false;
1715 }
double computeAdderPercent ( double  a,
double  b,
double  c 
)

Definition at line 6140 of file unit_generic.cpp.

Referenced by Unit::UpAndDownGrade().

6141 {
6142  return 0;
6143 }
signed char ComputeAutoGuarantee ( Unit un)

Definition at line 160 of file unit_functions_generic.cpp.

References _Universe, Universe::AccessCockpit(), active_missions, Mission::AUTO_NORMAL, Mission::AUTO_ON, i, and Universe::isPlayerStarship().

Referenced by Unit::AutoPilotToErrorMessage().

161 {
162  Cockpit *cp;
163  unsigned int cpnum = 0;
164  if ( ( cp = _Universe->isPlayerStarship( un ) ) )
165  cpnum = cp-_Universe->AccessCockpit( 0 );
166  else
167  return Mission::AUTO_ON;
168  unsigned int i;
169  for (i = 0; i < active_missions.size(); ++i)
170  if (active_missions[i]->player_num == cpnum && active_missions[i]->player_autopilot != Mission::AUTO_NORMAL)
171  return active_missions[i]->player_autopilot;
172  for (i = 0; i < active_missions.size(); i++)
173  if (active_missions[i]->global_autopilot != Mission::AUTO_NORMAL)
174  return active_missions[i]->global_autopilot;
175  return Mission::AUTO_NORMAL;
176 }
double computeDowngradePercent ( double  old,
double  upgrade,
double  isnew 
)

Definition at line 6148 of file unit_generic.cpp.

References UnitUtil::upgrade().

Referenced by Unit::UpAndDownGrade().

6149 {
6150  if (upgrade)
6151  return (old-isnew)/upgrade;
6152  else
6153  return 0;
6154 }
double ComputeMinDowngradePercent ( )

Definition at line 6702 of file unit_generic.cpp.

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

Referenced by Unit::FilterDowngradeList(), and Unit::UpAndDownGrade().

6703 {
6704  static float MyPercentMin =
6705  XMLSupport::parse_float( vs_config->getVariable( "general", "remove_downgrades_less_than_percent", ".9" ) );
6706  return MyPercentMin;
6707 }
double computeMultPercent ( double  a,
double  b,
double  c 
)

Definition at line 6144 of file unit_generic.cpp.

Referenced by Unit::UpAndDownGrade().

6145 {
6146  return 0;
6147 }
double computePercent ( double  old,
double  upgrade,
double  newb 
)

Definition at line 6124 of file unit_generic.cpp.

Referenced by Unit::UpAndDownGrade().

6125 {
6126  if (newb)
6127  return old/newb;
6128  else
6129  return 0;
6130 }
double computeWorsePercent ( double  old,
double  upgrade,
double  isnew 
)

Definition at line 6132 of file unit_generic.cpp.

6133 {
6134  if (old)
6135  return isnew/old;
6136  else
6137  return 1;
6138 }
float copysign ( float  x,
float  y 
)

Definition at line 633 of file unit_generic.cpp.

References x.

Referenced by Unit::ClampThrust(), Unit::ClampTorque(), Unit::MaxThrust(), and Unit::MaxTorque().

634 {
635  if (y > 0)
636  return x;
637  else
638  return -x;
639 }
bool CrashForceDock ( Unit thus,
Unit dockingUn,
bool  force 
)

Definition at line 365 of file unit_generic.cpp.

References _Universe, abletodock(), Unit::CanDockWithMe(), NetClient::dockRequest(), Unit::ForceDock(), Unit::GetSerial(), Network, Unit::Position(), QVector, Unit::rSize(), UniverseUtil::SafeEntrancePoint(), Unit::SetPosAndCumPos(), Unit::UpgradeInterface(), and Universe::whichPlayerStarship().

Referenced by GamePlanet::reactToCollision(), and Unit::reactToCollision().

366 {
367  Unit *un = dockingUn;
368  int whichdockport = thus->CanDockWithMe( un, force );
369  if (whichdockport != -1) {
370  if (Network == NULL) {
371  QVector place = UniverseUtil::SafeEntrancePoint( un->Position(), un->rSize()*1.5 );
372  un->SetPosAndCumPos( place );
373  if (un->ForceDock( thus, whichdockport ) > 0) {
374  abletodock( 3 );
375  un->UpgradeInterface( thus );
376  return true;
377  }
378  } else {
379  int playernum = _Universe->whichPlayerStarship( dockingUn );
380  if (playernum >= 0)
381  Network[playernum].dockRequest( thus->GetSerial() );
382  return false;
383  }
384  }
385  return false;
386 }
Unit* CreateGameTurret ( std::string  tur,
int  faction 
)

Definition at line 73 of file unit_functions_generic.cpp.

References UnitFactory::createUnit(), and StarSystemGent::faction.

74 {
75  return UnitFactory::createUnit( tur.c_str(), true, faction );
76 }
Unit* CreateGenericTurret ( std::string  tur,
int  faction 
)

Definition at line 6513 of file unit_generic.cpp.

References StarSystemGent::faction.

Referenced by Unit::UpgradeSubUnits().

6514 {
6515  return new Unit( tur.c_str(), true, faction, "", 0, 0 );
6516 }
float currentTotalShieldVal ( const Shield shield)

Definition at line 3593 of file unit_generic.cpp.

References Shield::number, Shield::shield2fb, Shield::shield4fbrl, and Shield::shield8.

Referenced by totalShieldEnergyCapacitance().

3594 {
3595  float maxshield = 0;
3596  switch (shield.number)
3597  {
3598  case 2:
3599  maxshield = shield.shield2fb.front+shield.shield2fb.back;
3600  break;
3601  case 4:
3602  maxshield = shield.shield4fbrl.front+shield.shield4fbrl.back+shield.shield4fbrl.left+shield.shield4fbrl.right;
3603  break;
3604  case 8:
3605  maxshield = shield.shield8.frontrighttop+shield.shield8.backrighttop+shield.shield8.frontlefttop
3606  +shield.shield8.backlefttop+shield.shield8.frontrightbottom+shield.shield8.backrightbottom
3607  +shield.shield8.frontleftbottom+shield.shield8.backleftbottom;
3608  break;
3609  }
3610  return maxshield;
3611 }
void DestroyMount ( Mount )

Definition at line 44 of file mount.cpp.

References AUDStopPlaying(), Mount::DESTROYED, Mount::sound, Mount::status, and Mount::UnFire().

Referenced by Unit::ClearMounts(), Unit::DamageRandSys(), Unit::Destroy(), and disableSubUnits().

45 {
46  mount->UnFire();
47  AUDStopPlaying( mount->sound );
48  mount->status = Mount::DESTROYED;
49 }
bool DestroyPlayerSystem ( float  hull,
float  maxhull,
float  numhits 
)

Definition at line 4956 of file unit_generic.cpp.

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

Referenced by Unit::DealDamageToHullReturnArmor().

4957 {
4958  static float damage_chance = XMLSupport::parse_float( vs_config->getVariable( "physics", "damage_player_chance", ".5" ) );
4959  static float guaranteed_chance = XMLSupport::parse_float( vs_config->getVariable( "physics", "definite_damage_chance", ".1" ) );
4960  float chance = 1-( damage_chance*(guaranteed_chance+(maxhull-hull)/maxhull) );
4961  if (numhits > 1)
4962  chance = pow( chance, numhits );
4963  bool ret = (rand01() > chance);
4964  if (ret) {
4965  //printf("DAAAAAAMAGED!!!!\n");
4966  }
4967  return ret;
4968 }
bool DestroySystem ( float  hull,
float  maxhull,
float  numhits 
)

Definition at line 4946 of file unit_generic.cpp.

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

Referenced by Unit::DealDamageToHullReturnArmor().

4947 {
4948  static float damage_chance = XMLSupport::parse_float( vs_config->getVariable( "physics", "damage_chance", ".005" ) );
4949  static float guaranteed_chance = XMLSupport::parse_float( vs_config->getVariable( "physics", "definite_damage_chance", ".1" ) );
4950  float chance = 1-( damage_chance*(guaranteed_chance+(maxhull-hull)/maxhull) );
4951  if (numhits > 1)
4952  chance = pow( chance, numhits );
4953  return rand01() > chance;
4954 }
void disableSubUnits ( Unit uhn)

Definition at line 1824 of file unit_generic.cpp.

References DestroyMount(), disableSubUnits(), Unit::getSubUnits(), j, and Unit::mounts.

Referenced by disableSubUnits(), and GameUnit< UnitType >::Explode().

1825 {
1826  Unit *un;
1827  for (un_iter i = uhn->getSubUnits(); (un = *i) != NULL; ++i)
1828  disableSubUnits( un );
1829  for (unsigned int j = 0; j < uhn->mounts.size(); ++j)
1830  DestroyMount( &uhn->mounts[j] );
1831 }
void ExecuteDirector ( )

Definition at line 617 of file star_system_generic.cpp.

618 {
619  unsigned int curcockpit = _Universe->CurrentCockpit();
620  {
621  for (unsigned int i = 0; i < active_missions.size(); ++i)
622  if (active_missions[i]) {
623  _Universe->SetActiveCockpit( active_missions[i]->player_num );
625  if (ss) _Universe->pushActiveStarSystem( ss );
627  active_missions[i]->DirectorLoop();
628  if (ss) _Universe->popActiveStarSystem();
629  }
630  }
631  _Universe->SetActiveCockpit( curcockpit );
634  {
635  for (unsigned int i = 1; i < active_missions.size();) {
636  if (active_missions[i]) {
637  if (active_missions[i]->runtime.pymissions) {
638  ++i;
639  } else {
640  unsigned int w = active_missions.size();
641  active_missions[i]->terminateMission();
642  if ( w == active_missions.size() ) {
643  printf( "MISSION NOT ERASED\n" );
644  break;
645  }
646  }
647  } else {
648  active_missions.Get()->erase( active_missions.Get()->begin()+i );
649  }
650  }
651  }
652 }
Unit* findUnitInStarsystem ( void *  unitDoNotDereference)

Definition at line 4194 of file unit_generic.cpp.

References _Universe, Universe::activeStarSystem(), UnitCollection::constIterator(), and StarSystem::getUnitList().

Referenced by Unit::ApplyDamage(), CockpitKeys::Inside(), Orders::AggressiveAI::ProcessCurrentFgDirective(), and Cockpit::Update().

4195 {
4196  Unit *un;
4197  for (un_kiter i = _Universe->activeStarSystem()->getUnitList().constIterator(); (un = *i) != NULL; ++i)
4198  if (un == unitDoNotDereference)
4199  return un;
4200  return NULL;
4201 }
bool flickerDamage ( Unit un,
float  hullpercent 
)

Definition at line 317 of file unit_generic.cpp.

References damagelevel, flickertime, GetElapsedTime(), getNewTime(), VegaConfig::getVariable(), int, XMLSupport::parse_float(), and vs_config.

Referenced by GameUnit< UnitType >::Draw().

318 {
319 #define damagelevel hullpercent
320  static double counter = getNewTime();
321  static float flickertime = XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "time", "30" ) );
322  static float flickerofftime =
323  XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "off-time", "2" ) );
324  static float minflickercycle =
325  XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "min-cycle", "2" ) );
326  static float flickeronprob =
327  XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "num-times-per-second-on", ".66" ) );
328  static float hullfornoflicker =
329  XMLSupport::parse_float( vs_config->getVariable( "graphics", "glowflicker", "hull-for-total-dark", ".04" ) );
330  float diff = getNewTime()-counter;
331  if (diff > flickertime) {
332  counter = getNewTime();
333  diff = 0;
334  }
335  float tmpflicker = flickertime*damagelevel;
336  if (tmpflicker < minflickercycle)
337  tmpflicker = minflickercycle;
338  diff = fmod( diff, tmpflicker );
339  //we know counter is somewhere between 0 and damage level
340  //cast this to an int for fun!
341  unsigned int thus = ( (unsigned int) (size_t) un )>>2;
342  thus = thus%( (unsigned int) tmpflicker );
343  diff = fmod( diff+thus, tmpflicker );
344  if (flickerofftime > diff) {
345  if (damagelevel > hullfornoflicker)
346  return rand() > RAND_MAX * GetElapsedTime()*flickeronprob;
347  else
348  return true;
349  }
350  return false;
351 
352 #undef damagelevel
353 }
static void GCCBugCheckFloat ( float f,
int  offset 
)
static

Definition at line 6606 of file unit_generic.cpp.

Referenced by Unit::UpAndDownGrade().

6607 {
6608  if (f[offset] > 1)
6609  f[offset] = 1; //keep it real
6610 }
std::string GenerateAutoError ( Unit me,
Unit targ 
)

Definition at line 2818 of file unit_generic.cpp.

References XMLSupport::escaped_string(), Unit::getRelation(), VegaConfig::getVariable(), UnitUtil::isAsteroid(), Unit::isPlanet(), and vs_config.

Referenced by Unit::AutoPilotToErrorMessage().

2819 {
2820  if ( UnitUtil::isAsteroid( targ ) ) {
2821  static std::string err =
2822  XMLSupport::escaped_string( vs_config->getVariable( "graphics", "hud", "AsteroidsNearMessage",
2823  "#ff0000Asteroids Near#000000" ) );
2824  return err;
2825  }
2826  if ( targ->isPlanet() ) {
2827  static std::string err =
2828  XMLSupport::escaped_string( vs_config->getVariable( "graphics", "hud", "PlanetNearMessage",
2829  "#ff0000Planetary Hazard Near#000000" ) );
2830  return err;
2831  }
2832  if (targ->getRelation( me ) < 0) {
2833  static std::string err =
2834  XMLSupport::escaped_string( vs_config->getVariable( "graphics", "hud", "EnemyNearMessage",
2835  "#ff0000Enemy Near#000000" ) );
2836  return err;
2837  }
2838  static std::string err =
2839  XMLSupport::escaped_string( vs_config->getVariable( "graphics", "hud", "StarshipNearMessage",
2840  "#ff0000Starship Near#000000" ) );
2841  return err;
2842 }
float getAutoRSize ( Unit orig,
Unit un,
bool  ignore_friend = false 
)

Definition at line 178 of file unit_functions_generic.cpp.

References ASTEROIDPTR, Unit::faction, Unit::getFlightgroup(), FactionUtil::GetNeutralFaction(), Unit::getRelation(), FactionUtil::GetUpgradeFaction(), VegaConfig::getVariable(), Unit::isUnit(), XMLSupport::parse_float(), PLANETPTR, Unit::rSize(), Unit::Target(), and vs_config.

Referenced by Unit::AutoPilotToErrorMessage().

179 {
180  static float gamespeed = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
181 
182  static float friendly_autodist =
183  XMLSupport::parse_float( vs_config->getVariable( "physics", "friendly_auto_radius", "00" ) )*gamespeed;
184  static float neutral_autodist =
185  XMLSupport::parse_float( vs_config->getVariable( "physics", "neutral_auto_radius", "0" ) )*gamespeed;
186  static float hostile_autodist =
187  XMLSupport::parse_float( vs_config->getVariable( "physics", "hostile_auto_radius", "1000" ) )*gamespeed;
188  int upgradefaction = FactionUtil::GetUpgradeFaction();
189  int neutral = FactionUtil::GetNeutralFaction();
190  if (un->isUnit() == ASTEROIDPTR) {
191  static float minasteroiddistance =
192  XMLSupport::parse_float( vs_config->getVariable( "physics", "min_asteroid_distance", "-100" ) );
193  return minasteroiddistance;
194  }
195  if ( un->isUnit() == PLANETPTR || ( un->getFlightgroup() == orig->getFlightgroup() && orig->getFlightgroup() ) )
196  //same flihgtgroup
197  return orig->rSize();
198  if (un->faction == upgradefaction)
199  return ignore_friend ? -FLT_MAX : ( -orig->rSize()-un->rSize() );
200  float rel = un->getRelation( orig );
201  if ( orig == un->Target() )
202  rel -= 1.5;
203  if (un->faction == neutral)
204  return neutral_autodist;
205  else if (rel > .1)
206  return ignore_friend ? -FLT_MAX : friendly_autodist; //min distance apart
207  else if (rel < 0)
208  return hostile_autodist;
209  else
210  return ignore_friend ? -FLT_MAX : neutral_autodist;
211 }
float GetFuelUsage ( bool  afterburner)

Definition at line 3275 of file unit_generic.cpp.

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

Referenced by Unit::ClampThrust(), and Unit::ClampTorque().

3276 {
3277  static float normalfuelusage = XMLSupport::parse_float( vs_config->getVariable( "physics", "FuelUsage", "1" ) );
3278  static float abfuelusage = XMLSupport::parse_float( vs_config->getVariable( "physics", "AfterburnerFuelUsage", "4" ) );
3279  if (afterburner)
3280  return abfuelusage;
3281  return normalfuelusage;
3282 }
std::set< std::string > GetListOfDowngrades ( )

Definition at line 6802 of file unit_generic.cpp.

References vsUMap.

Referenced by BaseComputer::loadSellUpgradeControls().

6803 {
6804  using vsUMap;
6805  vsUMap< int, DoubleName >::iterator i = downgrademap.begin();
6806  std::set< std::string >retval;
6807  for (; i != downgrademap.end(); ++i)
6808  retval.insert( (*i).second.s );
6809  return retval;
6810 }
Cargo* GetMasterPartList ( const char *  input_buffer)

Definition at line 8519 of file unit_generic.cpp.

References Unit::GetCargo(), and GetUnitMasterPartList().

Referenced by Beam::Collide(), showUnitStats(), and BaseComputer::SellUpgradeOperation::start().

8520 {
8521  unsigned int i;
8523 }
std::string getMasterPartListUnitName ( )

Definition at line 33 of file unit_factory.cpp.

References VegaConfig::getVariable(), and vs_config.

34 {
35  static std::string mpl = vs_config->getVariable( "data", "master_part_list", "master_part_list" );
36  return mpl;
37 }
int GetModeFromName ( const char *  )

Definition at line 87 of file unit_xml.cpp.

88 {
89  if (strlen( input_buffer ) > 3) {
90  if (input_buffer[0] == 'a'
91  && input_buffer[1] == 'd'
92  && input_buffer[2] == 'd')
93  return 1;
94  if (input_buffer[0] == 'm'
95  && input_buffer[1] == 'u'
96  && input_buffer[2] == 'l')
97  return 2;
98  }
99  return 0;
100 }
std::string GetReadPlayerSaveGame ( int  )

Definition at line 128 of file savegame.cpp.

References GetHelperPlayerSaveGame().

Referenced by SaveGame::ParseSaveGame().

129 {
130  string ret = GetHelperPlayerSaveGame( num );
131  if ( !ret.empty() )
132  if (*ret.begin() == '~')
133  return "";
134  return ret;
135 }
double GetsB ( double  a,
double  b 
)

Definition at line 6099 of file unit_generic.cpp.

References b.

Referenced by Unit::UpAndDownGrade().

6100 {
6101  return b;
6102 }
std::string getTurretSize ( const std::string &  size)

Definition at line 6312 of file unit_generic.cpp.

References CheckBasicSizes(), h, parseTurretSizes(), and Tokenize().

Referenced by Unit::UpgradeSubUnitsWithFactory().

6313 {
6314  static std::map< VCString, VCString > turretmap = parseTurretSizes();
6315  std::map< VCString, VCString >::iterator h = turretmap.find( size );
6316  if ( h != turretmap.end() )
6317  return (*h).second;
6318  vector< string >tokens;
6319  Tokenize( size, tokens, "_" );
6320  for (unsigned int i = 0; i < tokens.size(); ++i) {
6321  if (tokens[i].find( "turret" ) != string::npos) {
6322  string temp = CheckBasicSizes( tokens[i] );
6323  if ( !temp.empty() )
6324  return temp;
6325  } else {
6326  return tokens[i];
6327  }
6328  }
6329  return "capital";
6330 }
string GetUnitDir ( string  filename)

Definition at line 690 of file unit_generic.cpp.

691 {
692  return filename.substr( 0, filename.find( "." ) );
693 }
char* GetUnitDir ( const char *  filename)

Definition at line 695 of file unit_generic.cpp.

References i.

696 {
697  char *retval = strdup( filename );
698  if (retval[0] == '\0')
699  return retval;
700  if (retval[1] == '\0')
701  return retval;
702  for (int i = 0; retval[i] != 0; ++i)
703  if (retval[i] == '.') {
704  retval[i] = '\0';
705  break;
706  }
707  return retval;
708 }
const Unit* getUnitFromUpgradeName ( const string &  upgradeName,
int  myUnitFaction = 0 
)

Definition at line 37 of file unit_functions_generic.cpp.

38 {
39  const char *name = upgradeName.c_str();
41  if (!partUnit) {
45  }
46  if (partUnit->name == "LOAD_FAILED") {
47  partUnit = UnitConstCache::getCachedConst( StringIntKey( name, myUnitFaction ) );
48  if (!partUnit)
49  partUnit = UnitConstCache::setCachedConst( StringIntKey( name, myUnitFaction ),
50  UnitFactory::createUnit( name, true, myUnitFaction ) );
51  }
52  return partUnit;
53 }
CSVRow GetUnitRow ( string  filename,
bool  subu,
int  faction,
bool  readLast,
bool read 
)

Definition at line 1429 of file unit_csv.cpp.

References FactionUtil::GetFactionName(), i, and unitTables.

1430 {
1431  std::string hashname = filename+"__"+FactionUtil::GetFactionName( faction );
1432  for (int i = ( (int) unitTables.size() )-(readlast ? 1 : 2); i >= 0; --i) {
1433  unsigned int where;
1434  if ( unitTables[i]->RowExists( hashname, where ) ) {
1435  rread = true;
1436  return CSVRow( unitTables[i], where );
1437  } else if ( unitTables[i]->RowExists( filename, where ) ) {
1438  rread = true;
1439  return CSVRow( unitTables[i], where );
1440  }
1441  }
1442  rread = false;
1443  return CSVRow();
1444 }
float globQueryShell ( QVector  pos,
QVector  dir,
float  rad 
)

Definition at line 308 of file unit_collide.cpp.

References a, b, c, and UniverseUtil::sqrt().

Referenced by Unit::AutoPilotToErrorMessage(), and globQuerySphere().

309 {
310  float temp1 = radius;
311  float a, b, c;
312  c = st.Dot( st );
313  c = c-temp1*temp1;
314  b = 2.0f*( dir.Dot( st ) );
315  a = dir.Dot( dir );
316  //b^2-4ac
317  c = b*b-4.0f*a*c;
318  if (c < 0 || a == 0)
319  return 0.0f;
320  a *= 2.0f;
321 
322  float tmp = ( -b+sqrt( c ) )/a;
323  c = ( -b-sqrt( c ) )/a;
324  if (tmp > 0 && tmp <= 1)
325  return (c > 0 && c < tmp) ? c : tmp;
326  else if (c > 0 && c <= 1)
327  return c;
328  return 0.0f;
329 }
bool GreaterZero ( double  a,
double  b 
)

Definition at line 6084 of file unit_generic.cpp.

Referenced by Unit::UpAndDownGrade().

6085 {
6086  return a >= 0;
6087 }
static Transformation HoldPositionWithRespectTo ( Transformation  holder,
const Transformation changeold,
const Transformation changenew 
)
static

Definition at line 5769 of file unit_generic.cpp.

References Quaternion::Conjugate(), VegaConfig::getVariable(), Transformation::orientation, XMLSupport::parse_bool(), Transformation::position, Quaternion::to_matrix(), TransformNormal(), and vs_config.

Referenced by Unit::PerformDockingOperations().

5772 {
5773  Quaternion bak = holder.orientation;
5774  holder.position = holder.position-changeold.position;
5775 
5776  Quaternion invandrest = changeold.orientation.Conjugate();
5777  invandrest *= changenew.orientation;
5778  holder.orientation *= invandrest;
5779  Matrix m;
5780 
5781  invandrest.to_matrix( m );
5782  holder.position = TransformNormal( m, holder.position );
5783 
5784  holder.position = holder.position+changenew.position;
5785  static bool changeddockedorient =
5786  ( XMLSupport::parse_bool( vs_config->getVariable( "physics", "change_docking_orientation", "false" ) ) );
5787  if (!changeddockedorient)
5788  holder.orientation = bak;
5789  return holder;
5790 }
double howFarToJump ( )

Definition at line 2129 of file unit_generic.cpp.

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

Referenced by ComputeJumpPointArrival(), GameCockpit::Draw(), and Unit::UpdatePhysics().

2130 {
2131  static float tmp = XMLSupport::parse_float( vs_config->getVariable( "physics", "distance_to_warp", "1000000000000.0" ) );
2132  return tmp;
2133 }
bool insideDock ( const DockingPorts dock,
const QVector pos,
float  radius 
)
inline

Definition at line 5930 of file unit_generic.cpp.

References DockingPorts::GetPosition(), DockingPorts::GetRadius(), and DockingPorts::IsOccupied().

Referenced by Unit::CanDockWithMe().

5931 {
5932  if (dock.IsOccupied())
5933  return false;
5934  return IsShorterThan(pos - dock.GetPosition(), double(radius + dock.GetRadius()));
5935 }
bool isMissile ( const weapon_info weap)

Definition at line 306 of file unit_generic.cpp.

References VegaConfig::getVariable(), weapon_info::LIGHTMISSILE, XMLSupport::parse_bool(), weapon_info::PROJECTILE, weapon_info::size, weapon_info::type, and vs_config.

Referenced by Mount::Activate(), Unit::ActivateGuns(), WeaponComparator< FORWARD >::checkmount(), Mount::DeActive(), Mount::Fire(), Unit::Fire(), Unit::LockMissile(), Mount::PhysicsAlignedFire(), and Unit::setAverageGunSpeed().

307 {
308  static bool useProjectile =
309  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "projectile_means_missile", "false" ) );
310  if (useProjectile && weap->type == weapon_info::PROJECTILE)
311  return true;
312  if (useProjectile == false && weap->size >= weapon_info::LIGHTMISSILE)
313  return true;
314  return false;
315 }
bool isWeapon ( std::string  name)

Definition at line 8815 of file unit_generic.cpp.

Referenced by BaseComputer::buyUpgrade(), BaseComputer::configureUpgradeCommitControls(), UnitUtil::PercentOperational(), Unit::RepairUpgradeCargo(), and BaseComputer::sellUpgrade().

8816 {
8817  if (name.find( "Weapon" ) != std::string::npos)
8818  return true;
8819  if (name.find( "SubUnit" ) != std::string::npos)
8820  return true;
8821  if (name.find( "Ammunition" ) != std::string::npos)
8822  return true;
8823  return false;
8824 }
const Unit* loadUnitByCache ( std::string  name,
int  faction 
)

Definition at line 4937 of file unit_generic.cpp.

References UnitFactory::createUnit(), StarSystemGent::faction, ClassCache< Typ, Key >::getCachedConst(), and ClassCache< Typ, Key >::setCachedConst().

Referenced by Unit::DealDamageToHullReturnArmor(), and Unit::RepairUpgrade().

4938 {
4939  const Unit *temprate = UnitConstCache::getCachedConst( StringIntKey( name, faction ) );
4940  if (!temprate)
4941  temprate =
4943  return temprate;
4944 }
std::string lookupMountSize ( int  s)

Definition at line 711 of file unit_generic.cpp.

References weapon_info::AUTOTRACKING, weapon_info::CAPSHIPHEAVY, weapon_info::CAPSHIPHEAVYMISSILE, weapon_info::CAPSHIPLIGHT, weapon_info::CAPSHIPLIGHTMISSILE, weapon_info::HEAVY, weapon_info::HEAVYMISSILE, weapon_info::LIGHT, weapon_info::LIGHTMISSILE, weapon_info::MEDIUM, weapon_info::MEDIUMMISSILE, weapon_info::SPECIAL, and weapon_info::SPECIALMISSILE.

712 {
713  std::string result;
714  if (s&weapon_info::LIGHT)
715  result += "LIGHT ";
716  if (s&weapon_info::MEDIUM)
717  result += "MEDIUM ";
718  if (s&weapon_info::HEAVY)
719  result += "HEAVY ";
721  result += "CAPSHIP-LIGHT ";
723  result += "CAPSHIP-HEAVY ";
724  if (s&weapon_info::SPECIAL)
725  result += "SPECIAL ";
727  result += "LIGHT-MISSILE ";
729  result += "MEDIUM-MISSILE ";
731  result += "HEAVY-MISSILE ";
733  result += "LIGHT-CAPSHIP-MISSILE ";
735  result += "HEAVY-CAPSHIP-MISSILE ";
737  result += "SPECIAL-MISSILE ";
739  result += "AUTOTRACKING ";
740  return result;
741 }
Unit* makeBlankUpgrade ( string  templnam,
int  faction 
)

Definition at line 4893 of file unit_generic.cpp.

References UnitFactory::createServerSideUnit(), StarSystemGent::faction, Unit::GetCargo(), Unit::Mass, Unit::numCargo(), q, Cargo::quantity, and Unit::RemoveCargo().

Referenced by makeFinalBlankUpgrade().

4894 {
4895  Unit *bl = UnitFactory::createServerSideUnit( templnam.c_str(), true, faction );
4896  for (int i = bl->numCargo()-1; i >= 0; i--) {
4897  int q = bl->GetCargo( i ).quantity;
4898  bl->RemoveCargo( i, q );
4899  }
4900  bl->Mass = 0;
4901  return bl;
4902 }
const Unit* makeFinalBlankUpgrade ( string  name,
int  faction 
)

Definition at line 4906 of file unit_generic.cpp.

References ClassCache< Typ, Key >::getCachedConst(), GetUnitDir(), LOAD_FAILED, makeBlankUpgrade(), Unit::name, and ClassCache< Typ, Key >::setCachedConst().

Referenced by Unit::ReduceToTemplate(), Unit::RepairUpgrade(), and BaseComputer::SellUpgradeOperation::start().

4907 {
4908  char *unitdir = GetUnitDir( name.c_str() );
4909  string limiternam = name;
4910  if (unitdir != name)
4911  limiternam = string( unitdir )+string( ".blank" );
4912  free( unitdir );
4913  const Unit *lim = UnitConstCache::getCachedConst( StringIntKey( limiternam, faction ) );
4914  if (!lim)
4915  lim = UnitConstCache::setCachedConst( StringIntKey( limiternam, faction ), makeBlankUpgrade( limiternam, faction ) );
4916  if (lim->name == LOAD_FAILED)
4917  lim = NULL;
4918  return lim;
4919 }
const Unit* makeTemplateUpgrade ( string  name,
int  faction 
)

Definition at line 4921 of file unit_generic.cpp.

References UnitFactory::createUnit(), StarSystemGent::faction, ClassCache< Typ, Key >::getCachedConst(), GetUnitDir(), LOAD_FAILED, Unit::name, and ClassCache< Typ, Key >::setCachedConst().

Referenced by UnitUtil::PercentOperational(), Unit::Repair(), Unit::RepairUpgrade(), Unit::RepairUpgradeCargo(), and BaseComputer::BuyUpgradeOperation::start().

4922 {
4923  char *unitdir = GetUnitDir( name.c_str() );
4924  string limiternam = string( unitdir )+string( ".template" );
4925  free( unitdir );
4926  const Unit *lim = UnitConstCache::getCachedConst( StringIntKey( limiternam, faction ) );
4927  if (!lim) {
4928  lim =
4930  faction ), UnitFactory::createUnit( limiternam.c_str(), true, faction ) );
4931  }
4932  if (lim->name == LOAD_FAILED)
4933  lim = NULL;
4934  return lim;
4935 }
double MultUp ( double  a,
double  b 
)

Definition at line 6094 of file unit_generic.cpp.

References b.

Referenced by Unit::UpAndDownGrade().

6095 {
6096  return a*b;
6097 }
bool myless ( const Cargo a,
const Cargo b 
)

Definition at line 8371 of file unit_generic.cpp.

References b.

8372 {
8373  return a < b;
8374 }
static float mymax ( float  a,
float  b 
)
static

Definition at line 56 of file unit_generic.cpp.

References a.

57 {
58  return a < b ? b : a;
59 }
static float mymin ( float  a,
float  b 
)
static

Definition at line 60 of file unit_generic.cpp.

References b.

61 {
62  return a < b ? a : b;
63 }
static std::string NearestSystem ( std::string  currentsystem,
QVector  pos 
)
static

Definition at line 2145 of file unit_generic.cpp.

References _Universe, Universe::AccessCockpit(), Universe::getGalaxy(), GalaxyXML::SGalaxy::getHeirarchy(), Cockpit::GetNavSelectedSystem(), VegaConfig::getVariable(), j, Universe::numPlayers(), XMLSupport::parse_float(), QVector, SystemLocation(), test, and vs_config.

Referenced by Unit::UpdatePhysics().

2146 {
2147  if (pos.i == 0 && pos.j == 0 && pos.k == 0)
2148  return "";
2149  QVector posnorm = pos.Normalize();
2150  posnorm.Normalize();
2151  QVector cur = SystemLocation( currentsystem );
2152  if (cur.i == 0 && cur.j == 0 && cur.k == 0)
2153  return "";
2154  double closest_distance = 0.0;
2155  std::string closest_system;
2157  GalaxyXML::SubHeirarchy *sectors = &gal->getHeirarchy();
2158  vsUMap< std::string, class GalaxyXML::SGalaxy >::iterator j, i = sectors->begin();
2159  for (; i != sectors->end(); ++i) {
2160  GalaxyXML::SubHeirarchy *systems = &i->second.getHeirarchy();
2161  for (j = systems->begin(); j != systems->end(); ++j) {
2162  std::string place = j->second["xyz"];
2163  if ( place.length() ) {
2164  QVector pos2 = QVector( 0, 0, 0 );
2165  sscanf( place.c_str(), "%lf %lf %lf", &pos2.i, &pos2.j, &pos2.k );
2166  if ( (pos2.i != 0 || pos2.j != 0 || pos2.k != 0) && (pos2.i != cur.i || pos2.j != cur.j || pos2.k != cur.k) ) {
2167  QVector dir = pos2-cur;
2168  QVector norm = dir;
2169  norm.Normalize();
2170  double test = posnorm.Dot( norm );
2171  if (test > .2) {
2172  //test=1-test;
2173  double tmp = dir.MagnitudeSquared()/test/test/test;
2174  for (unsigned int cp = 0; cp < _Universe->numPlayers(); ++cp) {
2175  std::string whereto = _Universe->AccessCockpit( cp )->GetNavSelectedSystem();
2176  if ( whereto.length() == 1+i->first.length()+j->first.length() ) {
2177  if (whereto.substr( 0,
2178  i->first.length() ) == i->first && whereto.substr( i->first.length()+1 )
2179  == j->first) {
2180  static float SystemWarpTargetBonus =
2182  "target_distance_to_warp_bonus",
2183  "1.33" ) );
2184  tmp /= SystemWarpTargetBonus;
2185  }
2186  }
2187  }
2188  if (tmp < closest_distance || closest_distance == 0) {
2189  closest_distance = tmp;
2190  closest_system = i->first+"/"+j->first;
2191  }
2192  }
2193  }
2194  }
2195  }
2196  }
2197  return closest_system;
2198 }
std::map< VCString, VCString > parseTurretSizes ( )

Definition at line 6281 of file unit_generic.cpp.

References VSFileSystem::VSFile::Close(), VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), VSFileSystem::VSFile::ReadLine(), VSFileSystem::VSFile::Size(), VSFileSystem::UnknownFile, x, and y.

Referenced by getTurretSize().

6282 {
6283  using namespace VSFileSystem;
6284  std::map< VCString, VCString >t;
6285  VSFile f;
6286  VSError err = f.OpenReadOnly( "units/subunits/size.txt", UnknownFile );
6287  if (err <= Ok) {
6288  int siz = f.Size();
6289  char *filedata = (char*) malloc( siz+1 );
6290  filedata[siz] = 0;
6291  while (f.ReadLine( filedata, siz ) == Ok) {
6292  std::string x( filedata );
6293  string::size_type len = x.find( "," );
6294  if (len != std::string::npos) {
6295  std::string y = x.substr( len+1 );
6296  x = x.substr( 0, len );
6297  len = y.find( "," );
6298  y = y.substr( 0, len );
6299  sscanf( y.c_str(), "%s", filedata );
6300  y = filedata;
6301  VCString key( x );
6302  VCString value( y );
6303  t[key] = value;
6304  }
6305  }
6306  free( filedata );
6307  f.Close();
6308  }
6309  return t;
6310 }
bool preEmptiveClientFire ( const weapon_info wi)

Definition at line 1415 of file unit_generic.cpp.

References weapon_info::BEAM, VegaConfig::getVariable(), XMLSupport::parse_bool(), weapon_info::PROJECTILE, weapon_info::type, and vs_config.

Referenced by Unit::Fire().

1416 {
1417  static bool
1418  client_side_fire = XMLSupport::parse_bool( vs_config->getVariable( "network", "client_side_fire", "true" ) );
1419  return client_side_fire && wi->type != weapon_info::BEAM && wi->type != weapon_info::PROJECTILE;
1420 }
bool Quit ( const char *  input_buffer)

Definition at line 6235 of file unit_generic.cpp.

6236 {
6237  if (strcasecmp( input_buffer, "exit" ) == 0
6238  || strcasecmp( input_buffer, "quit" ) == 0)
6239  return true;
6240  return false;
6241 }
float rand01 ( )

Definition at line 641 of file unit_generic.cpp.

References float.

Referenced by Unit::DamageRandSys(), Unit::DealDamageToHullReturnArmor(), DestroyPlayerSystem(), DestroySystem(), GameCockpit::Draw(), and GameUniverse::StartDraw().

642 {
643  return (float) rand()/(float) RAND_MAX;
644 }
QVector randVector ( float  min,
float  max 
)
inline

Definition at line 7900 of file unit_generic.cpp.

References QVector, and uniformrand().

Referenced by Unit::EjectCargo().

7901 {
7902  return QVector( uniformrand( min, max ),
7903  uniformrand( min, max ),
7904  uniformrand( min, max ) );
7905 }
static QVector RealPosition ( Unit un)
static

Definition at line 2790 of file unit_generic.cpp.

References Unit::isSubUnit(), Unit::LocalPosition(), and Unit::Position().

Referenced by Unit::AutoPilotToErrorMessage(), AutoSafeEntrancePoint(), Unit::ResolveForces(), and Unit::UnDock().

2791 {
2792  if ( un->isSubUnit() )
2793  return un->Position();
2794  return un->LocalPosition();
2795 }
Vector ReflectNormal ( const Vector vel,
const Vector norm 
)

Definition at line 356 of file unit_generic.cpp.

357 {
358  //THIS ONE WORKS...but no...we don't want works return norm * (2*vel.Dot(norm)) - vel;
359  return norm*vel.Magnitude();
360 }
float RepairPrice ( float  operational,
float  price 
)

Definition at line 7684 of file unit_generic.cpp.

References game_data_t::difficulty, and g_game.

Referenced by BaseComputer::configureUpgradeCommitControls(), Unit::RepairUpgradeCargo(), SellPrice(), and BaseComputer::updateTransactionControlsForSelection().

7685 {
7686  return .5*price*(1-operational)*g_game.difficulty;
7687 }
static float safeacos ( float  mycos)
inlinestatic

Definition at line 1718 of file unit_generic.cpp.

References UniverseUtil::acos().

Referenced by Unit::cosAngleTo().

1719 {
1720  if (mycos > 1.)
1721  mycos = 1.;
1722  if (mycos < -1.)
1723  mycos = -1;
1724  return acos( mycos );
1725 }
void ScoreKill ( Cockpit cp,
Unit killer,
Unit killedUnit 
)

Definition at line 106 of file unit_functions_generic.cpp.

References _Universe, Universe::AccessCockpit(), UniverseUtil::adjustRelationModifierInt(), c, Order::Communicate(), StarSystemGent::faction, Unit::faction, CommunicationMessage::fsm, Unit::getAIState(), Pilot::getCommFaces(), FactionUtil::GetIntRelation(), SaveGame::getMissionData(), FactionUtil::GetNumFactions(), Cockpit::GetParent(), FactionUtil::GetPlanetFaction(), UniverseUtil::getRelationModifierInt(), UnitUtil::getRelationToFaction(), FSM::GetScoreKillNode(), UnitUtil::getUnitSystemFile(), FactionUtil::GetUpgradeFaction(), VegaConfig::getVariable(), i, int, Unit::isUnit(), Universe::numPlayers(), XMLSupport::parse_float(), Unit::pilot, Cockpit::savegame, CommunicationMessage::SetCurrentState(), UNITPTR, vs_config, and Universe::whichPlayerStarship().

Referenced by Unit::ApplyDamage().

107 {
108  if (un->isUnit() != UNITPTR || killedUnit->isUnit() != UNITPTR)
109  return;
110  static float KILL_FACTOR = -XMLSupport::parse_float( vs_config->getVariable( "AI", "kill_factor", ".2" ) );
111  int killedCp = _Universe->whichPlayerStarship( killedUnit );
112  int killerCp = killedCp;
113  if (killedCp != -1) {
114  UniverseUtil::adjustRelationModifierInt( killedCp, un->faction, KILL_FACTOR );
115  } else {
116  killerCp = _Universe->whichPlayerStarship( un );
117  if (killerCp != -1)
118  UniverseUtil::adjustRelationModifierInt( killerCp, killedUnit->faction, KILL_FACTOR );
119  }
120  int faction = killedUnit->faction;
121  static float FRIEND_FACTOR = -XMLSupport::parse_float( vs_config->getVariable( "AI", "friend_factor", ".1" ) );
122  for (unsigned int i = 0; i < FactionUtil::GetNumFactions(); i++) {
123  float relation;
124  if (faction != (int) i && un->faction != (int) i) {
125  relation = FactionUtil::GetIntRelation( i, faction );
126  if (killedCp != -1)
127  relation += UniverseUtil::getRelationModifierInt( i, faction );
128  if (relation)
129  if (killerCp != -1)
130  UniverseUtil::adjustRelationModifierInt( killerCp, i, FRIEND_FACTOR*relation );
131  }
132  }
133  int upgrades = FactionUtil::GetUpgradeFaction();
134  int planets = FactionUtil::GetPlanetFaction();
135  if (cp != NULL) {
136  vector< float > *killlist = &cp->savegame->getMissionData( string( "kills" ) );
137  while ( killlist->size() <= FactionUtil::GetNumFactions() )
138  killlist->push_back( (float) 0.0 );
139  if ( (int) killlist->size() > faction )
140  (*killlist)[faction]++;
141  killlist->back()++;
142  } else if (UnitUtil::getRelationToFaction( un, faction ) < 0 && faction != upgrades && faction != planets) {
143  int whichcp = rand()%_Universe->numPlayers();
144  Unit *whichrecv = _Universe->AccessCockpit( whichcp )->GetParent();
145  if (whichrecv != NULL) {
146  if ( UnitUtil::getUnitSystemFile( whichrecv ) == UnitUtil::getUnitSystemFile( un ) ) {
147  if ( un->getAIState() && whichrecv->getAIState() ) {
148  unsigned char sex;
149  vector< Animation* > *anim = un->pilot->getCommFaces( sex );
150  CommunicationMessage c( un, whichrecv, anim, sex );
151  c.SetCurrentState( c.fsm->GetScoreKillNode(), anim, sex );
152  whichrecv->getAIState()->Communicate( c );
153  }
154  }
155  }
156  }
157 }
int SelectDockPort ( Unit ,
Unit parent 
)

Definition at line 110 of file docking.cpp.

References Unit::DockingPortLocations(), Unit::GetTransformation(), i, Unit::Position(), Transform(), and Vector.

Referenced by Unit::EjectCargo(), FireKeyboard::Execute(), BaseComputer::loadCargoControls(), and Orders::DockingOps::RequestClearence().

111 {
112  const vector< DockingPorts >& dp = utdw->DockingPortLocations();
113  float dist = FLT_MAX;
114  int num = -1;
115  for (unsigned int i = 0; i < dp.size(); ++i)
116  if (!dp[i].IsOccupied()) {
117  Vector rez = Transform( utdw->GetTransformation(), dp[i].GetPosition() );
118  float wdist = ( rez - parent->Position() ).MagnitudeSquared();
119  if (wdist < dist) {
120  num = i;
121  dist = wdist;
122  }
123  }
124  return num;
125 }
void SetShieldZero ( Unit )

Definition at line 78 of file unit_functions_generic.cpp.

79 {
80  switch (un->shield.number)
81  {
82  case 8:
83 
84  un->shield.shield8.frontlefttop =
85  un->shield.shield8.frontrighttop =
86  un->shield.shield8.backlefttop =
87  un->shield.shield8.backrighttop =
88  un->shield.shield8.frontleftbottom =
89  un->shield.shield8.frontrightbottom =
90  un->shield.shield8.backleftbottom =
91  un->shield.shield8.backrightbottom = 0;
92  break;
93  case 4:
94  un->shield.shield4fbrl.front =
95  un->shield.shield4fbrl.back =
96  un->shield.shield4fbrl.left =
97  un->shield.shield4fbrl.right = 0;
98  break;
99  case 2:
100  un->shield.shield2fb.front = un->shield.shield2fb.back = 0;
101  break;
102  }
103 }
std::string speedStarHandler ( const XMLType input,
void *  mythis 
)

Definition at line 668 of file unit_generic.cpp.

References XMLType::wordlength::f, VegaConfig::getVariable(), XMLSupport::parse_float(), XMLSupport::tostring(), vs_config, and XMLType::w.

669 {
670  static float game_speed = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
671  return XMLSupport::tostring( (*input.w.f)/game_speed );
672 }
double SubtractClamp ( double  a,
double  b 
)

Definition at line 6114 of file unit_generic.cpp.

References b.

6115 {
6116  return (a-b < 0) ? 0 : a-b;
6117 }
double SubtractUp ( double  a,
double  b 
)

Definition at line 6109 of file unit_generic.cpp.

References b.

Referenced by Unit::UpAndDownGrade().

6110 {
6111  return a-b;
6112 }
void SwitchUnits ( Unit ,
Unit  
)

Definition at line 328 of file cockpit_generic.cpp.

References _Universe, Universe::AccessCockpit(), Universe::CurrentCockpit(), Cockpit::GetParent(), Unit::getRelation(), i, Universe::numPlayers(), Unit::PrimeOrders(), Unit::SetAI(), Unit::SetVisible(), SwitchUnits2(), and Unit::Target().

329 {
330  bool pointingtool = false;
331  bool pointingtonw = false;
332  for (unsigned int i = 0; i < _Universe->numPlayers(); ++i)
333  if ( i != _Universe->CurrentCockpit() ) {
334  if (_Universe->AccessCockpit( i )->GetParent() == ol)
335  pointingtool = true;
336  if (_Universe->AccessCockpit( i )->GetParent() == nw)
337  pointingtonw = true;
338  }
339  if ( ol && (!pointingtool) ) {
340  Unit *oltarg = ol->Target();
341  if (oltarg)
342  if (ol->getRelation( oltarg ) >= 0)
343  ol->Target( NULL );
344  ol->PrimeOrders();
345  ol->SetAI( new Orders::AggressiveAI( "default.agg.xml" ) );
346  ol->SetVisible( true );
347  }
348  SwitchUnits2( nw );
349 }
QVector SystemLocation ( std::string  system)

Definition at line 2135 of file unit_generic.cpp.

References _Universe, Universe::getGalaxyProperty(), and QVector.

Referenced by ComputeJumpPointArrival(), GameCockpit::Draw(), NearestSystem(), and WarpPursuit().

2136 {
2137  string xyz = _Universe->getGalaxyProperty( system, "xyz" );
2138  QVector pos;
2139  if ( xyz.size() && (sscanf( xyz.c_str(), "%lf %lf %lf", &pos.i, &pos.j, &pos.k ) >= 3) )
2140  return pos;
2141  else
2142  return QVector( 0, 0, 0 );
2143 }
static float tmpmax ( float  a,
float  b 
)
static

Definition at line 1343 of file unit_generic.cpp.

References b.

Referenced by Unit::calculate_extent(), and Unit::cosAngleTo().

1344 {
1345  return a > b ? a : b;
1346 }
static float tmpsqr ( float  x)
static

Definition at line 1690 of file unit_generic.cpp.

References x.

Referenced by CloseEnoughToAutotrack().

1691 {
1692  return x*x;
1693 }
void Tokenize ( const string &  str,
vector< string > &  tokens,
const string &  delimiters = " " 
)

Definition at line 6245 of file unit_generic.cpp.

Referenced by getTurretSize().

6246 {
6247  //Skip delimiters at beginning.
6248  string::size_type lastPos = str.find_first_not_of( delimiters, 0 );
6249  //Find first "non-delimiter".
6250  string::size_type pos = str.find_first_of( delimiters, lastPos );
6251  while (string::npos != pos || string::npos != lastPos) {
6252  //Found a token, add it to the vector.
6253  tokens.push_back( str.substr( lastPos, pos-lastPos ) );
6254  //Skip delimiters. Note the "not_of"
6255  lastPos = str.find_first_not_of( delimiters, pos );
6256  //Find next "non-delimiter"
6257  pos = str.find_first_of( delimiters, lastPos );
6258  }
6259 }
string toLowerCase ( string  in)

Definition at line 8988 of file unit_generic.cpp.

Referenced by MeshAnimation::Init().

8989 {
8990  string out;
8991  for(unsigned int i = 0; i < in.length(); i++)
8992  {
8993  switch(in[i])
8994  {
8995  case 'A': out +='a'; break;
8996  case 'B': out +='b'; break;
8997  case 'C': out +='c'; break;
8998  case 'D': out +='d'; break;
8999  case 'E': out +='e'; break;
9000  case 'F': out +='f'; break;
9001  case 'G': out +='g'; break;
9002  case 'H': out +='h'; break;
9003  case 'I': out +='i'; break;
9004  case 'J': out +='j'; break;
9005  case 'K': out +='k'; break;
9006  case 'L': out +='l'; break;
9007  case 'M': out +='m'; break;
9008  case 'N': out +='n'; break;
9009  case 'O': out +='o'; break;
9010  case 'P': out +='p'; break;
9011  case 'Q': out +='q'; break;
9012  case 'R': out +='r'; break;
9013  case 'S': out +='s'; break;
9014  case 'T': out +='t'; break;
9015  case 'U': out +='u'; break;
9016  case 'V': out +='v'; break;
9017  case 'W': out +='w'; break;
9018  case 'X': out +='x'; break;
9019  case 'Y': out +='y'; break;
9020  case 'Z': out +='z'; break;
9021  default:
9022  out += in[i];
9023  }
9024  }
9025  return out;
9026 }
float totalShieldEnergyCapacitance ( const Shield shield)

Definition at line 3613 of file unit_generic.cpp.

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

Referenced by Unit::EnergyData(), Unit::RegenShields(), and showUnitStats().

3614 {
3615  static float shieldenergycap =
3616  XMLSupport::parse_float( vs_config->getVariable( "physics", "shield_energy_capacitance", ".2" ) );
3617  static bool use_max_shield_value =
3618  XMLSupport::parse_bool( vs_config->getVariable( "physics", "use_max_shield_energy_usage", "false" ) );
3619  return shieldenergycap*use_max_shield_value ? totalShieldVal( shield ) : currentTotalShieldVal( shield );
3620 }
float totalShieldVal ( const Shield shield)

Definition at line 3572 of file unit_generic.cpp.

References Shield::number, Shield::shield2fb, Shield::shield4fbrl, and Shield::shield8.

Referenced by totalShieldEnergyCapacitance().

3573 {
3574  float maxshield = 0;
3575  switch (shield.number)
3576  {
3577  case 2:
3578  maxshield = shield.shield2fb.frontmax+shield.shield2fb.backmax;
3579  break;
3580  case 4:
3581  maxshield = shield.shield4fbrl.frontmax+shield.shield4fbrl.backmax+shield.shield4fbrl.leftmax
3582  +shield.shield4fbrl.rightmax;
3583  break;
3584  case 8:
3585  maxshield = shield.shield8.frontrighttopmax+shield.shield8.backrighttopmax+shield.shield8.frontlefttopmax
3586  +shield.shield8.backlefttopmax+shield.shield8.frontrightbottommax+shield.shield8.backrightbottommax
3587  +shield.shield8.frontleftbottommax+shield.shield8.backleftbottommax;
3588  break;
3589  }
3590  return maxshield;
3591 }
void TurnJumpOKLightOn ( Unit un,
Cockpit cp 
)

Definition at line 3078 of file unit_generic.cpp.

References Unit::UnitJump::drive, Unit::UnitJump::energy, Unit::GetJumpStatus(), Unit::GetWarpEnergy(), and Cockpit::jumpok.

Referenced by Unit::jumpReactToCollision().

3079 {
3080  if (cp) {
3081  if (un->GetWarpEnergy() >= un->GetJumpStatus().energy)
3082  if (un->GetJumpStatus().drive > -2)
3083  cp->jumpok = 1;
3084  }
3085 }
void UncheckUnit ( Unit un)

Definition at line 684 of file unit_generic.cpp.

References deletedUn.

Referenced by Unit::Init().

685 {
686  if (deletedUn.Get( (long) un ) != NULL)
687  deletedUn.Delete( (long) un );
688 }
float uniformrand ( float  min,
float  max 
)
inline

Definition at line 7895 of file unit_generic.cpp.

References min().

Referenced by randVector().

7896 {
7897  return ( (float) ( rand() )/RAND_MAX )*(max-min)+min;
7898 }
void update_ani_cache ( )

Definition at line 51 of file unit_functions.cpp.

52 {
53  for (std::set< std::string >::iterator it = tempcache.begin(); it != tempcache.end(); it++)
54  if ( cached_ani.find( *it ) == cached_ani.end() )
55  cached_ani.insert( std::pair< std::string, Animation* > ( *it,
56  new Animation( (*it).c_str(), false, .1, BILINEAR, false ) ) );
57  tempcache.clear();
58 }
void UpdateMasterPartList ( Unit )

Definition at line 1758 of file unit_csv.cpp.

References _Universe, Universe::AccessCockpit(), UnitImages< BOGUS >::cargo, Cargo::category, Cargo::content, Cargo::description, Unit::GetCargo(), Unit::GetImageInformation(), SaveGame::getMissionStringData(), i, j, Cargo::mass, Unit::numCargo(), Universe::numPlayers(), XMLSupport::parse_float(), Cargo::price, Cargo::quantity, Unit::RemoveCargo(), Cockpit::savegame, and Cargo::volume.

Referenced by Unit::ForceDock(), and Unit::makeMasterPartList().

1759 {
1760  for (unsigned int i = 0; i < _Universe->numPlayers(); ++i) {
1761  Cockpit *cp = _Universe->AccessCockpit( i );
1762  std::vector< std::string > *addedcargoname = &cp->savegame->getMissionStringData( "master_part_list_content" );
1763  std::vector< std::string > *addedcargocat = &cp->savegame->getMissionStringData( "master_part_list_category" );
1764  std::vector< std::string > *addedcargovol = &cp->savegame->getMissionStringData( "master_part_list_volume" );
1765  std::vector< std::string > *addedcargoprice = &cp->savegame->getMissionStringData( "master_part_list_price" );
1766  std::vector< std::string > *addedcargomass = &cp->savegame->getMissionStringData( "master_part_list_mass" );
1767  std::vector< std::string > *addedcargodesc = &cp->savegame->getMissionStringData( "master_part_list_description" );
1768  for (unsigned int j = 0; j < addedcargoname->size(); ++j) {
1769  Cargo carg;
1770  carg.content = (*addedcargoname)[j];
1771  carg.category = ( j < addedcargocat->size() ? (*addedcargocat)[j] : std::string( "Uncategorized" ) );
1772  carg.volume = (j < addedcargovol->size() ? XMLSupport::parse_float( (*addedcargovol)[j] ) : 1.0);
1773  carg.price = (j < addedcargoprice->size() ? XMLSupport::parse_float( (*addedcargoprice)[j] ) : 0.0);
1774  carg.mass = (j < addedcargomass->size() ? XMLSupport::parse_float( (*addedcargomass)[j] ) : .01);
1775  carg.description = ( j < addedcargodesc->size() ? (*addedcargodesc)[j] : std::string( "No Description Added" ) );
1776  carg.quantity = 1;
1777  ret->GetImageInformation().cargo.push_back( carg );
1778  }
1779  }
1780  std::sort( ret->GetImageInformation().cargo.begin(), ret->GetImageInformation().cargo.end() );
1781  {
1782  Cargo last_cargo;
1783  for (int i = ret->numCargo()-1; i >= 0; --i) {
1784  if (ret->GetCargo( i ).content == last_cargo.content
1785  && ret->GetCargo( i ).category == last_cargo.category)
1786  ret->RemoveCargo( i, ret->GetCargo( i ).quantity, true );
1787  else
1788  last_cargo = ret->GetCargo( i );
1789  }
1790  }
1791 }
int UpgradeBoolval ( int  a,
int  upga,
bool  touchme,
bool  downgrade,
int numave,
double &  percentage,
bool  force_nothing 
)

Definition at line 6206 of file unit_generic.cpp.

References a.

Referenced by Unit::UpAndDownGrade().

6207 {
6208  if (downgrade) {
6209  if (a && upga) {
6210  if (touchme) (a = false);
6211  ++numave;
6212  ++percentage;
6213  }
6214  } else {
6215  if (!a && upga) {
6216  if (touchme) a = true;
6217  ++numave;
6218  ++percentage;
6219  } else if (force_nothing && a && !upga) {
6220  if (touchme) a = false;
6221  ++numave;
6222  ++percentage;
6223  }
6224  }
6225  return a;
6226 }
static int UpgradeFloat ( double &  result,
double  tobeupgraded,
double  upgrador,
double  templatelimit,
double(*)(double, double)  myadd,
bool(*)(double a, double b betterthan,
double  nothing,
double  completeminimum,
double(*)(double oldvar, double upgrador, double newvar)  computepercentage,
double &  percentage,
bool  forcedowngrade,
bool  usetemplate,
double  at_least_this,
bool(*)(double a, double b atLeastthiscompare = AGreaterB,
bool  clamp = false,
bool  force_nothing = false 
)
static

we know we can replace result with newsum

Definition at line 6156 of file unit_generic.cpp.

References CAUSESDOWNGRADE, LIMITEDBYTEMPLATE, NOTTHERE, and UPGRADEOK.

6166 {
6167  //if upgrador is better than nothing
6168  if (upgrador != nothing || force_nothing) {
6169  if (clamp)
6170  if (tobeupgraded > upgrador)
6171  upgrador = tobeupgraded;
6172  float newsum = (*myadd)(tobeupgraded, upgrador);
6173  //if we're downgrading
6174  if (!force_nothing && newsum < tobeupgraded && at_least_this >= upgrador && at_least_this > newsum && at_least_this
6175  >= tobeupgraded)
6176  return newsum == upgrador ? CAUSESDOWNGRADE : NOTTHERE;
6177  if ( newsum != tobeupgraded && ( ( (*betterthan)(newsum, tobeupgraded) || forcedowngrade ) ) ) {
6178  if ( ( (*betterthan)(newsum, templatelimit) && usetemplate ) || newsum < completeminimum ) {
6179  if (!forcedowngrade)
6180  return LIMITEDBYTEMPLATE;
6181  if (newsum < completeminimum)
6182  newsum = completeminimum;
6183  else
6184  newsum = templatelimit;
6185  }
6187  percentage = (*computepercentage)(tobeupgraded, upgrador, newsum);
6188  if ( (*atLeastthiscompare)(at_least_this, newsum) && (!force_nothing) ) {
6189  if ( (*atLeastthiscompare)(at_least_this, tobeupgraded) )
6190  //no shift
6191  newsum = tobeupgraded;
6192  else
6193  //set it to its min
6194  newsum = at_least_this;
6195  }
6196  result = newsum;
6197  return UPGRADEOK;
6198  } else {
6199  return CAUSESDOWNGRADE;
6200  }
6201  } else {
6202  return NOTTHERE;
6203  }
6204 }
static std::string upgradeString ( "Upgrades"  )
static

Referenced by cell_has_recursive_data().

float WARPENERGYMULTIPLIER ( Unit un)

Definition at line 3550 of file unit_generic.cpp.

References _Universe, Unit::getFlightgroup(), UnitContainer::GetUnit(), VegaConfig::getVariable(), Universe::isPlayerStarship(), Flightgroup::leader, XMLSupport::parse_float(), and vs_config.

Referenced by Unit::RegenShields().

3551 {
3552  static float warpenergymultiplier =
3553  XMLSupport::parse_float( vs_config->getVariable( "physics", "warp_energy_multiplier", "0.12" ) );
3554  static float playerwarpenergymultiplier =
3555  XMLSupport::parse_float( vs_config->getVariable( "physics", "warp_energy_player_multiplier", ".12" ) );
3556  bool player = _Universe->isPlayerStarship( un ) != NULL;
3557  Flightgroup *fg = un->getFlightgroup();
3558  if (fg && !player)
3559  player = _Universe->isPlayerStarship( fg->leader.GetUnit() ) != NULL;
3560  return player ? playerwarpenergymultiplier : warpenergymultiplier;
3561 }
void WarpPursuit ( Unit un,
StarSystem sourcess,
std::string  destination 
)

Definition at line 5260 of file unit_generic.cpp.

References Unit::UnitJump::delay, float_to_int(), StarSystem::getFileName(), VegaConfig::getVariable(), Unit::jump, StarSystem::JumpTo(), Magnitude(), XMLSupport::parse_bool(), XMLSupport::parse_float(), SystemLocation(), and vs_config.

Referenced by Unit::Target(), and GameUnit< UnitType >::TransferUnitToSystem().

5261 {
5262  static bool AINotUseJump = XMLSupport::parse_bool( vs_config->getVariable( "physics", "no_ai_jump_points", "false" ) );
5263  if (AINotUseJump) {
5264  static float seconds_per_parsec =
5265  XMLSupport::parse_float( vs_config->getVariable( "physics", "seconds_per_parsec", "10" ) );
5266  float ttime =
5267  ( SystemLocation( sourcess->getFileName() )-SystemLocation( destination ) ).Magnitude()*seconds_per_parsec;
5268  un->jump.delay += float_to_int( ttime );
5269  sourcess->JumpTo( un, NULL, destination, true, true );
5270  un->jump.delay -= float_to_int( ttime );
5271  }
5272 }
bool withinShield ( const ShieldFacing facing,
float  theta,
float  rho 
)

Definition at line 5144 of file unit_generic.cpp.

References ShieldFacing::rhomax, ShieldFacing::rhomin, ShieldFacing::thetamax, and ShieldFacing::thetamin.

Referenced by Unit::DealDamageToShield().

5145 {
5146  float theta360 = theta+2*3.1415926536;
5147  return rho >= facing.rhomin && rho < facing.rhomax
5148  && ( (theta >= facing.thetamin
5149  && theta < facing.thetamax) || (theta360 >= facing.thetamin && theta360 < facing.thetamax) );
5150 }
void YoinkNewlines ( char *  input_buffer)

Definition at line 6228 of file unit_generic.cpp.

6229 {
6230  for (int i = 0; input_buffer[i] != '\0'; ++i)
6231  if (input_buffer[i] == '\n' || input_buffer[i] == '\r')
6232  input_buffer[i] = '\0';
6233 }

Variable Documentation

std::set< Unit* > arrested_list_do_not_dereference

Definition at line 5826 of file unit_generic.cpp.

Referenced by Unit::ForceDock().

float capship_size = 500

Definition at line 646 of file unit_generic.cpp.

Referenced by Unit::Init(), and Unit::InRange().

int curdowngrademapoffset = 5*sizeof (Unit)

Definition at line 6780 of file unit_generic.cpp.

int deathofvs = 1

Definition at line 676 of file unit_generic.cpp.

Referenced by CheckUnit().

Hashtable< long, Unit, 2095 > deletedUn
static

Definition at line 675 of file unit_generic.cpp.

Referenced by CheckUnit(), and UncheckUnit().

const GFXColor disable(1, 0, 0, 1)
static
vsUMap< int, DoubleName > downgrademap

Definition at line 6779 of file unit_generic.cpp.

HasRecursiveData has_recursive_data
static

Definition at line 6816 of file unit_generic.cpp.

const string LOAD_FAILED = "LOAD_FAILED"
static

Definition at line 4904 of file unit_generic.cpp.

Referenced by makeFinalBlankUpgrade(), and makeTemplateUpgrade().

vector< Vector > perplines

Definition at line 53 of file star_system_generic.cpp.

vector< int > switchunit

Definition at line 38 of file cockpit_generic.cpp.

Referenced by Cockpit::Update().

vector< int > turretcontrol

Definition at line 6004 of file unit_generic.cpp.

Referenced by Unit::UnDock(), and Cockpit::Update().

list< Unit* > Unitdeletequeue
static

Definition at line 674 of file unit_generic.cpp.

Referenced by Unit::Kill(), and Unit::ProcessDeleteQueue().