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
drawgalaxy.cpp
Go to the documentation of this file.
1 
4 #include <algorithm>
5 #include <cmath>
6 #include "vs_globals.h"
7 #include "vegastrike.h"
8 #include "gfx/gauge.h"
9 #include "gfx/cockpit.h"
10 #include "universe.h"
11 #include "star_system.h"
12 #include "cmd/unit_generic.h"
13 #include "cmd/unit_factory.h"
14 #include "cmd/collection.h"
15 #include "gfx/hud.h"
16 #include "gfx/vdu.h"
17 #include "lin_time.h" //for fps
18 #include "config_xml.h"
19 #include "lin_time.h"
20 #include "cmd/images.h"
21 #include "cmd/script/mission.h"
22 #include "cmd/script/msgcenter.h"
23 #include "cmd/ai/flyjoystick.h"
24 #include "cmd/ai/firekeyboard.h"
25 #include "cmd/ai/aggressive.h"
26 #include "main_loop.h"
27 #include <assert.h> //needed for assert() calls
28 #include "savegame.h"
29 #include "gfx/animation.h"
30 #include "gfx/mesh.h"
31 #include "universe_util.h"
32 #include "in_mouse.h"
33 #include "gui/glut_support.h"
34 #include "networking/netclient.h"
35 #include "cmd/unit_util.h"
36 #include "hashtable.h"
37 #include "navscreen.h"
38 #include "gfx/masks.h"
39 #include "navscreenoccupied.h"
40 
41 using std::string;
42 using std::vector;
43 
44 float SYSTEM_DEFAULT_SIZE = 0.02;
45 const int systemambiguous = 0;
46 static GFXColor GrayColor( .5, .5, .5, .5 );
47 float GrayColorArray[4] = {.5, .5, .5, .5};
48 
49 static void DrawNodeDescription( string text,
50  float x_,
51  float y_,
52  float size_x,
53  float size_y,
54  bool ignore_occupied_areas,
55  const GFXColor &col,
56  navscreenoccupied *screenoccupation )
57 {
58  //take the head and stick it in the back
59  if (text.size() == 0)
60  return;
61  TextPlane displayname; //will be used to display shits names
62  displayname.col = col;
63  static float background_alpha =
64  XMLSupport::parse_float( vs_config->getVariable( "graphics", "hud", "text_background_alpha", "0.0625" ) );
65  int length = text.size();
66  float offset = (float(length)*0.005);
67  if (ignore_occupied_areas) {
68  displayname.SetPos( (x_-offset), y_ );
69  displayname.SetText( text );
70  displayname.SetCharSize( size_x, size_y );
71 
72  GFXColor tpbg = displayname.bgcol;
73  bool automatte = (0 == tpbg.a);
74  if (automatte) displayname.bgcol = GFXColor( 0, 0, 0, background_alpha );
75  displayname.Draw( text, 0, true, false, automatte );
76  displayname.bgcol = tpbg;
77  } else {
78  float new_y = screenoccupation->findfreesector( x_, y_ );
79  displayname.SetPos( (x_-offset), new_y );
80  displayname.SetText( text );
81  displayname.SetCharSize( size_x, size_y );
82  GFXColor tpbg = displayname.bgcol;
83  bool automatte = (0 == tpbg.a);
84  if (automatte) displayname.bgcol = GFXColor( 0, 0, 0, background_alpha );
85  displayname.Draw( text, 0, true, false, automatte );
86  displayname.bgcol = tpbg;
87  }
88 }
89 
90 static char GetSystemColor( string source )
91 {
92  //FIXME: update me!!!
93  vector< float > *v = &_Universe->AccessCockpit()->savegame->getMissionData( "visited_"+source );
94  if ( v->size() ) {
95  float k = (*v)[0];
96  if (k >= 2)
97  return k == 2 ? 'm' : '?';
98  }
99  return 'v';
100 }
101 
102 static void DrawNode( int type,
103  float size,
104  float x,
105  float y,
106  std::string source,
107  navscreenoccupied *screenoccupation,
108  bool moused,
109  GFXColor race,
110  bool mouseover = false,
111  bool willclick = false,
112  string insector = "" )
113 {
114  char color = GetSystemColor( source );
115  if (moused)
116  return;
117  if (willclick == true && mouseover == false)
118  //Perhaps some key binding or mouseclick will be set in the future to do this.
119  mouseover = true;
120  static bool inited = false;
121  static GFXColor highlighted_tail_col;
122  static GFXColor highlighted_tail_text;
123  if (!inited) {
124  float col1[4] = {1, .3, .3, .8};
125  vs_config->getColor( "nav", "highlighted_unit_on_tail", col1, true );
126  highlighted_tail_col = GFXColor( col1[0], col1[1], col1[2], col1[3] );
127 
128  float col2[4] = {1, 1, .7, 1};
129  vs_config->getColor( "nav", "highlighted_text_on_tail", col2, true );
130  highlighted_tail_text = GFXColor( col2[0], col2[1], col2[2], col2[3] );
131  inited = true;
132  }
133  if (color == 'm')
134  race = GrayColor;
135  if (mouseover) {
136  if (willclick) {
137  race = highlighted_tail_col;
138  } else {
139  //Leave just a faint resemblence of the original color,
140  //but also make it look whiteish.
141  race.r += .75;
142  race.g += .75;
143  race.b += .75;
144  }
145  }
146  NavigationSystem::DrawCircle( x, y, size, race );
147  if ( (!mouseover) || (willclick) ) {
148  string tsector, nam;
149  Beautify( source, tsector, nam );
150  if (willclick) {
151  race = highlighted_tail_text;
152  nam = tsector+" / "+nam;
153  }
154  if ( willclick || !( insector.compare( "" ) ) || !( insector.compare( tsector ) ) )
155  DrawNodeDescription( nam, x, y, 1.0, 1.0, 0, race, screenoccupation );
156  }
157 }
158 
160 {
161  int type;
162  float size;
163  float x;
164  float y;
165  unsigned index;
166  std::string source;
167 //Vector of indicies
168 //std::vector<int> *dest; //let's just hope that the iterator doesn't get killed during the frame, which shouldn't happen.
169 //std::vector<string> *stringdest; //let's just hope that the iterator doesn't get killed during the frame, which shouldn't happen.
170  bool moused;
171  char color;
172  GFXColor race;
173  navscreenoccupied *screenoccupation;
174 public:
175  unsigned getIndex() const
176  {
177  return index;
178  }
179  friend bool operator<( const systemdrawnode &a, const systemdrawnode &b )
180  {
181  return a.source < b.source;
182  }
183  friend bool operator==( const systemdrawnode &a, const systemdrawnode &b )
184  {
185  return a.source == b.source;
186  }
187  systemdrawnode( int type,
188  float size,
189  float x,
190  float y,
191  std::string source,
192  unsigned index,
193  navscreenoccupied *so,
194  bool moused,
195  GFXColor race )
196  : type( type )
197  , size( size )
198  , x( x )
199  , y( y )
200  , index( index )
201  , source( source )
202  , moused( moused )
203  , color( GetSystemColor( source ) )
204  , race( race )
205  , screenoccupation( so )
206  {
207  }
209  : size( SYSTEM_DEFAULT_SIZE )
210  , x( 0 )
211  , y( 0 )
212  , index( 0 )
213  , source()
214  , moused( false )
215  , color( 'v' )
216  , race( GrayColor )
217  , screenoccupation( NULL )
218  {
219  }
220  void draw( bool mouseover = false, bool willclick = false )
221  {
222  DrawNode( type, size, x, y, source, screenoccupation, moused, race, mouseover, willclick );
223  }
224 };
225 
226 typedef vector< systemdrawnode >systemdrawlist;
227 //typedef Hashtable <std::string, const systemdrawnode, 127> systemdrawhashtable;
228 
229 bool testandset( bool &b, bool val )
230 {
231  bool tmp = b;
232  b = val;
233  return tmp;
234 }
235 
236 float screensmash = 1; //arbitrary constant used in calculating position below
237 
238 NavigationSystem::SystemIterator::SystemIterator( string current_system, unsigned int max )
239 {
240  count = 0;
241  maxcount = max;
242  vstack.push_back( current_system );
243  visited[current_system] = true;
244  which = 0;
245 }
246 
248 {
249  return which >= vstack.size();
250 }
251 
253 {
254  if ( done() )
255  return QVector( 0, 0, 0 );
256  string currentsystem = (**this);
257  string xyz = _Universe->getGalaxyProperty( currentsystem, "xyz" );
258  QVector pos;
259  if ( xyz.size() && (sscanf( xyz.c_str(), "%lf %lf %lf", &pos.i, &pos.j, &pos.k ) >= 3) ) {
260  pos.j = -pos.j;
261  return pos;
262  } else {
263  float ratio = ( (float) count )/maxcount;
264  float locatio = ( (float) which )/vstack.size();
265  unsigned int k = 0;
266  std::string::const_iterator start = vstack[which].begin();
267  std::string::const_iterator end = vstack[which].end();
268  for (; start != end; start++)
269  k += (k*128)+*start;
270  k %= 200000;
271 //float y = (k-100000)/(200000.);
272  return QVector( ratio*cos( locatio*2*3.1415926536 ), ratio*sin( locatio*2*3.1415926536 ), 0 )*screensmash;
273  }
274 }
275 
277 {
278  if ( which < vstack.size() )
279  return vstack[which];
280  return "-";
281 }
282 
284 {
285  return ++(*this);
286 }
287 
288 bool checkedVisited( const std::string &n )
289 {
290  static bool dontbothervisiting = !XMLSupport::parse_bool( vs_config->getVariable( "graphics", "explore_for_map", "false" ) );
291  if (dontbothervisiting) {
292  return true;
293  } else {
294  string key( string( "visited_" )+n );
295  vector< float > *v = &_Universe->AccessCockpit()->savegame->getMissionData( key );
296  if (v->size() > 0)
297  return true;
298  return false;
299  }
300 }
301 
303 {
304  which += 1;
305  if ( which >= vstack.size() ) {
306  vector< string >newsys;
307  for (unsigned int i = 0; i < vstack.size(); ++i) {
308  int nas = UniverseUtil::GetNumAdjacentSystems( vstack[i] );
309  for (int j = 0; j < nas; ++j) {
310  string n = UniverseUtil::GetAdjacentSystem( vstack[i], j );
311  if ( !testandset( visited[n], true ) )
312 //if (checkedVisited(n)) {
313  newsys.push_back( n );
314 //}
315  }
316  }
317  vstack.swap( newsys );
318  count += 1;
319  which = 0;
320  if (count > maxcount)
321  vstack.clear();
322  }
323  return *this;
324 }
325 
326 //************************************************
327 //
328 //SYSTEM SECTION
329 //
330 //************************************************
331 
333 {
334  const float *tcol =
335  ( ( !name.empty() )
336  && (name
338  : &(
339  GrayColorArray[0]);
340  col = GFXColor( tcol[0], tcol[1], tcol[2], tcol[3] );
341 }
342 
343 //May generate incorrect links to destinations, if called before destinations have been added.
344 //Since links are bidirectional, one WILL have to be created before the other
345 //It is recommended that placeholders are created and links updated later
347  const QVector &position,
348  const std::vector< std::string > &destinations,
350  name( name )
351  , position( position )
352  , part_of_path( false )
353 {
354  //Eww... double for loop!
355  UpdateColor();
356  if (csi) {
357  for (size_t i = 0; i < destinations.size(); ++i)
358  for (size_t j = 0; j < csi->systems.size(); ++j)
359  if ( (*csi)[j].name == destinations[i] ) {
360  lowerdestinations.push_back( j );
361  if ( std::find( (*csi)[j].lowerdestinations.begin(), (*csi)[j].lowerdestinations.end(),
362  i ) == (*csi)[j].lowerdestinations.end() )
363  (*csi)[j].lowerdestinations.push_back( i ); //this is in case of asymmetric links
364  //Push the destination back.
365  //Tasty....
366  //Mmm.......
367  //Destination tastes like chicken
368  }
369  }
370 }
371 
372 //Create a placeholder to avoid the problem described above
374  name( name )
375  , part_of_path( false ) {}
376 
377 void NavigationSystem::CachedSystemIterator::SystemInfo::loadData( map< string, unsigned > *index_table )
378 {
379  string xyz = _Universe->getGalaxyProperty( name, "xyz" );
380  QVector pos;
381  if ( xyz.size() && (sscanf( xyz.c_str(), "%lf %lf %lf", &pos.i, &pos.j, &pos.k ) >= 3) ) {
382  pos.j = -pos.j;
383  } else {
384  pos.i = 0;
385  pos.j = 0;
386  pos.k = 0;
387  }
388  position = pos;
389 
390  UpdateColor();
391  const vector< std::string > &destinations = _Universe->getAdjacentStarSystems( name );
392  for (size_t i = 0; i < destinations.size(); ++i)
393  if (index_table->count( destinations[i] ) != 0)
394  lowerdestinations.push_back( (*index_table)[destinations[i]] );
395 }
396 
397 void NavigationSystem::CachedSystemIterator::init( string current_system, unsigned max_systems )
398 {
399  systems.clear();
400  unsigned count = 0;
401  string sys;
402 
403  map< string, unsigned > index_table;
404  std::deque< std::string >frontier;
405  frontier.push_back( current_system );
406  systems.push_back( SystemInfo( current_system ) );
407  index_table[current_system] = 0;
408  while ( !frontier.empty() ) {
409  sys = frontier.front();
410  frontier.pop_front();
411 
412  int nas = UniverseUtil::GetNumAdjacentSystems( sys );
413  for (int j = 0; j < nas && count < max_systems; ++j) {
414  string n = UniverseUtil::GetAdjacentSystem( sys, j );
415  if (index_table.count( n ) == 0) {
416  frontier.push_back( n );
417  index_table[n] = systems.size();
418  systems.push_back( SystemInfo( n ) );
419  ++count;
420  }
421  }
422  systems[index_table[sys]].loadData( &index_table );
423  }
424 }
425 
427 
428 NavigationSystem::CachedSystemIterator::CachedSystemIterator( string current_system, unsigned max_systems )
429 {
430  init( current_system, max_systems );
431 }
432 
434  systems( other.systems )
435  , currentPosition( other.currentPosition ) {}
436 
438 {
439  if ( position < systems.size() ) {
440  currentPosition = position;
441  return true;
442  } else {
443  return false;
444  }
445 }
446 
448 {
449  return currentPosition;
450 }
451 
453 {
454  return systems.size();
455 }
456 
458 {
459  return currentPosition >= systems.size();
460 }
461 
463  std::vector< std::string > (), NULL );
464 
466 {
467  if ( pos >= size() )
468  return nullPair;
469  return systems[pos];
470 }
471 
474 {
475  if ( pos >= size() )
476  return nullPair;
477  return systems[pos];
478 }
479 
481 {
482  if ( done() )
483  return nullPair;
484  return systems[currentPosition];
485 }
486 
488 {
489  if ( done() )
490  return nullPair;
491  return systems[currentPosition];
492 }
493 
495 {
496  if ( done() )
497  return &nullPair;
498  return &systems[currentPosition];
499 }
500 
502 {
503  if ( done() )
504  return &nullPair;
505  return &systems[currentPosition];
506 }
507 
509 {
510  return name;
511 }
512 
514 {
515  return name;
516 }
517 
519 {
520  return checkedVisited( GetName() );
521 }
522 
524 {
525  return position;
526 }
527 
529 {
530  return position;
531 }
532 
534 {
535  return lowerdestinations[index];
536 }
537 
539 {
540  return lowerdestinations.size();
541 }
542 
544 {
545  static unsigned long lastupdate = 0;
546  lastupdate += 1299811;
547  lastupdate %= 104729;
548  if (lastupdate < 32)
549  UpdateColor();
550  return col;
551 }
552 
554 {
555  return ++(*this);
556 }
557 
559 {
560  ++currentPosition;
561  return *this;
562 }
563 
565 {
567  ++(*this);
568  return iter;
569 }
570 
571 //************************************************
572 //
573 //SECTOR SECTION
574 //
575 //************************************************
576 
578  name( name ) {}
579 
581 {
582  return name;
583 }
584 
586 {
587  return name;
588 }
589 
591 {
592  return subsystems[index];
593 }
594 
596 {
597  return subsystems.size();
598 }
599 
601 {
602  subsystems.push_back( index );
603 }
604 
606 
608 {
609  init( systemIter );
610 }
611 
613 {
614  map< string, unsigned >index_table;
615  sectors.clear();
616 
617  string sys, csector, csystem;
618  unsigned index;
619 
620  systemIter.seek();
621  while ( !systemIter.done() ) {
622  sys = systemIter->GetName();
623  Beautify( sys, csector, csystem );
624  if (index_table.count( csector ) == 0) {
625  index_table[csector] = sectors.size();
626  sectors.push_back( SectorInfo( csector ) );
627  }
628  index = index_table[csector];
629  sectors[index].AddSystem( systemIter.getIndex() );
630  ++systemIter;
631  }
632 }
633 
635  sectors( other.sectors )
636  , currentPosition( other.currentPosition ) {}
637 
639 {
640  if ( position < sectors.size() ) {
641  currentPosition = position;
642  return true;
643  } else {
644  return false;
645  }
646 }
647 
649 {
650  return currentPosition;
651 }
652 
654 {
655  return sectors.size();
656 }
657 
659 {
660  return currentPosition >= sectors.size();
661 }
662 
664 
666 {
667  if ( pos >= size() )
668  return nullSectorPair;
669  return sectors[pos];
670 }
671 
674 {
675  if ( pos >= size() )
676  return nullSectorPair;
677  return sectors[pos];
678 }
679 
681 {
682  if ( done() )
683  return nullSectorPair;
684  return sectors[currentPosition];
685 }
686 
688 {
689  if ( done() )
690  return nullSectorPair;
691  return sectors[currentPosition];
692 }
693 
695 {
696  if ( done() )
697  return &nullSectorPair;
698  return &sectors[currentPosition];
699 }
700 
702 {
703  if ( done() )
704  return &nullSectorPair;
705  return &sectors[currentPosition];
706 }
707 
709 {
710  return ++(*this);
711 }
712 
714 {
715  ++currentPosition;
716  return *this;
717 }
718 
720 {
722  ++(*this);
723  return iter;
724 }
725 
726 //static systemdrawhashtable jumptable;
727 float vsmax( float x, float y )
728 {
729  return x > y ? x : y;
730 }
731 
733 {
734 //systemdrawlist mainlist;//(0, screenoccupation, factioncolours); // lists of items to draw that are in mouse range
735 
736  systemdrawlist mouselist; //(1, screenoccupation, factioncolours); // lists of items to draw that are in mouse range
737 
738  string csector, csystem;
739 
740  Beautify( getCurrentSystem(), csector, csystem );
741  //what's my name
742  //***************************
743  TextPlane systemname; //will be used to display shits names
744  string systemnamestring = "Current System : "+csystem+" in the "+csector+" Sector.";
745 
746 //int length = systemnamestring.size();
747 //float offset = (float(length)*0.005);
748  systemname.col = GFXColor( 1, 1, .7, 1 );
749  systemname.SetPos( screenskipby4[0], screenskipby4[3] ); //Looks ugly when name is too long and goes off the edge.
750 //systemname.SetPos( (((screenskipby4[0]+screenskipby4[1])/2)-offset) , screenskipby4[3]);
751  systemname.SetText( systemnamestring );
752 //systemname.SetCharSize(1, 1);
753  systemname.Draw();
754  //***************************
755 
756  QVector pos; //item position
757  QVector pos_flat; //item position flat on plane
758 
759  float zdistance = 0.0;
760  float zscale = 1.0;
761  int l;
762 
763  Adjust3dTransformation( galaxy_view == VIEW_3D, 0 );
764 
765  float center_nav_x = ( (screenskipby4[0]+screenskipby4[1])/2 );
766  float center_nav_y = ( (screenskipby4[2]+screenskipby4[3])/2 );
767  //**********************************
768 
769  glEnable( GL_ALPHA );
770  GFXDisable( LIGHTING );
772  if (!camera_z) {
773  float max_x = 0.0;
774  float min_x = 0.0;
775  float max_y = 0.0;
776  float min_y = 0.0;
777  float max_z = 0.0;
778  float min_z = 0.0;
779 
780 //themaxvalue = fabs(pos.i);
781  themaxvalue = 0.0;
782 
783  {
784  {
785  systemIter.seek( focusedsystemindex );
786  pos = systemIter->Position();
787  ReplaceAxes( pos );
788 //if(galaxy_view==VIEW_3D){pos = dxyz(pos, 0, ry, 0);pos = dxyz(pos, rx, 0, 0);}
789 
790  max_x = (float) pos.i;
791  min_x = (float) pos.i;
792  max_y = (float) pos.j;
793  min_y = (float) pos.j;
794  max_z = (float) pos.k;
795  min_z = (float) pos.k;
796 
797  //Find Centers
798  //**********************************
799  //This will use the current system as the center
800  center_x = pos.i;
801  center_y = pos.j;
802  center_z = pos.k;
803  //**********************************
804 
805  unsigned destsize = systemIter->GetDestinationSize();
806  if (destsize != 0) {
807  for (unsigned i = 0; i < destsize; ++i) {
808  QVector posoth = systemIter[systemIter->GetDestinationIndex( i )].Position();
809  ReplaceAxes( posoth );
810 //if(galaxy_view==VIEW_3D){posoth = dxyz(pos, 0, ry, 0);posoth = dxyz(pos, rx, 0, 0);}
811 
812  RecordMinAndMax( posoth, min_x, max_x, min_y, max_y, min_z, max_z, themaxvalue );
813  }
814  }
815  }
816  }
817 
818  //Find Centers
819  //**********************************
820  //this will make the center be the center of the displayable area.
821 //center_x = (min_x + max_x)/2;
822 //center_y = (min_y + max_y)/2;
823 //center_z = (min_z + max_z)/2;
824  //**********************************
825 
826 /* min_x = (min_x+center_x)/2;
827  * min_y = (min_y+center_y)/2;
828  * min_z = (min_z+center_z)/2;
829  * max_x = (max_x+center_x)/2;
830  * max_y = (max_y+center_y)/2;
831  * max_z = (max_z+center_z)/2;
832  */
833  //Set Camera Distance
834  //**********************************
835 
836 #define SQRT3 1.7320508
837 //themaxvalue = sqrt(themaxvalue*themaxvalue + themaxvalue*themaxvalue + themaxvalue*themaxvalue);
838 //themaxvalue = SQRT3*themaxvalue;
839 
840  themaxvalue *= 3;
841 
842  {
843  float half_x = vsmax( max_x-center_x, center_x-min_x );
844  float half_y = vsmax( max_y-center_y, center_y-min_y );
845  float half_z = vsmax( max_z-center_z, center_z-min_z );
846 
847 //float half_x =(0.5*(max_x - min_x));
848 //float half_y =(0.5*(max_y - min_y));
849 //float half_z =(0.5*(max_z - min_z));
850 
851  camera_z = sqrt( (half_x*half_x)+(half_y*half_y)+(half_z*half_z) );
852 
853 //float halfmax = 0.5*themaxvalue;
854 //camera_z = sqrt( (halfmax*halfmax) + (halfmax*halfmax) + (halfmax*halfmax) );
855 //camera_z = 4.0*themaxvalue;
856 //camera_z = tihemaxvalue;
857  }
858 
859  //**********************************
860  }
861  DrawOriginOrientationTri( center_nav_x, center_nav_y, 0 );
862 
863  //Enlist the items and attributes
864  //**********************************
865  systemIter.seek();
866  while ( !systemIter.done() ) {
867  //this draws the points
868  //IGNORE UNDRAWABLE SYSTEMS
869  //**********************************
870  if ( !systemIter->isDrawable() ) {
871  ++systemIter;
872  continue;
873  }
874  //**********************************
875 
876  //Retrieve unit data
877  //**********************************
878  unsigned temp = systemIter.getIndex();
879 
880  pos = systemIter->Position();
881 
882  ReplaceAxes( pos ); //poop
883 
884  //Modify by old rotation amount
885  //*************************
886 //if(galaxy_view==VIEW_3D){pos = dxyz(pos, 0, ry, 0);pos = dxyz(pos, rx, 0, 0);}
887  //*************************
888  //*************************
889 
890  GFXColor col = systemIter->GetColor();
891  Vector oldpos = pos;
892  float the_x, the_y, the_x_flat, the_y_flat, system_item_scale_temp;
893  TranslateCoordinates( pos,
894  pos_flat,
895  center_nav_x,
896  center_nav_y,
897  themaxvalue,
898  zscale,
899  zdistance,
900  the_x,
901  the_y,
902  the_x_flat,
903  the_y_flat,
904  system_item_scale_temp,
905  0 );
906  float alphaadd;
907  {
908  float tmp = ( 1-(zoom/MAXZOOM) );
909  alphaadd = (tmp*tmp)-.5;
910 //if (alphaadd<=0)
911 //alphaadd=0;
912 //else
913  alphaadd *= 4;
914  }
915  col.a = (system_item_scale_temp-minimumitemscaledown)/(maximumitemscaleup-minimumitemscaledown)+alphaadd;
916 //col.a=GetAlpha(oldpos,center_x,center_y,center_z,zdistance);
917  //IGNORE DIM AND OFF SCREEN SYETEMS
918  //**********************************
919  if ( (col.a < .05)
920  || ( !TestIfInRange( screenskipby4[0], screenskipby4[1], screenskipby4[2], screenskipby4[3], the_x, the_y ) ) ) {
921  ++systemIter;
922  continue;
923  }
924  //**********************************
925 
926  //FIND OUT IF SYSTEM IS PART OF A VISIBLE PATH
927  //**********************************
928  bool isPath = false;
929  if (path_view != PATH_OFF) {
930  if (systemIter->part_of_path) {
931  for (std::set< NavPath* >::iterator paths = systemIter->paths.begin();
932  paths != systemIter->paths.end();
933  ++paths)
934  if ( (*paths)->getVisible() ) {
935  isPath = true;
936  break;
937  }
938  }
939  }
940  //**********************************
941  //IGNORE NON-PATH SYSTEMS IN PATH_ONLY MODE
942  //**********************************
943  if (!isPath && path_view == PATH_ONLY) {
944  ++systemIter;
945  continue;
946  }
947  //**********************************
948 
949  int insert_type = systemambiguous;
950  float insert_size = SYSTEM_DEFAULT_SIZE;
951  if ( system_item_scale_temp > (system_item_scale*3) )
952  system_item_scale_temp = (system_item_scale*3);
953  insert_size *= system_item_scale_temp/3;
954  if (currentsystemindex == temp)
955  DrawTargetCorners( the_x, the_y, (insert_size), currentcol );
956  if (destinationsystemindex == temp)
957  DrawTargetCorners( the_x, the_y, (insert_size)*1.2, destinationcol );
958  if (systemselectionindex == temp)
959  DrawTargetCorners( the_x, the_y, (insert_size)*1.4, selectcol );
960  bool moused = false;
961  DrawNode( insert_type, insert_size, the_x, the_y,
962  (*systemIter).GetName(), screenoccupation, moused, isPath ? pathcol : col, false, false,
963  isPath ? "" : csector );
964  if (std::fabs(zdistance) < 2.0f * camera_z)
965  {
966  DisplayOrientationLines( the_x, the_y, the_x_flat, the_y_flat, 0 );
967  }
968  if ( TestIfInRangeRad( the_x, the_y, insert_size, mouse_x_current, mouse_y_current ) ) {
969  mouselist.push_back( systemdrawnode( insert_type, insert_size, the_x, the_y, (*systemIter).GetName(),
970  systemIter.getIndex(), screenoccupation, false, isPath ? pathcol : col ) );
971  moused = true;
972  }
973  unsigned destsize = systemIter->GetDestinationSize();
974  if (destsize != 0) {
975  GFXDisable( LIGHTING );
976  GFXDisable( TEXTURE0 );
977  GFXBegin( GFXLINE );
978  for (unsigned i = 0; i < destsize; ++i) {
979  CachedSystemIterator::SystemInfo &oth = systemIter[systemIter->GetDestinationIndex( i )];
980  if ( oth.isDrawable() ) {
981  QVector posoth = oth.Position();
982  ReplaceAxes( posoth );
983  Vector oldposoth = posoth;
984  float the_new_x, the_new_y, new_system_item_scale_temp, the_new_x_flat, the_new_y_flat;
985  //WARNING: SOME VARIABLES FOR ORIGINAL SYSTEM MAY BE MODIFIED HERE!!!
986  TranslateCoordinates( posoth,
987  pos_flat,
988  center_nav_x,
989  center_nav_y,
990  themaxvalue,
991  zscale,
992  zdistance,
993  the_new_x,
994  the_new_y,
995  the_new_x_flat,
996  the_new_y_flat,
997  new_system_item_scale_temp,
998  0 );
999  GFXColor othcol = oth.GetColor();
1000  othcol.a =
1001  (new_system_item_scale_temp
1002  -minimumitemscaledown)/(maximumitemscaleup-minimumitemscaledown)+alphaadd;
1003  //GetAlpha(oldposoth,center_x,center_y,center_z,zdistance);
1004  IntersectBorder( the_new_x, the_new_y, the_x, the_y );
1005 
1006  bool isConnectionPath = false;
1007  if (path_view != PATH_OFF) {
1008  if (systemIter->part_of_path && oth.part_of_path) {
1009  for (std::set< NavPath* >::iterator paths = systemIter->paths.begin();
1010  paths != systemIter->paths.end();
1011  ++paths)
1012  if ( (*paths)->getVisible() ) {
1013  if ( (*paths)->isNeighborPath( temp, systemIter->GetDestinationIndex( i ) ) ) {
1014  isConnectionPath = true;
1015  GFXColorf( pathcol );
1016  GFXVertex3f( the_x, the_y, 0 );
1017  GFXColorf( pathcol );
1018  GFXVertex3f( the_new_x, the_new_y, 0 );
1019  break;
1020  }
1021  }
1022  }
1023  }
1024  if (!isConnectionPath && path_view != PATH_ONLY) {
1025  GFXColorf( col );
1026  GFXVertex3f( the_x, the_y, 0 );
1027  GFXColorf( othcol );
1028  GFXVertex3f( the_new_x, the_new_y, 0 );
1029  }
1030  }
1031  }
1032  GFXEnd();
1033  }
1034  ++systemIter;
1035  }
1036  //**********************************
1037  //Adjust mouse list for 'n' kliks
1038  //**********************************
1039  //STANDARD : (1 3 2) ~ [0] [2] [1]
1040  //VS : (1 2 3) ~ [0] [1] [2] <-- use this
1041  if (mouselist.size() > 0) {
1042  //mouse is over a target when this is > 0
1043  if (mouse_wentdown[2] == 1) //mouse button went down for mouse button 2(standard)
1044  rotations += 1;
1045  }
1046  if ( rotations >= static_cast<int>(mouselist.size()) ) //dont rotate more than there is
1047  rotations = 0;
1048  systemdrawlist tmpv;
1049  int siz = mouselist.size();
1050  for (l = 0; l < siz; ++l)
1051  tmpv.push_back( mouselist[( (unsigned int) (l+rotations) )%( (unsigned int) siz )] );
1052  mouselist.swap( tmpv );
1053  //**********************************
1054  //Give back the selected tail IF there is one
1055  //**********************************
1056  if (mouselist.size() > 0) {
1057  //mouse is over a target when this is > 0
1058  if (mouse_wentdown[0] == 1) {
1059  //mouse button went down for mouse button 1
1060  unsigned oldselection = systemselectionindex;
1061  systemselectionindex = mouselist.back().getIndex();
1062  //JUST FOR NOW, target == current selection. later it'll be used for other shit, that will then set target.
1063  if (systemselectionindex == oldselection)
1064  setFocusedSystemIndex( systemselectionindex );
1065  }
1066  }
1067  //**********************************
1068 
1069  //Clear the lists
1070  //**********************************
1071  {
1072  for (systemdrawlist::iterator it = mouselist.begin(); it != mouselist.end(); ++it)
1073  (*it).draw( true, &(*it) == &mouselist.back() );
1074  }
1075 
1076  mouselist.clear(); //whipe mouse over'd list
1077  //**********************************
1078 }
1079