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
cockpit.cpp File Reference
#include <boost/version.hpp>
#include <boost/python/object.hpp>
#include <boost/python/dict.hpp>
#include "vsfilesystem.h"
#include "vs_globals.h"
#include "vegastrike.h"
#include "gauge.h"
#include "cockpit.h"
#include "universe.h"
#include "star_system.h"
#include "cmd/unit_generic.h"
#include "cmd/unit_factory.h"
#include "cmd/collection.h"
#include "cmd/unit_util.h"
#include "cmd/unit_find.h"
#include "cmd/base_util.h"
#include "hud.h"
#include "vdu.h"
#include "lin_time.h"
#include "cmd/beam.h"
#include "config_xml.h"
#include "cmd/images.h"
#include "cmd/script/mission.h"
#include "cmd/script/msgcenter.h"
#include "cmd/ai/flyjoystick.h"
#include "cmd/ai/firekeyboard.h"
#include "cmd/ai/aggressive.h"
#include "cmd/ai/autodocking.h"
#include "main_loop.h"
#include <assert.h>
#include "savegame.h"
#include "animation.h"
#include "mesh.h"
#include "universe_util.h"
#include "in_mouse.h"
#include "gui/glut_support.h"
#include "networking/netclient.h"
#include "audiolib.h"
#include "save_util.h"
#include "cmd/base.h"
#include "in_kb_data.h"
#include <set>
#include <string>
#include "cmd/unit_const_cache.h"
#include "options.h"
#include <algorithm>

Go to the source code of this file.

Classes

class  UnivMap
 

Macros

#define SWITCH_CONST   (.9)
 
#define VERYNEAR_CONST   (0.004f)
 
#define COCKPITZ_HEADROOM   (1.01f)
 
#define sqr(x)   ( ( (x) )*( (x) ) )
 
#define SCATTER_CUBE   QVector( rand()/RAND_MAX -.5, rand()/RAND_MAX -.5, rand()/RAND_MAX -.5 )
 
#define TARGET_ARROW_COS_THETA   (0.93969262078590838405410927732473)
 
#define TARGET_ARROW_SIN_THETA   (0.34202014332566873304409961468226)
 
#define TARGET_ARROW_SIZE   (0.05)
 

Functions

float rand01 ()
 
static GFXColor RetrColor (const string &name, GFXColor def=GFXColor(1, 1, 1, 1))
 
void DrawOneTargetBox (const QVector &Loc, float rSize, const Vector &CamP, const Vector &CamQ, const Vector &CamR, float lock_percent, bool ComputerLockon, bool Diamond=false)
 
static GFXColor DockBoxColor (const string &name, GFXColor deflt=GFXColor(1, 1, 1, 1))
 
void DrawDockingBoxes (Unit *un, Unit *target, const Vector &CamP, const Vector &CamQ, const Vector &CamR)
 
void DrawITTSLine (QVector fromLoc, QVector aimLoc, GFXColor linecolor=GFXColor(1, 1, 1, 1))
 
void DrawITTSMark (float Size, QVector p, QVector q, QVector aimLoc, GFXColor markcolor=GFXColor(1, 1, 1, 1))
 
void DoCockpitKeys ()
 
void RespawnNow (Cockpit *cp)
 
void SuicideKey (const KBData &, KBSTATE k)
 
void MapKey (const KBData &, KBSTATE k)
 
void reset_time_compression (const KBData &, KBSTATE a)
 
static void DrawDamageFlash (int dtype)
 
static void DrawCrosshairs (float x, float y, float wid, float hei, const GFXColor &col)
 
QVector SystemLocation (std::string system)
 
double howFarToJump ()
 
void SetStartupView (Cockpit *)
 
void SwitchUnits2 (Unit *nw)
 
static void FaceCamTarget (Cockpit *cp, int cam, Unit *un)
 
static void ShoveCamBehindUnit (int cam, Unit *un, float zoomfactor)
 
static void ShoveCamBelowUnit (int cam, Unit *un, float zoomfactor)
 
static Vector lerp (const Vector &a, const Vector &b, float t)
 
static void translate_as (Vector &p, Vector &q, Vector &r, Vector p1, Vector q1, Vector r1, Vector p2, Vector q2, Vector r2)
 

Variables

vs_options game_options
 
static soundContainer disableautosound
 
static soundContainer enableautosound
 
vector< intrespawnunit
 
vector< intswitchunit
 
vector< intturretcontrol
 
std::vector< UnivMapunivmap
 
bool QuitAllow
 
bool screenshotkey
 

Macro Definition Documentation

#define COCKPITZ_HEADROOM   (1.01f)

Definition at line 70 of file cockpit.cpp.

Referenced by GameCockpit::Draw().

#define SCATTER_CUBE   QVector( rand()/RAND_MAX -.5, rand()/RAND_MAX -.5, rand()/RAND_MAX -.5 )

Definition at line 483 of file cockpit.cpp.

#define sqr (   x)    ( ( (x) )*( (x) ) )

Definition at line 81 of file cockpit.cpp.

Referenced by GameCockpit::Draw().

#define SWITCH_CONST   (.9)

Definition at line 66 of file cockpit.cpp.

Referenced by GameCockpit::Draw().

#define TARGET_ARROW_COS_THETA   (0.93969262078590838405410927732473)

Draw the arrow pointing to the target.

Definition at line 3207 of file cockpit.cpp.

#define TARGET_ARROW_SIN_THETA   (0.34202014332566873304409961468226)

Definition at line 3208 of file cockpit.cpp.

#define TARGET_ARROW_SIZE   (0.05)

Definition at line 3209 of file cockpit.cpp.

#define VERYNEAR_CONST   (0.004f)

Definition at line 68 of file cockpit.cpp.

Referenced by GameCockpit::Draw().

Function Documentation

static GFXColor DockBoxColor ( const string &  name,
GFXColor  deflt = GFXColor(1,1,1,1) 
)
static

Definition at line 382 of file cockpit.cpp.

References VegaConfig::getColor(), and vs_config.

Referenced by GameCockpit::Draw(), and DrawDockingBoxes().

383 {
384  vs_config->getColor( name, &deflt.r, true );
385  return deflt;
386 }
void DoCockpitKeys ( )

Definition at line 1730 of file cockpit.cpp.

Referenced by Cockpit::Update().

1731 {
1734 }
static void DrawCrosshairs ( float  x,
float  y,
float  wid,
float  hei,
const GFXColor col 
)
static

Definition at line 2064 of file cockpit.cpp.

References GFXBegin(), GFXBlendMode(), GFXCircle(), GFXColorf(), GFXDisable(), GFXEnable(), GFXEnd(), GFXLINE, GFXVertex3f(), INVSRCALPHA, LIGHTING, SMOOTH, SRCALPHA, and TEXTURE0.

Referenced by GameCockpit::Draw().

2065 {
2066  GFXColorf( col );
2067  GFXDisable( TEXTURE0 );
2068  GFXDisable( LIGHTING );
2070  GFXEnable( SMOOTH );
2071  GFXCircle( x, y, wid/4, hei/4 );
2072  GFXCircle( x, y, wid/7, hei/7 );
2073  GFXDisable( SMOOTH );
2074  GFXBegin( GFXLINE );
2075  GFXVertex3f( x-(wid/2), y, 0 );
2076  GFXVertex3f( x-(wid/6), y, 0 );
2077  GFXVertex3f( x+(wid/2), y, 0 );
2078  GFXVertex3f( x+(wid/6), y, 0 );
2079  GFXVertex3f( x, y-(hei/2), 0 );
2080  GFXVertex3f( x, y-(hei/6), 0 );
2081  GFXVertex3f( x, y+(hei/2), 0 );
2082  GFXVertex3f( x, y+(hei/6), 0 );
2083  GFXVertex3f( x-.001, y+.001, 0 );
2084  GFXVertex3f( x+.001, y-.001, 0 );
2085  GFXVertex3f( x+.001, y+.001, 0 );
2086  GFXVertex3f( x-.001, y-.001, 0 );
2087  GFXEnd();
2088  GFXEnable( TEXTURE0 );
2089 }
static void DrawDamageFlash ( int  dtype)
static

Definition at line 1990 of file cockpit.cpp.

References BILINEAR, f, VegaConfig::getColor(), VegaConfig::getVariable(), GFXBegin(), GFXBlendMode(), GFXColor4f(), GFXDisable(), GFXEnable(), GFXEnd(), GFXPopBlendMode(), GFXPushBlendMode(), GFXQUAD, GFXTexCoord2f(), GFXVertex3f(), height, INVSRCALPHA, AnimatedTexture::MakeActive(), ONE, XMLSupport::parse_bool(), SRCALPHA, TEXTURE0, vs_config, width, and ZERO.

Referenced by GameCockpit::Draw().

1991 {
1992  const int numtypes = 3;
1993  static string shieldflash = vs_config->getVariable( "graphics", "shield_flash_animation", "" );
1994  static string armorflash = vs_config->getVariable( "graphics", "armor_flash_animation", "armorflash.ani" );
1995  static string hullflash = vs_config->getVariable( "graphics", "hull_flash_animation", "hullflash.ani" );
1996  string flashes[numtypes];
1997  flashes[0] = shieldflash;
1998  flashes[1] = armorflash;
1999  flashes[2] = hullflash;
2000  float fallbackcolor[numtypes][4] = {
2001  {0, 1, .5, .2}, {1, 0, .2, .25}, {1, 0, 0, .5}
2002  };
2003 
2004  static bool init = false;
2005  static Animation *aflashes[numtypes];
2006  static bool doflash[numtypes];
2007  if (!init) {
2008  init = true;
2009  for (int i = 0; i < numtypes; ++i) {
2010  doflash[i] = (flashes[i].length() > 0);
2011  if (doflash[i])
2012  aflashes[i] = new Animation( flashes[i].c_str(), true, .1, BILINEAR, false, false );
2013  else
2014  aflashes[i] = NULL;
2015  }
2016  vs_config->getColor( "shield_flash", fallbackcolor[0] );
2017  vs_config->getColor( "armor_flash", fallbackcolor[1] );
2018  vs_config->getColor( "hull_flash", fallbackcolor[2] );
2019  }
2020  if (dtype < numtypes) {
2021  int i = dtype;
2022  if (aflashes[i]) {
2023  GFXPushBlendMode();
2024  static bool damage_flash_alpha =
2025  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "damage_flash_alpha", "true" ) );
2026  if (damage_flash_alpha)
2028  else
2029  GFXBlendMode( ONE, ZERO );
2030  if ( aflashes[i]->LoadSuccess() ) {
2031  aflashes[i]->MakeActive();
2032  GFXColor4f( 1, 1, 1, 1 );
2033  GFXBegin( GFXQUAD );
2034  float width = 1, height = 1;
2035  GFXTexCoord2f( 0.00F, 1.00F );
2036  GFXVertex3f( -width, -height, 1.00F ); //lower left
2037  GFXTexCoord2f( 1.00F, 1.00F );
2038  GFXVertex3f( width, -height, 1.00F ); //upper left
2039  GFXTexCoord2f( 1.00F, 0.00F );
2040  GFXVertex3f( width, height, 1.00F ); //upper right
2041  GFXTexCoord2f( 0.00F, 0.00F );
2042  GFXVertex3f( -width, height, 1.00F ); //lower right
2043  GFXEnd();
2044  } else {
2045  GFXColor4f( fallbackcolor[i][0],
2046  fallbackcolor[i][1],
2047  fallbackcolor[i][2],
2048  fallbackcolor[i][3] );
2049  GFXDisable( TEXTURE0 );
2050  GFXBegin( GFXQUAD );
2051  GFXVertex3f( -1.0f, -1.0f, 1.0f );
2052  GFXVertex3f( -1.0f, 1.0f, 1.0f );
2053  GFXVertex3f( 1.0f, 1.0f, 1.0f );
2054  GFXVertex3f( 1.0f, -1.0f, 1.0f );
2055  GFXEnd();
2056  GFXEnable( TEXTURE0 );
2057  }
2058  GFXPopBlendMode();
2059  }
2060  }
2061  GFXColor4f( 1, 1, 1, 1 );
2062 }
void DrawDockingBoxes ( Unit un,
Unit target,
const Vector CamP,
const Vector CamQ,
const Vector CamR 
)
inline

Definition at line 388 of file cockpit.cpp.

References _Universe, GFXColor::a, Universe::AccessCamera(), d, DEPTHTEST, DEPTHWRITE, DockBoxColor(), Unit::DockingPortLocations(), DrawOneTargetBox(), Camera::GetPosition(), Unit::GetTransformation(), GFXBlendMode(), GFXColor4f(), GFXColorf(), GFXDisable(), GFXEnable(), i, INVSRCALPHA, Unit::IsCleared(), QVector, UniverseUtil::sqrt(), SRCALPHA, and Transform().

389 {
390  if ( target->IsCleared( un ) ) {
392  static GFXColor dockboxstop = DockBoxColor( "docking_box_halt", GFXColor(1,0,0,1) );
393  static GFXColor dockboxgo = DockBoxColor( "docking_box_proceed", GFXColor(0,1,.5,1) );
394  const vector< DockingPorts >d = target->DockingPortLocations();
395  for (unsigned int i = 0; i < d.size(); i++)
396  {
397  float rad = d[i].GetRadius() / sqrt( 2.0 );
398  QVector dockpos = Transform(
399  target->GetTransformation(),
400  d[i].GetPosition().Cast()
402 
403  if (!d[i].IsDockable())
404  {
405  static GFXColor waypointcolor = DockBoxColor( "docking_box_waypoint", GFXColor(0, 1, 1, 0.3) );
406  if (waypointcolor.a > 0.01) {
407  GFXColorf( waypointcolor );
408  DrawOneTargetBox( dockpos, rad, CamP, CamQ, CamR, 1,
409  true, true );
410  }
411  continue;
412  }
413 
416  GFXColorf( dockboxstop );
417  DrawOneTargetBox( dockpos, rad, CamP, CamQ, CamR, 1,
418  true, true );
419  GFXEnable( DEPTHTEST );
421  GFXColorf( dockboxgo );
422  DrawOneTargetBox( dockpos, rad, CamP, CamQ, CamR, 1,
423  true, true );
424  }
427  GFXColor4f( 1, 1, 1, 1 );
428  }
429 }
void DrawITTSLine ( QVector  fromLoc,
QVector  aimLoc,
GFXColor  linecolor = GFXColor( 1, 1, 1, 1 ) 
)
inline

Definition at line 488 of file cockpit.cpp.

References GFXBegin(), GFXBlendMode(), GFXColorf(), GFXDisable(), GFXEnable(), GFXEnd(), GFXLINESTRIP, GFXVertexf(), INVSRCALPHA, SMOOTH, and SRCALPHA.

489 {
490  GFXColorf( linecolor );
491  GFXEnable( SMOOTH );
494  GFXVertexf( fromLoc );
495  GFXVertexf( aimLoc );
496  GFXEnd();
497  GFXDisable( SMOOTH );
498 }
void DrawITTSMark ( float  Size,
QVector  p,
QVector  q,
QVector  aimLoc,
GFXColor  markcolor = GFXColor( 1, 1, 1, 1 ) 
)
inline

Definition at line 500 of file cockpit.cpp.

References GFXBegin(), GFXBlendMode(), GFXColorf(), GFXDisable(), GFXEnable(), GFXEnd(), GFXLINESTRIP, GFXVertexf(), INVSRCALPHA, SMOOTH, and SRCALPHA.

501 {
502  GFXColorf( markcolor );
503  GFXEnable( SMOOTH );
506  GFXVertexf( aimLoc + p*Size );
507  GFXVertexf( aimLoc - q*Size );
508  GFXVertexf( aimLoc - p*Size );
509  GFXVertexf( aimLoc + q*Size );
510  GFXVertexf( aimLoc + p*Size );
511  GFXEnd();
512  GFXDisable( SMOOTH );
513 }
void DrawOneTargetBox ( const QVector Loc,
float  rSize,
const Vector CamP,
const Vector CamQ,
const Vector CamR,
float  lock_percent,
bool  ComputerLockon,
bool  Diamond = false 
)
inline

Definition at line 169 of file cockpit.cpp.

References center, UniverseUtil::cos(), VegaConfig::getVariable(), GFXBegin(), GFXBlendMode(), GFXDisable(), GFXEnable(), GFXEnd(), GFXLINE, GFXLINESTRIP, GFXLineWidth(), GFXVertexf(), INVSRCALPHA, M_PI, Magnitude(), max(), XMLSupport::parse_bool(), XMLSupport::parse_float(), QVector, UniverseUtil::sin(), SMOOTH, SRCALPHA, Vector, and vs_config.

Referenced by DrawDockingBoxes().

177 {
178  static float boxthick = XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "BoxLineThickness", "1" ) );
179  static float rat = XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "min_target_box_size", ".01" ) );
180  float len = (Loc).Magnitude();
181  float curratio = rSize/len;
182  if (curratio < rat)
183  rSize = len*rat;
184  GFXLineWidth( boxthick );
185  GFXEnable( SMOOTH );
187  if (Diamond) {
188  float ModrSize = rSize/1.41;
190  GFXVertexf( Loc+(.75*CamP+CamQ).Cast()*ModrSize );
191  GFXVertexf( Loc+(CamP+.75*CamQ).Cast()*ModrSize );
192  GFXVertexf( Loc+(CamP-.75*CamQ).Cast()*ModrSize );
193  GFXVertexf( Loc+(.75*CamP-CamQ).Cast()*ModrSize );
194  GFXVertexf( Loc+(-.75*CamP-CamQ).Cast()*ModrSize );
195  GFXVertexf( Loc+(-CamP-.75*CamQ).Cast()*ModrSize );
196  GFXVertexf( Loc+(.75*CamQ-CamP).Cast()*ModrSize );
197  GFXVertexf( Loc+(CamQ-.75*CamP).Cast()*ModrSize );
198  GFXVertexf( Loc+(.75*CamP+CamQ).Cast()*ModrSize );
199  GFXEnd();
200  } else if (ComputerLockon) {
202  GFXVertexf( Loc+(CamP+CamQ).Cast()*rSize );
203  GFXVertexf( Loc+(CamP-CamQ).Cast()*rSize );
204  GFXVertexf( Loc+(-CamP-CamQ).Cast()*rSize );
205  GFXVertexf( Loc+(CamQ-CamP).Cast()*rSize );
206  GFXVertexf( Loc+(CamP+CamQ).Cast()*rSize );
207  GFXEnd();
208  } else {
209  GFXBegin( GFXLINE );
210  GFXVertexf( Loc+(CamP+CamQ).Cast()*rSize );
211  GFXVertexf( Loc+(CamP+.66*CamQ).Cast()*rSize );
212 
213  GFXVertexf( Loc+(CamP-CamQ).Cast()*rSize );
214  GFXVertexf( Loc+(CamP-.66*CamQ).Cast()*rSize );
215 
216  GFXVertexf( Loc+(-CamP-CamQ).Cast()*rSize );
217  GFXVertexf( Loc+(-CamP-.66*CamQ).Cast()*rSize );
218 
219  GFXVertexf( Loc+(CamQ-CamP).Cast()*rSize );
220  GFXVertexf( Loc+(CamQ-.66*CamP).Cast()*rSize );
221 
222  GFXVertexf( Loc+(CamP+CamQ).Cast()*rSize );
223  GFXVertexf( Loc+(CamP+.66*CamQ).Cast()*rSize );
224 
225  GFXVertexf( Loc+(CamP+CamQ).Cast()*rSize );
226  GFXVertexf( Loc+(.66*CamP+CamQ).Cast()*rSize );
227 
228  GFXVertexf( Loc+(CamP-CamQ).Cast()*rSize );
229  GFXVertexf( Loc+(.66*CamP-CamQ).Cast()*rSize );
230 
231  GFXVertexf( Loc+(-CamP-CamQ).Cast()*rSize );
232  GFXVertexf( Loc+(-.66*CamP-CamQ).Cast()*rSize );
233 
234  GFXVertexf( Loc+(CamQ-CamP).Cast()*rSize );
235  GFXVertexf( Loc+(.66*CamQ-CamP).Cast()*rSize );
236 
237  GFXVertexf( Loc+(CamP+CamQ).Cast()*rSize );
238  GFXVertexf( Loc+(.66*CamP+CamQ).Cast()*rSize );
239 
240  GFXEnd();
241  }
242  if (lock_percent < .99) {
243  if (lock_percent < 0)
244  lock_percent = 0;
245  //eallySwitch=XMLSupport::parse_bool(vs_config->getVariable("graphics","hud","switchToTargetModeOnKey","true"));
246  static float diamondthick =
247  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "DiamondLineThickness", "1" ) ); //1.05;
248  glLineWidth( diamondthick );
249  static bool center =
250  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "LockCenterCrosshair", "false" ) );
251  static float absmin =
252  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "min_lock_box_size", ".001" ) );
253  static float endreticle =
254  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "MinMissileBracketSize", "1.05" ) ); //1.05;
255  static float startreticle =
256  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "MaxMissileBracketSize", "2.05" ) ); //2.05;
257  static float diamondsize = XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "DiamondSize", "2.05" ) ); //1.05;
258  static float bracketsize =
259  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "RotatingBracketSize", "0.58" ) ); //1.05;
260  static float thetaspeed =
261  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "DiamondRotationSpeed", "1" ) ); //1.05;
262  static float lockline =
263  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "LockConfirmLineLength", "1.5" ) ); //1.05;
264  if (center) {
265  static float bracketwidth =
266  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "RotatingBracketWidth", "0.1" ) ); //1.05;
267  static bool bracketinnerouter =
268  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "RotatingBracketInner", "true" ) ); //1.05;
269  float innerdis = endreticle+(startreticle-endreticle)*lock_percent;
270  float outerdis = innerdis+bracketsize;
271  float bracketdis = (bracketinnerouter ? innerdis : outerdis);
272  float r = rSize < absmin ? absmin : rSize;
273  GFXBegin( GFXLINE );
274 
275  GFXVertexf( Loc+CamP*(innerdis*r) );
276  GFXVertexf( Loc+CamP*(outerdis*r) );
277 
278  GFXVertexf( Loc+CamP*(bracketdis*r)+CamQ*(bracketwidth*r) );
279  GFXVertexf( Loc+CamP*(bracketdis*r)-CamQ*(bracketwidth*r) );
280 
281  GFXVertexf( Loc-CamP*(innerdis*r) );
282  GFXVertexf( Loc-CamP*(outerdis*r) );
283 
284  GFXVertexf( Loc-CamP*(bracketdis*r)+CamQ*(bracketwidth*r) );
285  GFXVertexf( Loc-CamP*(bracketdis*r)-CamQ*(bracketwidth*r) );
286 
287  GFXVertexf( Loc+CamQ*(innerdis*r) );
288  GFXVertexf( Loc+CamQ*(outerdis*r) );
289 
290  GFXVertexf( Loc+CamQ*(bracketdis*r)+CamP*(bracketwidth*r) );
291  GFXVertexf( Loc+CamQ*(bracketdis*r)-CamP*(bracketwidth*r) );
292 
293  GFXVertexf( Loc-CamQ*(innerdis*r) );
294  GFXVertexf( Loc-CamQ*(outerdis*r) );
295 
296  GFXVertexf( Loc-CamQ*(bracketdis*r)+CamP*(bracketwidth*r) );
297  GFXVertexf( Loc-CamQ*(bracketdis*r)-CamP*(bracketwidth*r) );
298 
299  GFXEnd();
300  } else {
301  float max = diamondsize;
302  //VSFileSystem::Fprintf (stderr,"lock percent %f\n",lock_percent);
303  float coord = endreticle+(startreticle-endreticle)*lock_percent; //rSize/(1-lock_percent);//this is a number between 1 and 100
304  double rtot = 1./sqrtf( 2 );
305 
306  //this causes the rotation!
307  float theta = 4*M_PI*lock_percent*thetaspeed;
308  Vector LockBox( -cos( theta )*rtot, -rtot, sin( theta )*rtot );
309  //Vector LockBox (0*rtot,-rtot,1*rtot);
310 
311  static float diamondthick =
312  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "DiamondLineThickness", "1" ) ); //1.05;
313  GFXLineWidth( diamondthick );
314  Vector TLockBox( rtot*LockBox.i+rtot*LockBox.j, rtot*LockBox.j-rtot*LockBox.i, LockBox.k );
315  Vector SLockBox( TLockBox.j, TLockBox.i, TLockBox.k );
316  QVector Origin = (CamP+CamQ).Cast()*(rSize*coord);
317  TLockBox = (TLockBox.i*CamP+TLockBox.j*CamQ+TLockBox.k*CamR);
318  SLockBox = (SLockBox.i*CamP+SLockBox.j*CamQ+SLockBox.k*CamR);
319  double r1Size = rSize*bracketsize;
320  if (r1Size < absmin)
321  r1Size = absmin;
323  max *= rSize*.75*endreticle;
324  if (lock_percent == 0) {
325  GFXVertexf( Loc+CamQ.Cast()*max*lockline );
326  GFXVertexf( Loc+CamQ.Cast()*max );
327  }
328  GFXVertexf( Loc+Origin+(TLockBox.Cast()*r1Size) );
329  GFXVertexf( Loc+Origin );
330  GFXVertexf( Loc+Origin+(SLockBox.Cast()*r1Size) );
331  if (lock_percent == 0) {
332  GFXVertexf( Loc+CamP.Cast()*max );
333  GFXVertexf( Loc+CamP.Cast()*max*lockline );
334 
335  GFXEnd();
337  GFXVertexf( Loc-CamP.Cast()*max );
338  } else {
339  GFXEnd();
341  }
342  GFXVertexf( Loc-Origin-(SLockBox.Cast()*r1Size) );
343  GFXVertexf( Loc-Origin );
344  GFXVertexf( Loc-Origin-(TLockBox.Cast()*r1Size) );
345 
346  Origin = (CamP-CamQ).Cast()*(rSize*coord);
347  if (lock_percent == 0) {
348  GFXVertexf( Loc-CamQ.Cast()*max );
349  GFXVertexf( Loc-CamQ.Cast()*max*lockline );
350 
351  GFXVertexf( Loc-CamQ.Cast()*max );
352  } else {
353  GFXEnd();
355  }
356  GFXVertexf( Loc+Origin+(TLockBox.Cast()*r1Size) );
357  GFXVertexf( Loc+Origin );
358  GFXVertexf( Loc+Origin-(SLockBox.Cast()*r1Size) );
359  if (lock_percent == 0) {
360  GFXVertexf( Loc+CamP.Cast()*max );
361  GFXEnd();
363  GFXVertexf( Loc-CamP.Cast()*max*lockline );
364 
365  GFXVertexf( Loc-CamP.Cast()*max );
366  } else {
367  GFXEnd();
369  }
370  GFXVertexf( Loc-Origin+(SLockBox.Cast()*r1Size) );
371  GFXVertexf( Loc-Origin );
372  GFXVertexf( Loc-Origin-(TLockBox.Cast()*r1Size) );
373  if (lock_percent == 0)
374  GFXVertexf( Loc+CamQ.Cast()*max );
375  GFXEnd();
376  }
377  }
378  GFXLineWidth( 1 );
379  GFXDisable( SMOOTH );
380 }
static void FaceCamTarget ( Cockpit cp,
int  cam,
Unit un 
)
static

Definition at line 2936 of file cockpit.cpp.

References Cockpit::AccessCamera(), Camera::GetPosition(), Unit::Position(), QVector, Camera::SetOrientation(), Vector, and z.

Referenced by GameCockpit::SetupViewPort().

2937 {
2938  QVector diff = un->Position()-cp->AccessCamera()->GetPosition();
2939  diff.Normalize();
2940  if (diff.i != 0 && diff.k != 0) {
2941  Vector z = diff.Cross( QVector( 0, 1, 0 ) ).Cast();
2942  cp->AccessCamera( cam )->SetOrientation( z, Vector( 0, 1, 0 ), diff.Cast() );
2943  }
2944 }
double howFarToJump ( )

Definition at line 2129 of file unit_generic.cpp.

2130 {
2131  static float tmp = XMLSupport::parse_float( vs_config->getVariable( "physics", "distance_to_warp", "1000000000000.0" ) );
2132  return tmp;
2133 }
static Vector lerp ( const Vector a,
const Vector b,
float  t 
)
static

Definition at line 2967 of file cockpit.cpp.

References f, max(), and min().

Referenced by GameCockpit::SetupViewPort().

2968 {
2969  t = min( 1.0f, max( 0.0f, t ) );
2970  return a*(1-t)+b*t;
2971 }
void MapKey ( const KBData ,
KBSTATE  k 
)

Definition at line 1882 of file cockpit.cpp.

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

Referenced by initGlobalCommandMap().

1883 {
1884  if (k == PRESS) {
1885  static VSSprite ul( "upper-left-map.spr" );
1886  static VSSprite ur( "upper-right-map.spr" );
1887  static VSSprite ll( "lower-left-map.spr" );
1888  static VSSprite lr( "lower-right-map.spr" );
1889  while ( univmap.size() <= _Universe->CurrentCockpit() )
1890  univmap.push_back( UnivMap( NULL, NULL, NULL, NULL ) );
1891  if ( univmap[_Universe->CurrentCockpit()].isNull() )
1892  univmap[_Universe->CurrentCockpit()] = UnivMap( &ul, &ur, &ll, &lr );
1893  else
1894  univmap[_Universe->CurrentCockpit()] = UnivMap( NULL, NULL, NULL, NULL );
1895  }
1896 }
float rand01 ( )

Definition at line 641 of file unit_generic.cpp.

642 {
643  return (float) rand()/(float) RAND_MAX;
644 }
void reset_time_compression ( const KBData ,
KBSTATE  a 
)

Definition at line 79 of file lin_time.cpp.

References PRESS.

80 {
81  if (a == PRESS) {
82  timecompression = 1;
83  timecount = 0;
84  }
85 }
void RespawnNow ( Cockpit cp)

Definition at line 1799 of file cockpit.cpp.

References _Universe, Universe::AccessCockpit(), and Universe::numPlayers().

Referenced by BaseComputer::actionConfirmedLoadGame(), and UniverseUtil::loadGame().

1800 {
1801  while ( respawnunit.size() <= _Universe->numPlayers() )
1802  respawnunit.push_back( 0 );
1803  for (unsigned int i = 0; i < _Universe->numPlayers(); i++)
1804  if (_Universe->AccessCockpit( i ) == cp)
1805  respawnunit[i] = 2;
1806 }
static GFXColor RetrColor ( const string &  name,
GFXColor  def = GFXColor( 1, 1, 1, 1 ) 
)
static

Definition at line 72 of file cockpit.cpp.

References VegaConfig::getColor(), and vs_config.

Referenced by GameCockpit::Draw(), and Radar::Sensor::GetColor().

73 {
74  vs_config->getColor( name, &def.r );
75  return def;
76 }
void SetStartupView ( Cockpit )

Definition at line 500 of file main.cpp.

References CP_BACK, CP_CHASE, CP_FRONT, CP_TARGET, VegaConfig::getVariable(), Cockpit::SetView(), and vs_config.

Referenced by bootstrap_main_loop(), and GameCockpit::UpdAutoPilot().

501 {
502  static std::string startupview = vs_config->getVariable( "graphics", "startup_cockpit_view", "front" );
503  cp->SetView( startupview
504  == "view_target" ? CP_TARGET : ( startupview
505  == "back" ? CP_BACK : (startupview == "chase" ? CP_CHASE : CP_FRONT) ) );
506 }
static void ShoveCamBehindUnit ( int  cam,
Unit un,
float  zoomfactor 
)
static

Definition at line 2946 of file cockpit.cpp.

References _Universe, Universe::AccessCamera(), g_game, Unit::GetAcceleration(), Unit::GetAngularVelocity(), Camera::GetR(), Unit::GetWarpVelocity(), Unit::LocalPosition(), Unit::Position(), QVector, Unit::rSize(), Camera::SetPosition(), and game_data_t::znear.

Referenced by GameCockpit::SetupViewPort().

2947 {
2948  //commented out by chuck_starchaser; --never used
2949  QVector unpos = (/*un->GetPlanetOrbit() && !un->isSubUnit()*/ NULL) ? un->LocalPosition() : un->Position();
2951  unpos-_Universe->AccessCamera()->GetR().Cast()*(un->rSize()+g_game.znear*2)*zoomfactor,
2952  un->GetWarpVelocity(), un->GetAngularVelocity(), un->GetAcceleration() );
2953 }
static void ShoveCamBelowUnit ( int  cam,
Unit un,
float  zoomfactor 
)
static

Definition at line 2955 of file cockpit.cpp.

References _Universe, Universe::AccessCamera(), g_game, Unit::GetAcceleration(), Unit::GetAngularVelocity(), Camera::GetOrientation(), VegaConfig::getVariable(), Unit::GetWarpVelocity(), Unit::LocalPosition(), XMLSupport::parse_float(), Unit::Position(), q, QVector, Unit::rSize(), Camera::SetPosition(), Vector, vs_config, and game_data_t::znear.

Referenced by GameCockpit::SetupViewPort().

2956 {
2957  //commented out by chuck_starchaser; --never used
2958  QVector unpos = (/*un->GetPlanetOrbit() && !un->isSubUnit()*/ NULL) ? un->LocalPosition() : un->Position();
2959  Vector p, q, r;
2960  _Universe->AccessCamera( cam )->GetOrientation( p, q, r );
2961  static float ammttoshovecam = XMLSupport::parse_float( vs_config->getVariable( "graphics", "shove_camera_down", ".3" ) );
2963  unpos-(r-ammttoshovecam*q).Cast()*(un->rSize()+g_game.znear*2)*zoomfactor, un->GetWarpVelocity(),
2964  un->GetAngularVelocity(), un->GetAcceleration() );
2965 }
void SuicideKey ( const KBData ,
KBSTATE  k 
)

Definition at line 1824 of file cockpit.cpp.

References _Universe, Universe::AccessCockpit(), Unit::ArmorData(), Unit::DealDamageToHull(), Unit::GetHull(), Cockpit::GetParent(), newtime, PRESS, and Vector.

Referenced by initGlobalCommandMap().

1825 {
1826  static int orig = 0;
1827  if (k == PRESS) {
1828  int newtime = time( NULL );
1829  if (newtime-orig > 8 || orig == 0) {
1830  orig = newtime;
1831  Unit *un = NULL;
1832  if ( ( un = _Universe->AccessCockpit()->GetParent() ) ) {
1833  float armor[8]; //short fix
1834  un->ArmorData( armor );
1835  un->DealDamageToHull( Vector( 0, 0,
1836  .1 ), un->GetHull()*256.+2+2
1837  *(armor[1]+armor[2]+armor[3]+armor[4]+armor[5]+armor[6]+armor[7]+armor[0]) );
1838  }
1839  }
1840  }
1841 }
void SwitchUnits2 ( Unit nw)

Definition at line 2808 of file cockpit.cpp.

Referenced by NetClient::Respawn(), and SwitchUnits().

2809 {
2810  if (nw) {
2811  nw->PrimeOrders();
2814 
2815  nw->SetTurretAI();
2816  nw->DisableTurretAI();
2817 
2818  static bool LoadNewCockpit =
2819  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "UnitSwitchCockpitChange", "false" ) );
2820  static bool DisCockpit =
2821  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "SwitchCockpitToDefaultOnUnitSwitch", "false" ) );
2822  if (nw->getCockpit().length() > 0 || DisCockpit)
2823  _Universe->AccessCockpit()->Init( nw->getCockpit().c_str(), LoadNewCockpit == false );
2824  /* Here is the old code:
2825  *
2826  * if (nw->getCockpit().length()>0&&LoadNewCockpit) {
2827  * _Universe->AccessCockpit()->Init (nw->getCockpit().c_str());
2828  * }else {
2829  * if (DisCockpit) {
2830  * _Universe->AccessCockpit()->Init ("disabled-cockpit.cpt");
2831  * }
2832  * }
2833  *
2834  */
2835  }
2836 }
QVector SystemLocation ( std::string  system)

Definition at line 2135 of file unit_generic.cpp.

2136 {
2137  string xyz = _Universe->getGalaxyProperty( system, "xyz" );
2138  QVector pos;
2139  if ( xyz.size() && (sscanf( xyz.c_str(), "%lf %lf %lf", &pos.i, &pos.j, &pos.k ) >= 3) )
2140  return pos;
2141  else
2142  return QVector( 0, 0, 0 );
2143 }
static void translate_as ( Vector p,
Vector q,
Vector r,
Vector  p1,
Vector  q1,
Vector  r1,
Vector  p2,
Vector  q2,
Vector  r2 
)
static

Definition at line 2973 of file cockpit.cpp.

References Vector.

Referenced by GameCockpit::SetupViewPort().

2974 {
2975  //Translate p,q,r to <p1,q1,r1> base
2976  p = Vector( p.Dot( p1 ), p.Dot( q1 ), p.Dot( r1 ) );
2977  q = Vector( q.Dot( p1 ), q.Dot( q1 ), q.Dot( r1 ) );
2978  r = Vector( r.Dot( p1 ), r.Dot( q1 ), r.Dot( r1 ) );
2979  //Interpret now as if it were in <p2,q2,r2> base
2980  p = p2*p.i+q2*p.j+r2*p.k;
2981  q = p2*q.i+q2*q.j+r2*q.k;
2982  r = p2*r.i+q2*r.j+r2*r.k;
2983 }

Variable Documentation

soundContainer disableautosound
static

Definition at line 78 of file cockpit.cpp.

soundContainer enableautosound
static

Definition at line 79 of file cockpit.cpp.

vs_options game_options

Draws cockpit parts Draws gauges, info strings, radar, ...

Definition at line 83 of file main.cpp.

bool QuitAllow

Definition at line 82 of file main_loop.cpp.

Referenced by CockpitKeys::_PitchDown(), CockpitKeys::LookDown(), and CockpitKeys::Quit().

vector< int > respawnunit

Definition at line 37 of file cockpit_generic.cpp.

Referenced by Cockpit::Update().

bool screenshotkey

Definition at line 77 of file config_xml.cpp.

vector< int > switchunit

Definition at line 38 of file cockpit_generic.cpp.

vector< int > turretcontrol

Definition at line 39 of file cockpit_generic.cpp.

std::vector< UnivMap > univmap

Definition at line 1880 of file cockpit.cpp.