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

#include <cockpit_generic.h>

Inheritance diagram for Cockpit:
GameCockpit

Public Member Functions

virtual void setTargetLabel (const string &msg)
 
virtual string getTargetLabel ()
 
void updateAttackers ()
 
virtual void ReceivedTargetInfo ()
 
bool autoInProgress ()
 
bool unitInAutoRegion (Unit *un)
 
void SetView (const enum VIEWSTYLE tmp)
 Sets the current viewstyle. More...
 
enum VIEWSTYLE GetView ()
 
virtual void InitStatic ()
 
virtual void Shake (float amt, int level)
 
virtual int Autopilot (Unit *target)
 
void RestoreGodliness ()
 
virtual void RestoreViewPort ()
 Restores the view from the IDentity Matrix needed to draw sprites. More...
 
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 float LookupTargetStat (int stat, Unit *target)
 Looks up a particular Gauge stat on target unit. More...
 
virtual void Init (const char *file, bool defaultCockpit=false)
 Loads cockpit info...just as constructor. More...
 
void recreate (const std::string &pilotname)
 
virtual void SetParent (Unit *unit, const char *filename, const char *unitmodname, const QVector &startloc)
 
UnitGetParent ()
 
UnitGetSaveParent ()
 
virtual void Draw ()
 Draws Cockpit then restores viewport. More...
 
bool Update ()
 
virtual void UpdAutoPilot ()
 
virtual void SetupViewPort (bool clip=true)
 Sets up the world for rendering...call before draw. More...
 
virtual int getVDUMode (int vdunum)
 
virtual void VDUSwitch (int vdunum)
 
virtual void ScrollVDU (int vdunum, int howmuch)
 
virtual void ScrollAllVDU (int howmuch)
 
virtual int getScrollOffset (unsigned int whichtype)
 
virtual void SelectProperCamera ()
 
virtual void Eject ()
 
virtual void EjectDock ()
 
virtual void SetInsidePanYawSpeed (float speed)
 
virtual void SetInsidePanPitchSpeed (float speed)
 
virtual void SetCommAnimation (Animation *ani, Unit *un)
 
virtual void SetStaticAnimation ()
 
virtual NavigationSystemAccessNavSystem ()
 Accesses the current navigationsystem. More...
 
virtual std::string GetNavSelectedSystem ()
 
virtual CameraAccessCamera ()
 Accesses the current camera. More...
 
virtual CameraAccessCamera (int)
 Returns the passed in cam. More...
 
virtual void SelectCamera (int)
 Changes current camera to selected camera. More...
 
virtual void SetViewport ()
 GFXLoadMatrix proper camera. More...
 
virtual void visitSystem (std::string systemName)
 
virtual bool SetDrawNavSystem (bool)
 
virtual bool CanDrawNavSystem ()
 
virtual bool DrawNavSystem ()
 
virtual bool CheckCommAnimation (Unit *un)
 
virtual void OnPauseBegin ()
 
virtual void OnPauseEnd ()
 
virtual void OnDockEnd (Unit *, Unit *)
 
virtual void OnJumpBegin (Unit *)
 
virtual void OnJumpEnd (Unit *)
 

Static Public Member Functions

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

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
 

Protected Member Functions

virtual void LoadXML (const char *file)
 
virtual void LoadXML (VSFileSystem::VSFile &f)
 
virtual void beginElement (const string &name, const AttributeList &attributes)
 
virtual void endElement (const string &name)
 
virtual void Delete ()
 Destructs cockpit info for new loading. More...
 
virtual void DrawNavigationSymbol (const Vector &loc, const Vector &p, const Vector &q, float size)
 draws the navigation symbol around targetted location More...
 
virtual float computeLockingSymbol (Unit *par)
 draws the target box around targetted unit More...
 
virtual void DrawTargetBox ()
 
virtual void DrawTargetBoxes (const Radar::Sensor &)
 draws the target box around all units More...
 
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...
 
virtual void DrawRadar (const Radar::Sensor &)
 Draws all the tracks on the radar. More...
 
virtual void DrawGauges (Unit *un)
 Draws gauges. More...
 

Static Protected Member Functions

static void beginElement (void *userData, const XML_Char *name, const XML_Char **atts)
 
static void endElement (void *userData, const XML_Char *name)
 

Protected Attributes

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

The Cockpit Contains all displayable information about a particular Unit * Gauges are used to indicate analog controls, and some diagital ones The ones starting from KPS are digital with text readout

Definition at line 34 of file cockpit_generic.h.

Constructor & Destructor Documentation

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

Definition at line 180 of file cockpit_generic.cpp.

References activeStarSystem, currentcamera, ejecting, fg, going_to_dock_screen, Init(), InitStatic(), jumpok, number_of_attackers, partial_number_of_attackers, RestoreGodliness(), secondsWithZeroEnergy, and TimeOfLastCollision.

180  : view( CP_FRONT )
181  , parent( parent )
182  , cockpit_offset( 0 )
183  , viewport_offset( 0 )
185  , savegame( new SaveGame( pilot_name ) )
186 {
187  //static int headlag = XMLSupport::parse_int (vs_config->getVariable("graphics","head_lag","10"));
188  //int i;
192  fg = NULL;
193  jumpok = 0;
194  TimeOfLastCollision = -200;
195  /*
196  * for (i=0;i<headlag;i++) {
197  * headtrans.push_back (Matrix());
198  * Identity(headtrans.back());
199  * }
200  * for (i=0;i<UnitImages::NUMGAUGES;i++) {
201  * gauges[i]=NULL;
202  * }
203  */
204  activeStarSystem = NULL;
205  InitStatic();
206  //mesh=NULL;
207  ejecting = false;
208  currentcamera = 0;
209  going_to_dock_screen = false;
210  //Radar=Pit[0]=Pit[1]=Pit[2]=Pit[3]=NULL;
212 
213  /*
214  * draw_all_boxes=XMLSupport::parse_bool(vs_config->getVariable("graphics","hud","drawAllTargetBoxes","false"));
215  * draw_line_to_target=XMLSupport::parse_bool(vs_config->getVariable("graphics","hud","drawLineToTarget","false"));
216  * draw_line_to_targets_target=XMLSupport::parse_bool(vs_config->getVariable("graphics","hud","drawLineToTargetsTarget","false"));
217  * draw_line_to_itts=XMLSupport::parse_bool(vs_config->getVariable("graphics","hud","drawLineToITTS","false"));
218  * always_itts=XMLSupport::parse_bool(vs_config->getVariable("graphics","hud","drawAlwaysITTS","false"));
219  * radar_type=vs_config->getVariable("graphics","hud","radarType","WC");
220  *
221  * friendly=GFXColor(-1,-1,-1,-1);
222  * enemy=GFXColor(-1,-1,-1,-1);
223  * neutral=GFXColor(-1,-1,-1,-1);
224  * targeted=GFXColor(-1,-1,-1,-1);
225  * targetting=GFXColor(-1,-1,-1,-1);
226  * planet=GFXColor(-1,-1,-1,-1);
227  * if (friendly.r==-1) {
228  * vs_config->getColor ("enemy",&enemy.r);
229  * vs_config->getColor ("friend",&friendly.r);
230  * vs_config->getColor ("neutral",&neutral.r);
231  * vs_config->getColor("target",&targeted.r);
232  * vs_config->getColor("targetting_ship",&targetting.r);
233  * vs_config->getColor("planet",&planet.r);
234  * }
235  */
236 
237  Init( file );
238 }
Cockpit::~Cockpit ( )
virtual

Definition at line 848 of file cockpit_generic.cpp.

References Delete(), and savegame.

849 {
850  Delete();
851  if (savegame != NULL)
852  delete savegame;
853 }

Member Function Documentation

virtual Camera* Cockpit::AccessCamera ( )
inlinevirtual

Accesses the current camera.

Reimplemented in GameCockpit.

Definition at line 246 of file cockpit_generic.h.

Referenced by CockpitKeys::_PitchDown(), CockpitKeys::_PitchUp(), CockpitKeys::_YawLeft(), CockpitKeys::_YawRight(), GameUniverse::AccessCamera(), FaceCamTarget(), UnitUtil::getPhysicsPriority(), and UpdateCameraSnds().

247  {
248  return NULL;
249  }
virtual Camera* Cockpit::AccessCamera ( int  )
inlinevirtual

Returns the passed in cam.

Reimplemented in GameCockpit.

Definition at line 251 of file cockpit_generic.h.

252  {
253  return NULL;
254  }
bool Cockpit::autoInProgress ( )
inline
int Cockpit::Autopilot ( Unit target)
virtual

Reimplemented in GameCockpit.

Definition at line 289 of file cockpit_generic.cpp.

References autopilot_target, autopilot_time, Unit::AutoPilotTo(), FaceTarget(), GetElapsedTime(), GetParent(), getTimeCompression(), VegaConfig::getVariable(), XMLSupport::parse_bool(), XMLSupport::parse_float(), UnitContainer::SetUnit(), vs_config, and zoomfactor.

Referenced by FlyByKeyboard::Execute().

290 {
291  int retauto = 0;
292  if (target) {
293  Unit *un = NULL;
294  if ( ( un = GetParent() ) ) {
295  if ( ( retauto = un->AutoPilotTo( un, false ) ) ) {
296  //can he even start to autopilot
297  //SetView (CP_PAN);
298  un->AutoPilotTo( target, false );
299  static bool face_target_on_auto =
300  XMLSupport::parse_bool( vs_config->getVariable( "physics", "face_on_auto", "false" ) );
301  if (face_target_on_auto)
302  FaceTarget( un );
303  static double averagetime = GetElapsedTime()/getTimeCompression();
304  static double numave = 1.0;
305  averagetime += GetElapsedTime()/getTimeCompression();
306  //static float autospeed = XMLSupport::parse_float (vs_config->getVariable ("physics","autospeed",".020"));//10 seconds for auto to kick in;
307  numave++;
308  /*
309  * AccessCamera(CP_PAN)->myPhysics.SetAngularVelocity(Vector(0,0,0));
310  * AccessCamera(CP_PAN)->myPhysics.ApplyBalancedLocalTorque(_Universe->AccessCamera()->P,
311  * _Universe->AccessCamera()->R,
312  * averagetime*autospeed/(numave));
313  */
314  static float initialzoom =
315  XMLSupport::parse_float( vs_config->getVariable( "graphics", "inital_zoom_factor", "2.25" ) );
316  zoomfactor = initialzoom;
317  static float autotime = XMLSupport::parse_float( vs_config->getVariable( "physics", "autotime", "10" ) ); //10 seconds for auto to kick in;
318 
319  autopilot_time = autotime;
320  autopilot_target.SetUnit( target );
321  }
322  }
323  }
324  return retauto;
325 }
void Cockpit::beginElement ( void *  userData,
const XML_Char *  name,
const XML_Char **  atts 
)
staticprotected

Definition at line 41 of file cockpit_generic.cpp.

42 {
43  ( (Cockpit*) userData )->beginElement( name, AttributeList( atts ) );
44 }
virtual void Cockpit::beginElement ( const string &  name,
const AttributeList attributes 
)
inlineprotectedvirtual

Definition at line 71 of file cockpit_generic.h.

71 {}
virtual bool Cockpit::CanDrawNavSystem ( )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 264 of file cockpit_generic.h.

Referenced by FireKeyboard::Execute().

265  {
266  return false;
267  }
virtual bool Cockpit::CheckCommAnimation ( Unit un)
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 272 of file cockpit_generic.h.

Referenced by FireKeyboard::ProcessCommMessage().

273  {
274  return false;
275  }
virtual float Cockpit::computeLockingSymbol ( Unit par)
inlineprotectedvirtual

draws the target box around targetted unit

Definition at line 78 of file cockpit_generic.h.

79  {
80  return 1;
81  }
void Cockpit::Delete ( )
protectedvirtual

Destructs cockpit info for new loading.

Definition at line 147 of file cockpit_generic.cpp.

Referenced by ~Cockpit().

148 {
149  //int i;
151 }
virtual void Cockpit::Draw ( )
inlinevirtual

Draws Cockpit then restores viewport.

Reimplemented in GameCockpit.

Definition at line 208 of file cockpit_generic.h.

Referenced by GameStarSystem::Draw().

208 {}
virtual void Cockpit::DrawGauges ( Unit un)
inlineprotectedvirtual

Draws gauges.

Definition at line 92 of file cockpit_generic.h.

92 {}
virtual void Cockpit::DrawNavigationSymbol ( const Vector loc,
const Vector p,
const Vector q,
float  size 
)
inlineprotectedvirtual

draws the navigation symbol around targetted location

Definition at line 76 of file cockpit_generic.h.

76 {}
virtual bool Cockpit::DrawNavSystem ( )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 268 of file cockpit_generic.h.

269  {
270  return false;
271  }
virtual void Cockpit::DrawRadar ( const Radar::Sensor )
inlineprotectedvirtual

Draws all the tracks on the radar.

Definition at line 90 of file cockpit_generic.h.

90 {}
virtual void Cockpit::DrawTacticalTargetBox ( )
inlineprotectedvirtual

Shows the flightgroup's target, if any.

Definition at line 88 of file cockpit_generic.h.

Referenced by GameCockpit::Draw().

88 {}
virtual void Cockpit::DrawTargetBox ( )
inlineprotectedvirtual

Definition at line 82 of file cockpit_generic.h.

Referenced by GameCockpit::Draw().

82 {}
virtual void Cockpit::DrawTargetBoxes ( const Radar::Sensor )
inlineprotectedvirtual

draws the target box around all units

Definition at line 84 of file cockpit_generic.h.

84 {}
virtual void Cockpit::DrawTurretTargetBoxes ( )
inlineprotectedvirtual

draws a target cross around all units targeted by your turrets // ** jay

Definition at line 86 of file cockpit_generic.h.

Referenced by GameCockpit::Draw().

86 {}
void Cockpit::Eject ( )
virtual

Reimplemented in GameCockpit.

Definition at line 68 of file cockpit_generic.cpp.

References ejecting, and going_to_dock_screen.

Referenced by FireKeyboard::Execute().

69 {
70  ejecting = true;
71  going_to_dock_screen = false;
72 }
void Cockpit::EjectDock ( )
virtual

Reimplemented in GameCockpit.

Definition at line 74 of file cockpit_generic.cpp.

References ejecting, and going_to_dock_screen.

Referenced by FireKeyboard::Execute().

75 {
76  ejecting = true;
77  going_to_dock_screen = true;
78 }
void Cockpit::endElement ( void *  userData,
const XML_Char *  name 
)
staticprotected

Definition at line 46 of file cockpit_generic.cpp.

47 {
48  ( (Cockpit*) userData )->endElement( name );
49 }
virtual void Cockpit::endElement ( const string &  name)
inlineprotectedvirtual

Definition at line 72 of file cockpit_generic.h.

72 {}
static void Cockpit::ForceSwitchControl ( const KBData ,
KBSTATE   
)
inlinestatic

Definition at line 231 of file cockpit_generic.h.

231 {}
virtual std::string Cockpit::GetNavSelectedSystem ( )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 241 of file cockpit_generic.h.

Referenced by NearestSystem(), and Unit::UpdatePhysics().

242  {
243  return "";
244  }
size_t Cockpit::GetNumUnits ( ) const
inline

Definition at line 174 of file cockpit_generic.h.

Referenced by buyShip(), CreateCargoForOwnerStarshipName(), BaseComputer::loadShipDealerControls(), PackUnitInfo(), sellShip(), and SwapInNewShipName().

175  {
176  return unitfilename.size();
177  }
Unit* Cockpit::GetParent ( )
inline

Definition at line 202 of file cockpit_generic.h.

Referenced by AddUnitToSystem(), UniverseUtil::AdjustRelation(), FlyByWire::Afterburn(), Unit::ApplyDamage(), GameCockpit::AutoLanding(), Autopilot(), GameCockpit::Autopilot(), Mission::call_unit_launch(), Orders::FireAt::ChooseTargets(), Beam::Collide(), CommunicatingAI::Destroy(), ZoneMgr::displayNPCs(), FireKeyboard::DockKey(), DockToSavedBases(), FireKeyboard::DoSpeechAndAni(), GameStarSystem::Draw(), GameUnit< UnitType >::Draw(), GameCockpit::Draw(), NavigationSystem::Draw(), NavigationSystem::DrawObjectives(), NavigationSystem::DrawShip(), NavigationSystem::DrawSystem(), FlyTo::Execute(), GameUnit< UnitType >::Explode(), NetActionConfirm::finalizeJoinGame(), Mount::Fire(), Unit::ForceDock(), UnitUtil::getPhysicsPriority(), UniverseUtil::getPlayer(), UniverseUtil::getPlayerX(), UniverseUtil::GetRelation(), SaveNetUtil::GetSaveStrings(), GameCockpit::getTargetLabel(), HelpOut(), CockpitKeys::Inside(), isPlayerFaction(), FireKeyboard::JoinFg(), FlyByKeyboard::JumpKey(), LeadMe(), UniverseUtil::loadGame(), LoadMission(), BaseComputer::loadMissionsMasterList(), Unit::PerformDockingOperations(), FireKeyboard::ProcessCommMessage(), RefreshGUI(), NetClient::Respawn(), NetServer::saveAccount(), ScoreKill(), NetServer::sendCustom(), NetServer::sendMessage(), NetServer::sendMission(), NetServer::sendSaveData(), GameCockpit::setTargetLabel(), starSystemOK(), SuicideKey(), SwapInNewShipName(), SwitchUnits(), CockpitKeys::TextMessageCallback(), GameUnit< UnitType >::Thrust(), GameUnit< UnitType >::TransferUnitToSystem(), FireKeyboard::UnDockKey(), Update(), GameCockpit::UpdAutoPilot(), UpdAutoPilot(), and GameUniverse::WriteSaveGame().

203  {
204  return parent.GetUnit();
205  }
Unit * Cockpit::GetSaveParent ( )

Definition at line 113 of file cockpit_generic.cpp.

Referenced by GameStarSystem::Draw(), UnitUtil::getPhysicsPriority(), TargIncomingMissile(), and WriteSaveGame().

114 {
115  Unit *un = parentturret.GetUnit();
116  if (!un)
117  un = parent.GetUnit();
118  return un;
119 }
virtual int Cockpit::getScrollOffset ( unsigned int  whichtype)
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 220 of file cockpit_generic.h.

Referenced by FireKeyboard::Execute().

221  {
222  return 1;
223  }
virtual string Cockpit::getTargetLabel ( )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 110 of file cockpit_generic.h.

Referenced by UniverseUtil::getTargetLabel().

111  {
112  return string();
113  }
std::string& Cockpit::GetUnitBaseName ( unsigned int  which = 0)
inline

Definition at line 154 of file cockpit_generic.h.

Referenced by CreateCargoForOwnerStarship(), PackUnitInfo(), and SwapInNewShipName().

155  {
156  while ( which >= unitbasename.size() )
157  unitbasename.push_back("");
158  return unitbasename[which];
159  }
const std::string & Cockpit::GetUnitBaseName ( unsigned int  which = 0) const

Definition at line 925 of file cockpit_generic.cpp.

References emptystring.

926 {
927  if ( which >= unitbasename.size() )
928  return emptystring;
929  else
930  return unitbasename[which];
931 }
std::string& Cockpit::GetUnitFileName ( unsigned int  which = 0)
inline

Definition at line 140 of file cockpit_generic.h.

Referenced by bootstrap_main_loop(), buyShip(), CreateCargoForOwnerStarship(), CreateCargoForOwnerStarshipName(), PackUnitInfo(), NetClient::Respawn(), sellShip(), SwapInNewShipName(), Update(), and GameUniverse::WriteSaveGame().

141  {
142  while ( which >= unitfilename.size() )
143  unitfilename.push_back("");
144  return unitfilename[which];
145  }
const std::string & Cockpit::GetUnitFileName ( unsigned int  which = 0) const

Definition at line 909 of file cockpit_generic.cpp.

References emptystring.

910 {
911  if ( which >= unitfilename.size() )
912  return emptystring;
913  else
914  return unitfilename[which];
915 }
std::string Cockpit::GetUnitModifications ( )
inline

Definition at line 169 of file cockpit_generic.h.

Referenced by buildShipDescription(), buyShip(), and WriteSaveGame().

170  {
171  return unitmodname;
172  }
std::string& Cockpit::GetUnitSystemName ( unsigned int  which = 0)
inline

Definition at line 147 of file cockpit_generic.h.

Referenced by CreateCargoForOwnerStarship(), PackUnitInfo(), sellShip(), and SwapInNewShipName().

148  {
149  while ( which >= unitsystemname.size() )
150  unitsystemname.push_back("");
151  return unitsystemname[which];
152  }
const std::string & Cockpit::GetUnitSystemName ( unsigned int  which = 0) const

Definition at line 917 of file cockpit_generic.cpp.

References emptystring.

918 {
919  if ( which >= unitsystemname.size() )
920  return emptystring;
921  else
922  return unitsystemname[which];
923 }
virtual int Cockpit::getVDUMode ( int  vdunum)
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 213 of file cockpit_generic.h.

Referenced by ExamineWhenTargetKey(), and SwitchVDUTo().

214  {
215  return 0;
216  }
enum VIEWSTYLE Cockpit::GetView ( )
inline

Definition at line 128 of file cockpit_generic.h.

References GFXMatrices::view.

Referenced by CockpitKeys::Inside(), CockpitKeys::LookDown(), CockpitKeys::LookLeft(), CockpitKeys::LookRight(), and CockpitKeys::LookUp().

129  {
130  return view;
131  }
void Cockpit::Init ( const char *  file,
bool  defaultCockpit = false 
)
virtual

Loads cockpit info...just as constructor.

Definition at line 81 of file cockpit_generic.cpp.

References VSFileSystem::VSFile::Close(), VSFileSystem::CockpitFile, f, accountXML::file, VSFileSystem::Ok, and VSFileSystem::VSFile::OpenReadOnly().

Referenced by Cockpit(), createObjects(), GameCockpit::Init(), CockpitKeys::Inside(), recreate(), and SwitchUnits2().

82 {
83  retry_dock = 0;
84  shakin = 0;
85  autopilot_time = 0;
86  bool f404 = false;
87  if (file == NULL || strlen( file ) == 0) {
88  if (isDisabled)
89  file = "cockpit.cpt";
90  else
91  file = "disabled-cockpit.cpt";
92  f404 = true;
93  }
94  if (isDisabled == true) {
95  std::string disname = std::string( "disabled-" )+file;
96  Init( disname.c_str() );
97  return;
98  }
99  VSFile f;
100  VSError err = f.OpenReadOnly( file, CockpitFile );
101  if (err > Ok) {
102  //File not found...
103  if ( isDisabled == false && (string( file ).find( "disabled-" ) == string::npos) )
104  Init( file, true );
105  else if (!f404)
106  Init( NULL );
107  return;
108  }
109  Delete();
110  LoadXML( f );
111  f.Close();
112 }
void Cockpit::InitStatic ( )
virtual

Reimplemented in GameCockpit.

Definition at line 160 of file cockpit_generic.cpp.

Referenced by Cockpit().

161 {
162  radar_time = 0;
163  cockpit_time = 0;
164 }
virtual void Cockpit::LoadXML ( const char *  file)
inlineprotectedvirtual

Definition at line 67 of file cockpit_generic.h.

67 {}
virtual void Cockpit::LoadXML ( VSFileSystem::VSFile f)
inlineprotectedvirtual

Definition at line 68 of file cockpit_generic.h.

68 {}
virtual float Cockpit::LookupTargetStat ( int  stat,
Unit target 
)
inlinevirtual

Looks up a particular Gauge stat on target unit.

Reimplemented in GameCockpit.

Definition at line 190 of file cockpit_generic.h.

191  {
192  return 1;
193  }
string Cockpit::MakeBaseName ( const Unit base)
static

Definition at line 943 of file cockpit_generic.cpp.

References Unit::getFgSubnumber(), Unit::getFlightgroup(), Unit::getFullname(), Flightgroup::name, and XMLSupport::tostring().

Referenced by CreateCargoForOwnerStarship(), and SwapInNewShipName().

944 {
945  string name;
946  if (base != NULL) {
947  if (base->getFlightgroup() != NULL)
948  name = base->getFlightgroup()->name + ':';
949  name += base->getFullname();
950  if (base->getFgSubnumber() > 0)
951  name += ':' + XMLSupport::tostring(base->getFgSubnumber());
952  }
953 
954  // remove all whitespace, it breaks savegames
955  std::replace(name.begin(), name.end(), ' ', '_');
956 
957  return name;
958 }
virtual void Cockpit::OnDockEnd ( Unit ,
Unit  
)
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 279 of file cockpit_generic.h.

Referenced by Unit::UnDock().

279 {}
virtual void Cockpit::OnJumpBegin ( Unit )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 280 of file cockpit_generic.h.

Referenced by StarSystem::JumpTo().

280 {}
virtual void Cockpit::OnJumpEnd ( Unit )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 281 of file cockpit_generic.h.

Referenced by StarSystem::ProcessPendingJumps().

281 {}
virtual void Cockpit::OnPauseBegin ( )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 277 of file cockpit_generic.h.

Referenced by FireKeyboard::Execute().

277 {}
virtual void Cockpit::OnPauseEnd ( )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 278 of file cockpit_generic.h.

Referenced by FireKeyboard::Execute().

278 {}
void Cockpit::PackUnitInfo ( vector< std::string > &  info) const

Definition at line 865 of file cockpit_generic.cpp.

References GetNumUnits(), GetUnitBaseName(), GetUnitFileName(), GetUnitSystemName(), and i.

Referenced by SaveNetUtil::GetSaveStrings(), and WriteSaveGame().

866 {
867  info.clear();
868 
869  // First entry, current ship
870  if (GetNumUnits() > 0)
871  info.push_back(GetUnitFileName());
872 
873  // Following entries, ship/location pairs
874  for (size_t i=1,n=GetNumUnits(); i<n; ++i) {
875  info.push_back(GetUnitFileName(i));
876  info.push_back(GetUnitSystemName(i) + "@" + GetUnitBaseName(i));
877  }
878 }
virtual void Cockpit::ReceivedTargetInfo ( )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 116 of file cockpit_generic.h.

116 {}
void Cockpit::recreate ( const std::string &  pilotname)

Definition at line 271 of file cockpit_generic.cpp.

References Init(), savegame, and SaveGame::SetCallsign().

272 {
273  savegame->SetCallsign( pilot_name );
274  Init( "" );
275 }
void Cockpit::RemoveUnit ( unsigned int  which = 0)

Definition at line 933 of file cockpit_generic.cpp.

Referenced by sellShip(), and SwapInNewShipName().

934 {
935  if (which < unitfilename.size())
936  unitfilename.erase(unitfilename.begin()+which);
937  if (which < unitsystemname.size())
938  unitsystemname.erase(unitsystemname.begin()+which);
939  if (which < unitbasename.size())
940  unitbasename.erase(unitbasename.begin()+which);
941 }
static void Cockpit::Respawn ( const KBData ,
KBSTATE   
)
inlinestatic

Definition at line 229 of file cockpit_generic.h.

229 {}
void Cockpit::RestoreGodliness ( )

Definition at line 152 of file cockpit_generic.cpp.

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

Referenced by Cockpit(), and Unit::RestoreGodliness().

153 {
154  static float maxgodliness = XMLSupport::parse_float( vs_config->getVariable( "physics", "player_godliness", "0" ) );
155  godliness = maxgodliness;
156  if (godliness > maxgodliness)
157  godliness = maxgodliness;
158 }
virtual void Cockpit::RestoreViewPort ( )
inlinevirtual

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

Reimplemented in GameCockpit.

Definition at line 138 of file cockpit_generic.h.

138 {}
virtual void Cockpit::ScrollAllVDU ( int  howmuch)
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 219 of file cockpit_generic.h.

Referenced by CockpitKeys::ScrollDown(), and CockpitKeys::ScrollUp().

219 {}
virtual void Cockpit::ScrollVDU ( int  vdunum,
int  howmuch 
)
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 218 of file cockpit_generic.h.

218 {}
virtual void Cockpit::SelectCamera ( int  )
inlinevirtual

Changes current camera to selected camera.

Reimplemented in GameCockpit.

Definition at line 256 of file cockpit_generic.h.

Referenced by GameUniverse::SelectCamera().

256 {}
virtual void Cockpit::SelectProperCamera ( )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 224 of file cockpit_generic.h.

Referenced by GameUniverse::StartDraw().

224 {}
virtual void Cockpit::SetCommAnimation ( Animation ani,
Unit un 
)
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 233 of file cockpit_generic.h.

Referenced by UnitUtil::commAnimation(), UnitUtil::communicateTo(), FireKeyboard::DoSpeechAndAni(), and MyFunction().

233 {}
virtual bool Cockpit::SetDrawNavSystem ( bool  )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 260 of file cockpit_generic.h.

261  {
262  return false;
263  }
void Cockpit::SetInsidePanPitchSpeed ( float  speed)
virtual

Reimplemented in GameCockpit.

Definition at line 860 of file cockpit_generic.cpp.

Referenced by CockpitKeys::LookDown(), and CockpitKeys::LookUp().

861 {
862  // No-op in generic cockpits
863 }
void Cockpit::SetInsidePanYawSpeed ( float  speed)
virtual

Reimplemented in GameCockpit.

Definition at line 855 of file cockpit_generic.cpp.

Referenced by CockpitKeys::LookLeft(), and CockpitKeys::LookRight().

856 {
857  // No-op in generic cockpits
858 }
void Cockpit::SetParent ( Unit unit,
const char *  filename,
const char *  unitmodname,
const QVector startloc 
)
virtual

Definition at line 120 of file cockpit_generic.cpp.

References _Universe, Universe::activeStarSystem(), Unit::ArmorData(), Unit::faction, Unit::FuelData(), Unit::getFlightgroup(), Unit::GetHull(), and SERVER.

Referenced by buyShip(), createObjects(), Unit::EjectCargo(), NetClient::Respawn(), and Update().

121 {
122  if (unit->getFlightgroup() != NULL)
123  fg = unit->getFlightgroup();
124  if (!SERVER)
125  activeStarSystem = _Universe->activeStarSystem(); //cannot switch to units in other star systems.
126  parent.SetUnit( unit );
127  savegame->SetPlayerLocation( pos );
128  if (filename[0] != '\0') {
129  this->GetUnitFileName() = std::string( filename );
130  this->unitmodname = std::string( unitmodname );
131  }
132  if (unit) {
133  this->unitfaction = unit->faction;
134  unit->ArmorData( StartArmor );
135  if (StartArmor[0] == 0) StartArmor[0] = 1;
136  if (StartArmor[1] == 0) StartArmor[1] = 1;
137  if (StartArmor[2] == 0) StartArmor[2] = 1;
138  if (StartArmor[3] == 0) StartArmor[3] = 1;
139  if (StartArmor[4] == 0) StartArmor[4] = 1;
140  if (StartArmor[5] == 0) StartArmor[5] = 1;
141  if (StartArmor[6] == 0) StartArmor[6] = 1;
142  if (StartArmor[7] == 0) StartArmor[7] = 1;
143  maxfuel = unit->FuelData();
144  maxhull = unit->GetHull();
145  }
146 }
virtual void Cockpit::SetStaticAnimation ( )
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 234 of file cockpit_generic.h.

Referenced by CommunicatingAI::Destroy().

234 {}
virtual void Cockpit::setTargetLabel ( const string &  msg)
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 109 of file cockpit_generic.h.

Referenced by UniverseUtil::setTargetLabel().

109 {}
virtual void Cockpit::SetupViewPort ( bool  clip = true)
inlinevirtual

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

Reimplemented in GameCockpit.

Definition at line 212 of file cockpit_generic.h.

Referenced by GameStarSystem::Draw(), and GameUnit< UnitType >::Draw().

212 {}
virtual void Cockpit::SetViewport ( )
inlinevirtual

GFXLoadMatrix proper camera.

Reimplemented in GameCockpit.

Definition at line 258 of file cockpit_generic.h.

Referenced by GameUniverse::SetViewport().

258 {}
virtual void Cockpit::Shake ( float  amt,
int  level 
)
inlinevirtual

Reimplemented in GameCockpit.

Definition at line 133 of file cockpit_generic.h.

Referenced by Unit::ApplyNetDamage().

133 {}
static void Cockpit::SwitchControl ( const KBData ,
KBSTATE   
)
inlinestatic

Definition at line 230 of file cockpit_generic.h.

230 {}
bool Cockpit::tooManyAttackers ( )
static

Definition at line 407 of file cockpit_generic.cpp.

References too_many_attackers.

Referenced by Orders::FireAt::ShouldFire().

408 {
409  return too_many_attackers;
410 }
static void Cockpit::TurretControl ( const KBData ,
KBSTATE   
)
inlinestatic

Definition at line 232 of file cockpit_generic.h.

232 {}
bool Cockpit::unitInAutoRegion ( Unit un)

Definition at line 165 of file cockpit_generic.cpp.

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

Referenced by FlyTo::Execute(), and Orders::AggressiveAI::ExecuteNoEnemies().

166 {
167  static float autopilot_term_distance =
168  XMLSupport::parse_float( vs_config->getVariable( "physics", "auto_pilot_termination_distance", "6000" ) );
169  Unit *targ = autopilot_target.GetUnit();
170  if (targ)
171  return UnitUtil::getSignificantDistance( un, targ ) < autopilot_term_distance*2.5; //if both guys just auto'd in.
172  else
173  return false;
174 }
void Cockpit::UnpackUnitInfo ( vector< std::string > &  info)

Definition at line 880 of file cockpit_generic.cpp.

References i.

Referenced by bootstrap_main_loop(), NetClient::Respawn(), and Update().

881 {
882  vector< string > filenames, systemnames, basenames;
883 
884  // First entry, current ship
885  if (!info.empty()) {
886  filenames.push_back( info[0] );
887  systemnames.push_back( "" );
888  basenames.push_back( "" );
889  }
890 
891  // Following entries, ship/location pairs
892  for (size_t i=1, n=info.size(); i < n; i += 2) {
893  filenames.push_back( info[i] );
894 
895  string location = ((i+1) < n) ? info[i+1] : "";
896  string::size_type atpos = location.find_first_of('@');
897 
898  systemnames.push_back(location.substr(0, atpos));
899  basenames.push_back((atpos != string::npos) ? location.substr(atpos+1) : "");
900  }
901 
902  unitfilename.swap(filenames);
903  unitsystemname.swap(systemnames);
904  unitbasename.swap(basenames);
905 }
bool Cockpit::Update ( )

Definition at line 497 of file cockpit_generic.cpp.

References _Universe, Universe::AccessCockpit(), active_missions, activeStarSystem, Universe::activeStarSystem(), StarSystem::AddUnit(), Background::Cache(), Universe::clearAllSystems(), CopySavedShips(), UnitCollection::createIterator(), UnitFactory::createUnit(), credits, Universe::CurrentCockpit(), Unit::DisableTurretAI(), dockingdistance(), DockToSavedBases(), DoCockpitKeys(), Unit::EjectCargo(), ejecting, Unit::EndRequestClearance(), Unit::EnergyData(), fg, findUnitInStarsystem(), Flightgroup::flightgroup_nr, Background::BackgroundClone::FreeClone(), Universe::GenerateStarSystem(), Universe::getActiveStarSystem(), StarSystem::getBackground(), SaveGame::GetCallsign(), Unit::GetDestinations(), StarSystem::getFileName(), GetFinalTurret(), Universe::getNumActiveStarSystem(), GetParent(), SaveGame::GetPlayerLocation(), Unit::getRelation(), SaveGame::GetSavedCredits(), UnitUtil::getSignificantDistance(), SaveGame::GetStarSystem(), Unit::getSubUnits(), UnitContainer::GetUnit(), GetUnitFileName(), StarSystem::getUnitList(), VegaConfig::getVariable(), Mission::getVariable(), going_to_dock_screen, UniverseUtil::hideSplashScreen(), i, index, Unit::IsCleared(), Unit::isDocked(), Universe::isPlayerStarship(), Unit::isUnit(), jumpok, k, Unit::Kill(), SaveGame::LoadSavedMissions(), Magnitude(), MISSILEPTR, mission, Unit::name, Network, Flightgroup::nr_ships, Flightgroup::nr_ships_left, Universe::numPlayers(), Unit::owner, parentturret, XMLSupport::parse_bool(), XMLSupport::parse_float(), SaveGame::ParseSaveGame(), PLANETPTR, Universe::popActiveStarSystem(), Unit::Position(), PowerDownShield(), Universe::pushActiveStarSystem(), QVector, SaveGame::ReloadPickledData(), RequestClearence(), NetClient::respawnRequest(), respawnunit, retry_dock, Unit::rSize(), UniverseUtil::SafeEntrancePoint(), savegame, secondsWithZeroEnergy, SERVER, Unit::SetCurPosition(), SetParent(), SaveGame::SetPlayerLocation(), SaveGame::SetStarSystem(), Unit::SetTurretAI(), UnitContainer::SetUnit(), Unit::shield, SIMULATION_ATOM, StarSystem::SwapIn(), StarSystem::SwapOut(), switchunit, SwitchUnits(), SwitchUnitsTurret(), Unit::Target(), turretcontrol, unitfaction, unitmodname, UnpackUnitInfo(), UpdAutoPilot(), Vector, vs_config, and zoomfactor.

Referenced by StarSystem::Update().

498 {
499  if (retry_dock && !SERVER && Network == NULL) {
500  QVector vec;
502  }
503  if (jumpok)
504  jumpok++;
505  if (jumpok > 5)
506  jumpok = 0;
507  UpdAutoPilot();
508  Unit *par = GetParent();
509  if (par != NULL) {
510  static float minEnergyForShieldDownpower =
511  XMLSupport::parse_float( vs_config->getVariable( "physics", "shield_energy_downpower", "-.125" ) );
512  static float minEnergyShieldTime =
513  XMLSupport::parse_float( vs_config->getVariable( "physics", "shield_energy_downpower_time", "5" ) );
514  static float minEnergyShieldPercent =
515  XMLSupport::parse_float( vs_config->getVariable( "physics", "shield_energy_downpower_percent", ".66666666666666" ) );
516 
517  bool toolittleenergy = (par->EnergyData() <= minEnergyForShieldDownpower);
518  if (toolittleenergy) {
520  if (secondsWithZeroEnergy > minEnergyShieldTime) {
522  PowerDownShield( &par->shield, minEnergyShieldPercent );
523  }
524  } else {
526  }
527  }
528  if ( turretcontrol.size() > _Universe->CurrentCockpit() ) {
531  Unit *par = GetParent();
532  //this being here, it will require poking the turret from the undock script
533  if (par) {
534  if (par->name == "return_to_cockpit") {
535  //if (par->owner->isUnit()==UNITPTR ) this->SetParent(par->owner,GetUnitFileName().c_str(),this->unitmodname.c_str(),savegame->GetPlayerLocation()); // this warps back to the parent unit if we're eject-docking. in this position it also causes badness upon loading a game.
536 
537  Unit *temp = findUnitInStarsystem( par->owner );
538  if (temp) {
539  SwitchUnits( NULL, temp );
540  this->SetParent( temp, GetUnitFileName().c_str(), this->unitmodname.c_str(), temp->Position() ); //this warps back to the parent unit if we're eject-docking. causes badness upon loading a game.
541  }
542  par->Kill();
543  }
544  }
545  if (par) {
546  static int index = 0;
547  int i = 0;
548  bool tmp = false;
549  bool tmpgot = false;
550  if (parentturret.GetUnit() == NULL) {
551  tmpgot = true;
552  Unit *un;
553  for (un_iter ui = par->getSubUnits(); (un = *ui);) {
554  if ( _Universe->isPlayerStarship( un ) ) {
555  ++ui;
556  continue;
557  }
558  if (i++ == index) {
559  //NOTE : this may have been a correction to the conditional bug
560  ++index;
561  if (un->name.get().find( "accessory" ) == string::npos) {
562  tmp = true;
563  SwitchUnitsTurret( par, un );
564  parentturret.SetUnit( par );
565  Unit *finalunit = GetFinalTurret( un );
566  this->SetParent( finalunit, GetUnitFileName().c_str(),
567  this->unitmodname.c_str(), savegame->GetPlayerLocation() );
568  break;
569  }
570  }
571  ++ui;
572  }
573  }
574  if (tmp == false) {
575  if (tmpgot) index = 0;
576  Unit *un = parentturret.GetUnit();
577  if ( un && ( !_Universe->isPlayerStarship( un ) ) ) {
578  SetParent( un, GetUnitFileName().c_str(), this->unitmodname.c_str(), savegame->GetPlayerLocation() );
579  SwitchUnits( NULL, un );
580  parentturret.SetUnit( NULL );
581  un->SetTurretAI();
582  un->DisableTurretAI();
583  }
584  }
585  }
586  }
587  }
588  static bool autoclear = XMLSupport::parse_bool( vs_config->getVariable( "AI", "autodock", "false" ) );
589  if (autoclear && par) {
590  Unit *targ = par->Target();
591  if (targ) {
592  static float autopilot_term_distance =
593  XMLSupport::parse_float( vs_config->getVariable( "physics", "auto_pilot_termination_distance", "6000" ) );
594  float doubled = dockingdistance( targ, par );
595  if ( ( (targ->isUnit() != PLANETPTR
596  && doubled < autopilot_term_distance)
598  par ) <= 0) )
599  && ( !( par->IsCleared( targ ) || targ->IsCleared( par ) || par->isDocked( targ )
600  || targ->isDocked( par ) ) ) && (par->getRelation( targ ) >= 0) && (targ->getRelation( par ) >= 0) ) {
601  if ( targ->isUnit() != PLANETPTR || targ->GetDestinations().empty() )
602  RequestClearence( par, targ, 0 ); //sex is always 0... don't know how to get it.
603  } else if ( ( par->IsCleared( targ )
604  || targ->IsCleared( par ) ) && ( !( par->isDocked( targ ) ) || targ->isDocked( par ) )
605  && ( (targ->isUnit() == PLANETPTR && UnitUtil::getSignificantDistance( par, targ ) > 0)
606  || ( ( targ->isUnit() != PLANETPTR
607  && UnitUtil::getSignificantDistance( par, targ ) > ( targ->rSize()+par->rSize() ) )
608  && (doubled >= autopilot_term_distance) ) ) ) {
609  if ( targ->isUnit() != PLANETPTR || targ->GetDestinations().empty() ) {
610  par->EndRequestClearance( targ );
611  targ->EndRequestClearance( par );
612  }
613  }
614  }
615  }
616  if ( switchunit.size() > _Universe->CurrentCockpit() ) {
618  parentturret.SetUnit( NULL );
619 
620  static float initialzoom =
621  XMLSupport::parse_float( vs_config->getVariable( "graphics", "inital_zoom_factor", "2.25" ) );
622  zoomfactor = initialzoom;
623  static int index = 0;
625  static bool switch_nonowned_units =
626  XMLSupport::parse_bool( vs_config->getVariable( "AI", "switch_nonowned_units", "true" ) );
627 //switch_nonowned_units = true;
628  //static bool switch_to_fac=XMLSupport::parse_bool(vs_config->getVariable("AI","switch_to_whole_faction","true"));
629 
630  Unit *un;
631  bool found = false;
632  int i = 0;
633  for (un_iter ui = _Universe->activeStarSystem()->getUnitList().createIterator(); (un = *ui); ++ui)
634  if (un->faction == this->unitfaction) {
635 //this switches units UNLESS we're an ejected pilot. Instead, if we are an ejected
636 //pilot, switch only if we're close enough.
637 //the trigger is to allow switching only between ships that are actually owned by you, this prevents
638 //stealing a ship from a hired wingman.
639  if ( ( ( (par != NULL)
640  && (i++) >= index )
641  || par == NULL ) && ( !_Universe->isPlayerStarship( un ) )
642  && ( switch_nonowned_units
643  || (par != NULL
644  && un->owner == par->owner)
645  || (par != NULL
646  && un == par->owner)
647  || (par != NULL
648  && un->owner == par)
649  || (par == NULL
650  && un->owner) ) && (un->name != "eject") && (un->name != "Pilot")
651  && (un->isUnit() != MISSILEPTR) ) {
652  found = true;
653  ++index;
654  Unit *k = GetParent();
655  bool proceed = true;
656  if (k)
657  if (k->name == "eject" || k->name == "Pilot" || k->name == "return_to_cockpit")
658  proceed = false;
659  //we are an ejected pilot, so, if we can get close enough to the related unit, jump into it and remove the seat. This said, always allow
660  //switching from the "fake" ejection seat (ejectdock).
661  if ( !proceed && k && ( k->Position()-un->Position() ).Magnitude() < ( un->rSize()+5*k->rSize() ) ) {
662  if ( !(k->name == "return_to_cockpit") )
663  SwitchUnits( k, un );
664  //this refers to cockpit
665  if ( !(k->name == "return_to_cockpit") )
666  this->SetParent( un, GetUnitFileName().c_str(),
667  this->unitmodname.c_str(), savegame->GetPlayerLocation() );
668  if ( !(k->name == "return_to_cockpit") )
669  k->Kill();
670  //un->SetAI(new FireKeyboard ())
671  }
672  if (proceed) {
673  //k->PrimeOrdersLaunched();
674 //k->SetAI (new Orders::AggressiveAI ("interceptor.agg.xml"));
675 //k->SetTurretAI();
676 
677 //Flightgroup * fg = k->getFlightgroup();
678 //if (fg!=NULL) {
679 //
680 //un->SetFg (fg,fg->nr_ships++);
681 //fg->nr_ships_left++;
682 //fg->leader.SetUnit(un);
683 //fg->directive="b";
684 //}
685  SwitchUnits( k, un );
686  this->SetParent( un, GetUnitFileName().c_str(),
687  this->unitmodname.c_str(), savegame->GetPlayerLocation() );
688  //un->SetAI(new FireKeyboard ())
689  }
690  break;
691  }
692  }
693  if (!found)
694  index = 0;
695  }
696  }
697  //this causes the physical ejecting. Check going_to_dock_screen in here, also.
698  if (ejecting) {
699  ejecting = false;
700 //going_to_dock_screen=true; // NO, clear this only after we've UNDOCKED that way we know we don't have issues.
701 
702  Unit *un = GetParent();
703  if (un) {
704  if (going_to_dock_screen == false)
705  un->EjectCargo( (unsigned int) -1 );
706  if (going_to_dock_screen == true) {
707  un->EjectCargo( (unsigned int) -2 );
708  going_to_dock_screen = false;
709  }
710  }
711  }
712  if (!par) {
713  if ( respawnunit.size() > _Universe->CurrentCockpit() ) {
715  static float initialzoom =
716  XMLSupport::parse_float( vs_config->getVariable( "graphics", "inital_zoom_factor", "2.25" ) );
717  zoomfactor = initialzoom;
718  if (Network != NULL) {
721  } else {
722  parentturret.SetUnit( NULL );
724  std::string savegamefile = mission->getVariable( "savegame", "" );
725  unsigned int k;
726  for (k = 0; k < _Universe->numPlayers(); ++k)
727  if (_Universe->AccessCockpit( k ) == this)
728  break;
729  if ( k == _Universe->numPlayers() ) k = 0;
730  if (active_missions.size() > 1) {
731  for (int i = active_missions.size()-1; i > 0; --i) //don't terminate zeroth mission
732  if (active_missions[i]->player_num == k)
733  active_missions[i]->terminateMission();
734  }
735  unsigned int whichcp = k;
736  string newsystem;
737  QVector pos;
738  bool setplayerXloc;
739  savegame->SetStarSystem( "" );
740  QVector tmpoldpos = savegame->GetPlayerLocation();
741  savegame->SetPlayerLocation( QVector( FLT_MAX, FLT_MAX, FLT_MAX ) );
742  vector< string > packedInfo;
743  savegame->ParseSaveGame( savegamefile,
744  newsystem,
745  newsystem,
746  pos,
747  setplayerXloc,
748  this->credits,
749  packedInfo,
750  k );
751  UnpackUnitInfo(packedInfo);
752  if (pos.i == FLT_MAX && pos.j == FLT_MAX && pos.k == FLT_MAX)
753  pos = tmpoldpos;
754  savegame->SetPlayerLocation( pos );
755  CopySavedShips( savegame->GetCallsign(), whichcp, packedInfo, true );
756  bool actually_have_save = false;
757  static bool persistent_on_load =
758  XMLSupport::parse_bool( vs_config->getVariable( "physics", "persistent_on_load", "true" ) );
759  if (savegame->GetStarSystem() != "") {
760  actually_have_save = true;
761  newsystem = savegame->GetStarSystem()+".system";
762  } else {
763  newsystem = _Universe->activeStarSystem()->getFileName();
764  if (newsystem.find( ".system" ) == string::npos)
765  newsystem += ".system";
766  }
767  Background::BackgroundClone savedtextures = {
768  {NULL, NULL, NULL, NULL, NULL, NULL, NULL}
769  };
770  if (persistent_on_load) {
772  } else {
774  savedtextures = tmp->Cache();
776  }
777  StarSystem *ss = _Universe->GenerateStarSystem( newsystem.c_str(), "", Vector( 0, 0, 0 ) );
778  if (!persistent_on_load)
779  savedtextures.FreeClone();
780  this->activeStarSystem = ss;
782 
783  vector< StarSystem* >saved;
784  while ( _Universe->getNumActiveStarSystem() ) {
785  saved.push_back( _Universe->activeStarSystem() );
787  }
788  if ( !saved.empty() )
789  saved.back() = ss;
790  unsigned int mysize = saved.size();
791  for (unsigned int i = 0; i < mysize; i++) {
792  _Universe->pushActiveStarSystem( saved.back() );
793  saved.pop_back();
794  }
795  ss->SwapIn();
796  int fgsnumber = 0;
797  if (fg) {
798  fgsnumber = fg->flightgroup_nr++;
799  fg->nr_ships++;
800  fg->nr_ships_left++;
801  }
803  GetUnitFileName().c_str(), false, this->unitfaction, unitmodname, fg, fgsnumber );
805  ss->AddUnit( un );
806 
807  this->SetParent( un, GetUnitFileName().c_str(), unitmodname.c_str(), savegame->GetPlayerLocation() );
808  SwitchUnits( NULL, un );
809  this->credits = savegame->GetSavedCredits();
810  DoCockpitKeys();
815  if (actually_have_save && !SERVER && Network == NULL) {
816  QVector vec;
817  DockToSavedBases( whichcp, vec );
818  }
821  if (!persistent_on_load)
823  return true;
824  }
825  }
826  }
827  }
828  return false;
829 }
void Cockpit::updateAttackers ( )

Definition at line 412 of file cockpit_generic.cpp.

References _Universe, Universe::AccessCockpit(), Universe::activeStarSystem(), UnitCollection::createIterator(), Unit::getAverageGunSpeed(), UnitUtil::getDistance(), StarSystem::getUnitList(), VegaConfig::getVariable(), UnitCollection::UnitIterator::isDone(), number_of_attackers, Universe::numPlayers(), parent, XMLSupport::parse_int(), partial_number_of_attackers, speed, Unit::Target(), too_many_attackers, and vs_config.

Referenced by StarSystem::Update().

413 {
414  static int max_attackers = XMLSupport::parse_int( vs_config->getVariable( "AI", "max_player_attackers", "0" ) );
415  if (max_attackers == 0) return;
416  static un_iter attack_iterator = _Universe->activeStarSystem()->getUnitList().createIterator();
417  static StarSystem *ss = _Universe->activeStarSystem();
418  if ( ss != _Universe->activeStarSystem() ) {
419  attack_iterator = _Universe->activeStarSystem()->getUnitList().createIterator();
420  ss = _Universe->activeStarSystem();
421  }
422  bool isDone = attack_iterator.isDone();
423  if (_Universe->AccessCockpit( _Universe->numPlayers()-1 ) == this) {
424  if (!isDone)
425  ++attack_iterator;
426  else
427  attack_iterator = _Universe->activeStarSystem()->getUnitList().createIterator();
428  //too_many_attackers=false;
429  }
430  if (isDone) {
431  if (_Universe->AccessCockpit( 0 ) == this)
432  too_many_attackers = false;
433  //printf ("There are %d folks attacking player\n",partial_number_of_attackers);
434  number_of_attackers = partial_number_of_attackers; //reupdate the count
436  too_many_attackers = max_attackers > 0 && (too_many_attackers || number_of_attackers > max_attackers);
437  }
438  Unit *un;
439  if (attack_iterator.isDone() == false && (un = *attack_iterator) != NULL) {
440  Unit *targ = un->Target();
441  float speed = 0, range = 0, mmrange = 0;
442  if (parent == targ && targ != NULL) {
443  un->getAverageGunSpeed( speed, range, mmrange );
444  float dist = UnitUtil::getDistance( targ, un );
445  if (dist <= range*2 || dist <= mmrange)
447  }
448  } else {
449  //
450 
451  //partial_number_of_attackers=-1;
452  }
453 }
void Cockpit::UpdAutoPilot ( )
virtual

Reimplemented in GameCockpit.

Definition at line 373 of file cockpit_generic.cpp.

References autopilot_target, autopilot_time, Unit::AutoPilotTo(), GetParent(), UnitContainer::GetUnit(), UnitContainer::SetUnit(), and SIMULATION_ATOM.

Referenced by Update().

374 {
375  if (autopilot_time != 0) {
377  if (autopilot_time <= 0) {
378  autopilot_time = 0;
379  Unit *par = GetParent();
380  if (par) {
381  Unit *autoun = autopilot_target.GetUnit();
382  autopilot_target.SetUnit( NULL );
383  if (autoun)
384  par->AutoPilotTo( autoun, false );
385  }
386  }
387  }
388 }
virtual void Cockpit::VDUSwitch ( int  vdunum)
inlinevirtual
void Cockpit::visitSystem ( std::string  systemName)
virtual

Reimplemented in GameCockpit.

Definition at line 840 of file cockpit_generic.cpp.

References UniverseUtil::GetAdjacentSystem(), UniverseUtil::GetNumAdjacentSystems(), i, and visitSystemHelp().

Referenced by NavigationSystem::Setup(), Unit::TransferUnitToSystem(), and GameCockpit::visitSystem().

841 {
842  visitSystemHelp( this, systemname, 1.0 );
844  for (int i = 0; i < adj; ++i)
846 }

Member Data Documentation

UnitContainer Cockpit::autopilot_target
protected
float Cockpit::autopilot_time
protected

Color of cockpit default text The font that the entire cockpit will use. Currently without color

Definition at line 61 of file cockpit_generic.h.

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

float Cockpit::cockpit_offset
protected

two values that represent the adjustment to perspective needed to center teh crosshairs in the perceived view.

Definition at line 66 of file cockpit_generic.h.

Referenced by GameCockpit::DrawNavSystem(), and GameCockpit::SetupViewPort().

float Cockpit::cockpit_time
protected

Definition at line 93 of file cockpit_generic.h.

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

std::string Cockpit::communication_choices

Definition at line 183 of file cockpit_generic.h.

Referenced by FireKeyboard::Execute().

int Cockpit::currentcamera
protected
bool Cockpit::ejecting
protected
class Flightgroup* Cockpit::fg

Sets owner of this cockpit.

Definition at line 199 of file cockpit_generic.h.

Referenced by Cockpit(), NetClient::Respawn(), and Update().

float Cockpit::gauge_time[UnitImages< void >::NUMGAUGES]
protected

Definition at line 41 of file cockpit_generic.h.

Referenced by GameCockpit::InitStatic().

float Cockpit::godliness

Definition at line 134 of file cockpit_generic.h.

Referenced by Unit::DealDamageToHullReturnArmor().

bool Cockpit::going_to_dock_screen
protected
char Cockpit::jumpok

Definition at line 108 of file cockpit_generic.h.

Referenced by Cockpit(), GameCockpit::LookupUnitStat(), TurnJumpOKLightOn(), and Update().

float Cockpit::maxfuel
protected

saved values to compare with current values (might need more for damage)

Definition at line 48 of file cockpit_generic.h.

Referenced by GameCockpit::LookupUnitStat().

float Cockpit::maxhull
protected

Definition at line 48 of file cockpit_generic.h.

Referenced by GameCockpit::LookupUnitStat().

int Cockpit::number_of_attackers

Definition at line 105 of file cockpit_generic.h.

Referenced by Cockpit(), Orders::FireAt::ShouldFire(), and updateAttackers().

UnitContainer Cockpit::parent
protected

this is the parent that Cockpit will read data from

Definition at line 50 of file cockpit_generic.h.

Referenced by GameCockpit::Draw(), GameCockpit::SetupViewPort(), updateAttackers(), and GameCockpit::VDUSwitch().

UnitContainer Cockpit::parentturret
protected

Definition at line 51 of file cockpit_generic.h.

Referenced by Update().

int Cockpit::partial_number_of_attackers
protected

Definition at line 96 of file cockpit_generic.h.

Referenced by Cockpit(), and updateAttackers().

float Cockpit::radar_time
protected

Definition at line 40 of file cockpit_generic.h.

Referenced by GameCockpit::InitStatic().

unsigned int Cockpit::retry_dock

Definition at line 106 of file cockpit_generic.h.

Referenced by DockToSavedBases(), and Update().

double Cockpit::secondsWithZeroEnergy

Definition at line 104 of file cockpit_generic.h.

Referenced by Cockpit(), and Update().

float Cockpit::shakin
protected

4 views f/r/l/b

Definition at line 54 of file cockpit_generic.h.

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

float Cockpit::StartArmor[9]
protected

8 armor vals and 1 for startfuel

Definition at line 45 of file cockpit_generic.h.

Referenced by GameCockpit::LookupUnitStat().

int Cockpit::unitfaction
protected

Definition at line 52 of file cockpit_generic.h.

Referenced by Update().

std::string Cockpit::unitmodname
protected

Video Display Units (may need more than 2 in future)

Definition at line 56 of file cockpit_generic.h.

Referenced by Update().

enum VIEWSTYLE Cockpit::view
protected

style of current view (chase cam, inside)

Definition at line 38 of file cockpit_generic.h.

Referenced by GameCockpit::Draw(), GameCockpit::SelectProperCamera(), and GameCockpit::SetupViewPort().

float Cockpit::viewport_offset
protected

Definition at line 66 of file cockpit_generic.h.

Referenced by GameCockpit::Init(), and GameCockpit::SetupViewPort().


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