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
gamemenu.cpp File Reference
#include "vegastrike.h"
#include "in_kb.h"
#include "in_kb_data.h"
#include "in_mouse.h"
#include "main_loop.h"
#include "universe_util.h"
#include "lin_time.h"
#include "gui/modaldialog.h"
#include "gui/eventmanager.h"
#include "gui/newbutton.h"
#include "gui/staticdisplay.h"
#include "gui/textinputdisplay.h"
#include "gui/simplepicker.h"
#include "gui/groupcontrol.h"
#include "gui/scroller.h"
#include "networking/netclient.h"
#include "gamemenu.h"
#include "gfxlib_struct.h"
#include "cmd/music.h"

Go to the source code of this file.

Classes

class  ShipSelectorCallback
 

Namespaces

 UniverseUtil
 

Constant Groups

 UniverseUtil
 

Functions

void TerminateCurrentBase (void)
 
int shiftup (int)
 
void gamemenu_keyboard_handler (unsigned int ch, unsigned int mod, bool release, int x, int y)
 
void gamemenu_draw ()
 
void UniverseUtil::startMenuInterface (bool firstTime, string error)
 
void bootstrap_main_loop ()
 
void enableNetwork (bool usenet)
 

Variables

vector< unsigned intgamemenu_keyboard_queue
 

Function Documentation

void bootstrap_main_loop ( )

return to idle func which now should call main_loop mohahahah

Draw Texture

return to idle func which now should call main_loop mohahahah

Draw Texture

Definition at line 507 of file main.cpp.

References Universe::AccessCockpit(), AddUnitToSystem(), VegaConfig::bindKeys(), cleanexit, CopySavedShips(), createObjects(), Cockpit::credits, cur_check, game_data_t::difficulty, DockToSavedBases(), forcefeedback, g_game, getNewTime(), Mission::GetOrigin(), Cockpit::GetUnitFileName(), VegaConfig::getVariable(), Mission::getVariable(), global_password, global_username, UniverseUtil::hideSplashScreen(), i, ignore_network, Universe::Init(), InitializeInput(), Mission::initMission(), InitTime(), int, UniverseUtil::IOmessage(), j, k, FactionUtil::LoadContrabandLists(), LoadMission(), SaveGame::LoadSavedMissions(), Universe::Loop(), main_loop(), mission, mission_name, Network, Universe::numPlayers(), XMLSupport::parse_bool(), XMLSupport::parse_float(), XMLSupport::parse_int(), SaveGame::ParseSaveGame(), LeakVector< MyType >::push_back(), QVector, run_only_player_starsystem, Cockpit::savegame, NetClient::SetConfigServerAddress(), setNewTime(), SaveGame::SetOutputFileName(), SetPlayerLoc(), SaveGame::SetPlayerLocation(), SetPlayerSystem(), SaveGame::SetStarSystem(), SetStarSystemLoading(), SetStartupView(), Universe::SetupCockpits(), UniverseUtil::showSplashScreen(), Cockpit::TimeOfLastCollision, tostring(), Cockpit::UnpackUnitInfo(), UpdateTime(), Vector, vs_config, VSExit(), winsys_exit(), and WriteSaveGame().

Referenced by bootstrap_first_loop(), and GameMenu::processSinglePlayerButton().

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 ) )
595  std::string st;
596  if ( SetPlayerSystem( st, false ) )
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 
616  mysystem,
617  mysystem,
618  pos,
619  setplayerXloc,
620  credits,
621  packedInfo,
622  k,
623  savefiles[k][0],
624  false );
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)
732  if ( XMLSupport::parse_bool( vs_config->getVariable( "splash", "auto_hide", "true" ) ) )
734  }
736 }
void enableNetwork ( bool  usenet)

Definition at line 95 of file main.cpp.

References ignore_network.

Referenced by GameMenu::processSinglePlayerButton(), and GameMenu::readJoinGameControls().

96 {
97  ignore_network = !usenetwork;
98 }
void gamemenu_draw ( )
void gamemenu_keyboard_handler ( unsigned int  ch,
unsigned int  mod,
bool  release,
int  x,
int  y 
)

Definition at line 48 of file gamemenu.cpp.

References gamemenu_keyboard_queue, KB_MOD_ALT, KB_MOD_CTRL, KB_MOD_SHIFT, setActiveModifiers(), shiftup(), WSK_MOD_LALT, WSK_MOD_LCTRL, WSK_MOD_LSHIFT, WSK_MOD_RALT, WSK_MOD_RCTRL, and WSK_MOD_RSHIFT.

Referenced by UniverseUtil::startMenuInterface().

49 {
50  //Set modifiers
51  unsigned int amods = 0;
52  amods |= ( mod&(WSK_MOD_LSHIFT|WSK_MOD_RSHIFT) ) ? KB_MOD_SHIFT : 0;
53  amods |= ( mod&(WSK_MOD_LCTRL|WSK_MOD_RCTRL) ) ? KB_MOD_CTRL : 0;
54  amods |= ( mod&(WSK_MOD_LALT|WSK_MOD_RALT) ) ? KB_MOD_ALT : 0;
55  setActiveModifiers( amods );
56  //Queue keystroke
57  if (!release)
58  gamemenu_keyboard_queue.push_back( ( ( WSK_MOD_LSHIFT == (mod&WSK_MOD_LSHIFT) )
59  || ( WSK_MOD_RSHIFT == (mod&WSK_MOD_RSHIFT) ) ) ? shiftup( ch ) : ch );
60 }
int shiftup ( int  )

Definition at line 72 of file in_kb.cpp.

73 {
74  if ( ch == (ch&0xFF) ) {
75  const char *c = strchr( _lomap, ch );
76  if (c)
77  return _himap[c-_lomap];
78 
79  else
80  return toupper( ch );
81  } else {return ch; }}
void TerminateCurrentBase ( void  )

Definition at line 1151 of file base_interface.cpp.

1152 {
1156  }
1157 }

Variable Documentation

vector< unsigned int > gamemenu_keyboard_queue

Definition at line 22 of file gamemenu.cpp.

Referenced by GameMenu::createControls(), and gamemenu_keyboard_handler().