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
vdu.cpp
Go to the documentation of this file.
1 
5 #include "vdu.h"
6 #include "cmd/unit_util.h"
7 #include "hud.h"
8 #include "vs_globals.h"
9 #include "cockpit.h"
10 #include "cmd/script/mission.h"
11 #include "cmd/script/flightgroup.h"
12 #include "cmd/script/msgcenter.h"
13 #include "cmd/images.h"
14 #include "cmd/planet.h"
15 #include "cmd/beam.h"
16 #include "config_xml.h"
17 #include "xml_support.h"
18 #include "gfx/animation.h"
19 #include "gfx/vsimage.h"
20 #include "galaxy_gen.h"
21 #include "universe_util.h"
22 #include "networking/netclient.h"
23 #include "vsfilesystem.h"
24 
25 template < typename T >
26 inline T mymin( T a, T b )
27 {
28  return (a < b) ? a : b;
29 }
30 
31 template < typename T >
32 inline T mymax( T a, T b )
33 {
34  return (a > b) ? a : b;
35 }
36 
37 bool VDU::staticable() const
38 {
39  unsigned int thismode = getMode();
40  static bool only_scanner_modes_static =
41  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "only_scanner_modes_static", "true" ) );
42  if (thismode != COMM && thismode != TARGETMANIFEST && thismode != TARGET && thismode != NAV && thismode != VIEW
43  && thismode != WEBCAM && only_scanner_modes_static)
44  return false;
45  return ( posmodes&(posmodes-1) ) != 0; //check not power of two
46 }
47 
49 const std::string vdu_modes[] =
50 {"Target", "Nav", "Objectives", "Comm", "Weapon", "Damage", "Shield", "Manifest", "TargetManifest", "View", "Message"};
51 
52 string reformatName( string nam )
53 {
54  nam = nam.substr( 0, nam.find( "." ) );
55  if ( nam.length() )
56  nam[0] = toupper( nam[0] );
57  return nam;
58 }
59 
60 string getUnitNameAndFgNoBase( Unit *target )
61 {
62  Flightgroup *fg = target->getFlightgroup();
63  if (target->isUnit() == PLANETPTR) {
64  string hr = ( (Planet*) target )->getHumanReadablePlanetType();
65  if ( !hr.empty() )
66  return hr+string( ":" )+reformatName( target->name );
67  } else if (target->isUnit() == UNITPTR) {
68  if (fg) {
69  int fgsnumber = target->getFgSubnumber();
70  string fgnstring = XMLSupport::tostring( fgsnumber );
71  static bool confignums =
72  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "print_fg_sub_id", "false" ) );
73  string fgname;
74  if (fg->name != "Base" && fg->name != "Asteroid" && fg->name != "Nebula") {
75  static bool printfgname =
76  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "print_fg_name", "true" ) );
77  static bool printshiptype =
78  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "print_ship_type", "true" ) );
79  if (printfgname)
80  fgname += fg->name
81  +(printshiptype ? ( ( confignums && ("" != fgnstring) ) ? " =" : " : " ) : "");
82  if ( confignums && ("" != fgnstring) )
83  fgname += fgnstring+"= ";
84  if (printshiptype)
85  return fgname+reformatName( target->getFullname() );
86  return fgname;
87  } else if (fg->name == "Base") {
88  static bool namecolonname =
89  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "basename:basename", "true" ) );
90  if ( namecolonname == false || reformatName( target->name ) == ( reformatName( target->getFullname() ) ) ) {
91  std::string retval( reformatName( target->getFullname() ) );
92  if ( confignums && ("" != fgnstring) ) retval += " : "+fgnstring;
93  return retval;
94  } else {
95  if ( reformatName( target->name ) == ( reformatName( target->getFullname() ) ) ) {
96  std::string retval( reformatName(
97  target->name )+" "
98  +( ( confignums && ("" != fgnstring) ) ? (": "+fgnstring) : "" ) );
99  return retval;
100  } else {
101  std::string retval( reformatName( target->name )+" : "+target->getFullname() );
102  return retval;
103  }
104  }
105  }
106  } else if (Network != NULL) {
107  std::string retval( reformatName( target->name )+":"+target->getFullname() );
108  return retval;
109  }
110  }
111  return reformatName( target->name );
112 }
113 
114 int vdu_lookup( char* &s )
115 {
116 #ifdef _WIN32
117 #define strcasecmp stricmp
118 #endif
119  int retval = 0;
120  char *t = strdup( s );
121  int i;
122  for (i = 0; t[i] != '\0'; i++)
123  if ( isspace( t[i] ) ) {
124  s += i+1;
125  break;
126  }
127  if (t[i] == '\0')
128  s[0] = '\0';
129  t[i] = '\0';
130  for (unsigned int j = 0; j < ( ( sizeof (vdu_modes)/sizeof (std::string) ) ); j++)
131  if ( 0 == strcasecmp( t, vdu_modes[j].c_str() ) )
132  retval |= (1<<j);
133  free( t );
134  return retval;
135 }
136 
137 int parse_vdu_type( const char *x )
138 {
139  char *mystr = strdup( x );
140  char *s = mystr;
141  int retval = 0;
142  while (s[0] != '\0')
143  retval |= vdu_lookup( s );
144  free( mystr );
145  return retval;
146 }
147 
148 char tohexdigit( int x )
149 {
150  if (x <= 9 && x >= 0)
151  return (char) (x+'0');
152  else
153  return (char) (x-10+'A');
154 }
155 
156 GFXColor colLerp( GFXColor a, GFXColor b, float bweight )
157 {
158  float aweight = 1-bweight;
159  return GFXColor( a.r*aweight+b.r*bweight,
160  a.g*aweight+b.g*bweight,
161  a.b*aweight+b.b*bweight,
162  a.a*aweight+b.a*bweight );
163 }
164 
166 {
167  char str[8];
168 };
169 
171 {
172  unsigned char r = (unsigned char) (col.r*255);
173  unsigned char g = (unsigned char) (col.g*255);
174  unsigned char b = (unsigned char) (col.b*255);
175  colorstring ret;
176  ret.str[0] = '#';
177  ret.str[7] = '\0';
178  ret.str[1] = tohexdigit( r/16 );
179  ret.str[2] = tohexdigit( r%16 );
180  ret.str[3] = tohexdigit( g/16 );
181  ret.str[4] = tohexdigit( g%16 );
182  ret.str[5] = tohexdigit( b/16 );
183  ret.str[6] = tohexdigit( b%16 );
184  return ret;
185 }
186 
187 VDU::VDU( const char *file, TextPlane *textp, unsigned short modes, short rwws, short clls, float *ma,
188  float *mh ) : VSSprite( file )
189  , tp( textp )
190  , posmodes( modes )
191  , rows( rwws )
192  , cols( clls )
193  , scrolloffset( 0 )
194 {
195  thismode.push_back( MSG );
196  if (_Universe->numPlayers() > 1)
197  posmodes &= (~VIEW);
198  comm_ani = NULL;
199  viewStyle = CP_TARGET;
200  StartArmor = ma;
201  maxhull = mh;
202  if (Network != NULL)
203  got_target_info = false;
204  else
205  got_target_info = true;
206  SwitchMode( NULL );
207 
208  //printf("\nVDU rows=%d,col=%d\n",rows,cols);
209  //cout << "vdu" << endl;
210 }
211 
212 GFXColor getDamageColor( float armor, bool gradient = false )
213 {
214  static bool init = false;
215  static float damaged[4] = {1, 0, 0, 1};
216  static float half_damaged[4] = {1, 1, 0, 1};
217  static float full[4] = {1, 1, 1, 1};
218  if (!init) {
219  vs_config->getColor( "default", "hud_target_damaged", damaged, true );
220  vs_config->getColor( "default", "hud_target_half_damaged", half_damaged, true );
221  vs_config->getColor( "default", "hud_target_full", full, true );
222  init = true;
223  }
224  if (armor >= .9)
225  return GFXColor( full[0], full[1], full[2], full[3] );
226  float avghalf = armor >= .3 ? 1 : 0;
227  if (gradient && armor >= .3)
228  avghalf = (armor-.3)/.6;
229  float avgdamaged = 1-avghalf;
230  return GFXColor( half_damaged[0]*avghalf+damaged[0]*avgdamaged,
231  half_damaged[1]*avghalf+damaged[1]*avgdamaged,
232  half_damaged[2]*avghalf+damaged[2]*avgdamaged,
233  half_damaged[3]*avghalf+damaged[3]*avgdamaged );
234 }
235 
236 static void DrawHUDSprite( VDU *thus,
237  VSSprite *s,
238  float per,
239  float &sx,
240  float &sy,
241  float &w,
242  float &h,
243  float aup,
244  float aright,
245  float aleft,
246  float adown,
247  float hull,
248  bool drawsprite,
249  bool invertsprite )
250 {
251  static bool HighQTargetVSSprites =
252  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "high_quality_sprites", "false" ) );
253  float nw, nh;
254  thus->GetPosition( sx, sy );
255  thus->GetSize( w, h );
256 
257  //Use margins specified from config file
258  static float width_factor = XMLSupport::parse_float( vs_config->getVariable( "graphics", "reduced_vdus_width", "0" ) );
259  static float height_factor = XMLSupport::parse_float( vs_config->getVariable( "graphics", "reduced_vdus_height", "0" ) );
260  w = w-width_factor;
261  h = h+height_factor;
262 
263  h = -fabs( h*per );
264  if (!s) {
265  h = -h;
266  w = fabs( w*per );
267  } else {
268  if (HighQTargetVSSprites) {
270  } else {
271  GFXBlendMode( ONE, ZERO );
272  GFXAlphaTest( GREATER, .4 );
273  }
274  s->SetPosition( sx, sy );
275  s->GetSize( nw, nh );
276  w = fabs( nw*h/nh );
277  s->SetSize( w, invertsprite ? -h : h );
278  Texture *spritetex = s->getTexture();
279  if (drawsprite && spritetex) {
280  static const float middle_point =
281  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "armor_hull_size", ".55" ) );
282  static bool top_view = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "top_view", "false" ) );
283  float middle_point_small = 1-middle_point;
284  Vector ll, lr, ur, ul, mll, mlr, mur, mul;
285  spritetex->MakeActive();
286  GFXDisable( CULLFACE );
287  s->DrawHere( ll, lr, ur, ul );
288  mll = middle_point*ll+middle_point_small*ur;
289  mlr = middle_point*lr+middle_point_small*ul;
290  mur = middle_point*ur+middle_point_small*ll;
291  mul = middle_point*ul+middle_point_small*lr;
292  GFXBegin( GFXQUAD );
293  GFXColorf( getDamageColor( top_view ? adown : aleft ) );
294  GFXTexCoord2f( 0, 0 );
295  GFXVertexf( ul );
296  GFXColorf( getDamageColor( top_view ? adown : aup ) );
297  GFXTexCoord2f( 1, 0 );
298  GFXVertexf( ur );
299  GFXColorf( getDamageColor( hull, true ) );
300  GFXTexCoord2f( middle_point, middle_point_small );
301  GFXVertexf( mur );
302  GFXColorf( getDamageColor( hull, true ) );
303  GFXTexCoord2f( middle_point_small, middle_point_small );
304  GFXVertexf( mul );
305  GFXColorf( getDamageColor( top_view ? aright : aup ) );
306  GFXTexCoord2f( 1, 0 );
307  GFXVertexf( ur );
308  GFXColorf( getDamageColor( aright ) );
309  GFXTexCoord2f( 1, 1 );
310  GFXVertexf( lr );
311  GFXColorf( getDamageColor( hull, true ) );
312  GFXTexCoord2f( middle_point, middle_point );
313  GFXVertexf( mlr );
314  GFXColorf( getDamageColor( hull, true ) );
315  GFXTexCoord2f( middle_point, middle_point_small );
316  GFXVertexf( mur );
317  GFXColorf( getDamageColor( top_view ? aup : aright ) );
318  GFXTexCoord2f( 1, 1 );
319  GFXVertexf( lr );
320  GFXColorf( getDamageColor( top_view ? aup : adown ) );
321  GFXTexCoord2f( 0, 1 );
322  GFXVertexf( ll );
323  GFXColorf( getDamageColor( hull, true ) );
324  GFXTexCoord2f( middle_point_small, middle_point );
325  GFXVertexf( mll );
326  GFXColorf( getDamageColor( hull, true ) );
327  GFXTexCoord2f( middle_point, middle_point );
328  GFXVertexf( mlr );
329  GFXColorf( getDamageColor( top_view ? aleft : adown ) );
330  GFXTexCoord2f( 0, 1 );
331  GFXVertexf( ll );
332  GFXColorf( getDamageColor( aleft ) );
333  GFXTexCoord2f( 0, 0 );
334  GFXVertexf( ul );
335  GFXTexCoord2f( middle_point_small, middle_point_small );
336  GFXColorf( getDamageColor( hull, true ) );
337  GFXVertexf( mul );
338  GFXColorf( getDamageColor( hull, true ) );
339  GFXTexCoord2f( middle_point_small, middle_point );
340  GFXVertexf( mll );
341  GFXColorf( getDamageColor( hull, true ) );
342  GFXTexCoord2f( middle_point_small, middle_point_small );
343  GFXVertexf( mul );
344  GFXColorf( getDamageColor( hull, true ) );
345  GFXTexCoord2f( middle_point, middle_point_small );
346  GFXVertexf( mur );
347  GFXColorf( getDamageColor( hull, true ) );
348  GFXTexCoord2f( middle_point, middle_point );
349  GFXVertexf( mlr );
350  GFXColorf( getDamageColor( hull, true ) );
351  GFXTexCoord2f( middle_point_small, middle_point );
352  GFXVertexf( mll );
353  GFXEnd();
354 
355  GFXEnable( CULLFACE );
356  }
357  s->SetSize( nw, nh );
358  h = fabs( h );
359  if (HighQTargetVSSprites)
360  GFXBlendMode( ONE, ZERO );
361  else
362  GFXAlphaTest( ALWAYS, 0 );
363  }
364 }
365 
366 void VDU::DrawTargetSpr( VSSprite *s, float per, float &sx, float &sy, float &w, float &h )
367 {
368  DrawHUDSprite( this, s, per, sx, sy, w, h, 1, 1, 1, 1, 1, true, false );
369 }
370 
371 void VDU::Scroll( int howmuch )
372 {
373  scrolloffset += howmuch;
374 }
375 
376 #define MangleString( a, b ) (a)
377 
378 /*
379 static std::string MangleStrung( std::string in, float probability )
380 {
381  //fails with ppc
382  vector< char >str;
383  for (int i = 0; i < (int) in.length(); i++) {
384  if (in[i] != '\n') {
385  str.push_back( in[i] );
386  if (rand() < probability*RAND_MAX)
387  str.back() += rand()%12-6;
388  if (rand() < .1*probability*RAND_MAX)
389  str.push_back( 'a'+rand()%26 );
390  } else {
391  if (rand() < .1*probability*RAND_MAX)
392  while (rand()%5)
393  str.push_back( 'a'+rand()%26 );
394  str.push_back( in[i] );
395  }
396  }
397  return std::string( str.begin(), str.end() );
398 }
399 */
400 
401 static void DrawShield( float fs,
402  float rs,
403  float ls,
404  float bs,
405  float x,
406  float y,
407  float w,
408  float h,
409  bool invert,
410  GFXColor outershield,
411  GFXColor middleshield,
412  GFXColor innershield )
413 {
414  //FIXME why is this static?
415  GFXEnable( SMOOTH );
418  GFXBegin( GFXLINE );
419  if (invert) {
420  float tmp = fs;
421  fs = bs;
422  bs = tmp;
423  }
424  GFXColor shcolor[4][3] = {
425  {innershield, middleshield, outershield},
426  {innershield, middleshield, outershield},
427  {innershield, middleshield, outershield},
428  {innershield, middleshield, outershield}
429  };
430  static bool do_shield_fade = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "shield_vdu_fade", "true" ) );
431 
432  static float shthresh[3] = {
433  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud",
434  "shield_vdu_thresh0",
435  do_shield_fade ? "0" : ".25" ) ),
436  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud",
437  "shield_vdu_thresh1",
438  do_shield_fade ? ".33" : ".50" ) ),
439  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud",
440  "shield_vdu_thresh2",
441  do_shield_fade ? ".66" : ".75" ) )
442  }; //PM me if you don't know why I did this.
443  float shtrans[3] = {1.0f, 1.0f, 1.0f};
444  if (do_shield_fade) {
445  shcolor[0][0].a *= mymax( 0.0f, mymin( 1.0f, (fs-shthresh[0])/(shthresh[1]-shthresh[0])*shtrans[0] ) );
446  shcolor[0][1].a *= mymax( 0.0f, mymin( 1.0f, (fs-shthresh[1])/(shthresh[2]-shthresh[1])*shtrans[1] ) );
447  shcolor[0][2].a *= mymax( 0.0f, mymin( 1.0f, (fs-shthresh[2])/(1.0f-shthresh[2])*shtrans[2] ) );
448  shcolor[1][0].a *= mymax( 0.0f, mymin( 1.0f, (rs-shthresh[0])/(shthresh[1]-shthresh[0])*shtrans[0] ) );
449  shcolor[1][1].a *= mymax( 0.0f, mymin( 1.0f, (rs-shthresh[1])/(shthresh[2]-shthresh[1])*shtrans[1] ) );
450  shcolor[1][2].a *= mymax( 0.0f, mymin( 1.0f, (rs-shthresh[2])/(1.0f-shthresh[2])*shtrans[2] ) );
451  shcolor[2][0].a *= mymax( 0.0f, mymin( 1.0f, (ls-shthresh[0])/(shthresh[1]-shthresh[0])*shtrans[0] ) );
452  shcolor[2][1].a *= mymax( 0.0f, mymin( 1.0f, (ls-shthresh[1])/(shthresh[2]-shthresh[1])*shtrans[1] ) );
453  shcolor[2][2].a *= mymax( 0.0f, mymin( 1.0f, (ls-shthresh[2])/(1.0f-shthresh[2])*shtrans[2] ) );
454  shcolor[3][0].a *= mymax( 0.0f, mymin( 1.0f, (bs-shthresh[0])/(shthresh[1]-shthresh[0])*shtrans[0] ) );
455  shcolor[3][1].a *= mymax( 0.0f, mymin( 1.0f, (bs-shthresh[1])/(shthresh[2]-shthresh[1])*shtrans[1] ) );
456  shcolor[3][2].a *= mymax( 0.0f, mymin( 1.0f, (bs-shthresh[2])/(1.0f-shthresh[2])*shtrans[2] ) );
457  }
458  if (fs > shthresh[0]) {
459  GFXColorf( shcolor[0][0] );
460  GFXVertex3d( (double) x-w/8, y+h/2, 0. );
461  GFXVertex3d( (double) x-w/3, y+.9*h/2, 0. );
462  GFXVertex3d( (double) x+w/8, y+h/2, 0. );
463  GFXVertex3d( (double) x+w/3, y+.9*h/2, 0. );
464  GFXVertex3d( (double) x+w/8, y+h/2, 0. );
465  GFXVertex3d( (double) x-w/8, y+h/2, 0. );
466  }
467  if (fs > shthresh[1]) {
468  GFXColorf( shcolor[0][1] );
469  GFXVertex3d( (double) x-w/8, y+1.1*h/2, 0. );
470  GFXVertex3d( (double) x+w/8, y+1.1*h/2, 0. );
471  GFXVertex3d( (double) x-w/8, y+1.1*h/2, 0. );
472  GFXVertex3d( (double) x-w/3, y+h/2, 0. );
473  GFXVertex3d( (double) x+w/8, y+1.1*h/2, 0. );
474  GFXVertex3d( (double) x+w/3, y+h/2, 0. );
475  }
476  if (fs > shthresh[2]) {
477  GFXColorf( shcolor[0][2] );
478  GFXVertex3d( (double) x-w/8, y+1.2*h/2, 0. );
479  GFXVertex3d( (double) x+w/8, y+1.2*h/2, 0. );
480  GFXVertex3d( (double) x-w/8, y+1.2*h/2, 0. );
481  GFXVertex3d( (double) x-w/3, y+1.1*h/2, 0. );
482  GFXVertex3d( (double) x+w/8, y+1.2*h/2, 0. );
483  GFXVertex3d( (double) x+w/3, y+1.1*h/2, 0. );
484  }
485  if (rs > shthresh[0]) {
486  GFXColorf( shcolor[1][0] );
487  GFXVertex3d( (double) x+1*w/2, y-h/8, 0. );
488  GFXVertex3d( (double) x+.9*w/2, y-h/3, 0. );
489  GFXVertex3d( (double) x+1*w/2, y+h/8, 0. );
490  GFXVertex3d( (double) x+1*w/2, y-h/8, 0. );
491  GFXVertex3d( (double) x+.9*w/2, y+h/3, 0. );
492  GFXVertex3d( (double) x+1*w/2, y+h/8, 0. );
493  }
494  if (rs > shthresh[1]) {
495  GFXColorf( shcolor[1][1] );
496  GFXVertex3d( (double) x+1.1*w/2, y-h/8, 0. );
497  GFXVertex3d( (double) x+1*w/2, y-h/3, 0. );
498  GFXVertex3d( (double) x+1.1*w/2, y+h/8, 0. );
499  GFXVertex3d( (double) x+1.1*w/2, y-h/8, 0. );
500  GFXVertex3d( (double) x+1*w/2, y+h/3, 0. );
501  GFXVertex3d( (double) x+1.1*w/2, y+h/8, 0. );
502  }
503  if (rs > shthresh[2]) {
504  GFXColorf( shcolor[1][2] );
505  GFXVertex3d( (double) x+1.2*w/2, y-h/8, 0. );
506  GFXVertex3d( (double) x+1.1*w/2, y-h/3, 0. );
507  GFXVertex3d( (double) x+1.2*w/2, y+h/8, 0. );
508  GFXVertex3d( (double) x+1.2*w/2, y-h/8, 0. );
509  GFXVertex3d( (double) x+1.1*w/2, y+h/3, 0. );
510  GFXVertex3d( (double) x+1.2*w/2, y+h/8, 0. );
511  }
512  if (ls > shthresh[0]) {
513  GFXColorf( shcolor[2][0] );
514  GFXVertex3d( (double) x-1*w/2, y-h/8, 0. );
515  GFXVertex3d( (double) x-.9*w/2, y-h/3, 0. );
516  GFXVertex3d( (double) x-1*w/2, y+h/8, 0. );
517  GFXVertex3d( (double) x-1*w/2, y-h/8, 0. );
518  GFXVertex3d( (double) x-.9*w/2, y+h/3, 0. );
519  GFXVertex3d( (double) x-1*w/2, y+h/8, 0. );
520  }
521  if (ls > shthresh[1]) {
522  GFXColorf( shcolor[2][1] );
523  GFXVertex3d( (double) x-1.1*w/2, y-h/8, 0. );
524  GFXVertex3d( (double) x-1*w/2, y-h/3, 0. );
525  GFXVertex3d( (double) x-1.1*w/2, y+h/8, 0. );
526  GFXVertex3d( (double) x-1.1*w/2, y-h/8, 0. );
527  GFXVertex3d( (double) x-1*w/2, y+h/3, 0. );
528  GFXVertex3d( (double) x-1.1*w/2, y+h/8, 0. );
529  }
530  if (ls > shthresh[2]) {
531  GFXColorf( shcolor[2][2] );
532  GFXVertex3d( (double) x-1.2*w/2, y-h/8, 0. );
533  GFXVertex3d( (double) x-1.1*w/2, y-h/3, 0. );
534  GFXVertex3d( (double) x-1.2*w/2, y+h/8, 0. );
535  GFXVertex3d( (double) x-1.2*w/2, y-h/8, 0. );
536  GFXVertex3d( (double) x-1.1*w/2, y+h/3, 0. );
537  GFXVertex3d( (double) x-1.2*w/2, y+h/8, 0. );
538  }
539  if (bs > shthresh[0]) {
540  GFXColorf( shcolor[3][0] );
541  GFXVertex3d( (double) x-w/8, y-h/2, 0. );
542  GFXVertex3d( (double) x-w/3, y-.9*h/2, 0. );
543  GFXVertex3d( (double) x+w/8, y-h/2, 0. );
544  GFXVertex3d( (double) x+w/3, y-.9*h/2, 0. );
545  GFXVertex3d( (double) x+w/8, y-h/2, 0. );
546  GFXVertex3d( (double) x-w/8, y-h/2, 0. );
547  }
548  if (bs > shthresh[1]) {
549  GFXColorf( shcolor[3][1] );
550  GFXVertex3d( (double) x-w/8, y-1.1*h/2, 0. );
551  GFXVertex3d( (double) x+w/8, y-1.1*h/2, 0. );
552  GFXVertex3d( (double) x-w/8, y-1.1*h/2, 0. );
553  GFXVertex3d( (double) x-w/3, y-h/2, 0. );
554  GFXVertex3d( (double) x+w/8, y-1.1*h/2, 0. );
555  GFXVertex3d( (double) x+w/3, y-h/2, 0. );
556  }
557  if (bs > shthresh[2]) {
558  GFXColorf( shcolor[3][2] );
559  GFXVertex3d( (double) x-w/8, y-1.2*h/2, 0. );
560  GFXVertex3d( (double) x+w/8, y-1.2*h/2, 0. );
561  GFXVertex3d( (double) x-w/8, y-1.2*h/2, 0. );
562  GFXVertex3d( (double) x-w/3, y-1.1*h/2, 0. );
563  GFXVertex3d( (double) x+w/8, y-1.2*h/2, 0. );
564  GFXVertex3d( (double) x+w/3, y-1.1*h/2, 0. );
565  }
566  GFXEnd();
567  GFXDisable( SMOOTH );
568  GFXPopBlendMode();
569 }
570 
571 /*
572 static void DrawShieldArmor( Unit *parent, const float StartArmor[8], float x, float y, float w, float h, bool invertfrontback )
573 {
574  static bool drawVSarmor = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "drawVSarmor", "true" ) );
575  float fs = parent->FShieldData();
576  float rs = parent->RShieldData();
577  float ls = parent->LShieldData();
578  float bs = parent->BShieldData();
579  float armor[8];
580 
581  static float ishieldcolor[4] = {.4, .4, 1, 1};
582  static float mshieldcolor[4] = {.4, .4, 1, 1};
583  static float oshieldcolor[4] = {.4, .4, 1, 1};
584 
585  static float iarmorcolor[4] = {1, .6, 0, 1};
586  static float marmorcolor[4] = {1, .6, 0, 1};
587  static float oarmorcolor[4] = {1, .6, 0, 1};
588  static float iBarmorcolor[4] = {.75, .45, .1, 1};
589  static float mBarmorcolor[4] = {.75, .45, .1, 1};
590  static float oBarmorcolor[4] = {.75, .45, .1, 1};
591 
592  GFXDisable( TEXTURE0 );
593  DrawShield( fs, rs, ls, bs, x, y, w, h, invertfrontback,
594  GFXColor( ishieldcolor[0], ishieldcolor[1], ishieldcolor[2], ishieldcolor[3] ),
595  GFXColor( mshieldcolor[0], mshieldcolor[1], mshieldcolor[2], mshieldcolor[3] ),
596  GFXColor( oshieldcolor[0], oshieldcolor[1], oshieldcolor[2], oshieldcolor[3] ) );
597  parent->ArmorData( armor );
598  if (drawVSarmor) {
599  //FrontRightTop
600  DrawShield( armor[0]/(float) StartArmor[0], 0, 0, 0, x+w/6, y, w/3, h/2, invertfrontback,
601  GFXColor( iarmorcolor[0], iarmorcolor[1], iarmorcolor[2], iarmorcolor[3] ),
602  GFXColor( marmorcolor[0], marmorcolor[1], marmorcolor[2], marmorcolor[3] ),
603  GFXColor( oarmorcolor[0], oarmorcolor[1], oarmorcolor[2], oarmorcolor[3] ) );
604  //backrighttop;
605  DrawShield( 0, 0, 0, armor[1]/(float) StartArmor[1], x+w/6, y, w/3, h/2, invertfrontback,
606  GFXColor( iarmorcolor[0], iarmorcolor[1], iarmorcolor[2], iarmorcolor[3] ),
607  GFXColor( marmorcolor[0], marmorcolor[1], marmorcolor[2], marmorcolor[3] ),
608  GFXColor( oarmorcolor[0], oarmorcolor[1], oarmorcolor[2], oarmorcolor[3] ) );
609  //frontlefttop;
610  DrawShield( armor[2]/(float) StartArmor[2], 0, 0, 0, x-w/6, y, w/3, h/2, invertfrontback,
611  GFXColor( iarmorcolor[0], iarmorcolor[1], iarmorcolor[2], iarmorcolor[3] ),
612  GFXColor( marmorcolor[0], marmorcolor[1], marmorcolor[2], marmorcolor[3] ),
613  GFXColor( oarmorcolor[0], oarmorcolor[1], oarmorcolor[2], oarmorcolor[3] ) );
614  //backlefttop;
615  DrawShield( 0, 0, 0, armor[3]/(float) StartArmor[3], x-w/6, y, w/3, h/2, invertfrontback,
616  GFXColor( iarmorcolor[0], iarmorcolor[1], iarmorcolor[2], iarmorcolor[3] ),
617  GFXColor( marmorcolor[0], marmorcolor[1], marmorcolor[2], marmorcolor[3] ),
618  GFXColor( oarmorcolor[0], oarmorcolor[1], oarmorcolor[2], oarmorcolor[3] ) );
619  //frontrightbottom;
620  DrawShield( 0, armor[4]/(float) StartArmor[4], 0, 0, x, y+w/6, w/2, h/4, invertfrontback,
621  GFXColor( iBarmorcolor[0], iBarmorcolor[1], iBarmorcolor[2], iBarmorcolor[3] ),
622  GFXColor( mBarmorcolor[0], mBarmorcolor[1], mBarmorcolor[2], mBarmorcolor[3] ),
623  GFXColor( oBarmorcolor[0], oBarmorcolor[1], oBarmorcolor[2], oBarmorcolor[3] ) );
624  //backrightbottom;
625  DrawShield( 0, armor[5]/(float) StartArmor[5], 0, 0, x, y-w/6, w/2, h/4, invertfrontback,
626  GFXColor( iBarmorcolor[0], iBarmorcolor[1], iBarmorcolor[2], iBarmorcolor[3] ),
627  GFXColor( mBarmorcolor[0], mBarmorcolor[1], mBarmorcolor[2], mBarmorcolor[3] ),
628  GFXColor( oBarmorcolor[0], oBarmorcolor[1], oBarmorcolor[2], oBarmorcolor[3] ) );
629  //frontleftbottom;
630  DrawShield( 0, 0, armor[6]/(float) StartArmor[6], 0, x, y+w/6, w/2, h/4, invertfrontback,
631  GFXColor( iBarmorcolor[0], iBarmorcolor[1], iBarmorcolor[2], iBarmorcolor[3] ),
632  GFXColor( mBarmorcolor[0], mBarmorcolor[1], mBarmorcolor[2], mBarmorcolor[3] ),
633  GFXColor( oBarmorcolor[0], oBarmorcolor[1], oBarmorcolor[2], oBarmorcolor[3] ) );
634  //backleftbottom;
635  DrawShield( 0, 0, armor[7]/(float) StartArmor[7], 0, x, y-w/6, w/2, h/4, invertfrontback,
636  GFXColor( iBarmorcolor[0], iBarmorcolor[1], iBarmorcolor[2], iBarmorcolor[3] ),
637  GFXColor( mBarmorcolor[0], mBarmorcolor[1], mBarmorcolor[2], mBarmorcolor[3] ),
638  GFXColor( oBarmorcolor[0], oBarmorcolor[1], oBarmorcolor[2], oBarmorcolor[3] ) );
639  } else {
640  DrawShield( (armor[0]+armor[2]+armor[4]+armor[6])/(float) (StartArmor[0]+StartArmor[2]+StartArmor[4]+StartArmor[6]),
641  (armor[0]+armor[1]+armor[4]+armor[5])/(float) (StartArmor[0]+StartArmor[1]+StartArmor[4]+StartArmor[5]),
642  (armor[2]+armor[3]+armor[6]+armor[7])/(float) (StartArmor[2]+StartArmor[3]+StartArmor[6]+StartArmor[7]),
643  (armor[1]+armor[3]+armor[5]+armor[7])/(float) (StartArmor[1]+StartArmor[3]+StartArmor[5]+StartArmor[7]),
644  x,
645  y, w/2, h/2,
646  invertfrontback,
647  GFXColor( iarmorcolor[0], iarmorcolor[1], iarmorcolor[2],
648  iarmorcolor[3] ),
649  GFXColor( marmorcolor[0], marmorcolor[1], marmorcolor[2], marmorcolor[3] ),
650  GFXColor( oarmorcolor[0], oarmorcolor[1], oarmorcolor[2], oarmorcolor[3] ) );
651  }
652 }
653 */
654 
655 void VDU::DrawVDUShield( Unit *parent )
656 {
657  float x, y, w, h;
658  GetPosition( x, y );
659  GetSize( w, h );
660  //Use margins specified from config file
661  static float width_factor = XMLSupport::parse_float( vs_config->getVariable( "graphics", "reduced_vdus_width", "0" ) );
662  static float height_factor = XMLSupport::parse_float( vs_config->getVariable( "graphics", "reduced_vdus_height", "0" ) );
663  w = w-width_factor;
664  h = h+height_factor;
665 
666  h = fabs( h*.6 );
667  w = fabs( w*.6 );
668  //static bool invert_friendly_shields =
669  // XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "invert_friendly_shields", "false" ) );
670  //DrawShieldArmor(parent,StartArmor,x,y,w,h,invert_friendly_shields);
671  GFXColor4f( 1, parent->GetHullPercent(), parent->GetHullPercent(), 1 );
672  GFXEnable( TEXTURE0 );
673  GFXColor4f( 1, parent->GetHullPercent(), parent->GetHullPercent(), 1 );
674  static bool invert_friendly_sprite =
675  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "invert_friendly_sprite", "false" ) );
676  DrawHUDSprite( this, parent->getHudImage(), .25, x, y, w, h, parent->GetHullPercent(),
677  parent->GetHullPercent(), parent->GetHullPercent(), parent->GetHullPercent(),
678  parent->GetHullPercent(), true, invert_friendly_sprite );
679 }
680 
681 #define RETURN_STATIC_SPRITE( name ) \
682  do { \
683  static VSSprite s( name ".sprite" ); \
684  static VSSprite sCompat( name ".spr" ); \
685  if ( s.LoadSuccess() ) \
686  return &s; \
687  else \
688  return &sCompat; \
689  } \
690  while (0)
691 
693 {
694  RETURN_STATIC_SPRITE( "shield_quad" );
695 }
696 
698 {
699  RETURN_STATIC_SPRITE( "shield_dual" );
700 }
701 
703 {
704  RETURN_STATIC_SPRITE( "jump-hud" );
705 }
706 
708 {
709  RETURN_STATIC_SPRITE( "sun-hud" );
710 }
711 
713 {
714  RETURN_STATIC_SPRITE( "planet-hud" );
715 }
716 
718 {
719  RETURN_STATIC_SPRITE( "nav-hud" );
720 }
721 
722 double DistanceTwoTargets( Unit *parent, Unit *target )
723 {
724  double tmp =
725  ( ( parent->Position()-target->Position() ).Magnitude()-( (target->isUnit() == PLANETPTR) ? target->rSize() : 0 ) );
726  if (tmp < 0) return 0;
727  return tmp;
728 }
729 
731 {
732  char str[128];
733 };
734 
736 {
737  //OVERRUN
738  struct retString128 qr;
739  static float game_speed = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
740  static bool lie = XMLSupport::parse_bool( vs_config->getVariable( "physics", "game_speed_lying", "true" ) );
741  if (lie) {
742  sprintf( qr.str, "%.2lf", distance/game_speed );
743  } else {
744  if (distance < 20000) //use meters up to 20,000 m
745  sprintf( qr.str, "%.0lf meters", distance );
746  else if (distance < 100000) //use kilometers with two decimals up to 100 km
747  sprintf( qr.str, "%.2lf kilometers", distance/1000 );
748  else if (distance < 299792458) //use kilometers without decimals up to 299792.458 km
749  sprintf( qr.str, "%.0lf kilometers", distance/1000 );
750  else if ( distance < (120*299792458.) ) //use light seconds up to 120
751  sprintf( qr.str, "%.2lf light seconds", distance/299792458 );
752  else if ( distance < (120*60*299792458.) ) //use light minutes up to 120
753  sprintf( qr.str, "%.2lf light minutes", distance/(60*299792458.) );
754  else if ( distance < (48*3600*299792458.) ) //use light hours up to 48
755  sprintf( qr.str, "%.2lf light hours", distance/(3600*299792458.) );
756  else if ( distance < (365*24*3600*299792458.) ) //use light days up to 365
757  sprintf( qr.str, "%.2lf light days", distance/(24*3600*299792458.) );
758  else //use light years
759  sprintf( qr.str, "%.2lf lightyears", distance/(365*24*3600*299792458.) );
760  }
761  return qr;
762 }
763 
764 static float OneOfFour( float a, float b, float c, float d )
765 {
766  int aa = a != 0 ? 1 : 0;
767  int bb = b != 0 ? 1 : 0;
768  int cc = c != 0 ? 1 : 0;
769  int dd = d != 0 ? 1 : 0;
770  if (aa+bb+cc+dd == 4)
771  return 1;
772  if (aa+bb+cc+dd == 3)
773  return .85;
774  if (aa+bb+cc+dd == 2)
775  return .4;
776  return 0;
777 }
778 
779 static float TwoOfFour( float a, float b, float c, float d )
780 {
781  int aa = a != 0 ? 1 : 0;
782  int bb = b != 0 ? 1 : 0;
783  int cc = c != 0 ? 1 : 0;
784  int dd = d != 0 ? 1 : 0;
785  if (aa+bb+cc+dd == 4)
786  return 1;
787  if (aa+bb+cc+dd == 3)
788  return 1;
789  if (aa+bb+cc+dd == 2)
790  return .8;
791  if (aa+bb+cc+dd == 1)
792  return .4;
793  return 0;
794 }
795 
796 void VDU::DrawTarget( GameCockpit *cp, Unit *parent, Unit *target )
797 {
798  float x, y, w, h;
799  float fs = target->FShieldData();
800  float rs = target->RShieldData();
801  float ls = target->LShieldData();
802  float bs = target->BShieldData();
803  GFXEnable( TEXTURE0 );
804  static bool invert_target_sprite =
805  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "invert_target_sprite", "false" ) );
806  static bool invert_target_shields =
807  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "invert_target_shields", "false" ) );
808  float armor[8];
809  target->ArmorData( armor );
810  float au, ar, al, ad;
811  au = OneOfFour( armor[0], armor[2], armor[4], armor[6] );
812  ar = TwoOfFour( armor[0], armor[1], armor[4], armor[5] );
813  al = TwoOfFour( armor[2], armor[3], armor[6], armor[7] );
814  ad = OneOfFour( armor[1], armor[3], armor[5], armor[7] );
815  if (invert_target_shields) {
816  float tmp = au;
817  au = ad;
818  ad = tmp;
819  }
820  if (target->isUnit() == PLANETPTR)
821  au = ar = al = ad = target->GetHullPercent();
822  DrawHUDSprite( this, ( (target->isUnit() != PLANETPTR || target->getHudImage() != NULL) ? target->getHudImage()
823  : ( target->GetDestinations().size() != 0 ? getJumpImage()
824  : ( ( (Planet*) target )->hasLights() ? getSunImage()
825  : ( target->getFullname().find(
826  "invisible" ) != string::npos ? getNavImage() : getPlanetImage() ) ) ) ), .6, x, y, w, h,
827  au, ar, al, ad,
828  target->GetHullPercent(),
829  true, invert_target_sprite );
830 
831  GFXDisable( TEXTURE0 );
832  //sprintf (t,"\n%4.1f %4.1f",target->FShieldData()*100,target->RShieldData()*100);
833  double mm = 0;
834  string unitandfg = getUnitNameAndFgNoBase( target ).c_str();
835  static bool out_of_cone_information =
836  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "out_of_cone_distance", "false" ) );
837  bool inrange = parent->InRange( target, mm, out_of_cone_information == false && !UnitUtil::isSignificant(
838  target ), false, false );
839  if (inrange) {
840  static int neut = FactionUtil::GetFactionIndex( "neutral" );
841  static int upgr = FactionUtil::GetFactionIndex( "upgrades" );
842  if (target->faction != neut && target->faction != upgr) {
843  static bool printFac = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "print_faction", "true" ) );
844  if (printFac)
845  unitandfg += std::string( "\n" )+FactionUtil::GetFaction( target->faction );
846  }
847  }
848  unitandfg += std::string( "\n" );
849  unitandfg += cp->getTargetLabel();
850  static float background_alpha =
851  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
852  GFXColor tpbg = tp->bgcol;
853  bool automatte = (0 == tpbg.a);
854  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
855  tp->Draw( MangleString( unitandfg, _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), 0, true, false, automatte );
856  tp->bgcol = tpbg;
857  static float auto_message_lim = XMLSupport::parse_float( vs_config->getVariable( "graphics", "auto_message_time_lim", "5" ) );
858  float delautotime = UniverseUtil::GetGameTime()-cp->autoMessageTime;
859  bool draw_auto_message = (delautotime < auto_message_lim && cp->autoMessage.length() != 0);
860  if (inrange) {
861  char st[1024];
862  memset( st, '\n', 1023 );
863  int tmplim = rows-3;
864  if (draw_auto_message == true)
865  tmplim--;
866  st[tmplim] = '\0';
867  std::string newst( st );
868  if (draw_auto_message)
869  newst += cp->autoMessage+"\n";
870  newst += '\n';
871  double dist = DistanceTwoTargets( parent, target );
872  double actual_range = dist;
873  if ( (target->isUnit() == PLANETPTR) && (target->CanDockWithMe( parent, 1 ) != -1) ) {
874  dist -= target->rSize()*UniverseUtil::getPlanetRadiusPercent();
875  if (dist < 0)
876  newst += string( "Docking: Ready" );
877  else if ( dist < target->rSize() )
878  newst += string( "Docking: " )+string( PrettyDistanceString( dist ).str );
879  }
880  newst += string( "\nRange: " )+string( PrettyDistanceString( actual_range ).str );
881  static float background_alpha =
882  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
883  GFXColor tpbg = tp->bgcol;
884  bool automatte = (0 == tpbg.a);
885  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
886  tp->Draw( MangleString( newst, _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), 0, true, false, automatte );
887  tp->bgcol = tpbg;
888  static float ishieldcolor[4] = {.4, .4, 1, 1};
889  static float mshieldcolor[4] = {.4, .4, 1, 1};
890  static float oshieldcolor[4] = {.4, .4, 1, 1};
891  //code replaced by target shields defined in cockpit.cpt files, preserve for mods
892  static bool builtin_shields =
893  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "vdu_builtin_shields", "false" ) );
894  if (builtin_shields) {
895  DrawShield( fs, rs, ls, bs, x, y, w, h, invert_target_shields,
896  GFXColor( ishieldcolor[0], ishieldcolor[1], ishieldcolor[2], ishieldcolor[3] ),
897  GFXColor( mshieldcolor[0], mshieldcolor[1], mshieldcolor[2], mshieldcolor[3] ),
898  GFXColor( oshieldcolor[0], oshieldcolor[1], oshieldcolor[2], oshieldcolor[3] ) );
899  }
900  //this is a possibility to draw target shields but without gauging
901  //the gauging method is implemented in cockpit.cpp
902 /* if (target->isUnit()!=PLANETPTR) {
903  * GFXEnable (TEXTURE0);
904  * //Dev:GFXColor4f (1,target->GetHullPercent(),target->GetHullPercent(),1);
905  * DrawHUDSprite(this,getTargetQuadShield(),0.9,x,y,w,h,fs,rs,ls,bs,target->GetHullPercent(),true,invert_target_sprite);
906  * GFXDisable (TEXTURE0);
907  * }*/
908  GFXColor4f( 1, 1, 1, 1 );
909  } else {
910  static float background_alpha =
911  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
912  GFXColor tpbg = tp->bgcol;
913  bool automatte = (0 == tpbg.a);
914  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
915  if (draw_auto_message)
916  tp->Draw( MangleString( std::string( "\n" )+cp->autoMessage, _Universe->AccessCamera()->GetNebula()
917  != NULL ? .4 : 0 ), 0, true, false, automatte );
918  else
919  tp->Draw( MangleString( "\n[OutOfRange]",
920  _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), 0, true, false, automatte );
921  tp->bgcol = tpbg;
922  }
923 }
924 
925 void VDU::DrawMessages( GameCockpit *parentcp, Unit *target )
926 {
927  static bool network_draw_messages = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "network_chat_text", "true" ) );
928  static bool draw_messages = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "chat_text", "true" ) );
929 
930  if (Network != NULL && network_draw_messages == false)
931  return;
932  if (Network == NULL && draw_messages == false)
933  return;
934 
935  string fullstr;
936  double nowtime = mission->getGametime(); //for message display duration
937 
938  string targetstr;
939  //int msglen = targetstr.size();
940  int rows_needed = 0; //msglen/(cols>0?cols:1);
942  int rows_used = rows_needed;
943  vector< std::string >whoNOT;
944  whoNOT.push_back( "briefing" );
945  whoNOT.push_back( "news" );
946  whoNOT.push_back( "bar" );
947 
948  static float oldtime = XMLSupport::parse_float( vs_config->getVariable( "graphics", "last_message_time", "5" ) );
949  static int num_messages = XMLSupport::parse_int( vs_config->getVariable( "graphics", "num_messages", "2" ) );
950  static bool showStardate = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "show_stardate", "true" ) );
951 
952  vector< std::string >message_people; //should be "all", parent's name
953  gameMessage lastmsg;
954  int row_lim = ( (scrolloffset< 0 || num_messages >rows) ? rows : num_messages );
955 
956  for (int i = scrolloffset < 0 ? -scrolloffset-1 : 0;
957  rows_used < row_lim && mc->last( i, lastmsg, message_people, whoNOT );
958  i++) {
959  char timebuf[100];
960  double sendtime = lastmsg.time;
961  if (scrolloffset >= 0 && sendtime < nowtime-oldtime*4)
962  break;
963  if ( sendtime <= nowtime && (sendtime > nowtime-oldtime || scrolloffset < 0) ) {
964  if (showStardate) {
966  sprintf( timebuf, "%s", stardate.c_str() );
967  } else {
968  int sendtime_mins = (int) (sendtime/60.0);
969  int sendtime_secs = (int) (sendtime-sendtime_mins*60);
970  sprintf( timebuf, "%d.%02d", sendtime_mins, sendtime_secs );
971  }
972 
973  string mymsg;
974  if (lastmsg.from != "game")
975  mymsg = lastmsg.from + " (" + timebuf + "): " + lastmsg.message;
976  else
977  mymsg = string( timebuf )+": "+lastmsg.message;
978  int msglen = mymsg.size();
979  int rows_needed = (int) ( msglen/(1.6*cols) );
980  fullstr = mymsg+"\n"+fullstr;
981  //fullstr=fullstr+mymsg+"\n";
982 
983  rows_used += rows_needed+1;
984  //cout << "nav " << mymsg << " rows " << rows_needed << endl;
985  }
986  }
987  static std::string newline( "\n" );
988  std::string textMessage = parentcp->textMessage;
989  if (parentcp->editingTextMessage) {
990  textMessage = "Chat> "+textMessage;
991  if (floor( nowtime/2 ) != floor( nowtime )/2.0)
992  textMessage += "]";
993  }
994  /*
995  * if (rows_used>=row_lim&&parentcp->editingTextMessage) {
996  * size_t where=fullstr.find(newline);
997  * if (where!=string::npos) {
998  * if (where>1.6*cols) {
999  * where=(size_t)(1.6*cols+1);
1000  * }
1001  * fullstr=fullstr.substr(where+1);
1002  * }
1003  * }
1004  */
1005  if (parentcp->editingTextMessage) {
1006  fullstr += textMessage;
1007  fullstr += newline;
1008  }
1009  static string message_prefix =
1010  XMLSupport::escaped_string( vs_config->getVariable( "graphics", "hud", "message_prefix", "" ) );
1011  fullstr = targetstr+fullstr;
1012  static float background_alpha =
1013  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1014  GFXColor tpbg = tp->bgcol;
1015  bool automatte = (0 == tpbg.a);
1016  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1017  tp->Draw( message_prefix+MangleString( fullstr,
1018  _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), 0, true, false, automatte );
1019  tp->bgcol = tpbg;
1020 }
1021 
1022 void VDU::DrawScanningMessage()
1023 {
1024  //tp->Draw(MangleString ("Scanning target...",_Universe->AccessCamera()->GetNebula()!=NULL?.4:0),0,true);
1025 }
1026 
1027 bool VDU::SetCommAnimation( Animation *ani, Unit *un, bool force )
1028 {
1029  if (comm_ani == NULL || force) {
1030  if (posmodes&COMM) {
1031  if (ani != NULL && comm_ani == NULL)
1032  thismode.push_back( COMM );
1033  else if (comm_ani != NULL && thismode.size() > 1 && ani != NULL)
1034  thismode.back() = COMM;
1035  if (ani) {
1036  comm_ani = ani;
1037  ani->Reset();
1038  }
1039  communicating.SetUnit( un );
1040  return true;
1041  }
1042  }
1043  return false;
1044 }
1045 
1047 {
1048  if (comm_ani)
1049  if ( !comm_ani->Done() )
1050  return communicating.GetUnit();
1051  return NULL;
1052 }
1053 
1054 void VDU::DrawNav( GameCockpit *cp, Unit *you, Unit *targ, const Vector &nav )
1055 {
1056  //Unit * you = _Universe->AccessCockpit()->GetParent();
1057  //Unit * targ = you!=NULL?you->Target():NULL;
1058  //static float game_speed = XMLSupport::parse_float( vs_config->getVariable( "physics", "game_speed", "1" ) );
1059  //static bool lie = XMLSupport::parse_bool( vs_config->getVariable( "physics", "game_speed_lying", "true" ) );
1060  string nam = "none";
1061  if (targ)
1062  nam = reformatName( targ->name );
1064  //std::string systemname = _Universe->activeStarSystem()->getFileName(); // as Sector/System
1065  //string sectorname = getStarSystemSector(systemname);
1066  //printf ("(debug) Sector: %s\n", sectorname.c_str());
1067  std::string navdata =
1068  std::string( "#ff0000Sector:\n #ffff00"+getStarSystemSector(
1070  +"\n\n#ff0000System:\n #ffff00" )+_Universe->activeStarSystem()->getName()+" ("
1071  +FactionUtil::GetFactionName( faction )
1072  +")\n\n#ff0000Target:\n #ffff00"+( targ ? getUnitNameAndFgNoBase( targ ) : std::string( "Nothing" ) )
1073  +"\n\n#ff0000Range: #ffff00"+std::string( PrettyDistanceString( ( (you && targ) ? DistanceTwoTargets( you,
1074  targ ) : 0.0 ) )
1075  .
1076  str );
1077  static float auto_message_lim = XMLSupport::parse_float( vs_config->getVariable( "graphics", "auto_message_time_lim", "5" ) );
1078  float delautotime = UniverseUtil::GetGameTime()-cp->autoMessageTime;
1079  bool draw_auto_message = (delautotime < auto_message_lim && cp->autoMessage.length() != 0);
1080  std::string msg = cp->autoMessage;
1081  std::string::size_type where = msg.find( "#" );
1082  while (where != std::string::npos) {
1083  msg = msg.substr( 0, where )+msg.substr( where+7 );
1084  where = msg.find( "#" );
1085  }
1086  msg = std::string( "\n\n#ffff00 " )+msg;
1087  static float background_alpha =
1088  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1089  GFXColor tpbg = tp->bgcol;
1090  bool automatte = (0 == tpbg.a);
1091  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1092  tp->Draw( MangleString( navdata+( draw_auto_message ? msg : std::string() ), _Universe->AccessCamera()->GetNebula()
1093  != NULL ? .4 : 0 ), scrolloffset, true, true, automatte );
1094  tp->bgcol = tpbg;
1095 }
1096 
1097 void VDU::DrawComm()
1098 {
1099  if (comm_ani != NULL) {
1100  GFXDisable( TEXTURE1 );
1101  GFXEnable( TEXTURE0 );
1102  GFXDisable( LIGHTING );
1103 
1104  static bool switch_back_from_comms =
1105  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "switch_back_from_comms", "true" ) );
1106 
1107  comm_ani->DrawAsVSSprite( this );
1108  if ( comm_ani->Done() ) {
1109  if (thismode.size() > 1) {
1110  if (switch_back_from_comms) {
1111  thismode.pop_back();
1112  } else {
1113  unsigned int blah = thismode.back();
1114  thismode.pop_back();
1115  thismode.back() = blah;
1116  }
1117  }
1118  communicating.SetUnit( NULL );
1119  comm_ani = NULL;
1120  }
1121  GFXDisable( TEXTURE0 );
1122  } else {
1123  static string message_prefix =
1124  XMLSupport::escaped_string( vs_config->getVariable( "graphics", "hud", "message_prefix", "" ) );
1125  static float background_alpha =
1126  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1127  GFXColor tpbg = tp->bgcol;
1128  bool automatte = (0 == tpbg.a);
1129  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1130  tp->Draw( message_prefix
1133  != NULL ? .4 : 0 ), scrolloffset, true, false, automatte );
1134  tp->bgcol = tpbg;
1135  }
1136 }
1137 
1138 void VDU::DrawManifest( Unit *parent, Unit *target )
1139 {
1140  //zadeVDUmanifest
1141  static string manifest_heading =
1142  XMLSupport::escaped_string( vs_config->getVariable( "graphics", "hud", "manifest_heading", "Manifest\n" ) );
1143  static bool simple_manifest =
1144  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "simple_manifest", "false" ) );
1145  string retval( manifest_heading );
1146  if (target != parent && simple_manifest == false)
1147  retval += string( "Tgt: " )+reformatName( target->name )+string( "\n" );
1148  else
1149  retval += string( "--------\nCredits: " )+tostring( (int) _Universe->AccessCockpit()->credits )+string( "\n" );
1150  unsigned int load = 0;
1151  unsigned int cred = 0;
1152  unsigned int vol = 0;
1153  unsigned int numCargo = target->numCargo();
1154  unsigned int maxCargo = 16;
1155  string lastCat;
1156  for (unsigned int i = 0; i < numCargo; i++)
1157  if ( (target->GetCargo( i ).GetCategory().find( "upgrades/" ) != 0)
1158  && (target->GetCargo( i ).quantity > 0) ) {
1159  Cargo ca = target->GetCargo( i );
1160  int cq = ca.quantity;
1161  float cm = ca.mass;
1162  float cv = ca.volume;
1163  float cp = ca.price;
1164  string cc = ca.GetCategory();
1165  cred += cq*(int) cp;
1166  vol += (int) ( (float) cq*cv );
1167  load += (int) ( (float) cq*cm );
1168  if ( ( (target == parent) || (maxCargo+i >= numCargo) || lastCat.compare( cc ) ) && (maxCargo > 0) ) {
1169  maxCargo--;
1170  lastCat = cc;
1171  if (target == parent && !simple_manifest) {
1172  //retval += string("(") + tostring(cq)+string(") "); // show quantity
1173  if (cm >= cv)
1174  retval += tostring( (int) ( (float) cq*cm ) )+string( "t " );
1175  else
1176  retval += tostring( (int) ( (float) cq*cv ) )+string( "m3 " );
1177  } else {
1178  retval += tostring( (int) cq )+" ";
1179  }
1180  retval += target->GetManifest( i, parent, parent->GetVelocity() );
1181  if (!simple_manifest)
1182  retval += string( " " )+tostring( ( (target == parent) ? cq : 1 )*(int) cp )
1183  +string( "Cr." );
1184  retval += "\n";
1185  }
1186  }
1187  if (target == parent && !simple_manifest)
1188  retval += string( "--------\nLoad: " )+tostring( load )+string( "t " )
1189  +tostring( vol )+string( "m3 " )+tostring( cred )+string( "Cr.\n" );
1190  static float background_alpha =
1191  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1192  GFXColor tpbg = tp->bgcol;
1193  bool automatte = (0 == tpbg.a);
1194  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1195  tp->Draw( MangleString( retval,
1196  _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), scrolloffset, true, false, automatte );
1197  tp->bgcol = tpbg;
1198 }
1199 
1200 static void DrawGun( Vector pos, float w, float h, weapon_info::MOUNT_SIZE sz )
1201 {
1202  w = fabs( w );
1203  h = fabs( h );
1204  float oox = 1./g_game.x_resolution;
1205  float ooy = 1./g_game.y_resolution;
1206  pos.j -= h/3.8;
1207  if (sz == weapon_info::NOWEAP) {
1208  GFXPointSize( 4 );
1209  GFXBegin( GFXPOINT );
1210  GFXVertexf( pos );
1211  GFXEnd();
1212  GFXPointSize( 1 );
1213  } else if (sz < weapon_info::SPECIAL) {
1214  GFXBegin( GFXLINE );
1215  GFXVertex3d( pos.i+oox, pos.j, 0 );
1216  GFXVertex3d( pos.i+oox, pos.j-h/15, 0 );
1217  GFXVertex3d( pos.i-oox, pos.j, 0 );
1218  GFXVertex3d( pos.i-oox, pos.j-h/15, 0 );
1219  GFXVertex3d( pos.i+oox, pos.j-h/15, 0 );
1220  GFXVertex3d( pos.i-oox, pos.j-h/15, 0 );
1221  if (sz == weapon_info::LIGHT) {
1222  GFXVertex3d( pos.i, pos.j, 0 );
1223  GFXVertex3d( pos.i, pos.j+h/4, 0 );
1224  GFXVertex3d( pos.i, pos.j+h/4+ooy*2, 0 );
1225  GFXVertex3d( pos.i, pos.j+h/4+ooy*5, 0 );
1226  } else if (sz == weapon_info::MEDIUM) {
1227  GFXVertex3d( pos.i, pos.j, 0 );
1228  GFXVertex3d( pos.i, pos.j+h/5, 0 );
1229  GFXVertex3d( pos.i, pos.j+h/5+ooy*4, 0 );
1230  GFXVertex3d( pos.i, pos.j+h/5+ooy*5, 0 );
1231  GFXVertex3d( pos.i+oox, pos.j+h/5+ooy*2, 0 );
1232  GFXVertex3d( pos.i-oox, pos.j+h/5+ooy*2, 0 );
1233  } else if (sz == weapon_info::HEAVY) {
1234  GFXVertex3d( pos.i, pos.j, 0 );
1235  GFXVertex3d( pos.i, pos.j+h/5, 0 );
1236  GFXVertex3d( pos.i, pos.j+h/5+ooy*4, 0 );
1237  GFXVertex3d( pos.i, pos.j+h/5+ooy*5, 0 );
1238  GFXVertex3d( pos.i+2*oox, pos.j+h/5+ooy*3, 0 );
1239  GFXVertex3d( pos.i, pos.j+h/5+ooy*2, 0 );
1240  GFXVertex3d( pos.i-2*oox, pos.j+h/5+ooy*3, 0 );
1241  GFXVertex3d( pos.i, pos.j+h/5+ooy*2, 0 );
1242  } else {
1243  //capship gun
1244  GFXVertex3d( pos.i, pos.j, 0 );
1245  GFXVertex3d( pos.i, pos.j+h/6, 0 );
1246  GFXVertex3d( pos.i, pos.j+h/6+ooy*6, 0 );
1247  GFXVertex3d( pos.i, pos.j+h/6+ooy*7, 0 );
1248  GFXVertex3d( pos.i-oox, pos.j+h/6+ooy*2, 0 );
1249  GFXVertex3d( pos.i+oox, pos.j+h/6+ooy*2, 0 );
1250  GFXVertex3d( pos.i-2*oox, pos.j+h/6+ooy*4, 0 );
1251  GFXVertex3d( pos.i+2*oox, pos.j+h/6+ooy*4, 0 );
1252  }
1253  GFXEnd();
1254  } else if (sz == weapon_info::SPECIAL || sz == weapon_info::SPECIALMISSILE) {
1255  GFXPointSize( 4 );
1256  GFXBegin( GFXPOINT );
1257  GFXVertexf( pos );
1258  GFXEnd();
1259  GFXPointSize( 1 ); //classified... FIXME
1260  } else if (sz < weapon_info::HEAVYMISSILE) {
1261  GFXBegin( GFXLINE );
1262  GFXVertex3d( pos.i, pos.j-h/8, 0 );
1263  GFXVertex3d( pos.i, pos.j+h/8, 0 );
1264  GFXVertex3d( pos.i+2*oox, pos.j-h/8+2*ooy, 0 );
1265  GFXVertex3d( pos.i-2*oox, pos.j-h/8+2*ooy, 0 );
1266  GFXEnd();
1267  } else if (sz <= weapon_info::CAPSHIPHEAVYMISSILE) {
1268  GFXBegin( GFXLINE );
1269  GFXVertex3d( pos.i, pos.j-h/6, 0 );
1270  GFXVertex3d( pos.i, pos.j+h/6, 0 );
1271  GFXVertex3d( pos.i+3*oox, pos.j-h/6+2*ooy, 0 );
1272  GFXVertex3d( pos.i-3*oox, pos.j-h/6+2*ooy, 0 );
1273  GFXVertex3d( pos.i+oox, pos.j-h/6, 0 );
1274  GFXVertex3d( pos.i+oox, pos.j+h/9, 0 );
1275  GFXVertex3d( pos.i-oox, pos.j-h/6, 0 );
1276  GFXVertex3d( pos.i-oox, pos.j+h/9, 0 );
1277  GFXEnd();
1278  }
1279 }
1280 
1281 extern const char *DamagedCategory;
1282 
1283 void VDU::DrawDamage( Unit *parent )
1284 {
1285  //VDUdamage
1286  float x, y, w, h;
1287  //float th;
1288  //char st[1024];
1289  GFXColor4f( 1, parent->GetHull()/(*maxhull), parent->GetHull()/(*maxhull), 1 );
1290  GFXEnable( TEXTURE0 );
1291  float armor[8];
1292  parent->ArmorData( armor );
1293  static bool draw_damage_sprite =
1294  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_damage_sprite", "true" ) );
1295  DrawHUDSprite( this, draw_damage_sprite ? parent->getHudImage() : NULL, .6, x, y, w, h,
1296  (armor[0]+armor[2]+armor[4]+armor[6])/(float) (StartArmor[0]+StartArmor[2]+StartArmor[4]+StartArmor[6]),
1297  (armor[0]+armor[1]+armor[4]+armor[5])/(float) (StartArmor[0]+StartArmor[1]+StartArmor[4]+StartArmor[5]),
1298  (armor[2]+armor[3]+armor[6]+armor[7])/(float) (StartArmor[2]+StartArmor[3]+StartArmor[6]+StartArmor[7]),
1299  (armor[1]+armor[3]+armor[5]
1300  +armor[7])/(float) (StartArmor[1]+StartArmor[3]+StartArmor[5]+StartArmor[7]),
1301  parent->GetHull()/(*maxhull), true, false );
1302  GFXDisable( TEXTURE0 );
1303  //Unit *thr = parent->Threat();
1304  parent->Threat();
1305  std::string fullname( getUnitNameAndFgNoBase( parent ) );
1306  //sprintf (st,"%s\nHull: %.3f",blah.c_str(),parent->GetHull());
1307  //tp->Draw (MangleString (st,_Universe->AccessCamera()->GetNebula()!=NULL?.5:0),0,true);
1308  char ecmstatus[256];
1309  ecmstatus[0] = '\0';
1310  static bool print_ecm = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "print_ecm_status", "true" ) );
1311  if (print_ecm) {
1312  if (UnitUtil::getECM(parent) > 0) {
1313  GFXColor4f( 0, 1, 0, .5 );
1314  strcpy( ecmstatus, "ECM Active" );
1315  static float s = 0;
1316  s += .125*SIMULATION_ATOM;
1317  if (s > 1)
1318  s = 0;
1319  DrawShield( 0, s, s, 0, x, y, w, h, false, GFXColor( 0, 1, 0 ), GFXColor( 0, .75, 0 ), GFXColor( 0, .5, 0 ) );
1320  }
1321  }
1322  GFXColor4f( 1, 1, 1, 1 );
1323 
1324 /*
1325  *
1326  * Cargo & GetCargo (unsigned int i);
1327  * void GetCargoCat (const std::string &category, vector <Cargo> &cat);
1328  * ///below function returns NULL if not found
1329  * Cargo * GetCargo (const std::string &s, unsigned int &i);
1330  *
1331  */
1332 
1333  //*******************************************************zade
1334 
1335  //char hullval[128];
1336  //sprintf (hullval,"%.3f",parent->GetHull());
1337  //string retval (fullname+"\nHull: "+hullval+"\n");
1338  static float cfullpower[4] = {1, 1, 1, 1};
1339  static float cdamaged[4] = {1, 0, 0, 1};
1340  static float chdamaged[4] = {1, 1, 0, 1};
1341  static float cdestroyed[4] = {.2, .2, .2, 1};
1342  static bool init = false;
1343  if (!init) {
1344  init = true;
1345  vs_config->getColor( "default", "hud_repair_repaired", cfullpower, true );
1346  vs_config->getColor( "default", "hud_repair_half_damaged", chdamaged, true );
1347  vs_config->getColor( "default", "hud_repair_damaged", cdamaged, true );
1348  vs_config->getColor( "default", "hud_repair_destroyed", cdestroyed, true );
1349  }
1350  colorstring fpstring = colToString( GFXColor( cfullpower[0], cfullpower[1], cfullpower[2], cfullpower[3] ) );
1351  static string damage_report_heading =
1352  XMLSupport::escaped_string( vs_config->getVariable( "graphics", "hud", "damage_report_heading",
1353  "#00ff00DAMAGE REPORT\n\n" ) );
1354  string retval( damage_report_heading );
1355  retval += fpstring.str;
1356  unsigned int numCargo = parent->numCargo();
1357  double percent_working = 0.88;
1358  static std::string non_repair_screen_cargo = vs_config->getVariable( "graphics",
1359  "hud",
1360  "not_included_in_damage_report",
1361  "plasteel_hull tungsten_hull isometal_hull" );
1362  static bool print_percent_working =
1363  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "print_damage_percent", "true" ) );
1364 
1365 #define REPORTITEM(percent_working, max_functionality, print_percent_working, component_string) \
1366  do { \
1367  GFXColor final_color( (chdamaged[0]*percent_working)+( cdamaged[0]*(1.0-percent_working) ), \
1368  (chdamaged[1]*percent_working)+( cdamaged[1]*(1.0-percent_working) ), \
1369  (chdamaged[2]*percent_working)+( cdamaged[2]*(1.0-percent_working) ), \
1370  (chdamaged[3]*percent_working)+( cdamaged[3]*(1.0-percent_working) ) ); \
1371  if (percent_working == 0.0) \
1372  final_color = GFXColor( cdestroyed[0], cdestroyed[1], cdestroyed[2], cdestroyed[3] ); /*dead = grey*/ \
1373  std::string trailer; \
1374  if (percent_working < max_functionality) \
1375  retval += colToString( final_color ).str; \
1376  else \
1377  retval += fpstring.str; \
1378  trailer = fpstring.str; \
1379  retval += component_string; \
1380  if (print_percent_working) \
1381  retval += string( " (" )+tostring( int(percent_working*100) )+string( "%)" ); \
1382  retval += trailer+std::string( "\n" ); \
1383  } while(0)
1384 
1385 #define REPORTINTEGRATED(which, which_key, which_name_default) \
1386  do { \
1387  static string name = vs_config->getVariable( "graphics", "hud", which_key, which_name_default ); \
1388  if (!name.empty()) { \
1389  REPORTITEM( parent->pImage->which##Functionality, parent->pImage->which##FunctionalityMax, \
1390  print_percent_working, \
1391  name \
1392  ); \
1393  } \
1394  } while(0)
1395 
1396 #define REPORTINTEGRATEDFLAG(which, which_key, which_name_default) \
1397  do { \
1398  static string name = vs_config->getVariable( "graphics", "hud", which_key, which_name_default ); \
1399  if (!name.empty()) { \
1400  REPORTITEM( ((parent->damages & which) ? 0.1 : 1.0), 1.0, \
1401  false, \
1402  name \
1403  ); \
1404  } \
1405  } while(0)
1406 
1407 
1408  for (unsigned int i = 0; i < numCargo; i++) {
1409  percent_working = 0.88; //cargo.damage
1410  Cargo &the_cargo = parent->GetCargo( i );
1411  bool damaged = the_cargo.GetCategory().find( DamagedCategory ) == 0;
1412  if ( damaged
1413  || ( the_cargo.GetCategory().find( "upgrades/" ) == 0
1414  && the_cargo.installed
1415  && the_cargo.GetContent().find( "mult_" ) != 0
1416  && the_cargo.GetContent().find( "add_" ) != 0
1417  && non_repair_screen_cargo.find( the_cargo.GetContent() )
1418  == std::string::npos) ) {
1419  percent_working = UnitUtil::PercentOperational( parent, the_cargo.content, the_cargo.category, false );
1420  //retval+=parent->GetManifest (i,parent,parent->GetVelocity())+string (" (")+tostring (int(percent_working*100))+string ("%)" +the_cargo.GetCategory()+"\n");
1421  REPORTITEM(percent_working, 1.0, print_percent_working, parent->GetManifest( i, parent, parent->GetVelocity() ));
1422  }
1423  }
1424  if (parent->pImage != NULL) {
1425  // Integrated systems with percent working values
1426  REPORTINTEGRATED(LifeSupport, "damage.names.life_support", "Life Support");
1427  REPORTINTEGRATED(fireControl, "damage.names.fire_control", "Fire Control");
1428  REPORTINTEGRATED(SPECDrive, "damage.names.spec_drive", "SPEC Drive");
1429  REPORTINTEGRATED(Comm, "damage.names.comm", "Comm");
1430 
1431  // Integrated system with boolean damage flags
1432  REPORTINTEGRATEDFLAG(Unit::LIMITS_DAMAGED, "damage.names.limits_name", "Thrusters");
1433  REPORTINTEGRATEDFLAG(Unit::SHIELD_DAMAGED, "damage.names.shield_name", ""); // default invisible, is an upgrade
1434  REPORTINTEGRATEDFLAG(Unit::COMPUTER_DAMAGED, "damage.names.computer_name", "Targetting Computer");
1435  REPORTINTEGRATEDFLAG(Unit::JUMP_DAMAGED, "damage.names.jump_name", ""); // default invisible, is an upgrade
1436  REPORTINTEGRATEDFLAG(Unit::CLOAK_DAMAGED, "damage.names.cloak_name", ""); // default invisible, is an upgrade
1437  }
1438 
1439  retval += ecmstatus;
1440  static float background_alpha =
1441  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1442  GFXColor tpbg = tp->bgcol;
1443  bool automatte = (0 == tpbg.a);
1444  if (automatte)
1445  tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1446  tp->Draw( MangleString( retval,
1447  _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), scrolloffset, true, false, automatte );
1448  tp->bgcol = tpbg;
1449  //*******************************************************
1450 }
1451 
1453 {
1454  viewStyle = vs;
1455 }
1456 
1457 void VDU::DrawStarSystemAgain( float x, float y, float w, float h, VIEWSTYLE viewStyle, Unit *parent, Unit *target )
1458 {
1459 #ifdef CAR_SIM
1460  viewStyle = CP_BACK;
1461 #endif
1462  GFXEnable( DEPTHTEST );
1463  GFXEnable( DEPTHWRITE );
1464  VIEWSTYLE which = viewStyle;
1465  float tmpaspect = g_game.aspect;
1466  g_game.aspect = w/h;
1467  _Universe->AccessCamera( which )->SetSubwindow( x, y, w, h );
1468  _Universe->SelectCamera( which );
1470  _Universe->AccessCockpit()->SetView( viewStyle );
1472  _Universe->AccessCockpit()->SetupViewPort( true );
1473  GFXClear( GFXFALSE );
1474  GFXColor4f( 1, 1, 1, 1 );
1475  _Universe->activeStarSystem()->Draw( false );
1476  g_game.aspect = tmpaspect;
1477  _Universe->AccessCamera( which )->SetSubwindow( 0, 0, 1, 1 );
1478  _Universe->AccessCockpit()->SetView( tmp );
1480  _Universe->AccessCockpit()->SetupViewPort( true );
1482  GFXBlendMode( ONE, ZERO );
1483  GFXDisable( TEXTURE1 );
1484  GFXDisable( TEXTURE0 );
1485  GFXDisable( DEPTHTEST );
1487 #ifndef CAR_SIM
1488  char buf[1024];
1489  bool inrange = false;
1490  if (target) {
1491  double mm = 0;
1492  std::string blah( getUnitNameAndFgNoBase( target ) );
1493  sprintf( buf, "%s\n", blah.c_str() );
1494  static bool out_of_cone_information =
1495  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "out_of_cone_distance", "false" ) );
1496  inrange = parent->InRange( target, mm, out_of_cone_information || !UnitUtil::isSignificant( target ), false, false );
1497  }
1498  static float background_alpha =
1499  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1500  GFXColor tpbg = tp->bgcol;
1501  bool automatte = (0 == tpbg.a);
1502  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1503  tp->Draw( MangleString( buf, _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), 0, true, false, automatte );
1504  tp->bgcol = tpbg;
1505  if (inrange) {
1506  int i = 0;
1507  char st[1024];
1508  for (i = 0; i < rows-1 && i < 128; i++)
1509  st[i] = '\n';
1510  st[i] = '\0';
1511  struct retString128 qr = PrettyDistanceString( DistanceTwoTargets( parent, target ) );
1512  strcat( st, "Range: " );
1513  strcat( st, qr.str );
1514  GFXColor tpbg = tp->bgcol;
1515  bool automatte = (0 == tpbg.a);
1516  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1517  tp->Draw( MangleString( st, _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), 0, true, false, automatte );
1518  tp->bgcol = tpbg;
1519  GFXColor4f( .4, .4, 1, 1 );
1520  GetPosition( x, y );
1521  GetSize( w, h );
1522  static bool draw_vdu_target_info =
1523  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_vdu_view_shields", "true" ) );
1524  if (target && draw_vdu_target_info)
1525  if (viewStyle == CP_PANTARGET) {
1526  DrawHUDSprite( this, getSunImage(), 1, x, y, w, h, 1, 1, 1, 1, 1, false, false );
1527  h = fabs( h*.6 );
1528  w = fabs( w*.6 );
1529 
1530  //static float ishieldcolor[4] = {.4, .4, 1, 1};
1531  //static float mshieldcolor[4] = {.4, .4, 1, 1};
1532  //static float oshieldcolor[4] = {.4, .4, 1, 1};
1533 /*
1534  * static float iarmorcolor[4]={1,.6,0,1};
1535  * static float marmorcolor[4]={1,.6,0,1};
1536  * static float oarmorcolor[4]={1,.6,0,1};
1537  * static bool iarmorcolorloaded=(vs_config->getColor("default","inner_shield_color",ishieldcolor,true),true);
1538  * static bool marmorcolorloaded=(vs_config->getColor("default","middle_shield_color",mshieldcolor,true),true);
1539  * static bool oarmorcolorloaded=(vs_config->getColor("default","outer_shield_color",oshieldcolor,true),true);
1540 */ //uncomment if these are ever actually used
1541 /* static bool invert_view_shields = XMLSupport::parse_bool(vs_config->getVariable("graphics","hud","invert_view_shields","false"));
1542  * DrawShield(target->FShieldData(),target->RShieldData(),target->LShieldData(),target->BShieldData(),x,y,w,h,invert_view_shields,
1543  * GFXColor(ishieldcolor[0],ishieldcolor[1],ishieldcolor[2],ishieldcolor[3]),
1544  * GFXColor(mshieldcolor[0],mshieldcolor[1],mshieldcolor[2],mshieldcolor[3]),
1545  * GFXColor(oshieldcolor[0],oshieldcolor[1],oshieldcolor[2],oshieldcolor[3])); */
1546  }
1547  GFXColor4f( 1, 1, 1, 1 );
1548  } else if (target) {
1549  static float background_alpha =
1550  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1551  GFXColor tpbg = tp->bgcol;
1552  bool automatte = (0 == tpbg.a);
1553  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1554  tp->Draw( MangleString( "\n[OutOfRange]",
1555  _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), 0, true, false, automatte );
1556  tp->bgcol = tpbg;
1557  }
1558 #endif
1559  //_Universe->AccessCockpit()->RestoreViewPort();
1560 }
1561 
1563 {
1564  GFXColor mountcolor;
1565  switch (mnt->ammo != 0 ? mnt->status : 127)
1566  {
1567  case Mount::ACTIVE: {
1568  if (mnt->functionality == 1)
1569  {
1570  float ref = 1;
1571  float tref = mnt->type->Refire();
1572  float cref = 0;
1573  if (mnt->type->type == weapon_info::BEAM) {
1574  if (mnt->ref.gun)
1575  cref = mnt->ref.gun->refireTime();
1576  } else {
1577  cref = mnt->ref.refire;
1578  }
1579  if (cref < tref)
1580  ref = cref/tref;
1581  if (ref == 1.0)
1582  mountcolor = GFXColor( 0, 1, .2 );
1583  else
1584  mountcolor = colLerp( GFXColor( .2, .2, .2 ), GFXColor( 0, 1, 1 ), ref );
1585  } else // damaged
1586  {
1587  mountcolor = colLerp( GFXColor( 1, 0, 0 ), GFXColor( 0, 1, .2 ), mnt->functionality );
1588  }
1589  break;
1590  }
1591  case Mount::DESTROYED:
1592  mountcolor = GFXColor( 1, 0, 0, 1 );
1593  break;
1594  case Mount::INACTIVE:
1595  mountcolor = GFXColor( 1, 1, 1, 1 );
1596  break;
1597  case Mount::UNCHOSEN:
1598  mountcolor = GFXColor( 1, 1, 1, 1 );
1599  break;
1600  case 127:
1601  mountcolor = GFXColor( 0, .2, 0, 1 );
1602  break;
1603  default:
1604  mountcolor = GFXColor( 0, 1, .2, 1 );
1605  break;
1606  }
1607  return mountcolor;
1608 }
1609 
1610 void VDU::DrawWeapon( Unit *parent )
1611 {
1612  static bool drawweapsprite =
1613  XMLSupport::parse_bool( vs_config->getVariable( "graphics", "hud", "draw_weapon_sprite", "false" ) );
1614  float x, y, w, h;
1615  const float percent = .6;
1616  string buf( "#00ff00WEAPONS\n\n#ffffffGuns:#000000" );
1617  int len = buf.length();
1618  string mbuf( "\n#ffffffMissiles:#000000" );
1619  int mlen = mbuf.length();
1620  int count = 1;
1621  int mcount = 1;
1622  GFXEnable( TEXTURE0 );
1623  DrawTargetSpr( drawweapsprite ? parent->getHudImage() : NULL, percent, x, y, w, h );
1624  GFXDisable( TEXTURE0 );
1625  GFXDisable( LIGHTING );
1626  int nummounts = parent->GetNumMounts();
1627  int numave = 0;
1628  GFXColor average( 0, 0, 0, 0 );
1629  for (int i = 0; i < nummounts; i++) {
1630  if (drawweapsprite) {
1631  Vector pos( parent->mounts[i].GetMountLocation() );
1632  pos.i = -pos.i*fabs( w )/parent->rSize()*percent+x;
1633  pos.j = pos.k*fabs( h )/parent->rSize()*percent+y;
1634  pos.k = 0;
1635  DrawGun( pos, w, h, parent->mounts[i].type->size );
1636  }
1637  string ammo =
1638  (parent->mounts[i].ammo >= 0) ? string( "(" )+tostring( parent->mounts[i].ammo )+string( ")" ) : string( "" );
1639  GFXColor mntcolor = MountColor( &parent->mounts[i] );
1640  numave += 1;
1641  average.r += mntcolor.r;
1642  average.g += mntcolor.g;
1643  average.b += mntcolor.b;
1644  average.a += mntcolor.a;
1645  if (i+1 < nummounts && parent->mounts[i].bank) {
1646  //nothing
1647  } else if (parent->mounts[i].status == Mount::ACTIVE || parent->mounts[i].status == Mount::DESTROYED) {
1648  GFXColor mountcolor( average.r/numave, average.g/numave, average.b/numave, average.a/numave );
1649  if (parent->mounts[i].type->size < weapon_info::LIGHTMISSILE) {
1650  buf +=
1651  ( (buf.length()
1652  == (unsigned int) len) ? string( "" ) : string( "," ) )+( (count++%1 == 0) ? "\n" : "" )+string(
1653  colToString( mountcolor ).str )+parent->mounts[i].type->weapon_name+ammo;
1654  } else {
1655  mbuf +=
1656  ( (mbuf.length()
1657  == (unsigned int) mlen) ? string( "" ) : string( "," ) )
1658  +( (mcount++%1
1659  == 0) ? "\n" : "" )+string( colToString( mountcolor ).str )+parent->mounts[i].type->weapon_name+ammo;
1660  }
1661  numave = 0;
1662  average = GFXColor( 0, 0, 0, 0 );
1663  }
1664  }
1665  if (mbuf.length() != (unsigned int) mlen)
1666  buf += mbuf;
1667  static float background_alpha =
1668  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1669  GFXColor tpbg = tp->bgcol;
1670  bool automatte = (0 == tpbg.a);
1671  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1672  tp->Draw( buf, 0, true, false, automatte );
1673  tp->bgcol = tpbg;
1674 }
1675 
1676 using std::vector;
1677 /*
1678  * static GFXColor GetColorFromSuccess (float suc){
1679  * suc +=1.;
1680  * suc/=2.;
1681  * return GFXColor(1-suc,suc,0);
1682  * }
1683  */
1684 
1685 char printHex( unsigned int hex )
1686 {
1687  if (hex < 10)
1688  return hex+'0';
1689  return hex-10+'A';
1690 }
1691 
1692 static char suc_col_str[8] = "#000000";
1693 static const char suc_gt_plusone[8] = "#00FF00";
1694 static const char suc_gt_minusone[8] = "#FF0000";
1695 
1696 inline const char * GetColorFromSuccess( float suc )
1697 {
1698  if (suc >= 1)
1699  return suc_gt_plusone;
1700  if (suc <= -1)
1701  return suc_gt_minusone;
1702  suc += 1.;
1703  suc *= 128;
1704  unsigned int tmp2 = (unsigned int) suc;
1705  unsigned int tmp1 = (unsigned int) (255-suc);
1706  suc_col_str[0] = '#';
1707  suc_col_str[1] = printHex( tmp1/16 );
1708  suc_col_str[2] = printHex( tmp1%16 );
1709  suc_col_str[3] = printHex( tmp2/16 );
1710  suc_col_str[4] = printHex( tmp2%16 );
1711  suc_col_str[5] = '0';
1712  suc_col_str[6] = '0';
1713 
1714  return suc_col_str;
1715 }
1716 
1717 #if 0
1718 int VDU::DrawVDUObjective( void *obj, int offset )
1719 {
1720  static bool VDU_DrawVDUObjective_is_now_outdated = false;
1721  assert( VDU_DrawVDUObjective_is_now_outdated == true );
1722  return 0;
1723 }
1724 #endif
1725 
1726 void DrawObjectivesTextPlane( TextPlane *tp, int scrolloffset, Unit *parent )
1727 {
1728  std::string rez( "\n" );
1729  for (unsigned int i = 0; i < active_missions.size(); ++i)
1730  if ( !active_missions[i]->objectives.empty() ) {
1731  rez += "#FFFFFF";
1732  static bool force_anonymous_missions =
1733  XMLSupport::parse_bool( vs_config->getVariable( "general", "force_anonymous_mission_names", "true" ) );
1734  if (active_missions[i]->mission_name.empty() || force_anonymous_missions)
1735  rez += "Mission "+XMLSupport::tostring( (int) i )+"\n";
1736  else
1737  rez += active_missions[i]->mission_name+"\n";
1738  vector< Mission::Objective >::iterator j = active_missions[i]->objectives.begin();
1739  for (; j != active_missions[i]->objectives.end(); ++j)
1740  if (j->getOwner() == NULL || j->getOwner() == parent) {
1741  if ( (*j).objective.length() ) {
1742  rez += GetColorFromSuccess( (*j).completeness );
1743  rez += (*j).objective;
1744  rez += '\n';
1745  }
1746  }
1747  rez += '\n';
1748  }
1749  static float background_alpha =
1750  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1751  GFXColor tpbg = tp->bgcol;
1752  bool automatte = (0 == tpbg.a);
1753  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1754  tp->Draw( rez, scrolloffset, false, false, automatte );
1755  tp->bgcol = tpbg;
1756 }
1757 
1758 void VDU::DrawVDUObjectives( Unit *parent )
1759 {
1760  DrawObjectivesTextPlane( tp, scrolloffset, parent );
1761 }
1762 
1763 bool VDU::SetWebcamAnimation()
1764 {
1765  if (comm_ani == NULL) {
1766  if (posmodes&WEBCAM) {
1767  comm_ani = new Animation();
1768  communicating.SetUnit( NULL );
1769  thismode.push_back( WEBCAM );
1770  comm_ani->Reset();
1771  return true;
1772  }
1773  }
1774  return false;
1775 }
1776 
1777 void VDU::DrawWebcam( Unit *parent )
1778 {
1780  int length;
1781  char *netcam;
1782  int playernum = _Universe->whichPlayerStarship( parent );
1783  if ( Network[playernum].hasWebcam() ) {
1784  netcam = Network[playernum].getWebcamFromNetwork( length );
1785  if (netcam) {
1786  //Delete the previous displayed webcam shot if any
1787  if (this->webcam)
1788  delete webcam;
1789  //Read the new one
1790  VSFile f( netcam, length, JPEGBuffer );
1791  this->webcam = new Animation( &f );
1792  delete netcam;
1793  GFXDisable( TEXTURE1 );
1794  GFXEnable( TEXTURE0 );
1795  GFXDisable( LIGHTING );
1796  //Draw it
1797  webcam->DrawAsVSSprite( this );
1798  GFXDisable( TEXTURE0 );
1799  }
1800  } else {
1801  tp->Draw( MangleString( "No webcam to view",
1802  _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), scrolloffset, true );
1803  }
1804 }
1805 
1806 void VDU::Draw( GameCockpit *parentcp, Unit *parent, const GFXColor &color )
1807 {
1808  tp->col = color;
1809  GFXDisable( LIGHTING );
1811  GFXEnable( TEXTURE0 );
1812  GFXDisable( TEXTURE1 );
1813  VSSprite::Draw();
1814  //glDisable( GL_ALPHA_TEST);
1815  if (!parent)
1816  return;
1817  //configure text plane;
1818  float x, y;
1819  float h, w;
1820  GetSize( w, h );
1821 
1822  static float width_factor = XMLSupport::parse_float( vs_config->getVariable( "graphics", "reduced_vdus_width", "0" ) );
1823  static float height_factor = XMLSupport::parse_float( vs_config->getVariable( "graphics", "reduced_vdus_height", "0" ) );
1824  w = w-width_factor;
1825  h = h+height_factor;
1826 
1827  GetPosition( x, y );
1828  //tp->SetCharSize (fabs(w/cols),fabs(h/rows));
1829  float csx, csy;
1830  tp->GetCharSize( csx, csy );
1831  //This was as below:
1832  //cols = abs( (int) ceil( w/csx ) );
1833  //rows = abs( (int) ceil( h/csy ) );
1834  //I'm changing it to as below, which avoids abs blues with visual studio, and is
1835  //also faster, as computing the abs of a float amounts to setting the sign bit;
1836  //though I'm less than 100% entirely sure of the correctness of the change... --chuck_starchaser
1837  cols = int(fabs(ceil(w/csx)));
1838  rows = int(fabs(ceil(h/csy)));
1839 
1840  Unit *targ;
1841  h = fabs( h/2 );
1842  w = fabs( w/2 );
1843  tp->SetPos( x-w, y+h );
1844  tp->SetSize( x+w, y-h-.5*fabs( w/cols ) );
1845  targ = parent->GetComputerData().target.GetUnit();
1846  if (thismode.back() != COMM && comm_ani != NULL) {
1847  if ( comm_ani->Done() ) {
1848  comm_ani = NULL;
1849  communicating.SetUnit( NULL );
1850  }
1851  }
1852  float delautotime = UniverseUtil::GetGameTime()-parentcp->autoMessageTime;
1853  static float auto_switch_lim =
1854  XMLSupport::parse_float( vs_config->getVariable( "graphics", "auto_message_nav_switch_time_lim", ".15" ) );
1855  if ( (delautotime<auto_switch_lim) && (parentcp->autoMessage.length()!=0) ) {
1856  if ( (thismode.back()!=COMM) && ((posmodes&NAV)!=0) ) {
1857  thismode.back() = NAV;
1858  parentcp->autoMessageTime -= auto_switch_lim*1.125;
1859  }
1860  }
1861  switch ( thismode.back() )
1862  {
1863  case NETWORK:
1864  if (Network != NULL) {
1865  int playernum = _Universe->whichPlayerStarship( parent );
1866  char buf[32];
1867  string str( "Lag: " );
1868  unsigned int lag = Network[playernum].getLag();
1869  memset( buf, 0, 32 );
1870  sprintf( buf, "%.1Lf", (long double) lag );
1871  if (lag < 50)
1872  str += "#00FF00";
1873  else if (lag < 150)
1874  str += "#FFFF00";
1875  else if (lag > 0)
1876  str += "#FF0000";
1877  str += string( buf )+"#000000 ms\n";
1878  if ( Network[playernum].IsNetcommSecured() )
1879  str += "#DD0000";
1880  memset( buf, 0, 32 );
1881  sprintf( buf, "%g", Network[playernum].getCurrentFrequency() );
1882  str += string( buf )+"/";
1883  memset( buf, 0, 32 );
1884  sprintf( buf, "%g", Network[playernum].getSelectedFrequency() );
1885  str += string( buf )+" GHz";
1886  if ( Network[playernum].IsNetcommSecured() )
1887  str += "#000000";
1888  if ( Network[playernum].IsNetcommActive() )
1889  str += " - #0000FFON";
1890  else
1891  str += " - #FF0000OFF";
1892  str += "#000000\n";
1893  str += "SD: "+_Universe->current_stardate.GetFullTrekDate();
1894  static float background_alpha =
1895  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
1896  GFXColor tpbg = tp->bgcol;
1897  bool automatte = (0 == tpbg.a);
1898  if (automatte) tp->bgcol = GFXColor( 0, 0, 0, background_alpha );
1899  tp->Draw( MangleString( str, _Universe->AccessCamera()->GetNebula() != NULL ? .4 : 0 ), 0, true, false, automatte );
1900  tp->bgcol = tpbg;
1901  }
1902  break;
1903  case WEBCAM:
1904  if (Network != NULL)
1905  DrawWebcam( parent );
1906  break;
1907  case SCANNING:
1908  if (!got_target_info)
1909  DrawScanningMessage();
1910  /*
1911  * else
1912  * DrawScanner();
1913  */
1914  break;
1915  case TARGET:
1916  if (targ)
1917  DrawTarget( parentcp, parent, targ );
1918  break;
1919  case MANIFEST:
1920  DrawManifest( parent, parent );
1921  break;
1922  case TARGETMANIFEST:
1923  if (targ)
1924  DrawManifest( parent, targ );
1925  break;
1926  case VIEW:
1927  GetPosition( x, y );
1928  GetSize( w, h );
1929  DrawStarSystemAgain( .5*(x-fabs( w/2 )+1), .5*( ( y-fabs( h/2 ) )+1 ), fabs( w/2 ), fabs(
1930  h/2 ), viewStyle, parent, targ );
1931  break;
1932  case NAV:
1933  DrawNav( parentcp, parent, targ, parent->ToLocalCoordinates( parent->GetComputerData().NavPoint-parent->Position().Cast() ) );
1934  break;
1935  case MSG:
1936  DrawMessages( parentcp, targ );
1937  break;
1938  case COMM:
1939  DrawComm();
1940  break;
1941  case DAMAGE:
1942  DrawDamage( parent );
1943  break;
1944  case WEAPON:
1945  DrawWeapon( parent );
1946  break;
1947  case SHIELD:
1948  DrawVDUShield( parent );
1949  break;
1950  case OBJECTIVES:
1951  DrawVDUObjectives( parent );
1952  break;
1953  default:
1954  break; //FIXME --chuck_starchaser; please verify correctness and/or add a errlog or throw
1955  }
1956 }
1957 
1959 {
1960  switch (vs)
1961  {
1962  case CP_FRONT:
1963  vs = CP_TARGET;
1964  break;
1965  case CP_BACK:
1966  vs = CP_FRONT;
1967  break;
1968  case CP_LEFT:
1969  vs = CP_BACK;
1970  break;
1971  case CP_RIGHT:
1972  vs = CP_LEFT;
1973  break;
1974  case CP_CHASE:
1975  vs = CP_TARGET;
1976  break;
1977  case CP_PAN:
1978  vs = CP_CHASE;
1979  break;
1980  case CP_PANTARGET:
1981  vs = CP_CHASE;
1982  break;
1983  case CP_TARGET:
1984  vs = CP_PANTARGET;
1985  break;
1986  case CP_VIEWTARGET: //FIXME cases not previously handled in switch --added by chuck_starchaser; please verify correctness
1987  case CP_PANINSIDE:
1988  case CP_FIXED:
1989  case CP_FIXEDPOS:
1990  case CP_FIXEDPOSTARGET:
1991  case CP_NUMVIEWS:
1992  default:
1993  break;
1994  }
1995 }
1996 
1997 void VDU::SwitchMode( Unit *parent )
1998 {
1999  if (!posmodes)
2000  return;
2001  scrolloffset = 0;
2002  //If we switch from SCANNING VDU VIEW_MODE we loose target info
2003  if (thismode.back() == SCANNING && Network != NULL)
2004  got_target_info = false;
2005  //If we switch from WEBCAM VDU VIEW_MODE we stop dlding images
2006  if (thismode.back() == WEBCAM && Network != NULL && parent != NULL) {
2007  int playernum = _Universe->whichPlayerStarship( parent );
2008  Network[playernum].stopWebcamTransfer();
2009  }
2010  if ( thismode.back() == VIEW && viewStyle != CP_CHASE && (thismode.back()&posmodes) ) {
2011  UpdateViewstyle( viewStyle );
2012  } else {
2013  viewStyle = CP_TARGET;
2014  thismode.back() <<= 1;
2015  while ( !(thismode.back()&posmodes) ) {
2016  if (thismode.back() > posmodes)
2017  thismode.back() = 0x1;
2018  else
2019  thismode.back() <<= 1;
2020  }
2021  }
2022  //If we switch to SCANNING MODE we consider we lost target info
2023  if (thismode.back() == SCANNING && Network != NULL)
2024  got_target_info = false;
2025  //If we switch to WEBCAM MODE we start dlding images
2026  if (thismode.back() == WEBCAM && Network != NULL && parent != NULL) {
2027  int playernum = _Universe->whichPlayerStarship( parent );
2028  Network[playernum].startWebcamTransfer();
2029  }
2030 }
2031 
2033 {
2034  if (comm_ani && comm_ani->Done() == false)
2035  if (communicating == un || communicating == NULL)
2036  return true;
2037  return false;
2038 }
2039