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.h
Go to the documentation of this file.
1 // -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*-
2 
3 #ifndef _COCKPIT_H_
4 #define _COCKPIT_H_
5 #include "gfx/cockpit_generic.h"
6 #include "gfxlib.h"
7 #include "gfxlib_struct.h"
8 #include <vector>
9 #include <list>
10 using namespace XMLSupport;
11 class TextPlane;
12 class VSSprite;
13 class Gauge;
14 class Unit;
15 class NavigationSystem;
16 #include "radar/radar.h"
17 #include "radar/sensor.h"
18 #include "vdu.h"
19 #include "camera.h"
20 #include "physics.h"
21 #include "nav/navscreen.h"
22 #define NUM_CAM CP_NUMVIEWS
23 
29 struct soundContainer //used to contain static sounds that will only be
30 {
31  //created once and will get deleted automatically
32  int sound;
34  {
35  sound = -2;
36  }
37  void loadsound( string sooundfile, bool looping = false );
38  void playsound();
39  ~soundContainer();
40 };
41 
42 struct soundArray
43 {
46  {
47  ptr = NULL;
48  }
49  void deallocate()
50  {
51  if (ptr != NULL) {
52  delete[] ptr;
53  ptr = NULL;
54  }
55  }
56  void allocate( int siz )
57  {
58  deallocate();
59  ptr = new soundContainer[siz];
60  }
62  {
63  deallocate();
64  }
65 };
66 
67 class GameCockpit : public Cockpit
68 {
69  Camera cam[NUM_CAM];
70 
71  float insidePanYaw, insidePanPitch;
72  float insidePanYawSpeed, insidePanPitchSpeed;
73 
74  float vdu_time[MAXVDUS];
76  std::list< Matrix >headtrans;
77  float shake_time;
78  int shake_type;
79  Vector oaccel;
80  float smooth_fov;
81  float last_locktime;
82  float last_mlocktime;
83  bool armor8;
84  bool shield8;
85  std::vector< class Mesh* >mesh;
86  int soundfile;
87  VSSprite *Pit[4];
88  VSSprite *radarSprites[2];
89  std::auto_ptr<Radar::Display> radarDisplay;
91  std::vector< VDU* >vdu;
93  std::string targetLabel;
95  void *labeledTargetUnit;
97  GFXColor textcol;
99  TextPlane *text;
100  Gauge *gauges[UnitImages < void > ::NUMGAUGES];
102  std::vector< VSSprite* >Panel;
104  bool draw_all_boxes;
105  bool draw_line_to_target, draw_line_to_targets_target;
106  bool draw_line_to_itts;
108  bool always_itts;
110  bool steady_itts;
111  //colors of blips/targetting boxes
112  GFXColor friendly, enemy, neutral, targeted, targetting, planet;
113 
115  float projection_limit_x, projection_limit_y;
116  float inv_screen_aspect_ratio; //Precomputed division 1 / g_game.aspect.
117  virtual void SetParent( Unit *unit, const char *filename, const char *unitmodname, const QVector &startloc );
118  void LoadXML( const char *file );
119  void LoadXML( VSFileSystem::VSFile &f );
120  void beginElement( const string &name, const AttributeList &attributes );
121  void endElement( const string &name );
123  void Delete();
125  void DrawNavigationSymbol( const Vector &loc, const Vector &p, const Vector &q, float size );
127  float computeLockingSymbol( Unit *par );
128  void DrawTargetBox(const Radar::Sensor&);
130  void DrawTargetBoxes(const Radar::Sensor&);
132  void DrawTurretTargetBoxes(const Radar::Sensor&);
133  void DrawTacticalTargetBox(const Radar::Sensor&);
134  void DrawCommunicatingBoxes();
136  void DrawRadar(const Radar::Sensor&);
138  void DrawTargetGauges( Unit *target );
140  void DrawGauges( Unit *un );
141  NavigationSystem ThisNav;
142  //Draw the arrow pointing to the target.
143  void DrawArrowToTarget(const Radar::Sensor&, Unit*);
144  void DrawArrowToTarget(const Radar::Sensor&, Vector LocalCoordinates);
145  void updateRadar(Unit * un);
146 public:
147  std::string textMessage;
149  std::string autoMessage;
151  virtual void setTargetLabel( const string &msg );
152  virtual string getTargetLabel();
153  void ReceivedTargetInfo();
154  static void NavScreen( const KBData&, KBSTATE k ); //scheherazade
155  static string getsoundending( int which = 0 );
156  static string getsoundfile( string filename );
157  void InitStatic();
158  void Shake( float amt, int level /*0= shield 1=armor 2=hull*/ );
159  int Autopilot( Unit *target );
161  void RestoreViewPort();
162  GameCockpit( const char *file, Unit *parent, const std::string &pilotname );
163  ~GameCockpit();
165  float LookupTargetStat( int stat, Unit *target );
167  float LookupUnitStat( int stat, Unit *target );
169  void Init( const char *file );
171  void Draw();
172  //void Update();//respawns and the like.
173  void UpdAutoPilot();
175  void SetupViewPort( bool clip = true );
176  int getVDUMode( int vdunum );
177  void VDUSwitch( int vdunum );
178  void ScrollVDU( int vdunum, int howmuch );
179  void ScrollAllVDU( int howmuch );
180  int getScrollOffset( unsigned int whichtype );
181  void SelectProperCamera();
182  void Eject();
183  void EjectDock();
184  static void Respawn( const KBData &, KBSTATE );
185  static void SwitchControl( const KBData &, KBSTATE );
186  static void ForceSwitchControl( const KBData &, KBSTATE );
187  static void TurretControl( const KBData &, KBSTATE );
188  void SetSoundFile( std::string sound );
190  {
191  return soundfile;
192  }
193  void SetCommAnimation( Animation *ani, Unit *un );
194  void SetStaticAnimation();
197  {
198  return &ThisNav;
199  }
200  virtual std::string GetNavSelectedSystem();
203  {
204  return &cam[currentcamera];
205  }
207  Camera * AccessCamera( int );
209  void SelectCamera( int );
211  void SetViewport()
212  {
213  cam[currentcamera].UpdateGFX();
214  }
215 
216  virtual bool SetDrawNavSystem( bool );
217  virtual bool CanDrawNavSystem();
218  virtual bool DrawNavSystem();
219  virtual bool CheckCommAnimation( Unit *un );
220  virtual void visitSystem( std::string systemName );
221  void AutoLanding();
222  void DoAutoLanding(Unit *, Unit *);
223 
224  virtual void SetInsidePanYawSpeed( float speed );
225  virtual void SetInsidePanPitchSpeed( float speed );
226 
227  bool IsPaused() const;
228  // Game is paused
229  void OnPauseBegin();
230  void OnPauseEnd();
231  // Ship has undocked from station
232  void OnDockEnd(Unit *station, Unit *unit);
233  // Ship is jumping
234  void OnJumpBegin(Unit *unit);
235  void OnJumpEnd(Unit *unit);
236 };
237 #endif
238