vegastrike  0.5.1.r1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
main.cpp
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2001-2002 Daniel Horn
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19 #include "config.h"
20 #include "cs_python.h"
21 #include "audio/test.h"
22 #if defined (HAVE_SDL)
23 #include <SDL/SDL.h>
24 #endif
25 #include "cmd/role_bitmask.h"
26 #if defined (WITH_MACOSX_BUNDLE)
27 #import <sys/param.h>
28 #endif
29 #ifdef _WIN32
30 #include <direct.h>
31 #include <process.h>
32 #endif
33 #include "gfxlib.h"
34 #include "in_kb.h"
35 #include "lin_time.h"
36 #include "main_loop.h"
37 #include "config_xml.h"
38 #include "cmd/script/mission.h"
39 #include "audiolib.h"
40 #include "config_xml.h"
41 #include "vsfilesystem.h"
42 #include "vs_globals.h"
43 #include "gfx/animation.h"
44 #include "cmd/unit.h"
45 #include "gfx/cockpit.h"
46 #include "python/init.h"
47 #include "savegame.h"
48 #include "force_feedback.h"
49 #include "gfx/hud.h"
50 #include "gldrv/winsys.h"
51 #include "universe_util.h"
52 #include "networking/netclient.h"
53 #include "universe.h"
54 #include "save_util.h"
55 #include "gfx/masks.h"
56 #include "cmd/music.h"
57 #include "ship_commands.h"
58 #include "gamemenu.h"
59 
60 
61 #include "audio/SceneManager.h"
62 #include "audio/TemplateManager.h"
63 #include "audio/renderers/OpenAL/BorrowedOpenALRenderer.h"
64 
65 #include <time.h>
66 #if !defined(_WIN32) && !defined (__HAIKU__)
67 #include <sys/signal.h>
68 #endif
69 
70 #if defined (_MSC_VER) && defined (_DEBUG)
71 #include <crtdbg.h>
72 #endif
73 
74 #if defined (CG_SUPPORT)
75 #include "cg_global.h"
76 #endif
77 
78 #include "options.h"
79 
80 extern std::string global_username;
81 extern std::string global_password;
82 
84 
85 /*
86  * Globals
87  */
89 TextPlane *bs_tp = NULL;
90 char SERVER = 0;
91 
92 //false if command line option --net is given to start without network
93 static bool ignore_network = true;
94 
95 void enableNetwork( bool usenetwork )
96 {
97  ignore_network = !usenetwork;
98 }
99 
100 /*
101  * Function definitions
102  */
103 
105 {
106  //pass in config file l8r??
107  g_game.audio_frequency_mode = 4; //22050/16
108  g_game.sound_enabled = 1;
109  g_game.use_textures = 1;
112  g_game.use_sprites = 1;
114  g_game.use_videos = 1;
115  g_game.use_logos = 1;
116  g_game.music_enabled = 1;
117  g_game.sound_volume = 1;
118  g_game.music_volume = 1;
119  g_game.warning_level = 20;
121  g_game.y_resolution = 768;
122  g_game.x_resolution = 1024;
123  g_game.fov = 78;
126 }
127 VegaConfig * createVegaConfig( const char *file )
128 {
129  return new GameVegaConfig( file );
130 }
131 
132 std::string ParseCommandLine(int argc, char ** CmdLine);
137 int readCommandLineOptions(int argc, char ** argv);
138 
139 // FIXME: Code should throw exception instead of calling exit
140 void VSExit( int code)
141 {
142  Music::CleanupMuzak();
143  winsys_exit( code );
144 }
145 
146 void cleanup( void )
147 {
148  STATIC_VARS_DESTROYED = true;
149  printf( "Thank you for playing!\n" );
150  //In network mode, we may not do the save since it is useless
151  if (_Universe != NULL && Network == NULL)
152  _Universe->WriteSaveGame( true );
153 #ifdef _WIN32
154 #if defined (_MSC_VER) && defined (_DEBUG)
155  if (!cleanexit)
156  _RPT0( _CRT_ERROR, "WARNING: Vega Strike exit not clean\n" );
157  return;
158 #endif
159 #else
160  while (!cleanexit)
161  usleep(10000);
162 #endif
163  if (Network != NULL) {
164  cout<<"Number of players"<<_Universe->numPlayers()<<endl;
165  for (size_t i = 0; i < _Universe->numPlayers(); i++)
166  if ( Network[i].isInGame() )
167  Network[i].logout( false );
168  delete[] Network;
169  }
170 #if defined (CG_SUPPORT)
171  if (cloak_cg->vertexProgram) cgDestroyProgram( cloak_cg->vertexProgram );
172  if (cloak_cg->shaderContext) cgDestroyContext( cloak_cg->shaderContext );
173 #endif
174  Music::CleanupMuzak();
175  winsys_shutdown();
176  AUDDestroy();
177  delete[] CONFIGFILE;
178 }
179 
181 
182 char mission_name[1024];
183 
184 void bootstrap_main_loop();
185 void bootstrap_first_loop();
186 #if defined (WITH_MACOSX_BUNDLE)
187 //WTF! this causes windowed creation to fail... please justify yourself ;-) #undef main
188 #endif
189 void nothinghappens( unsigned int, unsigned int, bool, int, int ) {}
190 
192 {
193  cout << "Creating scene manager..." << endl;
194  Audio::SceneManager *sm = Audio::SceneManager::getSingleton();
195 
196  cout << "Creating template manager..." << endl;
197  Audio::TemplateManager::getSingleton();
198 
199  if (Audio::SceneManager::getSingleton() == 0)
200  throw Audio::Exception("Singleton null after SceneManager instantiation");
201 
202  sm->setMaxSources( g_game.max_sound_sources );
203 }
204 
206 {
207  cerr << " Initializing renderer..." << endl;
208  Audio::SceneManager *sm = Audio::SceneManager::getSingleton();
209 
210  if (g_game.sound_enabled) {
211  SharedPtr<Audio::Renderer> renderer(new Audio::BorrowedOpenALRenderer);
212  renderer->setMeterDistance(1.0);
213  renderer->setDopplerFactor(0.0);
214 
215  sm->setRenderer( renderer );
216  }
217 }
218 
220 {
221  Audio::SceneManager *sm = Audio::SceneManager::getSingleton();
222 
223  sm->createScene("video");
224  sm->createScene("music");
225  sm->createScene("cockpit");
226  sm->createScene("base");
227  sm->createScene("space");
228 
229  sm->setSceneActive("video", true);
230 }
231 
233 {
234  cerr << "Shutting down renderer..." << endl;
235  Audio::SceneManager::getSingleton()->setRenderer( SharedPtr<Audio::Renderer>() );
236 }
237 
238 extern void InitUnitTables();
239 extern void CleanupUnitTables();
240 bool isVista = false;
241 int main( int argc, char *argv[] )
242 {
244  CONFIGFILE = 0;
245  mission_name[0] = '\0';
246  {
247  char pwd[8192] = "";
248  if (NULL != getcwd( pwd, 8191 )) {
249  pwd[8191] = '\0';
250  printf( " In path %s\n", pwd );
251  } else {
252  printf( " In path <<path too long>>\n" );
253  }
254  }
255 #ifdef _WIN32
256  OSVERSIONINFO osvi;
257  ZeroMemory( &osvi, sizeof (OSVERSIONINFO) );
258  osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO);
259 
260  GetVersionEx( &osvi );
261  isVista = (osvi.dwMajorVersion == 6);
262  printf( "Windows version %d %d\n", osvi.dwMajorVersion, osvi.dwMinorVersion );
263 #endif
264  /* Print copyright notice */
265  printf( "Vega Strike " " \n"
266  "See http://www.gnu.org/copyleft/gpl.html for license details.\n\n" );
267  /* Seed the random number generator */
268  if (benchmark < 0.0)
269  srand( time( NULL ) );
270  else
271  //in benchmark mode, always use the same seed
272  srand( 171070 );
273  //this sets up the vegastrike config variable
274  setup_game_data();
275  //loads the configuration file .vegastrike/vegastrike.config from home dir if such exists
276  {
277  string subdir = ParseCommandLine( argc, argv );
278  cerr<<"GOT SUBDIR ARG = "<<subdir<<endl;
279  if (CONFIGFILE == 0) {
280  CONFIGFILE = new char[42];
281  sprintf( CONFIGFILE, "vegastrike.config" );
282  }
283  //Specify the config file and the possible mod subdir to play
285  }
286 
287  //This should be put into some common function...
288  //Keep in mind that initialization must also go into networking/netserver.cpp
289  game_options.init();
290  //If no debug argument is supplied, set to what the config file has.
291  if (g_game.vsdebug == '0')
292  g_game.vsdebug = game_options.vsdebug;
293  //can use the vegastrike config variable to read in the default mission
294  if ( XMLSupport::parse_bool( vs_config->getVariable( "network", "force_client_connect", "false" ) ) )
295  ignore_network = false;
296  g_game.music_enabled = XMLSupport::parse_bool( vs_config->getVariable( "audio", "Music", "true" ) );
297  if (mission_name[0] == '\0') {
298  std::string defmis = vs_config->getVariable( "general", "default_mission", "test/test1.mission" );
299  strncpy( mission_name, defmis.c_str(), 1023 );
300  mission_name[1023] = '\0';
301  cerr<<"MISSION_NAME is empty using : "<<mission_name<<endl;
302  }
303 
304 
305  int exitcode;
306  if ((exitcode = readCommandLineOptions(argc,argv)) >= 0)
307  return exitcode;
308 
309  //might overwrite the default mission with the command line
310  InitUnitTables();
311 #ifdef HAVE_PYTHON
312  Python::init();
313 
314  Python::test();
315 #endif
316 
317  std::vector<std::vector <char > > temp = ROLES::getAllRolePriorities();
318 #if defined(HAVE_SDL)
319 #ifndef NO_SDL_JOYSTICK
320  if ( SDL_InitSubSystem( SDL_INIT_JOYSTICK ) ) {
321  VSFileSystem::vs_fprintf( stderr, "Couldn't initialize SDL: %s\n", SDL_GetError() );
322  winsys_exit( 1 );
323  }
324 #endif
325 #endif
326 #if 0
327  InitTime();
328  UpdateTime();
329 #endif
330 
331  AUDInit();
332  AUDListenerGain( XMLSupport::parse_float( vs_config->getVariable( "audio", "sound_gain", ".5" ) ) );
333  Music::InitMuzak();
334 
336  initALRenderer();
337  initScenes();
338 
339  //Register commands
340  //COmmand Interpretor Seems to break VC8, so I'm leaving disabled for now - Patrick, Dec 24
341  if ( XMLSupport::parse_bool( vs_config->getVariable( "general", "command_interpretor", "false" ) ) ) {
344  }
345  _Universe = new GameUniverse( argc, argv, vs_config->getVariable( "general", "galaxy", "milky_way.xml" ).c_str() );
346  _Universe->Loop( bootstrap_first_loop );
347 
348  //Unregister commands - and cleanup memory
350 
351  closeRenderer();
352 
353  cleanup();
354 
355  delete _Universe;
357  return 0;
358 }
359 
360 static Animation *SplashScreen = NULL;
361 static bool BootstrapMyStarSystemLoading = true;
362 void SetStarSystemLoading( bool value )
363 {
364  BootstrapMyStarSystemLoading = value;
365 }
367 {
368  return BootstrapMyStarSystemLoading;
369 }
370 void SetSplashScreen( Animation *ss )
371 {
372  SplashScreen = ss;
373 }
374 Animation * GetSplashScreen()
375 {
376  return SplashScreen;
377 }
378 void bootstrap_draw( const std::string &message, Animation *newSplashScreen )
379 {
380  static Animation *ani = NULL;
381  static bool reentryWatchdog = false;
382  if (!BootstrapMyStarSystemLoading || reentryWatchdog)
383  return;
384  Music::MuzakCycle(); //Allow for loading music...
385  if (SplashScreen == NULL && newSplashScreen == NULL) {
386  //if there's no splashscreen, we don't draw on it
387  //this happens, when the splash screens texture is loaded
388  return;
389  }
390 
391  reentryWatchdog = true;
392  if (newSplashScreen != NULL)
393  ani = newSplashScreen;
394  UpdateTime();
395 
396  Matrix tmp;
397  Identity( tmp );
398  BootstrapMyStarSystemLoading = false;
399  static Texture dummy( "white.bmp", 0, MIPMAP, TEXTURE2D, TEXTURE_2D, 1 );
400  BootstrapMyStarSystemLoading = true;
401  dummy.MakeActive();
402  GFXDisable( LIGHTING );
404  GFXBlendMode( ONE, ZERO );
405  GFXEnable( TEXTURE0 );
406  GFXDisable( TEXTURE1 );
407  GFXColor4f( 1, 1, 1, 1 );
408  GFXClear( GFXTRUE );
411  GFXLoadMatrixModel( tmp );
412  GFXBeginScene();
413 
414  bs_tp->SetPos( -.99, -.97 ); //Leave a little bit of room for the bottoms of characters.
415  bs_tp->SetCharSize( .4, .8 );
416  ScaleMatrix( tmp, Vector( 6500, 6500, 0 ) );
417  GFXLoadMatrixModel( tmp );
418  GFXHudMode( GFXTRUE );
419  if (ani) {
420  if (GetElapsedTime() < 10) ani->UpdateAllFrame();
421  {
422  ani->DrawNow( tmp ); //VSFileSystem::vs_fprintf( stderr, "(new?) splash screen ('animation'?) %d. ", (long long)ani ); //temporary, by chuck
423  }
424  }
425 
426  static std::string defaultbootmessage = vs_config->getVariable( "graphics", "default_boot_message", "" );
427  static std::string initialbootmessage = vs_config->getVariable( "graphics", "initial_boot_message", "Loading..." );
428  bs_tp->Draw( defaultbootmessage.length() > 0 ? defaultbootmessage : message.length() > 0 ? message : initialbootmessage );
429 
430  GFXHudMode( GFXFALSE );
431  GFXEndScene();
432 
433  reentryWatchdog = false;
434 }
435 extern Unit **fighters;
436 
437 bool SetPlayerLoc( QVector &sys, bool set )
438 {
439  static QVector mysys;
440  static bool isset = false;
441  if (set) {
442  isset = true;
443  mysys = sys;
444  return true;
445  } else {
446  if (isset)
447  sys = mysys;
448  return isset;
449  }
450 }
451 bool SetPlayerSystem( std::string &sys, bool set )
452 {
453  static std::string mysys;
454  static bool isset = false;
455  if (set) {
456  isset = true;
457  mysys = sys;
458  return true;
459  } else {
460  if (isset)
461  sys = mysys;
462  return isset;
463  }
464 }
465 vector< string >parse_space_string( std::string s )
466 {
467  vector< string > ret;
468  string::size_type index = 0;
469  while ( ( index = s.find( " " ) ) != string::npos ) {
470  ret.push_back( s.substr( 0, index ) );
471  s = s.substr( index+1 );
472  }
473  ret.push_back( s );
474  return ret;
475 }
477 {
478  static int i = 0;
479  static std::string ss = vs_config->getVariable( "graphics", "splash_screen", "vega_splash.ani" );
480  static std::string sas = vs_config->getVariable( "graphics", "splash_audio", "" );
481  static bool isgamemenu = XMLSupport::parse_bool( vs_config->getVariable( "graphics", "main_menu", "false" ) );
482  if (i == 0) {
483  vector< string >s = parse_space_string( ss );
484  vector< string >sa = parse_space_string( sas );
485  int snum = time( NULL )%s.size();
486  SplashScreen = new Animation( s[snum].c_str(), 0 );
487  if ( sa.size() && sa[0].length() ) muzak->GotoSong( sa[snum%sa.size()] );
488  bs_tp = new TextPlane();
489  }
490  bootstrap_draw( "Vegastrike Loading...", SplashScreen );
491  if (i++ > 4) {
492  if (_Universe) {
493  if (isgamemenu)
495  else
496  _Universe->Loop( bootstrap_main_loop );
497  }
498  }
499 }
500 void SetStartupView( Cockpit *cp )
501 {
502  static std::string startupview = vs_config->getVariable( "graphics", "startup_cockpit_view", "front" );
503  cp->SetView( startupview
504  == "view_target" ? CP_TARGET : ( startupview
505  == "back" ? CP_BACK : (startupview == "chase" ? CP_CHASE : CP_FRONT) ) );
506 }
508 {
509  static bool LoadMission = true;
510  static bool loadLastSave = XMLSupport::parse_bool( vs_config->getVariable( "general", "load_last_savegame", "false" ) );
511  InitTime();
512  if (LoadMission) {
513  LoadMission = false;
514  active_missions.push_back( mission = new Mission( mission_name ) );
515 
516  mission->initMission();
517 
518  UniverseUtil::showSplashScreen( "" ); //Twice for double or triple-buffering
520 
521  QVector pos;
522  string planetname;
523 
524  mission->GetOrigin( pos, planetname );
525  bool setplayerloc = false;
526  string mysystem = mission->getVariable( "system", "sol.system" );
527 
528  int numplayers;
529  numplayers = XMLSupport::parse_int( mission->getVariable( "num_players", "1" ) );
530  vector< std::string >playername;
531  vector< std::string >playerpasswd;
532  string pname, ppasswd;
533  for (int p = 0; p < numplayers; p++) {
534  pname = vs_config->getVariable( "player"+( (p > 0) ? tostring( p+1 ) : string( "" ) ), "callsign", "" );
535  ppasswd = vs_config->getVariable( "player"+( (p > 0) ? tostring( p+1 ) : string( "" ) ), "password", "" );
536  if ( p == 0 && global_username.length() )
537  pname = global_username;
538  if ( p == 0 && global_password.length() )
539  ppasswd = global_password;
540  if (!ignore_network) {
541  //In network mode, test if all player sections are present
542  if (pname == "") {
543  cout<<"Missing or incomlpete section for player "<<p<<endl;
544  cleanexit = true;
545  winsys_exit( 1 );
546  }
547  }
548  playername.push_back( pname );
549  playerpasswd.push_back( ppasswd );
550  }
551  float credits = XMLSupport::parse_float( mission->getVariable( "credits", "0" ) );
552  g_game.difficulty = XMLSupport::parse_float( mission->getVariable( "difficulty", "1" ) );
553  string savegamefile = mission->getVariable( "savegame", "" );
554  vector< SavedUnits > savedun;
555  vector< string > playersaveunit;
556  vector< StarSystem* >ss;
557  vector< string > starsysname;
558  vector< QVector > playerNloc;
559 
560  /************************* NETWORK INIT ***************************/
561  vector< vector< std::string > >savefiles;
562  if (!ignore_network) {
563  cout<<"Number of local players = "<<numplayers<<endl;
564  //Initiate the network if in networking play mode for each local player
565  if (!ignore_network) {
566  setNewTime( 0. );
567  //Get the number of local players
568  Network = new NetClient[numplayers];
569 
570  //Here we say we want to only handle activity in 1 starsystem not more
572  } else {
573  Network = NULL;
574  cout<<"Non-networking mode"<<endl;
575  //Here we say we want to only handle activity in 1 starsystem not more
577  }
578  }
579  _Universe->SetupCockpits( playername );
580 
581  /************************* NETWORK INIT ***************************/
582  vector< std::string >::iterator it, jt;
583  unsigned int k = 0;
584  for (k = 0, it = playername.begin(), jt = playerpasswd.begin();
585  k < (unsigned int) _Universe->numPlayers();
586  k++, it++, jt++) {
587  Cockpit *cp = _Universe->AccessCockpit( k );
588  SetStartupView( cp );
589  bool setplayerXloc = false;
590  std::string psu;
591  if (k == 0) {
592  QVector myVec;
593  if ( SetPlayerLoc( myVec, false ) )
594  _Universe->AccessCockpit( 0 )->savegame->SetPlayerLocation( myVec );
595  std::string st;
596  if ( SetPlayerSystem( st, false ) )
597  _Universe->AccessCockpit( 0 )->savegame->SetStarSystem( st );
598  }
599  vector< SavedUnits >saved;
600  /************* NETWORK PART ***************/
601  vector< string > packedInfo;
602 
603  if (Network != NULL) {
604  string err;
605  string srvipadr;
606  unsigned short port;
607  //Are we using the directly account server to identify us ?
608  Network[k].SetConfigServerAddress( srvipadr, port ); //Sets from the config vars.
609  if ( !Network[k].connectLoad( pname, ppasswd, err ) ) {
610  cout<<"error while connecting: "<<err<<endl;
611  VSExit( 1 );
612  }
613  savefiles.push_back( *Network[k].loginSavedGame( 0 ) );
614 
615  _Universe->AccessCockpit( k )->savegame->ParseSaveGame( "",
616  mysystem,
617  mysystem,
618  pos,
619  setplayerXloc,
620  credits,
621  packedInfo,
622  k,
623  savefiles[k][0],
624  false );
625  _Universe->AccessCockpit( k )->TimeOfLastCollision = getNewTime();
626  } else {
627  if (loadLastSave) {
628  _Universe->AccessCockpit( k )->savegame->ParseSaveGame( savegamefile,
629  mysystem,
630  mysystem,
631  pos,
632  setplayerXloc,
633  credits,
634  packedInfo,
635  k );
636  } else {
637  _Universe->AccessCockpit( k )->savegame->SetOutputFileName( savegamefile );
638  }
639  }
640  _Universe->AccessCockpit( k )->UnpackUnitInfo(packedInfo);
641  CopySavedShips( playername[k], k, packedInfo, true );
642  playersaveunit.push_back( _Universe->AccessCockpit( k )->GetUnitFileName() );
643  _Universe->AccessCockpit( k )->credits = credits;
644  ss.push_back( _Universe->Init( mysystem, Vector( 0, 0, 0 ), planetname ) );
645  if (setplayerXloc)
646  playerNloc.push_back( pos );
647  else
648  playerNloc.push_back( QVector( FLT_MAX, FLT_MAX, FLT_MAX ) );
649  setplayerloc = setplayerXloc; //FIX ME will only set first player where he was
650  for (unsigned int j = 0; j < saved.size(); j++)
651  savedun.push_back( saved[j] );
652  }
653  SetStarSystemLoading( true );
654  InitializeInput();
655 
656  vs_config->bindKeys(); //gotta do this before we do ai
657 
658  createObjects( playersaveunit, ss, playerNloc, savefiles );
659  while ( !savedun.empty() ) {
660  AddUnitToSystem( &savedun.back() );
661  savedun.pop_back();
662  }
664 
665  UpdateTime();
667  {
668  string str = vs_config->getVariable(
669  "general",
670  "intro1",
671  "Welcome to Vega Strike! Use #8080FFTab#000000 to afterburn (#8080FF+,-#000000 cruise control), #8080FFarrows#000000 to steer." );
672  if ( !str.empty() ) {
673  UniverseUtil::IOmessage( 0, "game", "all", str );
674  str = vs_config->getVariable(
675  "general",
676  "intro2",
677  "The #8080FFt#000000 key targets objects; #8080FFspace#000000 fires at them & #8080FFa#000000 activates the SPEC drive. To" );
678  if ( !str.empty() ) {
679  UniverseUtil::IOmessage( 4, "game", "all", str );
680  str = vs_config->getVariable(
681  "general",
682  "intro3",
683  "go to another star system, buy a jump drive for about 10000 credits, fly to a" );
684  if ( !str.empty() ) {
685  UniverseUtil::IOmessage( 8, "game", "all", str );
686  str = vs_config->getVariable(
687  "general",
688  "intro4",
689  "wireframe jump-point and press #8080FFj#000000 to warp to a near star. Target a base or planet;" );
690  if ( !str.empty() ) {
691  UniverseUtil::IOmessage( 12, "game", "all", str );
692  str = vs_config->getVariable(
693  "general",
694  "intro5",
695  "When you get close a green box will appear. Inside the box, #8080FFd#000000 will land." );
696  if ( !str.empty() )
697  UniverseUtil::IOmessage( 16, "game", "all", str );
698  }
699  }
700  }
701  }
702  }
703  //Never dock on load in networking if it was said so in the save file NETFIXME--this may change
704  if ( Network == NULL
705  && mission->getVariable( "savegame",
706  "" ).length() != 0
707  && XMLSupport::parse_bool( vs_config->getVariable( "AI", "dockOnLoad", "true" ) ) ) {
708  for (size_t i = 0; i < _Universe->numPlayers(); i++) {
709  QVector vec;
710  DockToSavedBases( i, vec );
711  }
712  }
713  cout<<"Loading completed, now network init"<<endl;
714  //Send a network msg saying we are ready and also send position info
715  if (Network != NULL) {
716  size_t l;
717  //Downloading zone info before setting inGame (CMD_ADDCLIENT) causes a race condition.
718  //CMD_ADDEDYOU (response to CMD_ADDCLIENT) now sends zone info.
719  for (l = 0; l < _Universe->numPlayers(); l++)
720  Network[l].inGame();
721  }
722  if (loadLastSave) {
723  //Don't write if we didn't load...
724  for (unsigned int i = 0; i < _Universe->numPlayers(); ++i)
725  WriteSaveGame( _Universe->AccessCockpit( i ), false );
726  }
727  cur_check = getNewTime();
728  for (unsigned int i = 0; i < _Universe->numPlayers(); ++i)
729  _Universe->AccessCockpit( i )->savegame->LoadSavedMissions();
730  _Universe->Loop( main_loop );
732  if ( XMLSupport::parse_bool( vs_config->getVariable( "splash", "auto_hide", "true" ) ) )
734  }
736 }
737 
738 const char helpmessage[] =
739  "Command line options for vegastrike\n"
740  "\n"
741  " -D -d \t Specify data directory\n"
742  " -N -n \t Number of players\n"
743  " -M -m \t Specify a mod to play\n"
744  " -P -p \t Specify player location\n"
745  " -J -j \t Start in a specific system\n"
746  " -A -a \t Normal resolution (800x600)\n"
747  " -H -h \t High resolution (1024x768)\n"
748  " -V -v \t Super high resolution (1280x1024)\n"
749  " --net \t Networking Enabled (Experimental)\n"
750  " --debug[=#] \t Enable debugging output, 1 major warnings, 2 medium, 3 developer notes\n"
751  " --test-audio \t Run audio tests\n"
752  "\n";
753 std::string ParseCommandLine( int argc, char **lpCmdLine )
754 {
755  std::string st;
756  std::string retstr;
757  std::string datatmp;
758  g_game.vsdebug = '0';
759  QVector PlayerLocation;
760  for (int i = 1; i < argc; i++) {
761  if (lpCmdLine[i][0] == '-') {
762  cerr<<"ARG #"<<i<<" = "<<lpCmdLine[i]<<endl;
763  switch (lpCmdLine[i][1])
764  {
765  case 'd':
766  case 'D':
767  //Specifying data directory
768  if (lpCmdLine[i][2] == 0) {
769  cout<<"Option -D requires an argument"<<endl;
770  exit( 1 );
771  }
772  datatmp = &lpCmdLine[i][2];
773  if ( VSFileSystem::DirectoryExists( datatmp ) ) {
774  VSFileSystem::datadir = datatmp;
775  } else {
776  cout<<"Specified data directory not found... exiting"<<endl;
777  exit( 1 );
778  }
779  cout<<"Using data dir specified on command line : "<<datatmp<<endl;
780  break;
781  case 'r':
782  case 'R':
783  break;
784  case 'N':
785  case 'n':
786  if ( !(lpCmdLine[i][2] == '1' && lpCmdLine[i][3] == '\0') ) {
787  CONFIGFILE = new char[40+strlen( lpCmdLine[i] )+1];
788  sprintf( CONFIGFILE, "vegastrike.config.%splayer", lpCmdLine[i]+2 );
789  }
790  break;
791  case 'M':
792  case 'm':
793  retstr = string( lpCmdLine[i]+2 );
794  break;
795  case 'f':
796  case 'F':
797  break;
798  case 'U':
799  case 'u':
800  global_username = lpCmdLine[i]+2;
801  break;
802  case 'P':
803  case 'p':
804  global_password = lpCmdLine[i]+2;
805  break;
806  case 'L':
807  case 'l':
808  if ( 3 == sscanf( lpCmdLine[i]+2, "%lf,%lf,%lf", &PlayerLocation.i, &PlayerLocation.j, &PlayerLocation.k ) )
809  SetPlayerLoc( PlayerLocation, true );
810  break;
811  case 'J':
812  case 'j': //low rez
813  st = string( (lpCmdLine[i])+2 );
814  SetPlayerSystem( st, true );
815  break;
816  case 'A': //average rez
817  case 'a':
818  g_game.y_resolution = 600;
819  g_game.x_resolution = 800;
820  break;
821  case 'H':
822  case 'h': //high rez
823  g_game.y_resolution = 768;
824  g_game.x_resolution = 1024;
825  break;
826  case 'V':
827  case 'v':
828  g_game.y_resolution = 1024;
829  g_game.x_resolution = 1280;
830  break;
831  case 'G':
832  case 'g':
833  break;
834  case '-':
835  //long options
836  if (strcmp( lpCmdLine[i], "--benchmark" ) == 0) {
837  benchmark = atof( lpCmdLine[i+1] );
838  i++;
839  } else if (strcmp( lpCmdLine[i], "--net" ) == 0) {
840  //don't ignore the network section of the config file
841  ignore_network = false;
842  } else if (strcmp( lpCmdLine[i], "--help" ) == 0) {
843  cout<<helpmessage;
844  exit( 0 );
845  } else if (strncmp( lpCmdLine[i], "--debug", 7 ) == 0) {
846  if (lpCmdLine[i][7] == 0) {
847  g_game.vsdebug = 1;
848  } else if (lpCmdLine[i][8] == 0) {
849  cout<<helpmessage;
850  exit( 0 );
851  }
852  g_game.vsdebug = lpCmdLine[i][8] - '0';
853  ++i;
854  }
855  break;
856  }
857  } else {
858  //no "-" before it - it's the mission name
859  strncpy( mission_name, lpCmdLine[i], 1023 );
860  mission_name[1023] = '\0';
861  }
862  }
863  return retstr;
864 }
865 #undef main
866 int readCommandLineOptions(int argc, char ** argv)
867 {
868  for (int i=1; i < argc; ++i) {
869  if (argv[i][0] == '-') {
870  if (strcmp("--test-audio", argv[i])==0) {
871  return Audio::Test::main(argc, argv);
872  }
873  }
874  }
875  return -1;
876 }