vegastrike  0.5.1.r1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
universe_util.cpp
Go to the documentation of this file.
1 #include "cmd/script/mission.h"
4 #include "universe_util.h"
5 #include "universe.h"
6 #include "cmd/unit.h"
7 #include "cmd/unit_factory.h" //for UnitFactory::getMasterPartList()
8 #include "cmd/collection.h"
9 #include "star_system.h"
10 #include <string>
11 #include "networking/netclient.h"
12 #include "cmd/music.h"
13 #include "audiolib.h"
14 #include "gfx/animation.h"
15 #include "lin_time.h"
16 #include "load_mission.h"
17 #include "config_xml.h"
18 #include "vs_globals.h"
19 #include "gfx/particle.h"
20 #include "cmd/base.h"
21 #include "options.h"
22 
24 
25 extern unsigned int AddAnimation( const QVector &pos,
26  const float size,
27  bool mvolatile,
28  const std::string &name,
29  float percentgrow );
30 extern void RespawnNow( Cockpit *cp );
31 extern void TerminateCurrentBase( void );
32 extern void SetStarSystemLoading( bool value );
33 extern bool GetStarSystemLoading();
34 extern void bootstrap_draw( const std::string &message, Animation *newSplashScreen );
35 extern Animation * GetSplashScreen();
36 extern const vector< string >& ParseDestinations( const string &value );
37 
38 using std::string;
39 //less to write
40 #define activeSys _Universe->activeStarSystem()
42 {
43  GFXSetLightContext( lightcontext );
44 }
45 
46 namespace UniverseUtil
47 {
49 {
50  muzak->GotoSong( game_options.missionvictorysong );
51 }
52 int musicAddList( string str )
53 {
54  return muzak->Addlist( str.c_str() );
55 }
56 void musicLayerSkip( int layer )
57 {
58  muzak->Skip( layer );
59 }
60 void musicLayerStop( int layer )
61 {
62  muzak->Stop( layer );
63 }
64 void musicLayerPlaySong( string str, int layer )
65 {
66  muzak->GotoSong( str, layer );
67 }
68 void musicLayerPlayList( int which, int layer )
69 {
70  if (which != -1)
71  muzak->SkipRandSong( which, layer );
72 }
73 void musicLayerLoopList( int numloops, int layer )
74 {
75  muzak->SetLoops( numloops, layer );
76 }
77 void musicLayerSetSoftVolume( float vol, float latency_override, int layer )
78 {
79  Music::SetVolume( vol, layer, false, latency_override );
80 }
81 void musicLayerSetHardVolume( float vol, int layer )
82 {
83  Music::SetVolume( vol, layer, true );
84 }
85 void musicSetSoftVolume( float vol, float latency_override )
86 {
87  musicLayerSetSoftVolume( vol, latency_override, -1 );
88 }
89 void musicSetHardVolume( float vol )
90 {
91  musicLayerSetHardVolume( vol, -1 );
92 }
93 void musicMute( bool stopSound )
94 {
95  muzak->Mute( stopSound );
96 }
97 void playSound( string soundName, QVector loc, Vector speed )
98 {
99  int sound = AUDCreateSoundWAV( soundName, false );
100  AUDAdjustSound( sound, loc, speed );
101  AUDStartPlaying( sound );
102  AUDDeleteSound( sound );
103 }
104 void playSoundCockpit( string soundName )
105 {
106  int sound = AUDCreateSoundWAV( soundName, false );
107  AUDStartPlaying( sound );
108  AUDDeleteSound( sound );
109 }
110 void StopAllSounds( void )
111 {
113 }
114 void cacheAnimation( string aniName )
115 {
116  static vector< Animation* >anis;
117  anis.push_back( new Animation( aniName.c_str() ) );
118 }
119 void playAnimation( string aniName, QVector loc, float size )
120 {
121  AddAnimation( loc, size, true, aniName, 1 );
122 }
123 void playAnimationGrow( string aniName, QVector loc, float size, float growpercent )
124 {
125  AddAnimation( loc, size, true, aniName, growpercent );
126 }
127 unsigned int getCurrentPlayer()
128 {
129  return _Universe->CurrentCockpit();
130 }
131 unsigned int maxMissions()
132 {
133  return game_options.max_missions;
134 }
135 void addParticle( QVector loc, Vector velocity, Vector color, float size )
136 {
137  ParticlePoint p;
138  p.loc = loc;
139  p.col = color;
140  particleTrail.AddParticle( p, velocity, size );
141 }
142 
143 void loadGame( const string &savename )
144 {
145  Cockpit *cockpit = _Universe->AccessCockpit();
146  Unit *player = cockpit->GetParent();
148  if (player) {
149  if (Network)
150  Network[_Universe->CurrentCockpit()].dieRequest();
151  else
152  player->Kill();
153  }
154  RespawnNow( cockpit );
155  globalWindowManager().shutDown();
157 }
158 
159 void saveGame( const string &savename )
160 {
161  if (Network) {
162  Network[_Universe->CurrentCockpit()].saveRequest();
163  } else {
166  }
167 }
168 
169 void showSplashScreen( const string &filename )
170 {
171  static Animation *curSplash = 0;
172  if ( !filename.empty() ) {
173  if (curSplash)
174  delete curSplash;
175  curSplash = new Animation( filename.c_str(), 0 );
176  } else if ( !curSplash && !GetSplashScreen() ) {
177  static std::vector< std::string >s = ParseDestinations( game_options.splash_screen );
178  int snum = time( NULL )%s.size();
179  curSplash = new Animation( s[snum].c_str(), 0 );
180  }
181  SetStarSystemLoading( true );
182  bootstrap_draw( "Loading...", curSplash );
183 }
184 
185 void showSplashMessage( const string &text )
186 {
187  bootstrap_draw( text, 0 );
188 }
189 
190 void showSplashProgress( float progress ) //DELETE ?
191 {
192  //Unimplemented
193 }
194 
196 {
197  SetStarSystemLoading( false );
198 }
199 
201 {
202  return GetStarSystemLoading();
203 }
204 
205 void sendCustom( int cp, string cmd, string args, string id )
206 {
207  if ( cp < 0 || cp >= static_cast<int>(_Universe->numPlayers()) ) {
208  fprintf( stderr, "sendCustom %s with invalid player %d\n", cmd.c_str(), cp );
209  return;
210  }
211  if (Network != NULL)
212  Network[cp].sendCustom( cmd, args, id );
213  else
214  receivedCustom( cp, true, cmd, args, id );
215 }
216 }
217 
218 #undef activeSys
219