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
navscreen.cpp File Reference
#include <set>
#include "vsfilesystem.h"
#include "vs_globals.h"
#include "vegastrike.h"
#include "gfx/gauge.h"
#include "gfx/cockpit.h"
#include "universe.h"
#include "star_system.h"
#include "cmd/unit_generic.h"
#include "cmd/unit_factory.h"
#include "cmd/collection.h"
#include "gfx/hud.h"
#include "gfx/vdu.h"
#include "lin_time.h"
#include "config_xml.h"
#include "cmd/images.h"
#include "cmd/script/mission.h"
#include "cmd/script/msgcenter.h"
#include "cmd/ai/flyjoystick.h"
#include "cmd/ai/firekeyboard.h"
#include "cmd/ai/aggressive.h"
#include "main_loop.h"
#include <assert.h>
#include "savegame.h"
#include "gfx/animation.h"
#include "gfx/mesh.h"
#include "universe_util.h"
#include "in_mouse.h"
#include "gui/glut_support.h"
#include "networking/netclient.h"
#include "cmd/unit_util.h"
#include "math.h"
#include "save_util.h"
#include "navscreen.h"
#include "gfx/masks.h"
#include "navgetxmldata.h"
#include "navitemstodraw.h"
#include "navparse.h"
#include "navcomputer.h"
#include "navpath.h"

Go to the source code of this file.

Functions

string MakeUnitXMLPretty (string str, Unit *un)
 
template<class T >
static bool intersect (T x0, T y0, T x1, T y1, T sx0, T sy0, T sx1, T sy1, T &ansx, T &ansy)
 
void Beautify (string systemfile, string &sector, string &system)
 

Function Documentation

void Beautify ( string  systemfile,
string &  sector,
string &  system 
)

Definition at line 1878 of file navscreen.cpp.

Referenced by NavigationSystem::DrawGalaxy(), DrawNode(), NavigationSystem::DrawSectorList(), NavigationSystem::CachedSectorIterator::init(), and CriteriaSector::isDestination().

1879 {
1880  string::size_type slash = systemfile.find( "/" );
1881  if (slash == string::npos) {
1882  sector = "";
1883  system = systemfile;
1884  } else {
1885  sector = systemfile.substr( 0, slash );
1886  system = systemfile.substr( slash+1 );
1887  }
1888  if ( sector.size() )
1889  sector[0] = toupper( sector[0] );
1890  if ( system.size() )
1891  system[0] = toupper( system[0] );
1892 }
template<class T >
static bool intersect ( x0,
y0,
x1,
y1,
sx0,
sy0,
sx1,
sy1,
T &  ansx,
T &  ansy 
)
inlinestatic

Definition at line 1236 of file navscreen.cpp.

Referenced by NavigationSystem::IntersectBorder().

1237 {
1238  bool fxy = false;
1239  if ( ( (x1 == x0) && (sx1 == sx0) ) || ( (x1 == x0) && (y1 == y0) ) || ( (sx1 == sx0) && (sy1 == sy0) ) ) {
1240  //If both lines are vertical, then act as if they don't intersect.
1241  //If either one is a point, then for all practical purposes they do not intersect.
1242  return false;
1243  }
1244  if ( (x1 == x0) && (sy1 == sy0) ) {
1245  //Line 1 vertical, line 2 horizontal.
1246  ansx = x1;
1247  ansy = sy1;
1248  return ( (sx0 <= x1
1249  && x1 <= sx1) || (sx1 <= x1 && x1 <= sx0) ) && ( (y0 <= sy1 && sy1 <= y1) || (y1 <= sy1 && sy1 <= y0) );
1250  }
1251  if ( (sx1 == sx0) && (y1 == y0) ) {
1252  //line 1 horizontal, Line 2 vertical.
1253  ansx = sx1;
1254  ansy = y1;
1255  return ( (x0 <= sx1
1256  && sx1 <= x1) || (x1 <= sx1 && sx1 <= x0) ) && ( (sy0 <= y1 && y1 <= sy1) || (sy1 <= y1 && y1 <= sy0) );
1257  }
1258  //If either line is vertical (both was handled above), then flip the coordinate plane to prevent division by zero.
1259  if ( (x1 == x0) || (sx1 == sx0) ) {
1260  T temp = x0;
1261  x0 = y0;
1262  y0 = temp;
1263  temp = x1;
1264  x1 = y1;
1265  y1 = temp;
1266  fxy = true;
1267  temp = sx0;
1268  sx0 = sy0;
1269  sy0 = temp;
1270  temp = sx1;
1271  sx1 = sy1;
1272  sy1 = temp;
1273  fxy = true;
1274  }
1275  //Now we can be sure that no vertical lines exist.
1276  //Proceed with the operation.
1277  T m = (y1-y0)/(x1-x0);
1278  T sm = (sy1-sy0)/(sx1-sx0);
1279  if (m == sm)
1280  //Parallel Lines
1281  return false;
1282  ansx = (m*x1-sm*sx1-y1+sy1)/(m-sm);
1283  ansy = (y1-m*x1+m*ansx);
1284  if ( ( (x0 <= ansx
1285  && ansx <= x1)
1286  || (x1 <= ansx && ansx <= x0) ) && ( (sx0 <= ansx && ansx <= sx1) || (sx1 <= ansx && ansx <= sx0) ) ) {
1287  //Inside the line segment.
1288  if (fxy) {
1289  //Deswapify them!
1290  T temp = ansx;
1291  ansx = ansy;
1292  ansy = temp;
1293  }
1294  return true;
1295  }
1296  //Too bad. They are outside the line segment
1297  return false;
1298 }
string MakeUnitXMLPretty ( string  str,
Unit un 
)

Definition at line 39 of file unit_xml.cpp.

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

40 {
41  string writestr;
42  if (un) {
43  writestr += "Name: "+un->name;
44  writestr += " "+un->getFullname();
45  Flightgroup *fg = un->getFlightgroup();
46  if (fg)
47  writestr += " Designation "+fg->name+" "+XMLSupport::tostring( un->getFgSubnumber() );
48  writestr += "\n";
49  }
50  static std::set< string >lookfor;
51  if ( lookfor.empty() ) {
52  lookfor.insert( "Shie" );
53  lookfor.insert( "Armo" );
54 //lookfor.insert ("Hull");
55  lookfor.insert( "Reac" );
56  lookfor.insert( "Moun" );
57  lookfor.insert( "Comp" );
58 //lookfor.insert ("Desc");
59  lookfor.insert( "Engi" );
60  lookfor.insert( "Mane" );
61  lookfor.insert( "Jump" );
62 //lookfor.insert ("Defe");
63  lookfor.insert( "Stat" );
64  lookfor.insert( "Engi" );
65 //lookfor.insert ("Hold");
66  lookfor.insert( "Rada" );
67  }
68  std::string::size_type foundpos;
69  while ( ( foundpos = str.find( "<" ) ) != string::npos ) {
70  if (str.size() <= foundpos+1)
71  break;
72  str = str.substr( foundpos+1 );
73  if (str.size() > 3) {
74  char mycomp[5] = {str[0], str[1], str[2], str[3], 0};
75  if ( lookfor.find( mycomp ) != lookfor.end() ) {
76  int newline = str.find( ">" );
77  if (newline > 0)
78  if (str[newline-1] == '/')
79  newline -= 1;
80  writestr += KillQuadZeros( str.substr( 0, newline )+"\n" );
81  }
82  }
83  }
84  return writestr;
85 }