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
GameCockpit Class Reference

#include <cockpit.h>

Inheritance diagram for GameCockpit:
Cockpit

Public Member Functions

virtual void setTargetLabel (const string &msg)
 
virtual string getTargetLabel ()
 
void ReceivedTargetInfo ()
 
void InitStatic ()
 
void Shake (float amt, int level)
 
int Autopilot (Unit *target)
 
void RestoreViewPort ()
 Restores the view from the IDentity Matrix needed to draw sprites. More...
 
 GameCockpit (const char *file, Unit *parent, const std::string &pilotname)
 
 ~GameCockpit ()
 
float LookupTargetStat (int stat, Unit *target)
 Looks up a particular Gauge stat on target unit. More...
 
float LookupUnitStat (int stat, Unit *target)
 Looks up a particular Gauge stat on unit. More...
 
void Init (const char *file)
 Loads cockpit info...just as constructor. More...
 
void Draw ()
 Draws Cockpit then restores viewport. More...
 
void UpdAutoPilot ()
 
void SetupViewPort (bool clip=true)
 Sets up the world for rendering...call before draw. More...
 
int getVDUMode (int vdunum)
 
void VDUSwitch (int vdunum)
 
void ScrollVDU (int vdunum, int howmuch)
 
void ScrollAllVDU (int howmuch)
 
int getScrollOffset (unsigned int whichtype)
 
void SelectProperCamera ()
 
void Eject ()
 
void EjectDock ()
 
void SetSoundFile (std::string sound)
 
int GetSoundFile ()
 
void SetCommAnimation (Animation *ani, Unit *un)
 
void SetStaticAnimation ()
 
NavigationSystemAccessNavSystem ()
 Accesses the current navigationsystem. More...
 
virtual std::string GetNavSelectedSystem ()
 
CameraAccessCamera ()
 Accesses the current camera. More...
 
CameraAccessCamera (int)
 Returns the passed in cam. More...
 
void SelectCamera (int)
 Changes current camera to selected camera. More...
 
void SetViewport ()
 GFXLoadMatrix proper camera. More...
 
virtual bool SetDrawNavSystem (bool)
 
virtual bool CanDrawNavSystem ()
 
virtual bool DrawNavSystem ()
 
virtual bool CheckCommAnimation (Unit *un)
 
virtual void visitSystem (std::string systemName)
 
void AutoLanding ()
 
void DoAutoLanding (Unit *, Unit *)
 
virtual void SetInsidePanYawSpeed (float speed)
 
virtual void SetInsidePanPitchSpeed (float speed)
 
bool IsPaused () const
 
void OnPauseBegin ()
 
void OnPauseEnd ()
 
void OnDockEnd (Unit *station, Unit *unit)
 
void OnJumpBegin (Unit *unit)
 
void OnJumpEnd (Unit *unit)
 
- Public Member Functions inherited from Cockpit
void updateAttackers ()
 
bool autoInProgress ()
 
bool unitInAutoRegion (Unit *un)
 
void SetView (const enum VIEWSTYLE tmp)
 Sets the current viewstyle. More...
 
enum VIEWSTYLE GetView ()
 
void RestoreGodliness ()
 
std::string & GetUnitFileName (unsigned int which=0)
 
std::string & GetUnitSystemName (unsigned int which=0)
 
std::string & GetUnitBaseName (unsigned int which=0)
 
const std::string & GetUnitFileName (unsigned int which=0) const
 
const std::string & GetUnitSystemName (unsigned int which=0) const
 
const std::string & GetUnitBaseName (unsigned int which=0) const
 
void RemoveUnit (unsigned int which=0)
 
std::string GetUnitModifications ()
 
size_t GetNumUnits () const
 
void PackUnitInfo (vector< std::string > &info) const
 
void UnpackUnitInfo (vector< std::string > &info)
 
 Cockpit (const char *file, Unit *parent, const std::string &pilotname)
 
virtual ~Cockpit ()
 
virtual void Init (const char *file, bool defaultCockpit=false)
 Loads cockpit info...just as constructor. More...
 
void recreate (const std::string &pilotname)
 
UnitGetParent ()
 
UnitGetSaveParent ()
 
bool Update ()
 

Static Public Member Functions

static void NavScreen (const KBData &, KBSTATE k)
 
static string getsoundending (int which=0)
 
static string getsoundfile (string filename)
 
static void Respawn (const KBData &, KBSTATE)
 
static void SwitchControl (const KBData &, KBSTATE)
 
static void ForceSwitchControl (const KBData &, KBSTATE)
 
static void TurretControl (const KBData &, KBSTATE)
 
- Static Public Member Functions inherited from Cockpit
static bool tooManyAttackers ()
 
static std::string MakeBaseName (const Unit *base)
 
static void Respawn (const KBData &, KBSTATE)
 
static void SwitchControl (const KBData &, KBSTATE)
 
static void ForceSwitchControl (const KBData &, KBSTATE)
 
static void TurretControl (const KBData &, KBSTATE)
 

Public Attributes

std::string textMessage
 
bool editingTextMessage
 
std::string autoMessage
 
float autoMessageTime
 
- Public Attributes inherited from Cockpit
double secondsWithZeroEnergy
 
int number_of_attackers
 
unsigned int retry_dock
 
double TimeOfLastCollision
 
char jumpok
 
float godliness
 
std::string communication_choices
 
float credits
 
float zoomfactor
 How far away chasecam and pan cam is. More...
 
class Flightgroupfg
 Sets owner of this cockpit. More...
 
class StarSystemactiveStarSystem
 
class SaveGamesavegame
 

Additional Inherited Members

- Protected Member Functions inherited from Cockpit
virtual void DrawTargetBox ()
 
virtual void DrawTurretTargetBoxes ()
 draws a target cross around all units targeted by your turrets // ** jay More...
 
virtual void DrawTacticalTargetBox ()
 Shows the flightgroup's target, if any. More...
 
- Static Protected Member Functions inherited from Cockpit
static void beginElement (void *userData, const XML_Char *name, const XML_Char **atts)
 
static void endElement (void *userData, const XML_Char *name)
 
- Protected Attributes inherited from Cockpit
enum VIEWSTYLE view
 style of current view (chase cam, inside) More...
 
int currentcamera
 
float radar_time
 
float gauge_time [UnitImages< void >::NUMGAUGES]
 
float StartArmor [9]
 
float maxfuel
 saved values to compare with current values (might need more for damage) More...
 
float maxhull
 
UnitContainer parent
 this is the parent that Cockpit will read data from More...
 
UnitContainer parentturret
 
int unitfaction
 
float shakin
 4 views f/r/l/b More...
 
std::string unitmodname
 Video Display Units (may need more than 2 in future) More...
 
float autopilot_time
 
UnitContainer autopilot_target
 
float cockpit_offset
 
float viewport_offset
 
float cockpit_time
 
bool ejecting
 
bool going_to_dock_screen
 
int partial_number_of_attackers
 

Detailed Description

Definition at line 67 of file cockpit.h.

Constructor & Destructor Documentation

GameCockpit::GameCockpit ( const char *  file,
Unit parent,
const std::string &  pilotname 
)

Definition at line 1644 of file cockpit.cpp.

References game_data_t::aspect, autoMessageTime, editingTextMessage, Radar::Factory(), g_game, VegaConfig::getColor(), VegaConfig::getVariable(), Identity(), InitStatic(), M_PI, Radar::Type::NullDisplay, XMLSupport::parse_bool(), XMLSupport::parse_float(), XMLSupport::parse_int(), GFXColor::r, UniverseUtil::tan(), Vector, and vs_config.

1645  : Cockpit( file, parent, pilot_name )
1646  , insidePanYaw( 0 )
1647  , insidePanPitch( 0 )
1648  , insidePanYawSpeed( 0 )
1649  , insidePanPitchSpeed( 0 )
1650  , shake_time( 0 )
1651  , shake_type( 0 )
1652  , radarDisplay(0)
1653  , textcol( 1, 1, 1, 1 )
1654  , text( NULL )
1655 {
1656  autoMessageTime = 0;
1657  shield8 = armor8 = false;
1658  editingTextMessage = false;
1659  static int headlag = XMLSupport::parse_int( vs_config->getVariable( "graphics", "head_lag", "10" ) );
1660  int i;
1661  for (i = 0; i < headlag; i++) {
1662  headtrans.push_back( Matrix() );
1663  Identity( headtrans.back() );
1664  }
1665  for (i = 0; i < UnitImages< void >::NUMGAUGES; i++)
1666  gauges[i] = NULL;
1667  radarSprites[0] = radarSprites[1] = Pit[0] = Pit[1] = Pit[2] = Pit[3] = NULL;
1668 
1669  static bool st_draw_all_boxes =
1670  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawAllTargetBoxes", "false" ) );
1671  static bool st_draw_line_to_target =
1672  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawLineToTarget", "false" ) );
1673  static bool st_draw_line_to_targets_target =
1674  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawLineToTargetsTarget", "false" ) );
1675  static bool st_draw_line_to_itts =
1676  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawLineToITTS", "false" ) );
1677  static bool st_always_itts = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "drawAlwaysITTS", "false" ) );
1678  static bool st_steady_itts = XMLSupport::parse_bool( vs_config->getVariable( "physics", "steady_itts", "false" ) );
1679 
1680  draw_all_boxes = st_draw_all_boxes;
1681  draw_line_to_target = st_draw_line_to_target;
1682  draw_line_to_targets_target = st_draw_line_to_targets_target;
1683  draw_line_to_itts = st_draw_line_to_itts;
1684  always_itts = st_always_itts;
1685  steady_itts = st_steady_itts;
1686  last_locktime = last_mlocktime = -FLT_MAX;
1687 
1688  radarDisplay = Radar::Factory(Radar::Type::NullDisplay);
1689 
1690  //Compute the screen limits. Used to display the arrow pointing to the selected target.
1691  static float st_projection_limit_y = XMLSupport::parse_float( vs_config->getVariable( "graphics", "fov", "78" ) );
1692  smooth_fov = st_projection_limit_y;
1693  projection_limit_y = st_projection_limit_y;
1694  //The angle betwwen the center of the screen and the border is half the fov.
1695  projection_limit_y = tan( projection_limit_y*M_PI/(180*2) );
1696  projection_limit_x = projection_limit_y*g_game.aspect;
1697  //Precompute this division... performance.
1698  inv_screen_aspect_ratio = 1/g_game.aspect;
1699 
1700  oaccel = Vector( 0, 0, 0 );
1701 
1702  friendly = GFXColor( -1, -1, -1, -1 );
1703  enemy = GFXColor( -1, -1, -1, -1 );
1704  neutral = GFXColor( -1, -1, -1, -1 );
1705  targeted = GFXColor( -1, -1, -1, -1 );
1706  targetting = GFXColor( -1, -1, -1, -1 );
1707  planet = GFXColor( -1, -1, -1, -1 );
1708  soundfile = -1;
1709  if (friendly.r == -1) {
1710  vs_config->getColor( "enemy", &enemy.r );
1711  vs_config->getColor( "friend", &friendly.r );
1712  vs_config->getColor( "neutral", &neutral.r );
1713  vs_config->getColor( "target", &targeted.r );
1714  vs_config->getColor( "targetting_ship", &targetting.r );
1715  vs_config->getColor( "planet", &planet.r );
1716  }
1717  InitStatic();
1718  updateRadar(parent);
1719 }
GameCockpit::~GameCockpit ( )

Definition at line 2838 of file cockpit.cpp.

References Cockpit::savegame.

2839 {
2840  Delete();
2841  int i;
2842  for (i = 0; i < 4; i++)
2843  if (Pit[i]) {
2844  delete Pit[i];
2845  Pit[i] = NULL;
2846  }
2847  delete savegame;
2848 }

Member Function Documentation

Camera* GameCockpit::AccessCamera ( )
inlinevirtual

Accesses the current camera.

Reimplemented from Cockpit.

Definition at line 202 of file cockpit.h.

Referenced by Autopilot(), Draw(), DrawNavSystem(), and UpdAutoPilot().

203  {
204  return &cam[currentcamera];
205  }
Camera * GameCockpit::AccessCamera ( int  num)
virtual

Returns the passed in cam.

Reimplemented from Cockpit.

Definition at line 3195 of file cockpit.cpp.

3196 {
3197  if (num < NUM_CAM && num >= 0)
3198  return &cam[num];
3199  else
3200  return NULL;
3201 }
NavigationSystem* GameCockpit::AccessNavSystem ( )
inlinevirtual

Accesses the current navigationsystem.

Reimplemented from Cockpit.

Definition at line 196 of file cockpit.h.

Referenced by Draw(), GetNavSelectedSystem(), and visitSystem().

197  {
198  return &ThisNav;
199  }
void GameCockpit::AutoLanding ( )

Definition at line 914 of file cockpit.cpp.

References _Universe, Universe::activeStarSystem(), CollideArray::begin(), StarSystem::collidemap, DoAutoLanding(), CollideArray::end(), Cockpit::GetParent(), VegaConfig::getVariable(), XMLSupport::parse_bool(), Unit::UNIT_ONLY, and vs_config.

Referenced by Draw().

915 {
916  static bool autolanding_enable =
917  XMLSupport::parse_bool( vs_config->getVariable( "physics", "AutoLandingEnable", "false" ) );
918  if (autolanding_enable)
919  {
920  Unit *player = GetParent();
921  if (player == NULL)
922  return;
923 
925  for (CollideMap::iterator it = collideMap->begin(); it != collideMap->end(); ++it)
926  {
927  if (it->radius <= 0)
928  continue;
929 
930  Unit *target = it->ref.unit;
931  if (target == NULL)
932  continue;
933 
934  DoAutoLanding(player, target);
935  }
936  }
937 }
int GameCockpit::Autopilot ( Unit target)
virtual

Reimplemented from Cockpit.

Definition at line 1917 of file cockpit.cpp.

References AccessCamera(), autoMessage, autoMessageTime, Cockpit::autopilot_target, Cockpit::autopilot_time, Unit::AutoPilotToErrorMessage(), CP_FIXED, CP_FIXEDPOS, XMLSupport::escaped_string(), UniverseUtil::GetGameTime(), Unit::GetOrientation(), Cockpit::GetParent(), VegaConfig::getVariable(), soundContainer::loadsound(), Unit::LocalPosition(), Magnitude(), XMLSupport::parse_bool(), XMLSupport::parse_float(), soundContainer::playsound(), QVector, R, Unit::rSize(), Camera::SetOrientation(), Camera::SetPosition(), UnitContainer::SetUnit(), Cockpit::SetView(), soundContainer::sound, Vector, and vs_config.

1918 {
1919  static bool autopan = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "pan_on_auto", "true" ) );
1920  int retauto = 0;
1921  if (target) {
1922  if (enableautosound.sound < 0) {
1923  static string str = vs_config->getVariable( "cockpitaudio", "autopilot_enabled", "autopilot" );
1924  enableautosound.loadsound( str );
1925  }
1927  Unit *un = NULL;
1928  if ( ( un = GetParent() ) ) {
1929  autoMessage = std::string();
1931  QVector posA = un->LocalPosition();
1932  bool retautoA = false;
1933  if ( ( retauto = retautoA = un->AutoPilotToErrorMessage( un, false, autoMessage ) ) ) {
1934  //can he even start to autopilot
1935  retauto = un->AutoPilotToErrorMessage( target, false, autoMessage );
1936  QVector posB = un->LocalPosition();
1937  bool movedatall = (posA-posB).Magnitude() > un->rSize();
1938  if (autoMessage.length() == 0 && !movedatall) {
1939  autoMessage =
1940  XMLSupport::escaped_string( vs_config->getVariable( "graphics", "hud", "AlreadyNearMessage",
1941  "#ff0000Already Near#000000" ) );
1942  retauto = false;
1943  } else if ( (retauto || retautoA) && movedatall ) {
1944  if (autopan) {
1945  SetView( CP_FIXEDPOS );
1946  Vector P( 1, 0, 0 ), Q( 0, 1, 0 ), R( 0, 0, 1 );
1947  Vector uP, uQ, uR;
1948  un->GetOrientation( uP, uQ, uR );
1949  static float auto_side_bias =
1950  XMLSupport::parse_float( vs_config->getVariable( "graphics", "autopilot_side_bias", "1.1" ) );
1951  static float auto_front_bias =
1952  XMLSupport::parse_float( vs_config->getVariable( "graphics", "autopilot_front_bias", "1.65" ) );
1953  P += uP*auto_side_bias+uR*auto_front_bias;
1954  P.Normalize();
1955  R = P.Cross( Q );
1956  AccessCamera( CP_FIXED )->SetPosition( un->LocalPosition()+2*un->rSize()*P,
1957  Vector( 0, 0, 0 ), Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
1958  AccessCamera( CP_FIXED )->SetOrientation( R, Q, -P );
1959  AccessCamera( CP_FIXEDPOS )->SetPosition( un->LocalPosition()+2*un->rSize()*P, Vector( 0,
1960  0,
1961  0 ),
1962  Vector( 0, 0, 0 ), Vector( 0, 0, 0 ) );
1963  AccessCamera( CP_FIXEDPOS )->SetOrientation( R, Q, -P );
1964  }
1965 
1966  static float autotime = XMLSupport::parse_float( vs_config->getVariable( "physics", "autotime", "10" ) ); //10 seconds for auto to kick in;
1967 
1968  autopilot_time = autotime;
1969  autopilot_target.SetUnit( target );
1970  }
1971  }
1972  }
1973  }
1974  return retauto;
1975 }
bool GameCockpit::CanDrawNavSystem ( )
virtual

Reimplemented from Cockpit.

Definition at line 1762 of file cockpit.cpp.

References NavigationSystem::CheckDraw().

Referenced by NavScreen().

1763 {
1764  return ThisNav.CheckDraw();
1765 }
bool GameCockpit::CheckCommAnimation ( Unit un)
virtual

Reimplemented from Cockpit.

Definition at line 3294 of file cockpit.cpp.

3295 {
3296  for (unsigned int i = 0; i < vdu.size(); ++i)
3297  if ( vdu[i]->CheckCommAnimation( un ) )
3298  return true;
3299  return false;
3300 }
void GameCockpit::DoAutoLanding ( Unit un,
Unit target 
)

Definition at line 793 of file cockpit.cpp.

References FireKeyboard::DockKey(), getNewTime(), VegaConfig::getVariable(), UniverseUtil::IOmessage(), UnitUtil::isDockableUnit(), Unit::isPlanet(), soundContainer::loadsound(), Unit::name, XMLSupport::parse_float(), soundContainer::playsound(), Unit::Position(), PRESS, QVector, Unit::rSize(), UniverseUtil::SafeEntrancePoint(), SetCommAnimation(), Unit::SetPosAndCumPos(), SIMULATION_ATOM, and vs_config.

Referenced by AutoLanding().

794 {
795  if (!un || !target)
796  return;
797  if (UnitUtil::isDockableUnit( target ) == false)
798  return;
799  static std::set< std::string >autoLandingExcludeList;
800  static std::set< std::string >autoLandingExcludeWarningList;
801  static bool autoLandingExcludeList_initialised = false;
802  if (!autoLandingExcludeList_initialised) {
803  autoLandingExcludeList_initialised = true;
804  std::string excludes;
805 
806  excludes = vs_config->getVariable( "physics", "AutoLandingExcludeList", "" );
807  if ( !excludes.empty() ) {
808  std::string::size_type pos = 0, epos = 0;
809  while (epos != std::string::npos) {
810  std::string xx (excludes.substr( pos, epos = excludes.find( ' ', pos ) ));
811  autoLandingExcludeList.insert( xx );
812  pos = epos+1;
813  }
814  }
815  excludes = vs_config->getVariable( "physics", "AutoLandingExcludeWarningList", "" );
816  if ( !excludes.empty() ) {
817  std::string::size_type pos = 0, epos = 0;
818  while (epos != std::string::npos) {
819  std::string yy(excludes.substr( pos, epos = excludes.find( ' ', pos ) ));
820  autoLandingExcludeWarningList.insert( yy );
821  pos = epos+1;
822  }
823  }
824  }
825  std::string tname=target->name;
826  if (autoLandingExcludeList.find(tname) != autoLandingExcludeList.end())
827  return;
828  static float lessthan = XMLSupport::parse_float( vs_config->getVariable( "physics", "AutoLandingDockDistance", "50" ) );
829  static float warnless = XMLSupport::parse_float( vs_config->getVariable( "physics", "AutoLandingWarningDistance", "350" ) );
830  static float AutoLandingMoveDistance =
831  XMLSupport::parse_float( vs_config->getVariable( "physics", "AutoLandingMoveDistance", "50" ) );
832  static float moveout = XMLSupport::parse_float( vs_config->getVariable( "physics", "AutoLandingDisplaceDistance", "50" ) );
833  static float autorad = XMLSupport::parse_float( vs_config->getVariable( "physics", "unit_default_autodock_radius", "0" ) );
834  static bool adjust_unit_radius =
835  XMLSupport::parse_float( vs_config->getVariable( "physics", "use_unit_autodock_radius", "false" ) );
836  float rsize = target->isPlanet() ? target->rSize() : ( autorad+(adjust_unit_radius ? target->rSize() : 0) );
837  QVector diffvec = un->Position()-target->Position();
838  float dist = diffvec.Magnitude()-un->rSize()-rsize;
839  diffvec.Normalize();
840 
841  static bool haswarned = false;
842  static void *lastwarned = NULL;
843  static float docktime = -FLT_MAX;
844  if (dist < lessthan && haswarned && lastwarned == target) {
845  //CrashForceDock(target,un,true);
846  un->SetPosAndCumPos( target->Position()+diffvec.Scale( un->rSize()+rsize+AutoLandingMoveDistance ) );
848  haswarned = false;
849  lastwarned = target;
850  docktime = getNewTime();
851  } else if (haswarned == false && lastwarned == target) {
852  if (getNewTime()-docktime > SIMULATION_ATOM*2) {
853  haswarned = false;
854  un->SetPosAndCumPos( UniverseUtil::SafeEntrancePoint( target->Position()+diffvec*( rsize+moveout+un->rSize() ),
855  un->rSize()*1.1 ) );
856  lastwarned = NULL;
857  }
858  } else if (dist < warnless) {
859  if (lastwarned != target || !haswarned) {
860  if (autoLandingExcludeWarningList.count( target->name ) == 0) {
861  static string str = vs_config->getVariable( "cockpitaudio", "automatic_landing_zone", "als" );
862  static string str1 = vs_config->getVariable( "cockpitaudio", "automatic_landing_zone1", "als" );
863  static string str2 = vs_config->getVariable( "cockpitaudio", "automatic_landing_zone2", "als" );
864  static string autolandinga = vs_config->getVariable( "graphics",
865  "automatic_landing_zone_warning",
866  "comm_docking.ani" );
867  static string autolandinga1 = vs_config->getVariable( "graphics",
868  "automatic_landing_zone_warning1",
869  "comm_docking.ani" );
870  static string autolandinga2 = vs_config->getVariable( "graphics",
871  "automatic_landing_zone_warning2",
872  "comm_docking.ani" );
873  static string message = vs_config->getVariable( "graphics",
874  "automatic_landing_zone_warning_text",
875  "Now Entering an \"Automatic Landing Zone\"." );
876  UniverseUtil::IOmessage( 0, "game", "all", message );
877  static Animation *ani0 = new Animation( autolandinga.c_str() );
878  static Animation *ani1 = new Animation( autolandinga1.c_str() );
879  static Animation *ani2 = new Animation( autolandinga2.c_str() );
880  static soundContainer warnsound;
881  static soundContainer warnsound1;
882  static soundContainer warnsound2;
883  int num = rand() < RAND_MAX/2 ? 0 : (rand() < RAND_MAX/2 ? 1 : 2);
884  if (warnsound.sound < 0) {
885  warnsound.loadsound( str );
886  warnsound1.loadsound( str1 );
887  warnsound2.loadsound( str2 );
888  }
889  switch (num)
890  {
891  case 0:
892  warnsound.playsound();
893  SetCommAnimation( ani0, target );
894  break;
895  case 1:
896  warnsound1.playsound();
897  SetCommAnimation( ani1, target );
898  break;
899  default:
900  warnsound2.playsound();
901  SetCommAnimation( ani2, target );
902  break;
903  }
904  }
905  haswarned = true;
906  lastwarned = target;
907  }
908  } else if (lastwarned == target) {
909  haswarned = false;
910  lastwarned = NULL;
911  }
912 }
void GameCockpit::Draw ( )
virtual

Draws Cockpit then restores viewport.

Reimplemented from Cockpit.

Definition at line 2096 of file cockpit.cpp.

References _Universe, Universe::AccessCamera(), AccessCamera(), AccessNavSystem(), Universe::activateLightMap(), Universe::activeStarSystem(), ALWAYS, AutoLanding(), BILINEAR, blah, UnitImages< BOGUS >::cockpit_damage, Cockpit::cockpit_time, COCKPITZ_HEADROOM, Unit::computer, UniverseUtil::cos(), CP_CHASE, CP_FRONT, CP_PAN, CP_PANINSIDE, CP_PANTARGET, CP_TARGET, CP_VIEWTARGET, CULLFACE, Unit::curr_physical_state, Universe::CurrentCockpit(), DEPTHTEST, DEPTHWRITE, DockBoxColor(), VSSprite::Draw(), TextPlane::Draw(), DrawCrosshairs(), DrawDamageFlash(), DrawNavSystem(), Cockpit::DrawTacticalTargetBox(), Cockpit::DrawTargetBox(), Cockpit::DrawTurretTargetBoxes(), editingTextMessage, f, float, game_data_t::fov, g_game, Camera::GetAcceleration(), TextPlane::GetCharSize(), NavigationSystem::getCurrentSystem(), GetElapsedTime(), StarSystem::getFileName(), Camera::GetFov(), Unit::GetHull(), Unit::GetImageInformation(), getNewTime(), Cockpit::GetParent(), Camera::GetPQR(), NavigationSystem::getSelectedSystem(), getTimeCompression(), UnitContainer::GetUnit(), VegaConfig::getVariable(), GFXAlphaTest(), GFXBlendMode(), GFXClear(), GFXColor4f(), GFXColorf(), GFXDisable(), GFXEnable(), GFXFALSE, GFXHudMode(), GFXLoadIdentity(), GFXTRUE, GREATER, howFarToJump(), InitStatic(), INVSRCALPHA, LIGHTING, BaseUtil::LoadBaseInterface(), VSSprite::LoadSuccess(), LookupUnitStat(), max(), MAXVDUS, min(), MODEL, vs_options::mouse_deadband, mousex, mousey, Universe::numPlayers(), ONE, Cockpit::parent, XMLSupport::parse_bool(), XMLSupport::parse_float(), XMLSupport::parse_int(), CockpitKeys::PitchDown(), CockpitKeys::PitchUp(), Transformation::position, Unit::Position(), PRESS, Mesh::ProcessUndrawnMeshes(), Mesh::ProcessZFarMeshes(), queryTime(), QVector, R, rand01(), RELEASE, reset_time_compression(), RestoreKB(), RestoreViewPort(), RetrColor(), TextPlane::SetCharSize(), Camera::SetFov(), TextPlane::SetPos(), VSSprite::SetPosition(), TextPlane::SetSize(), TextPlane::SetText(), NavigationSystem::Setup(), Cockpit::SetView(), Cockpit::shakin, sqr, UniverseUtil::sqrt(), SRCALPHA, SWITCH_CONST, SystemLocation(), VDU::TARGET, Unit::Computer::target, Unit::Target(), TEXTURE0, TEXTURE1, Unit::Threat(), Unit::Threaten(), Unit::ToLocalCoordinates(), Camera::UpdateGFX(), Camera::UpdateGFXAgain(), Vector, VectorAndPositionToMatrix(), Unit::Velocity, VERYNEAR_CONST, Cockpit::view, vs_config, x, game_data_t::x_resolution, y, game_data_t::y_resolution, CockpitKeys::YawLeft(), CockpitKeys::YawRight(), ZERO, and Cockpit::zoomfactor.

2097 {
2098  static bool draw_star_destination_arrow =
2099  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_star_direction", "true" ) );
2100  static GFXColor destination_system_color = DockBoxColor( "destination_system_color" );
2101  Vector destination_system_location( 0, 0, 0 );
2103  if (cockpit_time >= 100000)
2104  InitStatic();
2105  _Universe->AccessCamera()->UpdateGFX( GFXFALSE, GFXFALSE, GFXTRUE ); //Preliminary frustum
2106  GFXDisable( TEXTURE0 );
2107  GFXDisable( TEXTURE1 );
2109  GFXDisable( LIGHTING );
2110  GFXDisable( DEPTHTEST );
2112  GFXColor4f( 1, 1, 1, 1 );
2113  std::string nav_current = AccessNavSystem()->getCurrentSystem();
2114  std::string universe_current = _Universe->activeStarSystem()->getFileName();
2115  if (nav_current != universe_current)
2116  AccessNavSystem()->Setup();
2117  static bool draw_any_boxes =
2118  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "DrawTargettingBoxes", "true" ) );
2119  static bool draw_boxes_inside_only =
2120  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "DrawTargettingBoxesInside", "true" ) );
2121  if ( draw_any_boxes && screenshotkey == false && (draw_boxes_inside_only == false || view < CP_CHASE) )
2122  {
2123  Unit *player = GetParent();
2124  if (player)
2125  {
2126  Radar::Sensor sensor(player);
2127  DrawTargetBox(sensor);
2128  DrawTurretTargetBoxes(sensor);
2129  DrawTacticalTargetBox(sensor);
2130  DrawCommunicatingBoxes();
2131  if (draw_all_boxes)
2132  DrawTargetBoxes(sensor);
2133  }
2134  if (draw_star_destination_arrow) {
2135  std::string destination_system = AccessNavSystem()->getSelectedSystem();
2136  std::string current_system = _Universe->activeStarSystem()->getFileName();
2137  if (destination_system != current_system) {
2138  QVector cur = SystemLocation( current_system );
2139  QVector dest = SystemLocation( destination_system );
2140  QVector delta = dest-cur;
2141  if (delta.i != 0 || dest.j != 0 || dest.k != 0) {
2142  delta.Normalize();
2143  Unit *par = GetParent();
2144  delta = delta*howFarToJump()*1.01-( par ? ( par->Position() ) : QVector( 0, 0, 0 ) );
2145  destination_system_location = delta.Cast();
2146  Vector P, Q, R;
2147  static float nav_symbol_size =
2148  XMLSupport::parse_float( vs_config->getVariable( "graphics", "nav_symbol_size", ".25" ) );
2149  AccessCamera()->GetPQR( P, Q, R );
2150 
2151  GFXColor4f( destination_system_color.r,
2152  destination_system_color.g,
2153  destination_system_color.b,
2154  destination_system_color.a );
2155 
2156  static GFXColor suncol = RetrColor( "remote_star", GFXColor( 0, 1, 1, .8 ) );
2157  GFXColorf( suncol );
2158  DrawNavigationSymbol( delta.Cast(), P, Q, delta.Magnitude()*nav_symbol_size );
2159 
2160  GFXColor4f( 1, 1, 1, 1 );
2161  }
2162  }
2163  }
2164  }
2165  GFXEnable( TEXTURE0 );
2166  GFXEnable( DEPTHTEST );
2167  GFXEnable( DEPTHWRITE );
2168  if (view < CP_CHASE) {
2169 /*broken velocity inidcator
2170  * static bool draw_velocity_indicator=XMLSupport::parse_bool(vs_config->getVariable("graphics","draw_velocity_indicator","true"));
2171  * if (draw_velocity_indicator) {
2172  * Vector P,Q,R;
2173  * Unit *par=GetParent();
2174  * if (par ) {
2175  * Vector vel=par->Velocity;
2176  * float speed=vel.Magnitude();
2177  * static float nav_symbol_size = XMLSupport::parse_float(vs_config->getVariable("graphics","nav_symbol_size",".25"));
2178  * AccessCamera()->GetPQR (P,Q,R);
2179  * DrawNavigationSymbol(vel,P,Q,speed*nav_symbol_size);
2180  * }
2181  * }*/
2182  if ( mesh.size() ) {
2183  Unit *par = GetParent();
2184  if (par) {
2185  //cockpit is unaffected by FOV WARP-Link
2186  float oldfov = AccessCamera()->GetFov();
2187  AccessCamera()->SetFov( g_game.fov );
2188 
2190 
2191  size_t i, j;
2192  float cockpitradial = 1; //LET IT NOT BE ZERO!
2193  for (i = 0; i < mesh.size(); ++i) {
2194  float meshmaxdepth = mesh[i]->corner_min().Max( mesh[i]->corner_max() ).Magnitude();
2195  if (meshmaxdepth > cockpitradial)
2196  cockpitradial = meshmaxdepth;
2197  }
2198  cockpitradial *= COCKPITZ_HEADROOM;
2199 
2200  GFXEnable( DEPTHTEST );
2201  GFXEnable( DEPTHWRITE );
2202  GFXEnable( TEXTURE0 );
2203  GFXEnable( LIGHTING );
2204  Vector P, Q, R;
2205  AccessCamera( CP_FRONT )->GetPQR( P, Q, R );
2206 
2207  headtrans.clear();
2208 
2209  headtrans.push_back( Matrix() );
2210  VectorAndPositionToMatrix( headtrans.back(), P, Q, R, QVector( 0, 0, 0 ) );
2211  static float theta = 0, wtheta = 0;
2212  static float shake_speed =
2213  XMLSupport::parse_float( vs_config->getVariable( "graphics", "shake_speed", "50" ) );
2214  static float shake_reduction =
2215  XMLSupport::parse_float( vs_config->getVariable( "graphics", "shake_reduction", "8" ) );
2216  static float shake_limit =
2217  XMLSupport::parse_float( vs_config->getVariable( "graphics", "shake_limit", "25" ) );
2218  static float shake_mag = XMLSupport::parse_float( vs_config->getVariable( "graphics", "shake_magnitude", "0.3" ) );
2219  static float drift_limit =
2220  XMLSupport::parse_float( vs_config->getVariable( "graphics", "cockpit_drift_limit", "1.00" ) );
2221  static float drift_amount =
2222  XMLSupport::parse_float( vs_config->getVariable( "graphics", "cockpit_drift_amount", "0.15" ) );
2223  static float drift_ref_accel =
2224  XMLSupport::parse_float( vs_config->getVariable( "graphics", "cockpit_drift_ref_accel", "100" ) );
2225 
2226  static float warp_shake_mag =
2227  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp_shake_magnitude", "0.125" ) );
2228  static float warp_shake_speed =
2229  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp_shake_speed", "70" ) );
2230  static float warp_shake_ref =
2231  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp_shake_ref", "2000" ) );
2232  if (warp_shake_ref <= 0) warp_shake_ref = 1;
2233  theta += shake_speed*GetElapsedTime()*sqrt( fabs( shakin ) )/10; //For small shakes, slower shakes
2234  wtheta += warp_shake_speed*GetElapsedTime(); //SPEC-related shaking
2235 
2236  float self_kps = ( (GetParent() != NULL) ? LookupUnitStat( UnitImages< void >::KPS, GetParent() ) : 0 );
2237  float self_setkps =
2238  max( 1.0f, ( (GetParent() != NULL) ? LookupUnitStat( UnitImages< void >::SETKPS, GetParent() ) : 0 ) );
2239  float warp_strength =
2240  max( 0.0f,
2241  min( max( 0.0f,
2242  min( 1.0f,
2243  self_kps/self_setkps ) ),
2245  GetParent() ) : 0.0f )/warp_shake_ref ) );
2246  if (shakin > shake_limit) shakin = shake_limit;
2247  headtrans.front().p.i = shake_mag*shakin*cos( theta )*cockpitradial/100; //AccessCamera()->GetPosition().i+shakin*cos(theta);
2248  headtrans.front().p.j = shake_mag*shakin*cos( 1.3731*theta )*cockpitradial/100; //AccessCamera()->GetPosition().j+shakin*cos(theta);
2249  headtrans.front().p.k = 0; //AccessCamera()->GetPosition().k;
2250  headtrans.front().p.i += warp_shake_mag*cos( wtheta )*sqr( warp_strength )*cockpitradial/100; //AccessCamera()->GetPosition().i+shakin*cos(theta);
2251  headtrans.front().p.j += warp_shake_mag*cos( 1.165864*wtheta )*sqr( warp_strength )*cockpitradial/100; //AccessCamera()->GetPosition().j+shakin*cos(theta);
2252  if (shakin > 0) {
2253  shakin -= GetElapsedTime()*shake_reduction*(shakin/5); //Fast convergence to 5% shaking, slow stabilization
2254  if (shakin <= 0)
2255  shakin = 0;
2256  }
2257  //Now, compute head drift
2259  float mag = caccel.Magnitude();
2260  float ref = drift_ref_accel*drift_ref_accel;
2261  if ( (mag > 0) && (ref > 0) ) caccel *= -( drift_amount*min( drift_limit, (float) (mag*mag/ref) ) )/mag;
2262 
2263  else caccel = Vector( 0, 0, 0 );
2264  float driftphase = pow( 0.25, GetElapsedTime() );
2265  oaccel = (1-driftphase)*caccel+driftphase*oaccel;
2266  headtrans.front().p += -cockpitradial*oaccel;
2267  float driftmag = cockpitradial*oaccel.Magnitude();
2268 
2269  //if (COCKPITZ_PARTITIONS>1) GFXClear(GFXFALSE,GFXFALSE,GFXTRUE);//only clear stencil buffer
2270  static size_t COCKPITZ_PARTITIONS =
2271  XMLSupport::parse_int( vs_config->getVariable( "graphics", "cockpit_z_partitions", "1" ) ); //Should not be needed if VERYNEAR_CONST is propperly set, but would be useful with stenciled inverse order rendering.
2272  float zrange = cockpitradial*(1-VERYNEAR_CONST)+driftmag;
2273  float zfloor = cockpitradial*VERYNEAR_CONST;
2274  for (j = COCKPITZ_PARTITIONS-1; j < COCKPITZ_PARTITIONS; j--) { //FIXME This is a program lockup!!! (actually, no; j is a size_t...)
2276  GFXTRUE,
2277  GFXTRUE,
2278  GFXTRUE,
2279  zfloor+zrange*j/COCKPITZ_PARTITIONS,
2280  zfloor+zrange*(j+1)/COCKPITZ_PARTITIONS ); //cockpit-specific frustrum (with clipping, with frustrum update)
2281  GFXClear( GFXFALSE, GFXTRUE, GFXFALSE ); //only clear Z
2282  /*if (COCKPITZ_PARTITIONS>1) {
2283  * //Setup stencil
2284  * GFXStencilOp(KEEP,KEEP,REPLACE);
2285  * GFXStencilFunc(LEQUAL,COCKPITZ_PARTITIONS-j,~0);
2286  * GFXStencilMask(~0);
2287  * GFXEnable(STENCIL);
2288  * };*/
2290  for (i = 0; i < mesh.size(); ++i)
2291  //mesh[i]->DrawNow(1,true,headtrans.front());
2292  mesh[i]->Draw( FLT_MAX, headtrans.front() );
2293  //Whether cockpits shouldn't cull faces - not sure why, probably because
2294  //modellers always set normals the wrong way for cockpits.
2295  static bool nocockpitcull =
2296  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "cockpit_no_face_cull", "true" ) );
2297 
2298  Mesh::ProcessZFarMeshes( true );
2299  if (nocockpitcull) GFXDisable( CULLFACE );
2300  Mesh::ProcessUndrawnMeshes( false, true );
2301  }
2302  headtrans.pop_front();
2303  //if (COCKPITZ_PARTITIONS>1) GFXDisable(STENCIL);
2304  GFXDisable( LIGHTING );
2305  GFXDisable( TEXTURE0 );
2306  GFXDisable( TEXTURE1 );
2307  AccessCamera()->SetFov( oldfov );
2308  }
2309  }
2310  _Universe->AccessCamera()->UpdateGFX( GFXFALSE, GFXFALSE, GFXTRUE, GFXFALSE, 0, 1000000 ); //Restore normal frustrum
2311  }
2312  GFXHudMode( true );
2313  static float damage_flash_length = XMLSupport::parse_float( vs_config->getVariable( "graphics", "damage_flash_length", ".1" ) );
2314  static bool damage_flash_first = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "flash_behind_hud", "true" ) );
2315  if (view < CP_CHASE && damage_flash_first && getNewTime()-shake_time < damage_flash_length)
2316  DrawDamageFlash( shake_type );
2317  GFXColor4f( 1, 1, 1, 1 );
2318  GFXBlendMode( ONE, ONE );
2319  GFXDisable( DEPTHTEST );
2321 
2322  Unit *un;
2323  float crosscenx = 0, crossceny = 0;
2324  static bool crosshairs_on_chasecam =
2325  parse_bool( vs_config->getVariable( "graphics", "hud", "crosshairs_on_chasecam", "false" ) );
2326  static bool crosshairs_on_padlock =
2327  parse_bool( vs_config->getVariable( "graphics", "hud", "crosshairs_on_padlock", "false" ) );
2328  if ( (view == CP_FRONT)
2329  || (view == CP_CHASE && crosshairs_on_chasecam)
2330  || ((view == CP_VIEWTARGET || view == CP_PANINSIDE) && crosshairs_on_padlock) ) {
2331  if (Panel.size() > 0 && Panel.front() && screenshotkey == false) {
2332  static bool drawCrosshairs =
2333  parse_bool( vs_config->getVariable( "graphics", "hud", "draw_rendered_crosshairs",
2334  vs_config->getVariable( "graphics", "draw_rendered_crosshairs", "true" ) ) );
2335  Panel.front()->GetPosition( crosscenx, crossceny );
2336  if (drawCrosshairs) {
2337  float x, y, wid, hei;
2338  Panel.front()->GetSize( wid, hei );
2339  x = crosscenx;
2340  y = crossceny;
2341  DrawCrosshairs( x, y, wid, hei, textcol );
2342  } else {
2344  GFXEnable( TEXTURE0 );
2345  Panel.front()->Draw(); //draw crosshairs
2346  }
2347  }
2348  }
2350  GFXEnable( TEXTURE0 );
2351 
2352  RestoreViewPort();
2353 
2354  static bool blend_panels = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "blend_panels", "false" ) );
2355  static bool blend_cockpit = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "blend_cockpit", "false" ) );
2356  static bool drawChaseVDU =
2357  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_vdus_from_chase_cam", "false" ) );
2358  static bool drawPanVDU =
2359  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_vdus_from_panning_cam", "false" ) );
2360  static bool drawTgtVDU =
2361  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_vdus_from_target_cam", "false" ) );
2362  static bool drawPadVDU =
2363  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_vdus_from_padlock_cam", "false" ) );
2364 
2365  static bool drawChasecp =
2366  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_cockpit_from_chase_cam", "false" ) );
2367  static bool drawPancp =
2368  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_cockpit_from_panning_cam", "false" ) );
2369  static bool drawTgtcp =
2370  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_cockpit_from_target_cam", "false" ) );
2371  static bool drawPadcp =
2372  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "draw_cockpit_from_padlock_cam", "false" ) );
2373 
2374  static float AlphaTestingCutoff = XMLSupport::parse_float( vs_config->getVariable( "graphics", "AlphaTestCutoff", ".8" ) );
2375  if (blend_cockpit) {
2376  GFXAlphaTest( ALWAYS, 0 );
2378  } else {
2379  GFXBlendMode( ONE, ZERO );
2380  GFXAlphaTest( GREATER, AlphaTestingCutoff );
2381  }
2382  GFXColor4f( 1, 1, 1, 1 );
2383  if (view < CP_CHASE) {
2384  if (Pit[view])
2385  Pit[view]->Draw();
2386  } else if ( (view == CP_CHASE
2387  && drawChasecp)
2388  || (view == CP_PAN && drawPancp) || (view == CP_TARGET && drawTgtcp) || ((view == CP_VIEWTARGET || view == CP_PANINSIDE) && drawPadcp) ) {
2389  if (Pit[0])
2390  Pit[0]->Draw();
2391  }
2392  if (blend_panels) {
2393  GFXAlphaTest( ALWAYS, 0 );
2395  } else {
2396  GFXBlendMode( ONE, ZERO );
2397  GFXAlphaTest( GREATER, AlphaTestingCutoff );
2398  }
2399  GFXColor4f( 1, 1, 1, 1 );
2400  if ( view == CP_FRONT
2401  || (view == CP_CHASE
2402  && drawChaseVDU)
2403  || (view == CP_PAN && drawPanVDU) || (view == CP_TARGET && drawTgtVDU) || ((view == CP_VIEWTARGET || view == CP_PANINSIDE) && drawPadVDU) ) {
2404  for (unsigned int j = 1; j < Panel.size(); j++)
2405  if (Panel[j])
2406  Panel[j]->Draw();
2407  }
2408  GFXAlphaTest( ALWAYS, 0 );
2410  GFXColor4f( 1, 1, 1, 1 );
2411  bool die = true;
2412  //draw target gauges
2413  for (unsigned int vd = 0; vd < vdu.size(); vd++)
2414  if (vdu[vd]->getMode() == VDU::TARGET) {
2415  if ( ( un = parent.GetUnit() ) ) {
2416  Unit *target = parent.GetUnit()->Target();
2417  if (target != NULL) {
2418  if ( view == CP_FRONT
2419  || (view == CP_CHASE
2420  && drawChaseVDU)
2421  || (view == CP_PAN
2422  && drawPanVDU) || (view == CP_TARGET && drawTgtVDU) || ((view == CP_VIEWTARGET || view == CP_PANINSIDE) && drawPadVDU) ) //{ //only draw crosshairs for front view
2423  //if (!UnitUtil::isSignificant(target)&&!UnitUtil::isSun(target)||UnitUtil::isCapitalShip(target)) //{
2424  DrawTargetGauges( target );
2425  }
2426  }
2427  }
2428  //draw unit gauges
2429  if ( ( un = parent.GetUnit() ) ) {
2430  if ( view == CP_FRONT
2431  || (view == CP_CHASE
2432  && drawChaseVDU)
2433  || (view == CP_PAN && drawPanVDU) || (view == CP_TARGET && drawTgtVDU) || ((view == CP_VIEWTARGET || view == CP_PANINSIDE) && drawPadVDU) ) {
2434  //only draw crosshairs for front view
2435  DrawGauges( un );
2436  Radar::Sensor sensor(un);
2437  DrawRadar(sensor);
2438 
2439  GFXColor4f( 1, 1, 1, 1 );
2440  for (unsigned int vd = 0; vd < vdu.size(); vd++)
2441  if (vdu[vd]) {
2442  vdu[vd]->Draw( this, un, textcol );
2443  GFXColor4f( 1, 1, 1, 1 );
2444  float damage = un->GetImageInformation().cockpit_damage[(1+vd)%(MAXVDUS+1)];
2445  if ( vdu[vd]->staticable() ) {
2446  if (damage < .985) {
2447  if (vdu_time[vd] >= 0) {
2448  if ( damage > .001 && ( cockpit_time > ( vdu_time[vd]+(1-damage) ) ) )
2449  if (rand01() > SWITCH_CONST)
2450  vdu_time[vd] = -cockpit_time;
2451  /*else {
2452  * static string vdustatic=vs_config->getVariable("graphics","vdu_static","static.ani");
2453  * static Animation vdu_ani(vdustatic.c_str(),true,.1,BILINEAR);
2454  * static soundContainer ejectstopsound;
2455  * if (ejectstopsound.sound<0) {
2456  * static string str=vs_config->getVariable("cockpitaudio","vdu_static","vdu_static");
2457  * ejectstopsound.loadsound(str);
2458  * }
2459  * if (!AUDIsPlaying(ejectstopsound.sound)) {
2460  * ejectstopsound.playsound();
2461  * }
2462  *
2463  * GFXEnable(TEXTURE0);
2464  * vdu_ani.DrawAsVSSprite(vdu[vd]);
2465  *
2466  * }*/
2467  } else if ( cockpit_time > ( ( 1-(-vdu_time[vd]) )+(damage) ) ) {
2468  if (rand01() > SWITCH_CONST)
2469  vdu_time[vd] = cockpit_time;
2470  }
2471  }
2472  }
2473  }
2474  //process VDU, damage VDU, targetting VDU
2476  static bool debug_position =
2477  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "debug_position", "false" ) );
2478  if (debug_position) {
2479  TextPlane tp;
2480  char str[400]; //don't make the sprintf format too big... :-P
2481  Unit *you = parent.GetUnit();
2482  if (you) {
2483  sprintf( str, "Your Position: (%lf,%lf,%lf); Velocity: (%f,%f,%f); Frame: %lf\n",
2485  you->curr_physical_state.position.k, you->Velocity.i, you->Velocity.j, you->Velocity.k,
2486  getNewTime() );
2487  Unit *yourtarg = you->computer.target.GetUnit();
2488  if (yourtarg) {
2489  sprintf( str+strlen(
2490  str ), "Target Position: (%lf,%lf,%lf); Velocity: (%f,%f,%f); Now: %lf\n",
2491  yourtarg->curr_physical_state.position.i, yourtarg->curr_physical_state.position.j,
2492  yourtarg->curr_physical_state.position.k, yourtarg->Velocity.i, yourtarg->Velocity.j,
2493  yourtarg->Velocity.k, queryTime() );
2494  }
2495  }
2496  tp.SetPos( -0.8, -0.8 );
2497  tp.SetText( str );
2498  tp.Draw();
2499  }
2501  }
2502  GFXColor4f( 1, 1, 1, 1 );
2503  if (un->GetHull() >= 0)
2504  die = false;
2505  if (un->Threat() != NULL) {
2506  if (0 && getTimeCompression() > 1)
2507  reset_time_compression( std::string(), PRESS );
2508  un->Threaten( NULL, 0 );
2509  }
2510  if ( _Universe->CurrentCockpit() < univmap.size() )
2511  univmap[_Universe->CurrentCockpit()].Draw();
2512  //Draw the arrow to the target.
2513  static bool drawarrow =
2514  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_arrow_to_target", "true" ) );
2515  static bool drawarrow_on_pancam =
2516  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_arrow_on_pancam", "false" ) );
2517  static bool drawarrow_on_pantgt =
2518  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_arrow_on_pantgt", "false" ) );
2519  static bool drawarrow_on_chasecam =
2520  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_arrow_on_chasecam", "true" ) );
2521  {
2522  //printf("view: %i\n",view);
2523  Unit *parent = NULL;
2524  if ( drawarrow && ( parent = this->parent.GetUnit() ) ) {
2525  Radar::Sensor sensor(parent);
2526  if ( (view == CP_PAN
2527  && !drawarrow_on_pancam)
2528  || (view == CP_PANTARGET
2529  && !drawarrow_on_pantgt) || (view == CP_CHASE && !drawarrow_on_chasecam) ) {} else {
2530  DrawArrowToTarget(sensor, parent->Target());
2531  if ( draw_star_destination_arrow
2532  && (destination_system_location.i || destination_system_location.j
2533  || destination_system_location.k) ) {
2534  GFXColorf( destination_system_color );
2535  DrawArrowToTarget(sensor, parent->ToLocalCoordinates(destination_system_location));
2536  }
2537  }
2538  }
2539  } //end: draw arrow
2540  }
2541  AutoLanding();
2542  GFXColor4f( 1, 1, 1, 1 );
2543  if (QuitAllow || getTimeCompression() < .5) {
2544  if (QuitAllow) {
2545  if (!die) {
2546  static VSSprite QuitSprite( "quit.sprite", BILINEAR, GFXTRUE );
2547  static VSSprite QuitCompatSprite( "quit.spr", BILINEAR, GFXTRUE );
2548 
2549  GFXEnable( TEXTURE0 );
2550  if ( QuitSprite.LoadSuccess() )
2551  QuitSprite.Draw();
2552  else
2553  QuitCompatSprite.Draw();
2554  }
2555  } else {
2556  static VSSprite PauseSprite( "pause.sprite", BILINEAR, GFXTRUE );
2557  static VSSprite PauseCompatSprite( "pause.spr", BILINEAR, GFXTRUE );
2558  GFXEnable( TEXTURE0 );
2559  if ( PauseSprite.LoadSuccess() )
2560  PauseSprite.Draw();
2561  else
2562  PauseCompatSprite.Draw();
2563  }
2564  }
2565  static float dietime = 0;
2566  if (die) {
2567  if (un)
2568  if (un->GetHull() >= 0)
2569  die = false;
2570  if (die) {
2571  if (text) {
2572  GFXColor4f( 1, 1, 1, 1 );
2573  text->SetSize( 1, -1 );
2574  float x;
2575  float y;
2576  if (dietime == 0) {
2577  editingTextMessage = false;
2578  RestoreKB();
2579  if ( respawnunit.size() > _Universe->CurrentCockpit() )
2580  if (respawnunit[_Universe->CurrentCockpit()] == 1 && _Universe->numPlayers() == 1)
2582  text->GetCharSize( x, y );
2583  text->SetCharSize( x*4, y*4 );
2584  text->SetPos( 0-(x*2*14), 0-(y*2) );
2585  char playr[3];
2586  playr[0] = 'p';
2587  playr[1] = '0'+_Universe->CurrentCockpit();
2588  playr[2] = '\0';
2589  }
2590  GFXColorf( textcol );
2591  static bool show_died_text =
2592  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "show_respawn_text", "false" ) );
2593  if (show_died_text)
2594  text->Draw(
2595  "#ff5555You Have Died!\n#000000Press #8080FF;#000000 (semicolon) to respawn\nOr Press #8080FFEsc and 'q'#000000 to quit" );
2596  GFXColor4f( 1, 1, 1, 1 );
2597 
2598  static float min_die_time =
2599  XMLSupport::parse_float( vs_config->getVariable( "graphics", "death_scene_time", "4" ) );
2600  if (dietime > min_die_time) {
2601  static std::string death_menu_script = vs_config->getVariable( "graphics", "death_menu_script", "" );
2602  if ( death_menu_script.empty() ) {
2603  static VSSprite DieSprite( "died.sprite", BILINEAR, GFXTRUE );
2604  static VSSprite DieCompatSprite( "died.spr", BILINEAR, GFXTRUE );
2606  GFXEnable( TEXTURE0 );
2607  if ( DieSprite.LoadSuccess() )
2608  DieSprite.Draw();
2609  else
2610  DieCompatSprite.Draw();
2611  } else {
2612  BaseUtil::LoadBaseInterface( death_menu_script );
2613  dietime = 0;
2614  }
2615  }
2616  dietime += GetElapsedTime();
2617  SetView( CP_PAN );
2618  CockpitKeys::YawLeft( std::string(), RELEASE );
2619  CockpitKeys::YawRight( std::string(), RELEASE );
2620  CockpitKeys::PitchUp( std::string(), RELEASE );
2621  CockpitKeys::PitchDown( std::string(), RELEASE );
2622  zoomfactor = dietime*10;
2623  }
2624  QuitAllow = true;
2625  } else {}
2626  } else if (dietime != 0) {
2627  QuitAllow = false;
2628  dietime = 0;
2629  }
2630  //if(CommandInterpretor.console){
2631  //GFXColorf(textcol);
2632  //CommandInterpretor.renderconsole();
2633  //}
2634  GFXAlphaTest( ALWAYS, 0 );
2635  static bool mouseCursor = XMLSupport::parse_bool( vs_config->getVariable( "joystick", "mouse_cursor", "false" ) );
2636  static bool mousecursor_pancam =
2637  XMLSupport::parse_bool( vs_config->getVariable( "joystick", "mouse_cursor_pancam", "false" ) );
2638  static bool mousecursor_pantgt =
2639  XMLSupport::parse_bool( vs_config->getVariable( "joystick", "mouse_cursor_pantgt", "false" ) );
2640  static bool mousecursor_chasecam =
2641  XMLSupport::parse_bool( vs_config->getVariable( "joystick", "mouse_cursor_chasecam", "true" ) );
2642  if (mouseCursor && screenshotkey == false) {
2643  if ( (view == CP_PAN
2644  && !mousecursor_pancam)
2645  || (view == CP_PANTARGET && !mousecursor_pantgt) || (view == CP_CHASE && !mousecursor_chasecam) ) {} else {
2647  GFXColor4f( 1, 1, 1, 1 );
2648  GFXEnable( TEXTURE0 );
2649  //GFXDisable (DEPTHTEST);
2650  //GFXDisable(TEXTURE1);
2651  static float deadband = game_options.mouse_deadband;
2652  static int revspr =
2653  XMLSupport::parse_bool( vs_config->getVariable( "joystick", "reverse_mouse_spr", "true" ) ) ? 1 : -1;
2654  static string blah = vs_config->getVariable( "joystick", "mouse_crosshair", "crosshairs.spr" );
2655  static VSSprite MouseVSSprite( blah.c_str(), BILINEAR, GFXTRUE );
2656  float xcoord = ( -1+float(mousex)/(.5*g_game.x_resolution) );
2657  float ycoord = ( -revspr+float(revspr*mousey)/(.5*g_game.y_resolution) );
2658  MouseVSSprite.SetPosition( xcoord*( 1-fabs( crosscenx ) )+crosscenx, ycoord*( 1-fabs( crossceny ) )+crossceny );
2659  float xs, ys;
2660  MouseVSSprite.GetSize( xs, ys );
2661  if (xcoord < deadband && ycoord < deadband && xcoord > -deadband && ycoord > -deadband) {
2662  //The other option would be to place it in the center.
2663  //but it's sometimes useful to know where the mouse actually is.
2664  MouseVSSprite.SetSize( xs/2, ys/2 );
2665  } else if (xcoord < deadband && xcoord > -deadband) {
2666  MouseVSSprite.SetSize( xs/2, ys*5/6 );
2667  } else if (ycoord < deadband && ycoord > -deadband) {
2668  MouseVSSprite.SetSize( xs*5/6, ys/2 );
2669  }
2670  MouseVSSprite.Draw();
2671  MouseVSSprite.SetSize( xs, ys );
2672  //DrawGlutMouse(mousex,mousey,&MouseVSSprite);
2673  //DrawGlutMouse(mousex,mousey,&MouseVSSprite);
2674  }
2675  }
2676  if (view < CP_CHASE && damage_flash_first == false && getNewTime()-shake_time < damage_flash_length)
2677  DrawDamageFlash( shake_type );
2678  GFXHudMode( false );
2679 
2680  {
2681  //again, NAV computer is unaffected by FOV WARP-Link
2682  float oldfov = AccessCamera()->GetFov();
2683  AccessCamera()->SetFov( g_game.fov );
2685  DrawNavSystem();
2686  AccessCamera()->SetFov( oldfov );
2688  }
2689 
2690  GFXEnable( DEPTHWRITE );
2691  GFXEnable( DEPTHTEST );
2692  GFXEnable( TEXTURE0 );
2693 }
bool GameCockpit::DrawNavSystem ( )
virtual

Reimplemented from Cockpit.

Definition at line 1779 of file cockpit.cpp.

References AccessCamera(), NavigationSystem::CheckDraw(), Cockpit::cockpit_offset, Cockpit::currentcamera, NavigationSystem::Draw(), Camera::GetFov(), VegaConfig::getVariable(), GFXFALSE, GFXTRUE, XMLSupport::parse_float(), Camera::setCockpitOffset(), Camera::SetFov(), Camera::UpdateGFX(), and vs_config.

Referenced by Draw().

1780 {
1781  bool ret = ThisNav.CheckDraw();
1782  if (ret) {
1784  float c_o = cockpit_offset;
1785  float o_fov = cam->GetFov();
1786  static float standard_fov = XMLSupport::parse_float( vs_config->getVariable( "graphics", "base_fov", "90" ) );
1787  cam->SetFov( standard_fov );
1788  cam->setCockpitOffset( 0 );
1789  cam->UpdateGFX( GFXFALSE, GFXFALSE, GFXTRUE );
1790  ThisNav.Draw();
1791  cockpit_offset = c_o;
1792  cam->SetFov( o_fov );
1793  cam->setCockpitOffset( c_o );
1794  cam->UpdateGFX( GFXFALSE, GFXFALSE, GFXTRUE );
1795  }
1796  return ret;
1797 }
void GameCockpit::Eject ( )
virtual

Reimplemented from Cockpit.

Definition at line 781 of file cockpit.cpp.

References Cockpit::ejecting, and Cockpit::going_to_dock_screen.

782 {
783  ejecting = true;
784  going_to_dock_screen = false;
785 }
void GameCockpit::EjectDock ( )
virtual

Reimplemented from Cockpit.

Definition at line 787 of file cockpit.cpp.

References Cockpit::ejecting, and Cockpit::going_to_dock_screen.

788 {
789  ejecting = true;
790  going_to_dock_screen = true;
791 }
void GameCockpit::ForceSwitchControl ( const KBData ,
KBSTATE  k 
)
static

Definition at line 1817 of file cockpit.cpp.

References _Universe, and Universe::CurrentCockpit().

1818 {
1819  while ( switchunit.size() <= _Universe->CurrentCockpit() )
1820  switchunit.push_back( 0 );
1822 }
std::string GameCockpit::GetNavSelectedSystem ( )
virtual

Reimplemented from Cockpit.

Definition at line 82 of file cockpit.cpp.

References AccessNavSystem(), and NavigationSystem::getSelectedSystem().

83 {
85 }
int GameCockpit::getScrollOffset ( unsigned int  whichtype)
virtual

Reimplemented from Cockpit.

Definition at line 2695 of file cockpit.cpp.

2696 {
2697  for (unsigned int i = 0; i < vdu.size(); i++)
2698  if (vdu[i]->getMode()&whichtype)
2699  return vdu[i]->scrolloffset;
2700  return 0;
2701 }
string GameCockpit::getsoundending ( int  which = 0)
static

Definition at line 2703 of file cockpit.cpp.

References VegaConfig::getVariable(), and vs_config.

Referenced by getsoundfile().

2704 {
2705  static bool gotten = false;
2706  static string strs[9];
2707  if (gotten == false) {
2708  char tmpstr[2] = {'\0'};
2709  for (int i = 0; i < 9; i++) {
2710  tmpstr[0] = i+'1';
2711  string vsconfigvar = string( "sounds_extension_" )+tmpstr;
2712  strs[i] = vs_config->getVariable( "cockpitaudio", vsconfigvar, "\n" );
2713  if (strs[i] == "\n") {
2714  strs[i] = "";
2715  break;
2716  }
2717  }
2718  gotten = true;
2719  }
2720  return strs[which];
2721 }
string GameCockpit::getsoundfile ( string  filename)
static

Definition at line 2724 of file cockpit.cpp.

References getsoundending(), VSFileSystem::LookForFile(), VSFileSystem::Ok, and VSFileSystem::SoundFile.

Referenced by soundContainer::loadsound().

2725 {
2726  bool ok = false;
2727  int i;
2728  string lastsound = "";
2729  string anothertmpstr = "";
2730  for (i = 0; i < 9 && !ok; i++) {
2731  anothertmpstr = getsoundending( i );
2732  bool foundyet = false;
2733  while (1) {
2734  std::string::iterator found = std::find( anothertmpstr.begin(), anothertmpstr.end(), '*' );
2735  if ( found != anothertmpstr.end() ) {
2736  anothertmpstr.erase( found );
2737  anothertmpstr.insert( ( found-anothertmpstr.begin() ), sound );
2738  foundyet = true;
2739  } else {
2740  if (!foundyet)
2741  anothertmpstr = sound+anothertmpstr;
2742  break;
2743  }
2744  }
2745  if (VSFileSystem::LookForFile( anothertmpstr, SoundFile ) < Ok)
2746  ok = true;
2747  }
2748  if (ok)
2749  //return lastsound;
2750  return anothertmpstr;
2751  else
2752  return "";
2753 }
int GameCockpit::GetSoundFile ( )
inline

Definition at line 189 of file cockpit.h.

190  {
191  return soundfile;
192  }
string GameCockpit::getTargetLabel ( )
virtual

Reimplemented from Cockpit.

Definition at line 2911 of file cockpit.cpp.

References Cockpit::GetParent(), and Unit::Target().

2912 {
2913  Unit *par = GetParent();
2914  if ( ( !targetLabel.empty() )
2915  && (!par || ( (void*) par->Target() ) != labeledTargetUnit) ) {
2916  targetLabel = string();
2917  if (par)
2918  labeledTargetUnit = par->Target();
2919  }
2920  return targetLabel;
2921 }
int GameCockpit::getVDUMode ( int  vdunum)
virtual

Reimplemented from Cockpit.

Definition at line 2850 of file cockpit.cpp.

2851 {
2852  if ( vdunum < (int) vdu.size() )
2853  if (vdu[vdunum])
2854  return vdu[vdunum]->getMode();
2855  return 0;
2856 }
void GameCockpit::Init ( const char *  file)

Loads cockpit info...just as constructor.

Definition at line 1563 of file cockpit.cpp.

References editingTextMessage, game_data_t::fov, g_game, Cockpit::Init(), Cockpit::viewport_offset, x, and y.

1564 {
1565  smooth_fov = g_game.fov;
1566  editingTextMessage = false;
1567  armor8 = false;
1568  shield8 = false;
1569  Cockpit::Init( file );
1570  if (Panel.size() > 0) {
1571  float x, y;
1572  Panel.front()->GetPosition( x, y );
1573  Panel.front()->SetPosition( x, y+viewport_offset );
1574  }
1575 }
void GameCockpit::InitStatic ( )
virtual

Reimplemented from Cockpit.

Definition at line 1632 of file cockpit.cpp.

References Cockpit::cockpit_time, Cockpit::gauge_time, MAXVDUS, and Cockpit::radar_time.

Referenced by Draw(), and GameCockpit().

1633 {
1634  int i;
1635  for (i = 0; i < UnitImages< void >::NUMGAUGES; i++)
1636  gauge_time[i] = 0;
1637  for (i = 0; i < MAXVDUS; i++)
1638  vdu_time[i] = 0;
1639  radar_time = 0;
1640  cockpit_time = 0;
1641 }
bool GameCockpit::IsPaused ( ) const

Definition at line 3302 of file cockpit.cpp.

References GetElapsedTime().

3303 {
3304  return (GetElapsedTime() <= 0.001);
3305 }
float GameCockpit::LookupTargetStat ( int  stat,
Unit target 
)
virtual

Looks up a particular Gauge stat on target unit.

Reimplemented from Cockpit.

Definition at line 973 of file cockpit.cpp.

References Unit::BShieldData(), Unit::FShieldData(), Unit::LShieldData(), and Unit::RShieldData().

974 {
975  switch (stat)
976  {
978  return target->FShieldData();
979 
981  return target->RShieldData();
982 
984  return target->LShieldData();
985 
987  return target->BShieldData();
988  }
989  return 1;
990 }
float GameCockpit::LookupUnitStat ( int  stat,
Unit target 
)

Looks up a particular Gauge stat on unit.

Definition at line 992 of file cockpit.cpp.

References Unit::ArmorData(), Unit::autopilotactive, Unit::AutoPilotTo(), Unit::BShieldData(), Orders::AutoDocking::CanDock(), Unit::CanDockWithMe(), Unit::cloaking, Unit::cloakmin, Unit::CombatMode(), Unit::computer, Unit::cosAngleTo(), Unit::cumulative_velocity, Unit::UnitJump::drive, UnitImages< BOGUS >::ecm, Unit::Computer::ecmactive, Unit::UnitJump::energy, Unit::EnergyData(), float, Unit::FShieldData(), Unit::FuelData(), Unit::GetComputerData(), UnitUtil::getECM(), GetElapsedTime(), UniverseUtil::GetGameTime(), Unit::GetHull(), Unit::GetImageInformation(), Unit::GetJumpStatus(), getNewTime(), UnitContainer::GetUnit(), VegaConfig::getVariable(), Unit::GetWarpEnergy(), Unit::GetWarpVelocity(), Unit::graphicOptions, Unit::inertialmode, Unit::graphic_options::InWarp, Cockpit::jumpok, soundContainer::loadsound(), UniverseUtil::LookupUnitStat(), Unit::LShieldData(), Magnitude(), Unit::Mass, Unit::Computer::max_combat_ab_speed, Unit::Computer::max_combat_speed, Unit::Computer::max_speed(), Cockpit::maxfuel, Cockpit::maxhull, Unit::graphic_options::missilelock, Unit::name, XMLSupport::parse_bool(), XMLSupport::parse_float(), soundContainer::playsound(), Unit::Position(), Unit::RShieldData(), Unit::rSize(), Unit::Computer::set_speed, Shield::shield, Unit::shield, soundContainer::sound, Cockpit::StartArmor, Unit::Target(), Unit::Computer::threat, Cockpit::TimeOfLastCollision, Unit::turretstatus, Unit::Computer::velocity_ref, vs_config, Unit::WarpEnergyData(), Unit::graphic_options::WarpFieldStrength, and Unit::graphic_options::WarpRamping.

Referenced by Draw(), and SetupViewPort().

993 {
994  static float game_speed = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
995  static bool display_in_meters = XMLSupport::parse_bool( vs_config->getVariable( "physics", "display_in_meters", "true" ) );
996  static bool lie = XMLSupport::parse_bool( vs_config->getVariable( "physics", "game_speed_lying", "true" ) );
997  static float fpsval = 0;
998  const float fpsmax = 1;
999  static float numtimes = fpsmax;
1000  float armordat[8]; //short fix
1001  int armori;
1002  Unit *tmpunit;
1003  if (shield8) {
1004  switch (stat)
1005  {
1015  return target->shield.shield.cur[stat-UnitImages < void
1016  > ::SHIELDF]/target->shield.shield.max[stat-UnitImages < void > ::SHIELDF];
1017  else return 0;
1018  default:
1019  break;
1020  }
1021  }
1022  switch (stat)
1023  {
1025  return target->FShieldData();
1026 
1028  return target->RShieldData();
1029 
1031  return target->LShieldData();
1032 
1034  return target->BShieldData();
1035 
1044  target->ArmorData( armordat );
1045  if (armor8) {
1046  return armordat[stat-UnitImages < void > ::ARMORF]/StartArmor[stat-UnitImages < void > ::ARMORF];
1047  } else {
1048  for (armori = 0; armori < 8; ++armori) {
1049  if (armordat[armori] > StartArmor[armori])
1050  StartArmor[armori] = armordat[armori];
1051  armordat[armori] /= StartArmor[armori];
1052  }
1053  }
1054  switch (stat)
1055  {
1057  return .25*(armordat[0]+armordat[1]+armordat[4]+armordat[5]);
1058 
1060  return .25*(armordat[2]+armordat[3]+armordat[6]+armordat[7]);
1061 
1063  return .25*(armordat[1]+armordat[3]+armordat[5]+armordat[7]);
1064 
1066  default:
1067  return .25*(armordat[0]+armordat[2]+armordat[4]+armordat[6]);
1068  }
1070  if (target->FuelData() > maxfuel)
1071  maxfuel = target->FuelData();
1072  if (maxfuel > 0) return target->FuelData()/maxfuel;
1073  return 0;
1074 
1076  return target->EnergyData();
1077 
1079  {
1080  static bool warpifnojump =
1081  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "display_warp_energy_if_no_jump_drive",
1082  "true" ) );
1083  return (warpifnojump || target->GetJumpStatus().drive != -2) ? target->WarpEnergyData() : 0;
1084  }
1086  if ( maxhull < target->GetHull() )
1087  maxhull = target->GetHull();
1088  return target->GetHull()/maxhull;
1089 
1091  {
1092  int go =
1093  ( ( (target->GetHull()/maxhull) < .25 )
1094  && (target->BShieldData() < .25 || target->FShieldData() < .25) ) ? 1 : 0;
1095  static int overload = 0;
1096  if (overload != go) {
1097  if (go == 0) {
1098  static soundContainer ejectstopsound;
1099  if (ejectstopsound.sound < 0) {
1100  static string str = vs_config->getVariable( "cockpitaudio", "overload_stopped", "overload_stopped" );
1101  ejectstopsound.loadsound( str );
1102  }
1103  ejectstopsound.playsound();
1104  } else {
1105  static soundContainer ejectsound;
1106  if (ejectsound.sound < 0) {
1107  static string str = vs_config->getVariable( "cockpitaudio", "overload", "overload" );
1108  ejectsound.loadsound( str );
1109  }
1110  ejectsound.playsound();
1111  }
1112  overload = go;
1113  }
1114  return go;
1115  }
1117  {
1118  static float locklight_time = XMLSupport::parse_float( vs_config->getVariable( "graphics", "locklight_time", "1" ) );
1119  bool res = false;
1120  if ( ( tmpunit = target->GetComputerData().threat.GetUnit() ) ) {
1121  res = tmpunit->cosAngleTo( target, *&armordat[0], FLT_MAX, FLT_MAX ) > .95;
1122  if (res) last_locktime = UniverseUtil::GetGameTime();
1123  }
1124  return ( res || ( (UniverseUtil::GetGameTime()-last_locktime) < locklight_time ) ) ? 1.0f : 0.0f;
1125  }
1127  {
1128  static float locklight_time = XMLSupport::parse_float( vs_config->getVariable( "graphics", "locklight_time", "1" ) );
1129  bool res = target->graphicOptions.missilelock;
1130  if (res) last_mlocktime = UniverseUtil::GetGameTime();
1131  return ( res || ( (UniverseUtil::GetGameTime()-last_mlocktime) < locklight_time ) ) ? 1.0f : 0.0f;
1132  }
1134  {
1135  static double collidepanic =
1136  XMLSupport::parse_float( vs_config->getVariable( "physics", "collision_inertial_time", "1.25" ) );
1137  return (getNewTime()-TimeOfLastCollision) < collidepanic;
1138  }
1140  return (UnitUtil::getECM(target) > 0) ? 1 : 0;
1141 
1143  return target->graphicOptions.WarpFieldStrength;
1144 
1146  return jumpok ? 1 : 0;
1147 
1153  {
1154  static bool use_relative_velocity =
1155  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "display_relative_velocity", "true" ) );
1156  float value;
1157  switch (stat)
1158  {
1160  if (target->graphicOptions.WarpFieldStrength != 1.0) {
1161  if ( use_relative_velocity && target->computer.velocity_ref.GetUnit() ) {
1163  value =
1164  ( target->GetWarpVelocity()
1166  } else {
1167  value =
1168  (target->GetWarpVelocity()
1170  }
1171  } else {
1172  value = target->GetWarpVelocity().Magnitude();
1173  }
1174  } else {
1175  if ( use_relative_velocity && target->computer.velocity_ref.GetUnit() ) {
1177  value =
1178  ( target->cumulative_velocity
1180  } else {
1181  value =
1182  (target->cumulative_velocity
1184  }
1185  } else {
1186  value = target->cumulative_velocity.Magnitude();
1187  }
1188  }
1189  break;
1191  value = target->GetComputerData().set_speed;
1192  break;
1194  value = target->GetComputerData().max_speed();
1195  break;
1197  value = target->GetComputerData().max_combat_speed;
1198  break;
1200  value = target->GetComputerData().max_combat_ab_speed;
1201  break;
1202  default:
1203  value = 0;
1204  }
1205  if (lie)
1206  return value/game_speed;
1207  else
1208  return display_in_meters ? value : value*3.6; //JMS 6/28/05 - converted back to raw meters/second
1209  }
1211  {
1212  float basemass = atof( UniverseUtil::LookupUnitStat( target->name, "", "Mass" ).c_str() );
1213  if (basemass > 0)
1214  return 100*target->Mass/basemass;
1215  else
1216  return 0;
1217  }
1219  {
1220  static int wasautopilot = 0;
1221  int abletoautopilot = 0;
1222  static bool auto_valid =
1223  XMLSupport::parse_bool( vs_config->getVariable( "physics", "insystem_jump_or_timeless_auto-pilot", "false" ) );
1224  if (target) {
1225  if (!auto_valid) {
1226  abletoautopilot = (target->graphicOptions.InWarp);
1227  } else {
1228  abletoautopilot = (target->AutoPilotTo( target, false ) ? 1 : 0);
1229  static float no_auto_light_below =
1230  XMLSupport::parse_float( vs_config->getVariable( "physics", "no_auto_light_below", "2000" ) );
1231  Unit *targtarg = target->Target();
1232  if (targtarg) {
1233  if ( ( target->Position()-targtarg->Position() ).Magnitude()-targtarg->rSize()-target->rSize()
1234  < no_auto_light_below )
1235  abletoautopilot = false;
1236  }
1237  }
1238  }
1239  if (abletoautopilot != wasautopilot) {
1240  if (abletoautopilot == 0) {
1241  static soundContainer autostopsound;
1242  if (autostopsound.sound < 0) {
1243  static string str = vs_config->getVariable( "cockpitaudio",
1244  "autopilot_available",
1245  "autopilot_available" );
1246  autostopsound.loadsound( str );
1247  }
1248  autostopsound.playsound();
1249  } else {
1250  static soundContainer autosound;
1251  if (autosound.sound < 0) {
1252  static string str = vs_config->getVariable( "cockpitaudio",
1253  "autopilot_unavailable",
1254  "autopilot_unavailable" );
1255  autosound.loadsound( str );
1256  }
1257  autosound.playsound();
1258  }
1259  wasautopilot = abletoautopilot;
1260  }
1261  return abletoautopilot;
1262  }
1264  if (fpsval >= 0 && fpsval < .5*FLT_MAX)
1265  numtimes -= .1+fpsval;
1266  if (numtimes <= 0) {
1267  numtimes = fpsmax;
1268  fpsval = GetElapsedTime();
1269  }
1270  if (fpsval)
1271  return 1./fpsval;
1273  if (target->autopilotactive)
1274  return (float) UnitImages< void >::ACTIVE;
1275  else
1276  return (float) UnitImages< void >::OFF;
1278  if (target->graphicOptions.WarpRamping)
1279  return (float) UnitImages< void >::SWITCHING;
1280  else if (target->graphicOptions.InWarp)
1281  return (float) UnitImages< void >::ACTIVE;
1282  else
1283  return (float) UnitImages< void >::OFF;
1285  if (target->inertialmode)
1286  return (float) UnitImages< void >::OFF;
1287  else
1288  return (float) UnitImages< void >::ON;
1290  if (0 == target->turretstatus)
1291  return (float) UnitImages< void >::NOTAPPLICABLE;
1292  else if (2 == target->turretstatus) //FIXME -- need to check if turrets are active
1293  return (float) UnitImages< void >::ACTIVE;
1294  else if (3 == target->turretstatus) //FIXME -- need to check if turrets are in FireAtWill state
1295  return (float) UnitImages< void >::FAW;
1296  else
1297  return (float) UnitImages< void >::OFF;
1299  if (target->GetImageInformation().ecm > 0)
1301  else
1302  return (float) UnitImages< void >::NOTAPPLICABLE;
1304  if (-1 == target->cloaking)
1305  return (float) UnitImages< void >::NOTAPPLICABLE;
1306  else if ( ( (int) (-2147483647)-1 ) == target->cloaking )
1307  return (float) UnitImages< void >::READY;
1308  else if (target->cloaking == target->cloakmin)
1309  return (float) UnitImages< void >::ACTIVE;
1310  else
1311  return (float) UnitImages< void >::SWITCHING;
1313  if ( target->CombatMode() )
1314  return (float) UnitImages< void >::MANEUVER;
1315  else
1316  return (float) UnitImages< void >::TRAVEL;
1318  if (!target) //FIXME
1319  return (float) UnitImages< void >::WARNING;
1320  else
1321  return (float) UnitImages< void >::NOMINAL;
1323  if (!target) //FIXME
1324  return (float) UnitImages< void >::WARNING;
1325  else
1326  return (float) UnitImages< void >::NOMINAL;
1328  if (!target) //FIXME
1329  return (float) UnitImages< void >::WARNING;
1330  else
1331  return (float) UnitImages< void >::NOMINAL;
1333  if (!target) //FIXME
1334  return (float) UnitImages< void >::WARNING;
1335  else
1336  return (float) UnitImages< void >::NOMINAL;
1338  if (!target) //FIXME
1339  return (float) UnitImages< void >::WARNING;
1340  else
1341  return (float) UnitImages< void >::NOMINAL;
1343  if (-2 == target->GetJumpStatus().drive)
1344  return (float) UnitImages< void >::NODRIVE;
1345  else if (target->GetWarpEnergy() < target->GetJumpStatus().energy)
1346  return (float) UnitImages< void >::NOTENOUGHENERGY;
1347  else if (target->graphicOptions.InWarp) //FIXME
1348  return (float) UnitImages< void >::OFF;
1349  else if (jumpok)
1350  return (float) UnitImages< void >::READY;
1351  else
1352  return (float) UnitImages< void >::TOOFAR;
1354  {
1355  Unit *station = target->Target();
1356  if (station)
1357  {
1358  if (station->CanDockWithMe(target, true) != -1)
1359  {
1360  if (station->CanDockWithMe(target, false) != -1)
1361  {
1362  return (float) UnitImages<void>::READY;
1363  }
1364  if (Orders::AutoDocking::CanDock(target, station))
1365  {
1366  return (float) UnitImages<void>::AUTOREADY;
1367  }
1368  return (float) UnitImages<void>::TOOFAR;
1369  }
1370  }
1371  return (float) UnitImages< void >::NOMINAL;
1372  }
1373  }
1374  return 1.0f;
1375 }
void GameCockpit::NavScreen ( const KBData ,
KBSTATE  k 
)
static

Definition at line 1736 of file cockpit.cpp.

References _Universe, Universe::AccessCockpit(), BaseInterface::ActiveMouseOverWin(), CanDrawNavSystem(), BaseInterface::ClickWin(), BaseInterface::PassiveMouseOverWin(), PRESS, RestoreMouse(), SetDrawNavSystem(), winsys_set_motion_func(), winsys_set_mouse_func(), and winsys_set_passive_motion_func().

Referenced by IncrementStartupVariable(), initGlobalCommandMap(), and NavComputer::toggleVisibility().

1737 {
1738  //scheherazade
1739  if (k == PRESS) {
1740  //UniverseUtil::IOmessage(0,"game","all","hit key");
1741  if ( ( _Universe->AccessCockpit() )->CanDrawNavSystem() ) {
1743  //UniverseUtil::IOmessage(0,"game","all","DRAWNAV - OFF");
1744  RestoreMouse();
1745  } else {
1747  //UniverseUtil::IOmessage(0,"game","all","DRAWNAV - ON");
1748 
1752  }
1753  }
1754 }
void GameCockpit::OnDockEnd ( Unit station,
Unit unit 
)
virtual

Reimplemented from Cockpit.

Definition at line 3345 of file cockpit.cpp.

References _Universe, and Universe::isPlayerStarship().

3346 {
3347  if (_Universe->isPlayerStarship(ship))
3348  updateRadar(ship);
3349 }
void GameCockpit::OnJumpBegin ( Unit unit)
virtual

Reimplemented from Cockpit.

Definition at line 3351 of file cockpit.cpp.

References _Universe, and Universe::isPlayerStarship().

3352 {
3353  if (_Universe->isPlayerStarship(ship))
3354  {
3355  radarDisplay->OnJumpBegin();
3356  }
3357 }
void GameCockpit::OnJumpEnd ( Unit unit)
virtual

Reimplemented from Cockpit.

Definition at line 3359 of file cockpit.cpp.

References _Universe, and Universe::isPlayerStarship().

3360 {
3361  if (_Universe->isPlayerStarship(ship))
3362  {
3363  radarDisplay->OnJumpEnd();
3364  }
3365 }
void GameCockpit::OnPauseBegin ( )
virtual

Reimplemented from Cockpit.

Definition at line 3307 of file cockpit.cpp.

3308 {
3309  radarDisplay->OnPauseBegin();
3310 }
void GameCockpit::OnPauseEnd ( )
virtual

Reimplemented from Cockpit.

Definition at line 3312 of file cockpit.cpp.

3313 {
3314  radarDisplay->OnPauseEnd();
3315 }
void GameCockpit::ReceivedTargetInfo ( )
virtual

Reimplemented from Cockpit.

Definition at line 117 of file cockpit.cpp.

References j.

118 {
119  for (size_t j = 0; j < vdu.size(); j++)
120  vdu[j]->ReceivedTargetData();
121 }
void GameCockpit::Respawn ( const KBData ,
KBSTATE  k 
)
static

Definition at line 1907 of file cockpit.cpp.

References _Universe, Universe::CurrentCockpit(), and PRESS.

Referenced by initGlobalCommandMap().

1908 {
1909  if (k == PRESS) {
1910  while ( respawnunit.size() <= _Universe->CurrentCockpit() )
1911  respawnunit.push_back( 0 );
1913  }
1914 }
void GameCockpit::RestoreViewPort ( )
virtual

Restores the view from the IDentity Matrix needed to draw sprites.

Reimplemented from Cockpit.

Definition at line 2931 of file cockpit.cpp.

References _Universe, Universe::AccessCamera(), and Camera::RestoreViewPort().

Referenced by Draw().

2932 {
2934 }
void GameCockpit::ScrollAllVDU ( int  howmuch)
virtual

Reimplemented from Cockpit.

Definition at line 2878 of file cockpit.cpp.

References NavigationSystem::CheckDraw(), NavigationSystem::scroll(), and ScrollVDU().

2879 {
2880  if ( ThisNav.CheckDraw() )
2881  ThisNav.scroll( howmuch );
2882  else
2883  for (unsigned int i = 0; i < vdu.size(); i++)
2884  ScrollVDU( i, howmuch );
2885 }
void GameCockpit::ScrollVDU ( int  vdunum,
int  howmuch 
)
virtual

Reimplemented from Cockpit.

Definition at line 2868 of file cockpit.cpp.

References AUDPlay(), QVector, and Vector.

Referenced by ScrollAllVDU().

2869 {
2870  if (soundfile >= 0)
2871  //AUDPlay (soundfile, AccessCamera()->GetPosition(), Vector (0,0,0),.5);
2872  AUDPlay( soundfile, QVector( 0, 0, 0 ), Vector( 0, 0, 0 ), 1 );
2873  if ( vdunum < (int) vdu.size() )
2874  if (vdu[vdunum])
2875  vdu[vdunum]->Scroll( howmuch );
2876 }
void GameCockpit::SelectCamera ( int  cam)
virtual

Changes current camera to selected camera.

Reimplemented from Cockpit.

Definition at line 3189 of file cockpit.cpp.

References Cockpit::currentcamera.

Referenced by SelectProperCamera().

3190 {
3191  if (cam < NUM_CAM && cam >= 0)
3192  currentcamera = cam;
3193 }
void GameCockpit::SelectProperCamera ( )
virtual

Reimplemented from Cockpit.

Definition at line 1721 of file cockpit.cpp.

References SelectCamera(), and Cockpit::view.

1722 {
1723  SelectCamera( view );
1724 }
void GameCockpit::SetCommAnimation ( Animation ani,
Unit un 
)
virtual

Reimplemented from Cockpit.

Definition at line 2896 of file cockpit.cpp.

Referenced by DoAutoLanding(), and SetStaticAnimation().

2897 {
2898  bool seti = false;
2899  for (unsigned int i = 0; i < vdu.size(); i++)
2900  if ( vdu[i]->SetCommAnimation( ani, un, false ) ) {
2901  seti = true;
2902  break;
2903  }
2904  if (!seti) {
2905  for (unsigned int i = 0; i < vdu.size(); i++)
2906  if ( vdu[i]->SetCommAnimation( ani, un, true ) )
2907  break;
2908  }
2909 }
bool GameCockpit::SetDrawNavSystem ( bool  what)
virtual

Reimplemented from Cockpit.

Definition at line 1756 of file cockpit.cpp.

References NavigationSystem::SetDraw().

Referenced by NavScreen().

1757 {
1758  ThisNav.SetDraw( what );
1759  return what;
1760 }
void GameCockpit::SetInsidePanPitchSpeed ( float  speed)
virtual

Reimplemented from Cockpit.

Definition at line 3372 of file cockpit.cpp.

References speed.

3373 {
3374  insidePanPitchSpeed = speed;
3375 }
void GameCockpit::SetInsidePanYawSpeed ( float  speed)
virtual

Reimplemented from Cockpit.

Definition at line 3367 of file cockpit.cpp.

References speed.

3368 {
3369  insidePanYawSpeed = speed;
3370 }
void GameCockpit::SetSoundFile ( std::string  sound)

Definition at line 123 of file cockpit.cpp.

References AUDCreateSoundWAV().

124 {
125  soundfile = AUDCreateSoundWAV( sound, false );
126 }
void GameCockpit::SetStaticAnimation ( )
virtual

Reimplemented from Cockpit.

Definition at line 2887 of file cockpit.cpp.

References VDU::COMM, VegaConfig::getVariable(), SetCommAnimation(), and vs_config.

2888 {
2889  static string comm_static = vs_config->getVariable( "graphics", "comm_static", "static.ani" );
2890  static Animation Statuc( comm_static.c_str() );
2891  for (unsigned int i = 0; i < vdu.size(); i++)
2892  if (vdu[i]->getMode() == VDU::COMM)
2893  vdu[i]->SetCommAnimation( &Statuc, NULL, true );
2894 }
void GameCockpit::setTargetLabel ( const string &  msg)
virtual

Reimplemented from Cockpit.

Definition at line 2923 of file cockpit.cpp.

References Cockpit::GetParent(), and Unit::Target().

2924 {
2925  if ( GetParent() ) {
2926  targetLabel = newLabel;
2927  labeledTargetUnit = GetParent()->Target();
2928  }
2929 }
void GameCockpit::SetupViewPort ( bool  clip = true)
virtual

Sets up the world for rendering...call before draw.

Reimplemented from Cockpit.

Definition at line 2985 of file cockpit.cpp.

References _Universe, Universe::AccessCamera(), UniverseUtil::atan(), Cockpit::cockpit_offset, UniverseUtil::cos(), CP_BACK, CP_CHASE, CP_FIXEDPOS, CP_FIXEDPOSTARGET, CP_FRONT, CP_LEFT, CP_PAN, CP_PANINSIDE, CP_PANTARGET, CP_RIGHT, CP_TARGET, CP_VIEWTARGET, f, FaceCamTarget(), float, game_data_t::fov, g_game, GetElapsedTime(), Camera::GetOrientation(), Unit::GetOrientation(), Camera::GetR(), UnitContainer::GetUnit(), VegaConfig::getVariable(), Unit::GetVelocity(), GFXFALSE, GFXTRUE, GFXViewPort(), lerp(), LookupUnitStat(), max(), min(), Cockpit::parent, XMLSupport::parse_bool(), XMLSupport::parse_float(), Unit::Position(), q, Camera::RestoreViewPort(), RotateAxisAngle(), Camera::setCockpitOffset(), Camera::SetFov(), Camera::SetOrientation(), Unit::SetVisible(), ShoveCamBehindUnit(), ShoveCamBelowUnit(), Unit::Target(), Transform(), translate_as(), Camera::UpdateGFX(), Unit::UpdateHudMatrix(), Vector, Cockpit::view, Cockpit::viewport_offset, vs_config, game_data_t::x_resolution, game_data_t::y_resolution, and Cockpit::zoomfactor.

2986 {
2988  GFXViewPort( 0,
2989  (int) ( (view == CP_FRONT ? viewport_offset : 0)*g_game.y_resolution ),
2991  g_game.y_resolution );
2993  Unit *un, *tgt;
2994  if ( ( un = parent.GetUnit() ) ) {
2995  //Previous frontal orientation - useful, sometimes...
2996  Vector prev_fp, prev_fq, prev_fr;
2997  _Universe->AccessCamera( CP_FRONT )->GetOrientation( prev_fp, prev_fq, prev_fr );
2998 
2999  un->UpdateHudMatrix( CP_FRONT );
3000  un->UpdateHudMatrix( CP_LEFT );
3001  un->UpdateHudMatrix( CP_RIGHT );
3002  un->UpdateHudMatrix( CP_BACK );
3003  un->UpdateHudMatrix( CP_CHASE );
3005 
3006  insidePanYaw += insidePanYawSpeed * GetElapsedTime();
3007  insidePanPitch += insidePanPitchSpeed * GetElapsedTime();
3008 
3009  Vector p, q, r, tmp;
3011  _Universe->AccessCamera( CP_LEFT )->SetOrientation( r, q, -p );
3012  _Universe->AccessCamera( CP_RIGHT )->SetOrientation( -r, q, p );
3013  _Universe->AccessCamera( CP_BACK )->SetOrientation( -p, q, -r );
3014 #ifdef IWANTTOPVIEW
3015  _Universe->AccessCamera( CP_CHASE )->SetOrientation( p, r, -q );
3016 #endif
3017 
3018  Matrix pitchMatrix, yawMatrix, panMatrix;
3019  RotateAxisAngle(pitchMatrix, Vector( 1, 0, 0 ), insidePanPitch);
3020  RotateAxisAngle(yawMatrix, Transform(pitchMatrix, Vector( 0, 1, 0 )), insidePanYaw);
3021  panMatrix = yawMatrix * pitchMatrix;
3023  Transform(panMatrix, p),
3024  Transform(panMatrix, q),
3025  Transform(panMatrix, r) );
3026 
3027  tgt = un->Target();
3028  if (tgt) {
3029  un->GetOrientation( p, q, r );
3030  r = ( tgt->Position()-un->Position() ).Cast();
3031  r.Normalize();
3032  CrossProduct( r, q, tmp );
3033  CrossProduct( tmp, r, q );
3034  //Padlock block
3035  if (view == CP_VIEWTARGET) {
3036  static float PadlockViewLag =
3037  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "PadlockViewLag", "1.5" ) );
3038  static float PadlockViewLag_inv = 1.f/PadlockViewLag;
3039  static float PadlockViewLag_fix =
3040  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "PadlockViewLagFixZone", "0.0872" ) ); //~5 deg
3041  static float PadlockViewLag_fixcos = (float) cos( PadlockViewLag_fix );
3042 
3043  //pp,qq,rr <-- world-relative padlock target
3044  //p_p,p_q,p_r <-- previous head orientation translated to new front orientation
3045  Vector p_p, p_q, p_r, f_p, f_q, f_r, pp = tmp, qq = q, rr = r;
3046  _Universe->AccessCamera( CP_VIEWTARGET )->GetOrientation( p_p, p_q, p_r );
3047  _Universe->AccessCamera( CP_FRONT )->GetOrientation( f_p, f_q, f_r );
3048  translate_as( p_p, p_q, p_r, prev_fp, prev_fq, prev_fr, f_p, f_q, f_r );
3049 
3050  //Compute correction amount (vtphase), accounting for lag and fix-zone
3052  bool fixzone = (rr.Dot( p_r ) >= PadlockViewLag_fixcos) && (qq.Dot( p_q ) >= PadlockViewLag_fixcos);
3053  float vtphase = 1.0f-(float) pow( 0.1, GetElapsedTime()*PadlockViewLag_inv*(fixzone ? 0.1f : 1.0f) );
3054 
3055  //Apply correction
3057  lerp( p_p, pp, vtphase ).Normalize(),
3058  lerp( p_q, qq, vtphase ).Normalize(),
3059  lerp( p_r, rr, vtphase ).Normalize() );
3060  } else {
3061  //Reset padlock matrix
3063  }
3064  _Universe->AccessCamera( CP_TARGET )->SetOrientation( tmp, q, r );
3065  //_Universe->AccessCamera(CP_PANTARGET)->SetOrientation(tmp,q,r);
3068  FaceCamTarget( this, CP_FIXEDPOSTARGET, tgt );
3069  } else {
3071  un->UpdateHudMatrix( CP_TARGET );
3073  }
3074  static bool draw_unit_on_chasecam =
3075  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_unit_on_chasecam", "true" ) );
3076  if (view == CP_CHASE && !draw_unit_on_chasecam) {} else {
3078  //ShoveCamBehindUnit (CP_PANTARGET,un,zoomfactor);
3079  }
3080  FaceCamTarget( this, CP_FIXEDPOS, un );
3081 
3083  un->SetVisible( view >= CP_CHASE );
3084 
3085  //WARP-FOV link
3086  {
3087  static float stable_lowarpref =
3088  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.stable.loref", "1" ) );
3089  static float stable_hiwarpref =
3090  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.stable.hiref", "100000" ) );
3091  static float stable_refexp =
3092  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.stable.exp", "0.5" ) );
3093  static bool stable_asymptotic =
3094  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "warp.fovlink.stable.asymptotic", "1" ) );
3095  static float stable_offset_f =
3096  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.stable.offset.front", "0" ) );
3097  static float stable_offset_b =
3098  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.stable.offset.back", "0" ) );
3099  static float stable_offset_p =
3100  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.stable.offset.perpendicular", "0" ) );
3101  static float stable_multiplier_f =
3102  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.stable.multiplier.front", "0.85" ) );
3103  static float stable_multiplier_b =
3104  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.stable.multiplier.back", "1.5" ) );
3105  static float stable_multiplier_p =
3106  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.stable.multiplier.perpendicular",
3107  "1.25" ) );
3108 
3109  static float shake_lowarpref =
3110  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.loref", "10000" ) );
3111  static float shake_hiwarpref =
3112  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.hiref", "200000" ) );
3113  static float shake_refexp =
3114  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.exp", "1.5" ) );
3115  static bool shake_asymptotic =
3116  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "warp.fovlink.shake.asymptotic", "1" ) );
3117  static float shake_speed =
3118  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.speed", "10" ) );
3119  static float shake_offset_f =
3120  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.offset.front", "0" ) );
3121  static float shake_offset_b =
3122  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.offset.back", "0" ) );
3123  static float shake_offset_p =
3124  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.offset.perpendicular", "0" ) );
3125  static float shake_multiplier_f =
3126  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.multiplier.front", "0" ) );
3127  static float shake_multiplier_b =
3128  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.multiplier.back", "0" ) );
3129  static float shake_multiplier_p =
3130  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.shake.multiplier.perpendicular", "0" ) );
3131 
3132  static float refkpsoverride =
3133  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.referencekps", "0" ) ); //0 means automatic
3134 
3135  static float theta = 0;
3136  theta += shake_speed*GetElapsedTime();
3137  if (stable_lowarpref == stable_hiwarpref) stable_hiwarpref = stable_lowarpref+1;
3138  if (shake_lowarpref == shake_hiwarpref) shake_hiwarpref = shake_lowarpref+1;
3139  float warpfieldstrength = LookupUnitStat( UnitImages< void >::WARPFIELDSTRENGTH, un );
3140  float refkps = (refkpsoverride > 0) ? refkpsoverride : LookupUnitStat( UnitImages< void >::MAXCOMBATABKPS, un ); //This one is stable, as opposed to SETKPS - for full stability, use the override (user override of governor settings will create weird behaviour if done under SPEC)
3141  float kps = LookupUnitStat( UnitImages< void >::KPS, un );
3142  float st_warpfieldstrength =
3143  pow( (max( stable_lowarpref,
3144  min( stable_asymptotic ? FLT_MAX : stable_hiwarpref,
3145  warpfieldstrength ) )-stable_lowarpref)/(stable_hiwarpref-stable_lowarpref), stable_refexp );
3146  float sh_warpfieldstrength =
3147  pow( (max( shake_lowarpref, min( shake_asymptotic ? FLT_MAX : shake_hiwarpref,
3148  warpfieldstrength ) )-shake_lowarpref)/(shake_hiwarpref-shake_lowarpref),
3149  shake_refexp );
3150  float costheta = cos( theta );
3151  if (stable_asymptotic) st_warpfieldstrength = atan( st_warpfieldstrength );
3152  if (shake_asymptotic) sh_warpfieldstrength = atan( sh_warpfieldstrength );
3153  if (refkps <= 1) refkps = 1;
3154  if (kps > refkps) kps = refkps;
3155  float unv = un->GetVelocity().Magnitude();
3156  float camv = _Universe->AccessCamera()->GetR().Magnitude();
3157  if (unv <= 1) unv = 1;
3158  if (camv <= 1) camv = 1;
3159  float cosangle = ( un->GetVelocity()*_Universe->AccessCamera()->GetR() )/(unv*camv)*(kps/refkps);
3160  float st_offs, sh_offs, st_mult, sh_mult;
3161  if (cosangle > 0) {
3162  st_offs = stable_offset_f*cosangle+stable_offset_p*(1-cosangle);
3163  sh_offs = shake_offset_f*cosangle+shake_offset_p*(1-cosangle);
3164  st_mult = stable_multiplier_f*cosangle+stable_multiplier_p*(1-cosangle);
3165  sh_mult = shake_multiplier_f*cosangle+shake_multiplier_p*(1-cosangle);
3166  } else {
3167  st_offs = stable_offset_b* -cosangle+stable_offset_p*(1+cosangle);
3168  sh_offs = shake_offset_b* -cosangle+shake_offset_p*(1+cosangle);
3169  st_mult = stable_multiplier_b* -cosangle+stable_multiplier_p*(1+cosangle);
3170  sh_mult = shake_multiplier_b* -cosangle+shake_multiplier_p*(1+cosangle);
3171  }
3172  st_offs *= st_warpfieldstrength;
3173  sh_offs *= sh_warpfieldstrength*costheta;
3174  st_mult = (1-st_warpfieldstrength)+st_mult*st_warpfieldstrength;
3175  sh_mult *= sh_warpfieldstrength*costheta;
3176  static float fov_smoothing =
3177  XMLSupport::parse_float( vs_config->getVariable( "graphics", "warp.fovlink.smoothing", ".4" ) );
3178  float fov_smoot = pow( double(fov_smoothing), GetElapsedTime() );
3179  smooth_fov =
3180  min( 170.0f, max( 5.0f, (1-fov_smoot)*smooth_fov+fov_smoot*(g_game.fov*(st_mult+sh_mult)+st_offs+sh_offs) ) );
3181  _Universe->AccessCamera()->SetFov( smooth_fov );
3182  }
3183  }
3185 
3186  //parent->UpdateHudMatrix();
3187 }
void GameCockpit::SetViewport ( )
inlinevirtual

GFXLoadMatrix proper camera.

Reimplemented from Cockpit.

Definition at line 211 of file cockpit.h.

212  {
213  cam[currentcamera].UpdateGFX();
214  }
void GameCockpit::Shake ( float  amt,
int  level 
)
virtual

Reimplemented from Cockpit.

Definition at line 1979 of file cockpit.cpp.

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

1980 {
1981  static float shak = XMLSupport::parse_float( vs_config->getVariable( "graphics", "cockpit_shake", "3" ) );
1982  static float shak_max = XMLSupport::parse_float( vs_config->getVariable( "graphics", "cockpit_shake_max", "20" ) );
1983  shakin += shak;
1984  if (shakin > shak_max)
1985  shakin = shak_max;
1986  this->shake_time = getNewTime();
1987  this->shake_type = dtype;
1988 }
void GameCockpit::SwitchControl ( const KBData ,
KBSTATE  k 
)
static

Definition at line 1808 of file cockpit.cpp.

References _Universe, Universe::CurrentCockpit(), and PRESS.

Referenced by initGlobalCommandMap().

1809 {
1810  if (k == PRESS) {
1811  while ( switchunit.size() <= _Universe->CurrentCockpit() )
1812  switchunit.push_back( 0 );
1814  }
1815 }
void GameCockpit::TurretControl ( const KBData ,
KBSTATE  k 
)
static

Definition at line 1898 of file cockpit.cpp.

References _Universe, Universe::CurrentCockpit(), and PRESS.

Referenced by initGlobalCommandMap().

1899 {
1900  if (k == PRESS) {
1901  while ( turretcontrol.size() <= _Universe->CurrentCockpit() )
1902  turretcontrol.push_back( 0 );
1904  }
1905 }
void GameCockpit::UpdAutoPilot ( )
virtual

Reimplemented from Cockpit.

Definition at line 2757 of file cockpit.cpp.

References AccessCamera(), Cockpit::autopilot_target, Cockpit::autopilot_time, Unit::AutoPilotTo(), CP_FIXED, Cockpit::GetParent(), UnitContainer::GetUnit(), VegaConfig::getVariable(), soundContainer::loadsound(), Camera::myPhysics, XMLSupport::parse_bool(), XMLSupport::parse_float(), soundContainer::playsound(), PhysicsSystem::SetAngularVelocity(), SetStartupView(), UnitContainer::SetUnit(), SIMULATION_ATOM, soundContainer::sound, Vector, vs_config, and Cockpit::zoomfactor.

2758 {
2759  static bool autopan = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "pan_on_auto", "true" ) );
2760  if (autopilot_time != 0) {
2762  {
2763  if (autopan) {
2764  Vector origR = Vector( 0, 0, 1 );
2765  Vector origP = Vector( 1, 0, 0 );
2766 
2767  static float rotspd =
2768  XMLSupport::parse_float( vs_config->getVariable( "graphics", "autopilot_rotation_speed", ".15" ) );
2769 
2770  static float curtime = 0;
2771  curtime += SIMULATION_ATOM;
2772  float ang = curtime*rotspd;
2773  origR.Yaw( ang );
2774  origP.Yaw( ang );
2775  Vector origQ = Vector( 0, 1, 0 );
2776  origP.Normalize();
2777  origQ.Normalize();
2778  origR.Normalize();
2779  AccessCamera( CP_FIXED )->myPhysics.SetAngularVelocity( Vector( 0, 0, 0 ) ); //hack
2780  static float initialzoom =
2781  XMLSupport::parse_float( vs_config->getVariable( "graphics", "inital_zoom_factor", "2.25" ) );
2782  zoomfactor = initialzoom;
2783  }
2784  }
2785  if (autopilot_time <= 0) {
2787  if (disableautosound.sound < 0) {
2788  static string str = vs_config->getVariable( "cockpitaudio", "autopilot_disabled", "autopilot_disabled" );
2789  disableautosound.loadsound( str );
2790  }
2792  if (autopan) {
2794  SetStartupView( this );
2795  }
2796  autopilot_time = 0;
2797  Unit *par = GetParent();
2798  if (par) {
2799  Unit *autoun = autopilot_target.GetUnit();
2800  autopilot_target.SetUnit( NULL );
2801  if (autoun && autopan)
2802  par->AutoPilotTo( autoun, false );
2803  }
2804  }
2805  }
2806 }
void GameCockpit::VDUSwitch ( int  vdunum)
virtual

Reimplemented from Cockpit.

Definition at line 2858 of file cockpit.cpp.

References AUDPlay(), UnitContainer::GetUnit(), Cockpit::parent, QVector, and Vector.

2859 {
2860  if (soundfile >= 0)
2861  //AUDPlay (soundfile, AccessCamera()->GetPosition(), Vector (0,0,0), .5);
2862  AUDPlay( soundfile, QVector( 0, 0, 0 ), Vector( 0, 0, 0 ), 1 );
2863  if ( vdunum < (int) vdu.size() )
2864  if (vdu[vdunum])
2865  vdu[vdunum]->SwitchMode( this->parent.GetUnit() );
2866 }
void GameCockpit::visitSystem ( std::string  systemName)
virtual

Reimplemented from Cockpit.

Definition at line 1767 of file cockpit.cpp.

References AccessNavSystem(), VegaConfig::getVariable(), XMLSupport::parse_bool(), NavigationSystem::pathman, NavigationSystem::setCurrentSystem(), PathManager::updatePaths(), Cockpit::visitSystem(), and vs_config.

1768 {
1770  if ( AccessNavSystem() ) {
1771  static bool AlwaysUpdateNavMap =
1772  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "update_nav_after_jump", "false" ) ); //causes occasional crash--only may have tracked it down
1773  if (AlwaysUpdateNavMap)
1776  }
1777 }

Member Data Documentation

std::string GameCockpit::autoMessage

Definition at line 149 of file cockpit.h.

Referenced by Autopilot(), and VDU::Draw().

float GameCockpit::autoMessageTime

Definition at line 150 of file cockpit.h.

Referenced by Autopilot(), VDU::Draw(), and GameCockpit().

bool GameCockpit::editingTextMessage

Definition at line 148 of file cockpit.h.

Referenced by Draw(), GameCockpit(), Init(), and CockpitKeys::TextMessageCallback().

std::string GameCockpit::textMessage

Definition at line 147 of file cockpit.h.

Referenced by CockpitKeys::TextMessageCallback().


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