6 #include <boost/version.hpp>
7 #if BOOST_VERSION != 102800
8 #include <boost/python/object.hpp>
9 #include <boost/python/dict.hpp>
11 #include <boost/python/objects.hpp>
66 #define SWITCH_CONST (.9)
68 #define VERYNEAR_CONST (0.004f)
70 #define COCKPITZ_HEADROOM (1.01f)
81 #define sqr( x ) ( ( (x) )*( (x) ) )
89 if ( this->
sound == -2 && soundfile.size() ) {
119 for (
size_t j = 0;
j < vdu.size();
j++)
120 vdu[
j]->ReceivedTargetData();
131 static float crossthick =
164 float GameCockpit::computeLockingSymbol(
Unit *par )
176 bool Diamond =
false )
181 float curratio = rSize/len;
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 );
200 }
else if (ComputerLockon) {
211 GFXVertexf( Loc+(CamP+.66*CamQ).Cast()*rSize );
214 GFXVertexf( Loc+(CamP-.66*CamQ).Cast()*rSize );
217 GFXVertexf( Loc+(-CamP-.66*CamQ).Cast()*rSize );
220 GFXVertexf( Loc+(CamQ-.66*CamP).Cast()*rSize );
223 GFXVertexf( Loc+(CamP+.66*CamQ).Cast()*rSize );
226 GFXVertexf( Loc+(.66*CamP+CamQ).Cast()*rSize );
229 GFXVertexf( Loc+(.66*CamP-CamQ).Cast()*rSize );
232 GFXVertexf( Loc+(-.66*CamP-CamQ).Cast()*rSize );
235 GFXVertexf( Loc+(.66*CamQ-CamP).Cast()*rSize );
238 GFXVertexf( Loc+(.66*CamP+CamQ).Cast()*rSize );
242 if (lock_percent < .99) {
243 if (lock_percent < 0)
246 static float diamondthick =
248 glLineWidth( diamondthick );
251 static float absmin =
253 static float endreticle =
255 static float startreticle =
258 static float bracketsize =
260 static float thetaspeed =
262 static float lockline =
265 static float bracketwidth =
267 static bool bracketinnerouter =
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;
278 GFXVertexf( Loc+CamP*(bracketdis*r)+CamQ*(bracketwidth*r) );
279 GFXVertexf( Loc+CamP*(bracketdis*r)-CamQ*(bracketwidth*r) );
284 GFXVertexf( Loc-CamP*(bracketdis*r)+CamQ*(bracketwidth*r) );
285 GFXVertexf( Loc-CamP*(bracketdis*r)-CamQ*(bracketwidth*r) );
290 GFXVertexf( Loc+CamQ*(bracketdis*r)+CamP*(bracketwidth*r) );
291 GFXVertexf( Loc+CamQ*(bracketdis*r)-CamP*(bracketwidth*r) );
296 GFXVertexf( Loc-CamQ*(bracketdis*r)+CamP*(bracketwidth*r) );
297 GFXVertexf( Loc-CamQ*(bracketdis*r)-CamP*(bracketwidth*r) );
301 float max = diamondsize;
303 float coord = endreticle+(startreticle-endreticle)*lock_percent;
304 double rtot = 1./sqrtf( 2 );
307 float theta = 4*
M_PI*lock_percent*thetaspeed;
308 Vector LockBox( -
cos( theta )*rtot, -rtot,
sin( theta )*rtot );
311 static float 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;
323 max *= rSize*.75*endreticle;
324 if (lock_percent == 0) {
328 GFXVertexf( Loc+Origin+(TLockBox.Cast()*r1Size) );
330 GFXVertexf( Loc+Origin+(SLockBox.Cast()*r1Size) );
331 if (lock_percent == 0) {
342 GFXVertexf( Loc-Origin-(SLockBox.Cast()*r1Size) );
344 GFXVertexf( Loc-Origin-(TLockBox.Cast()*r1Size) );
346 Origin = (CamP-CamQ).Cast()*(rSize*coord);
347 if (lock_percent == 0) {
356 GFXVertexf( Loc+Origin+(TLockBox.Cast()*r1Size) );
358 GFXVertexf( Loc+Origin-(SLockBox.Cast()*r1Size) );
359 if (lock_percent == 0) {
370 GFXVertexf( Loc-Origin+(SLockBox.Cast()*r1Size) );
372 GFXVertexf( Loc-Origin-(TLockBox.Cast()*r1Size) );
373 if (lock_percent == 0)
395 for (
unsigned int i = 0;
i < d.size();
i++)
397 float rad = d[
i].GetRadius() /
sqrt( 2.0 );
400 d[
i].GetPosition().Cast()
403 if (!d[
i].IsDockable())
406 if (waypointcolor.
a > 0.01) {
431 void GameCockpit::DrawTargetBoxes(
const Radar::Sensor& sensor)
453 if (target != player) {
458 switch (track.GetType())
465 static bool draw_dock_box =
483 #define SCATTER_CUBE \
484 QVector( rand()/RAND_MAX -.5, rand()/RAND_MAX -.5, rand()/RAND_MAX -.5 )
540 if (draw_nav_symbol) {
548 if (draw_line_to_target) {
557 if (draw_line_to_targets_target && targets_target != NULL) {
564 static bool draw_target_nav_symbol =
566 static bool draw_jump_nav_symbol =
568 bool nav_symbol =
false;
570 if ( draw_target_nav_symbol
571 && ( (target->
faction == neutral
574 && ( draw_jump_nav_symbol
578 DrawNavigationSymbol( Loc, CamP, CamQ, Loc.Magnitude()*nav_symbol_size );
581 static bool lock_nav_symbol =
593 float scatter = .25*player->
rSize();
594 static bool ITTS_averageguns =
596 static bool ITTS_for_locks =
598 static bool ITTS_for_beams =
600 static bool line_to_itts_alpha =
609 if (ITTS_averageguns) {
611 iLoc = target->
PositionITTS( PlayerPosition, PlayerVelocity, speed, steady_itts ) - offs;
612 if (draw_line_to_itts)
618 if (draw_line_to_itts) {
619 for (
int i = 0;
i < nummounts;
i++) {
622 && (ITTS_for_locks || (player->
mounts[i].type->LockTime == 0)) )
624 iLoc = target->
PositionITTS( PlayerPosition, PlayerVelocity, player->
mounts[i].type->Speed, steady_itts ) - offs;
629 for (
int i = 0;
i < nummounts;
i++) {
632 && (ITTS_for_locks || (player->
mounts[i].type->LockTime == 0)) )
635 iLoc = target->
PositionITTS( PlayerPosition, PlayerVelocity, player->
mounts[i].type->Speed, steady_itts ) - offs;
643 void GameCockpit::DrawCommunicatingBoxes()
648 for (
unsigned int i = 0;
i < vdu.size(); ++
i) {
649 Unit *target = vdu[
i]->GetCommunicating();
681 std::set<Unit *> drawn_targets;
686 if (!target || (drawn_targets.find(target) != drawn_targets.end()))
688 drawn_targets.insert(target);
695 static bool draw_nav_symbol =
697 if (draw_nav_symbol) {
708 float rSize = track.GetSize();
731 static bool drawtactarg =
754 glLineWidth( (
int) thethick );
764 GFXVertexf( Loc+( (-CamP).Cast()+(-CamQ).Cast() )*rSize*(foci+fudge) );
765 GFXVertexf( Loc+( (-CamP).Cast()+(-CamQ).Cast() )*rSize*(foci-fudge) );
767 GFXVertexf( Loc+( (-CamP).Cast()+(CamQ).Cast() )*rSize*(foci+fudge) );
768 GFXVertexf( Loc+( (-CamP).Cast()+(CamQ).Cast() )*rSize*(foci-fudge) );
770 GFXVertexf( Loc+( (CamP).Cast()+(-CamQ).Cast() )*rSize*(foci+fudge) );
771 GFXVertexf( Loc+( (CamP).Cast()+(-CamQ).Cast() )*rSize*(foci-fudge) );
773 GFXVertexf( Loc+( (CamP).Cast()+(CamQ).Cast() )*rSize*(foci+fudge) );
774 GFXVertexf( Loc+( (CamP).Cast()+(CamQ).Cast() )*rSize*(foci-fudge) );
777 glLineWidth( (
int) 1 );
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;
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 );
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 );
825 std::string tname=target->
name;
826 if (autoLandingExcludeList.find(tname) != autoLandingExcludeList.end())
830 static float AutoLandingMoveDistance =
834 static bool adjust_unit_radius =
836 float rsize = target->
isPlanet() ? target->
rSize() : ( autorad+(adjust_unit_radius ? target->
rSize() : 0) );
838 float dist = diffvec.Magnitude()-un->
rSize()-rsize;
841 static bool haswarned =
false;
842 static void *lastwarned = NULL;
843 static float docktime = -FLT_MAX;
844 if (dist < lessthan && haswarned && lastwarned == target) {
851 }
else if (haswarned ==
false && lastwarned == target) {
858 }
else if (dist < warnless) {
859 if (lastwarned != target || !haswarned) {
860 if (autoLandingExcludeWarningList.count( target->
name ) == 0) {
862 static string str1 =
vs_config->
getVariable(
"cockpitaudio",
"automatic_landing_zone1",
"als" );
863 static string str2 =
vs_config->
getVariable(
"cockpitaudio",
"automatic_landing_zone2",
"als" );
865 "automatic_landing_zone_warning",
866 "comm_docking.ani" );
868 "automatic_landing_zone_warning1",
869 "comm_docking.ani" );
871 "automatic_landing_zone_warning2",
872 "comm_docking.ani" );
874 "automatic_landing_zone_warning_text",
875 "Now Entering an \"Automatic Landing Zone\"." );
883 int num = rand() < RAND_MAX/2 ? 0 : (rand() < RAND_MAX/2 ? 1 : 2);
884 if (warnsound.sound < 0) {
892 warnsound.playsound();
908 }
else if (lastwarned == target) {
916 static bool autolanding_enable =
918 if (autolanding_enable)
930 Unit *target = it->ref.unit;
941 if (radarSprites[0] || radarSprites[1])
946 assert(radarDisplay.get() != 0);
947 radarDisplay->Draw(sensor, radarSprites[0], radarSprites[1]);
962 radar_ani.DrawAsVSSprite( radarSprites[0] );
963 radar_ani.DrawAsVSSprite( radarSprites[1] );
997 static float fpsval = 0;
998 const float fpsmax = 1;
999 static float numtimes = fpsmax;
1048 for (armori = 0; armori < 8; ++armori) {
1057 return .25*(armordat[0]+armordat[1]+armordat[4]+armordat[5]);
1060 return .25*(armordat[2]+armordat[3]+armordat[6]+armordat[7]);
1063 return .25*(armordat[1]+armordat[3]+armordat[5]+armordat[7]);
1067 return .25*(armordat[0]+armordat[2]+armordat[4]+armordat[6]);
1080 static bool warpifnojump =
1086 if ( maxhull < target->GetHull() )
1095 static int overload = 0;
1096 if (overload != go) {
1099 if (ejectstopsound.
sound < 0) {
1100 static string str =
vs_config->
getVariable(
"cockpitaudio",
"overload_stopped",
"overload_stopped" );
1106 if (ejectsound.
sound < 0) {
1121 res = tmpunit->
cosAngleTo( target, *&armordat[0], FLT_MAX, FLT_MAX ) > .95;
1135 static double collidepanic =
1154 static bool use_relative_velocity =
1206 return value/game_speed;
1208 return display_in_meters ? value : value*3.6;
1214 return 100*target->
Mass/basemass;
1220 static int wasautopilot = 0;
1221 int abletoautopilot = 0;
1222 static bool auto_valid =
1228 abletoautopilot = (target->
AutoPilotTo( target,
false ) ? 1 : 0);
1229 static float no_auto_light_below =
1234 < no_auto_light_below )
1235 abletoautopilot =
false;
1239 if (abletoautopilot != wasautopilot) {
1240 if (abletoautopilot == 0) {
1242 if (autostopsound.
sound < 0) {
1244 "autopilot_available",
1245 "autopilot_available" );
1251 if (autosound.
sound < 0) {
1253 "autopilot_unavailable",
1254 "autopilot_unavailable" );
1259 wasautopilot = abletoautopilot;
1261 return abletoautopilot;
1264 if (fpsval >= 0 && fpsval < .5*FLT_MAX)
1265 numtimes -= .1+fpsval;
1266 if (numtimes <= 0) {
1306 else if ( ( (
int) (-2147483647)-1 ) == target->
cloaking )
1377 void GameCockpit::DrawTargetGauges(
Unit *target )
1389 void GameCockpit::DrawGauges(
Unit *un )
1392 for (i = 0; i < UnitImages< void >::TARGETSHIELDF; i++) {
1416 static float background_alpha =
1418 bool automatte = (0 == origbgcol.
a);
1419 if (automatte) text->
bgcol =
GFXColor( 0, 0, 0, background_alpha );
1422 float sx, sy, px, py;
1430 int len = sprintf( ourchar,
"%.0f", tmp );
1432 float c = 300000000.0f;
1435 len = sprintf( ourchar,
"%.2f C", tmp2 );
1439 len = sprintf( ourchar,
"MASS:%.0f%% (base)", tmp );
1442 text->
Draw(
string( ourchar ), 0,
false,
false, automatte );
1447 float sx, sy, px, py;
1453 int ivalue = (
int) tmp;
1454 std::string modename;
1455 std::string modevalue;
1515 modevalue =
"ACTIVE";
1521 modevalue =
"MANEUVER";
1524 modevalue =
"TRAVEL";
1527 modevalue =
"N / A";
1530 modevalue =
"READY";
1533 modevalue =
"NO DRIVE";
1536 modevalue =
"TOO FAR";
1539 modevalue =
"LOW ENERGY";
1542 modevalue =
"WARNING!";
1548 modevalue =
"AUTO READY";
1551 modevalue =
"MALFUNCTION!";
1556 text->
Draw( modename+modevalue, 0,
false,
false, automatte );
1559 text->
bgcol = origbgcol;
1570 if (Panel.size() > 0) {
1572 Panel.front()->GetPosition( x, y );
1577 void GameCockpit::Delete()
1586 for (i = 0; i < (
int) mesh.size(); ++i) {
1592 if (soundfile >= 0) {
1597 for (i = 0; i < 4; i++) {
1605 for (i = 0; i < UnitImages< void >::NUMGAUGES; i++)
1610 if (radarSprites[0]) {
1611 delete radarSprites[0];
1612 radarSprites[0] = NULL;
1614 if (radarSprites[1]) {
1615 delete radarSprites[1];
1616 radarSprites[1] = NULL;
1619 for (j = 0; j < vdu.size(); j++)
1625 for (j = 0; j < Panel.size(); j++) {
1635 for (i = 0; i < UnitImages< void >::NUMGAUGES; i++)
1645 :
Cockpit( file, parent, pilot_name )
1647 , insidePanPitch( 0 )
1648 , insidePanYawSpeed( 0 )
1649 , insidePanPitchSpeed( 0 )
1653 , textcol( 1, 1, 1, 1 )
1657 shield8 = armor8 =
false;
1661 for (i = 0; i < headlag; i++) {
1662 headtrans.push_back(
Matrix() );
1665 for (i = 0; i < UnitImages< void >::NUMGAUGES; i++)
1667 radarSprites[0] = radarSprites[1] = Pit[0] = Pit[1] = Pit[2] = Pit[3] = NULL;
1669 static bool st_draw_all_boxes =
1671 static bool st_draw_line_to_target =
1673 static bool st_draw_line_to_targets_target =
1675 static bool st_draw_line_to_itts =
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;
1692 smooth_fov = st_projection_limit_y;
1693 projection_limit_y = st_projection_limit_y;
1695 projection_limit_y =
tan( projection_limit_y*
M_PI/(180*2) );
1700 oaccel =
Vector( 0, 0, 0 );
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 );
1709 if (friendly.
r == -1) {
1718 updateRadar(parent);
1771 static bool AlwaysUpdateNavMap =
1773 if (AlwaysUpdateNavMap)
1785 float o_fov = cam->
GetFov();
1787 cam->
SetFov( standard_fov );
1802 respawnunit.push_back( 0 );
1812 switchunit.push_back( 0 );
1820 switchunit.push_back( 0 );
1826 static int orig = 0;
1829 if (newtime-orig > 8 || orig == 0) {
1837 *(armor[1]+armor[2]+armor[3]+armor[4]+armor[5]+armor[6]+armor[7]+armor[0]) );
1863 if (ul || ur || ll || lr) {
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" );
1890 univmap.push_back(
UnivMap( NULL, NULL, NULL, NULL ) );
1902 turretcontrol.push_back( 0 );
1911 respawnunit.push_back( 0 );
1922 if (enableautosound.
sound < 0) {
1923 static string str =
vs_config->
getVariable(
"cockpitaudio",
"autopilot_enabled",
"autopilot" );
1932 bool retautoA =
false;
1941 "#ff0000Already Near#000000" ) );
1943 }
else if ( (retauto || retautoA) && movedatall ) {
1946 Vector P( 1, 0, 0 ), Q( 0, 1, 0 ),
R( 0, 0, 1 );
1949 static float auto_side_bias =
1951 static float auto_front_bias =
1953 P += uP*auto_side_bias+uR*auto_front_bias;
1984 if (shakin > shak_max)
1987 this->shake_type = dtype;
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}
2004 static bool init =
false;
2006 static bool doflash[numtypes];
2009 for (
int i = 0; i < numtypes; ++i) {
2010 doflash[i] = (flashes[i].length() > 0);
2012 aflashes[i] =
new Animation( flashes[i].c_str(),
true, .1,
BILINEAR,
false,
false );
2020 if (dtype < numtypes) {
2024 static bool damage_flash_alpha =
2026 if (damage_flash_alpha)
2030 if ( aflashes[i]->LoadSuccess() ) {
2046 fallbackcolor[i][1],
2047 fallbackcolor[i][2],
2048 fallbackcolor[i][3] );
2098 static bool draw_star_destination_arrow =
2101 Vector destination_system_location( 0, 0, 0 );
2115 if (nav_current != universe_current)
2117 static bool draw_any_boxes =
2119 static bool draw_boxes_inside_only =
2121 if ( draw_any_boxes && screenshotkey ==
false && (draw_boxes_inside_only ==
false ||
view <
CP_CHASE) )
2130 DrawCommunicatingBoxes();
2132 DrawTargetBoxes(sensor);
2134 if (draw_star_destination_arrow) {
2137 if (destination_system != current_system) {
2141 if (delta.i != 0 || dest.j != 0 || dest.k != 0) {
2145 destination_system_location = delta.Cast();
2147 static float nav_symbol_size =
2152 destination_system_color.g,
2153 destination_system_color.b,
2154 destination_system_color.a );
2158 DrawNavigationSymbol( delta.Cast(), P, Q, delta.Magnitude()*nav_symbol_size );
2182 if ( mesh.size() ) {
2192 float cockpitradial = 1;
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;
2209 headtrans.push_back(
Matrix() );
2211 static float theta = 0, wtheta = 0;
2212 static float shake_speed =
2214 static float shake_reduction =
2216 static float shake_limit =
2219 static float drift_limit =
2221 static float drift_amount =
2223 static float drift_ref_accel =
2226 static float warp_shake_mag =
2228 static float warp_shake_speed =
2230 static float warp_shake_ref =
2232 if (warp_shake_ref <= 0) warp_shake_ref = 1;
2239 float warp_strength =
2243 self_kps/self_setkps ) ),
2247 headtrans.front().p.i = shake_mag*
shakin*
cos( theta )*cockpitradial/100;
2248 headtrans.front().p.j = shake_mag*
shakin*
cos( 1.3731*theta )*cockpitradial/100;
2249 headtrans.front().p.k = 0;
2250 headtrans.front().p.i += warp_shake_mag*
cos( wtheta )*
sqr( warp_strength )*cockpitradial/100;
2251 headtrans.front().p.j += warp_shake_mag*
cos( 1.165864*wtheta )*
sqr( warp_strength )*cockpitradial/100;
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;
2263 else caccel =
Vector( 0, 0, 0 );
2265 oaccel = (1-driftphase)*caccel+driftphase*oaccel;
2266 headtrans.front().p += -cockpitradial*oaccel;
2267 float driftmag = cockpitradial*oaccel.Magnitude();
2270 static size_t COCKPITZ_PARTITIONS =
2274 for (j = COCKPITZ_PARTITIONS-1; j < COCKPITZ_PARTITIONS; j--) {
2279 zfloor+zrange*j/COCKPITZ_PARTITIONS,
2280 zfloor+zrange*(j+1)/COCKPITZ_PARTITIONS );
2290 for (i = 0; i < mesh.size(); ++i)
2292 mesh[i]->
Draw( FLT_MAX, headtrans.front() );
2295 static bool nocockpitcull =
2302 headtrans.pop_front();
2323 float crosscenx = 0, crossceny = 0;
2324 static bool crosshairs_on_chasecam =
2326 static bool crosshairs_on_padlock =
2331 if (Panel.size() > 0 && Panel.front() && screenshotkey ==
false) {
2332 static bool drawCrosshairs =
2335 Panel.front()->GetPosition( crosscenx, crossceny );
2336 if (drawCrosshairs) {
2337 float x,
y, wid, hei;
2338 Panel.front()->GetSize( wid, hei );
2345 Panel.front()->Draw();
2356 static bool drawChaseVDU =
2358 static bool drawPanVDU =
2360 static bool drawTgtVDU =
2362 static bool drawPadVDU =
2365 static bool drawChasecp =
2367 static bool drawPancp =
2369 static bool drawTgtcp =
2371 static bool drawPadcp =
2375 if (blend_cockpit) {
2404 for (
unsigned int j = 1; j < Panel.size(); j++)
2413 for (
unsigned int vd = 0; vd < vdu.size(); vd++)
2417 if (target != NULL) {
2424 DrawTargetGauges( target );
2440 for (
unsigned int vd = 0; vd < vdu.size(); vd++)
2442 vdu[vd]->Draw(
this, un, textcol );
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) ) ) )
2467 }
else if (
cockpit_time > ( ( 1-(-vdu_time[vd]) )+(damage) ) ) {
2476 static bool debug_position =
2478 if (debug_position) {
2483 sprintf( str,
"Your Position: (%lf,%lf,%lf); Velocity: (%f,%f,%f); Frame: %lf\n",
2489 sprintf( str+strlen(
2490 str ),
"Target Position: (%lf,%lf,%lf); Velocity: (%f,%f,%f); Now: %lf\n",
2505 if (un->
Threat() != NULL) {
2513 static bool drawarrow =
2515 static bool drawarrow_on_pancam =
2517 static bool drawarrow_on_pantgt =
2519 static bool drawarrow_on_chasecam =
2524 if ( drawarrow && ( parent = this->parent.GetUnit() ) ) {
2527 && !drawarrow_on_pancam)
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) ) {
2553 QuitCompatSprite.
Draw();
2562 PauseCompatSprite.
Draw();
2565 static float dietime = 0;
2584 text->
SetPos( 0-(x*2*14), 0-(y*2) );
2591 static bool show_died_text =
2595 "#ff5555You Have Died!\n#000000Press #8080FF;#000000 (semicolon) to respawn\nOr Press #8080FFEsc and 'q'#000000 to quit" );
2598 static float min_die_time =
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() ) {
2610 DieCompatSprite.
Draw();
2626 }
else if (dietime != 0) {
2636 static bool mousecursor_pancam =
2638 static bool mousecursor_pantgt =
2640 static bool mousecursor_chasecam =
2642 if (mouseCursor && screenshotkey ==
false) {
2644 && !mousecursor_pancam)
2658 MouseVSSprite.
SetPosition( xcoord*( 1-fabs( crosscenx ) )+crosscenx, ycoord*( 1-fabs( crossceny ) )+crossceny );
2660 MouseVSSprite.GetSize( xs, ys );
2661 if (xcoord < deadband && ycoord < deadband && xcoord > -deadband && ycoord > -deadband) {
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 );
2670 MouseVSSprite.Draw();
2671 MouseVSSprite.SetSize( xs, ys );
2697 for (
unsigned int i = 0; i < vdu.size(); i++)
2698 if (vdu[i]->getMode()&whichtype)
2699 return vdu[i]->scrolloffset;
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++) {
2711 string vsconfigvar = string(
"sounds_extension_" )+tmpstr;
2713 if (strs[i] ==
"\n") {
2723 #include <algorithm>
2728 string lastsound =
"";
2729 string anothertmpstr =
"";
2730 for (i = 0; i < 9 && !ok; i++) {
2732 bool foundyet =
false;
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 );
2741 anothertmpstr = sound+anothertmpstr;
2750 return anothertmpstr;
2767 static float rotspd =
2770 static float curtime = 0;
2772 float ang = curtime*rotspd;
2780 static float initialzoom =
2787 if (disableautosound.
sound < 0) {
2788 static string str =
vs_config->
getVariable(
"cockpitaudio",
"autopilot_disabled",
"autopilot_disabled" );
2801 if (autoun && autopan)
2818 static bool LoadNewCockpit =
2820 static bool DisCockpit =
2822 if (nw->
getCockpit().length() > 0 || DisCockpit)
2842 for (i = 0; i < 4; i++)
2852 if ( vdunum < (
int) vdu.size() )
2854 return vdu[vdunum]->getMode();
2863 if ( vdunum < (
int) vdu.size() )
2873 if ( vdunum < (
int) vdu.size() )
2875 vdu[vdunum]->Scroll( howmuch );
2881 ThisNav.
scroll( howmuch );
2883 for (
unsigned int i = 0; i < vdu.size(); i++)
2890 static Animation Statuc( comm_static.c_str() );
2891 for (
unsigned int i = 0; i < vdu.size(); i++)
2899 for (
unsigned int i = 0; i < vdu.size(); i++)
2905 for (
unsigned int i = 0; i < vdu.size(); i++)
2914 if ( ( !targetLabel.empty() )
2915 && (!par || ( (
void*) par->
Target() ) != labeledTargetUnit) ) {
2916 targetLabel = string();
2918 labeledTargetUnit = par->
Target();
2926 targetLabel = newLabel;
2940 if (diff.i != 0 && diff.k != 0) {
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 ) );
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;
2996 Vector prev_fp, prev_fq, prev_fr;
3018 Matrix pitchMatrix, yawMatrix, panMatrix;
3021 panMatrix = yawMatrix * pitchMatrix;
3032 CrossProduct( r, q, tmp );
3033 CrossProduct( tmp, r, q );
3036 static float PadlockViewLag =
3038 static float PadlockViewLag_inv = 1.f/PadlockViewLag;
3039 static float PadlockViewLag_fix =
3041 static float PadlockViewLag_fixcos = (
float)
cos( PadlockViewLag_fix );
3045 Vector p_p, p_q, p_r, f_p, f_q, f_r, pp = tmp, qq =
q, rr = r;
3048 translate_as( p_p, p_q, p_r, prev_fp, prev_fq, prev_fr, f_p, f_q, f_r );
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) );
3057 lerp( p_p, pp, vtphase ).Normalize(),
3058 lerp( p_q, qq, vtphase ).Normalize(),
3059 lerp( p_r, rr, vtphase ).Normalize() );
3074 static bool draw_unit_on_chasecam =
3076 if (
view ==
CP_CHASE && !draw_unit_on_chasecam) {}
else {
3087 static float stable_lowarpref =
3089 static float stable_hiwarpref =
3091 static float stable_refexp =
3093 static bool stable_asymptotic =
3095 static float stable_offset_f =
3097 static float stable_offset_b =
3099 static float stable_offset_p =
3101 static float stable_multiplier_f =
3103 static float stable_multiplier_b =
3105 static float stable_multiplier_p =
3109 static float shake_lowarpref =
3111 static float shake_hiwarpref =
3113 static float shake_refexp =
3115 static bool shake_asymptotic =
3117 static float shake_speed =
3119 static float shake_offset_f =
3121 static float shake_offset_b =
3123 static float shake_offset_p =
3125 static float shake_multiplier_f =
3127 static float shake_multiplier_b =
3129 static float shake_multiplier_p =
3132 static float refkpsoverride =
3135 static float theta = 0;
3137 if (stable_lowarpref == stable_hiwarpref) stable_hiwarpref = stable_lowarpref+1;
3138 if (shake_lowarpref == shake_hiwarpref) shake_hiwarpref = shake_lowarpref+1;
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),
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;
3157 if (unv <= 1) unv = 1;
3158 if (camv <= 1) camv = 1;
3160 float st_offs, sh_offs, st_mult, sh_mult;
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);
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);
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 =
3178 float fov_smoot = pow(
double(fov_smoothing),
GetElapsedTime() );
3180 min( 170.0
f,
max( 5.0
f, (1-fov_smoot)*smooth_fov+fov_smoot*(
g_game.
fov*(st_mult+sh_mult)+st_offs+sh_offs) ) );
3191 if (cam < NUM_CAM && cam >= 0)
3197 if (num < NUM_CAM && num >= 0)
3207 #define TARGET_ARROW_COS_THETA (0.93969262078590838405410927732473)
3208 #define TARGET_ARROW_SIN_THETA (0.34202014332566873304409961468226)
3209 #define TARGET_ARROW_SIZE (0.05)
3214 if (player && target) {
3223 float s, t, s_normalized, t_normalized, inv_len;
3227 inv_len = 1/fabs( localcoord.k );
3228 s = -localcoord.i*inv_len;
3229 t = localcoord.j*inv_len;
3230 if (localcoord.k > 0) {
3233 if ( (fabs( s ) < projection_limit_x) && (fabs( t ) < projection_limit_y) )
3236 inv_len = 1/
sqrt( s*s+t*t );
3237 s_normalized = s*inv_len;
3238 t_normalized = t*inv_len;
3241 s *= inv_screen_aspect_ratio;
3242 if ( fabs( t ) > fabs( s ) ) {
3284 glBegin( GL_LINE_LOOP );
3296 for (
unsigned int i = 0; i < vdu.size(); ++i)
3309 radarDisplay->OnPauseBegin();
3314 radarDisplay->OnPauseEnd();
3317 void GameCockpit::updateRadar(
Unit*ship) {
3337 radarDisplay->OnDockEnd();
3341 void GameCockpit::SetParent(
Unit *unit,
const char *filename,
const char *unitmodname,
const QVector &startloc ){
3355 radarDisplay->OnJumpBegin();
3363 radarDisplay->OnJumpEnd();
3369 insidePanYawSpeed =
speed;
3374 insidePanPitchSpeed =
speed;