vegastrike  0.5.1.r1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
universe_generic.h
Go to the documentation of this file.
1 /*
2  * Vega Strike
3  * Copyright (C) 2001-2002 Daniel Horn
4  *
5  * http://vegastrike.sourceforge.net/
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20  */
21 #ifndef _GENERICUNIVERSE_H
22 #define _GENERICUNIVERSE_H
23 
24 #define NUM_LIGHT 8
25 #define NUM_FORCES 64
26 
27 #include <memory>
28 #include "star_system_generic.h"
29 #include "faction_generic.h"
30 #include "stardate.h"
31 
32 class Cockpit;
33 class Camera;
34 class Unit;
35 class Texture;
36 
46 namespace GalaxyXML
47 {
48 class Galaxy;
49 }
50 class Universe
51 {
52 protected:
53  std::auto_ptr<GalaxyXML::Galaxy> galaxy;
55  unsigned int current_cockpit;
56  std::vector< Cockpit* >cockpit;
58 //Camera hud_camera;
60 //void StartGL();
62  std::vector< StarSystem* >active_star_system;
63 
64 //the system currently used by the scripting
66  bool is_server;
68 
69 private:
71  friend class Faction;
72 //friend void bootstrap_main_loop();//so it can get all cockpits
74 
75 public:
76  void netLock( bool enable );
77  bool netLocked();
78 
80  bool isServer()
81  {
82  return is_server;
83  }
84  Cockpit * isPlayerStarship( const Unit *fighter );
85  Cockpit * isPlayerStarshipVoid( const void *pointercompare )
86  {
87 //void *newp = const_cast<void *>(pointercompare);
88 //return this->isPlayerStarship(reinterpret_cast<Unit*>(newp));
89  return isPlayerStarship( (const Unit*) pointercompare );
90  }
91  int whichPlayerStarship( const Unit *fighter );
92  Cockpit * AccessCockpit()
93  {
94  return cockpit[current_cockpit];
95  }
96  Cockpit * AccessCockpit( int i )
97  {
98  return cockpit[i];
99  }
100  unsigned int CurrentCockpit()
101  {
102  return current_cockpit;
103  }
105  virtual Camera * AccessCamera( int num )
106  {
107  return NULL;
108  }
109  virtual Camera * AccessCamera()
110  {
111  return NULL;
112  }
114  virtual Camera * AccessHudCamera()
115  {
116  return NULL;
117  }
119  virtual void SetViewport() {}
120  void SetActiveCockpit( int whichcockpit );
121  void SetActiveCockpit( Cockpit *which );
122  virtual void WriteSaveGame( bool auto_save ) {}
123  virtual void SetupCockpits( std::vector< std::string >players );
124  virtual void activateLightMap( int stage = 1 ) {}
125  virtual Texture * getLightMap()
126  {
127  return NULL;
128  }
129  virtual void SelectCamera( int cam ) {}
130 //virtual unsigned int CurrentCockpit(){return 0;}
131  Cockpit * createCockpit( std::string player );
132 
133  void getJumpPath( const std::string &from, const std::string &to, std::vector< std::string > &path ) const;
134  const std::vector< std::string >& getAdjacentStarSystems( const std::string &ss ) const;
135  std::string getGalaxyProperty( const std::string &sys, const std::string &prop );
136  std::string getGalaxyPropertyDefault( const std::string &sys, const std::string &prop, const std::string def = "" );
138  {
139  return galaxy.get();
140  }
141  bool StillExists( StarSystem *ss );
143  {
144  if ( active_star_system.empty() )
145  pushActiveStarSystem( ss );
146  else
147  active_star_system.back() = ss;
148  }
150  {
151  active_star_system.push_back( ss );
152  }
154  {
155  if ( !active_star_system.empty() )
156  active_star_system.pop_back();
157  }
158  void clearAllSystems();
159 //void SetActiveCockpit (int whichcockpit);
160 //void SetActiveCockpit (Cockpit * which);
161  StarSystem * getActiveStarSystem( unsigned int size )
162  {
163  return size >= active_star_system.size() ? NULL : active_star_system[size];
164  }
165  unsigned int getNumActiveStarSystem()
166  {
167  return active_star_system.size();
168  }
169  void LoadStarSystem( StarSystem *ss );
170  void UnloadStarSystem( StarSystem *ss );
171  void Generate1( const char *file, const char *jumpback );
172  void Generate2( StarSystem *ss );
173  virtual StarSystem * GenerateStarSystem( const char *file, const char *jumpback, Vector origin );
175  void LoadFactionXML( const char *factfile )
176  {
177  Faction::LoadXML( factfile );
178  }
179 //void SetupCockpits (std::vector <std::string> players);
180 //void WriteSaveGame(bool auto_save);
181 //void activateLightMap();
183  Universe();
184  Universe( int argc, char **argv, const char *galaxy, bool server = false );
185  void Init( const char *gal );
186  virtual ~Universe();
188 //void StartGFX();
190  virtual class StarSystem * Init( string systemfile, const Vector &centroid = Vector( 0,
191  0,
192  0 ), const string planetname = string() );
194  virtual void StartDraw() {}
195 //Update starsystems (for server side)
196  void Update();
198  virtual void Loop( void f() ) {}
201  {
202  return active_star_system.empty() ? NULL
203  : active_star_system.back();
204  }
206 /*
207  * void SelectCamera(int cam) {
208  * AccessCockpit()->SelectCamera(cam);
209  * }
210  */
212 //unsigned int CurrentCockpit(){return current_cockpit;}
213 //Cockpit *AccessCockpit() {return cockpit[current_cockpit];}
214  unsigned int numPlayers()
215  {
216  return cockpit.size();
217  }
218 //Cockpit *AccessCockpit (int i) {return cockpit[i];}
220 /*
221  * Camera *AccessCamera(int num) {
222  * return AccessCockpit()->AccessCamera(num);
223  * }
224  */
226 /*
227  * Camera *AccessCamera() {
228  * return AccessCockpit()->AccessCamera();
229  * }
230  */
232 //Camera *AccessHudCamera() { return &hud_camera; }
234 /*
235  * void SetViewport() {
236  * AccessCockpit()->SetViewport();
237  * }
238  */
239 
240  StarSystem * getStarSystem( string name );
242  {
243  if (script_system != NULL) return script_system;
244 
245  else return activeStarSystem();
246  ;
247  }
248  bool setScriptSystem( string name )
249  {
250  if (name == "-active-") {
251  script_system = NULL;
252  return true;
253  }
254  StarSystem *ss = getStarSystem( name );
255  if (script_system != NULL) {
256  script_system = ss;
257  return true;
258  }
259  return false;
260  }
261 public:
262  std::vector< StarSystem* >star_system;
263  int StarSystemIndex( StarSystem *ss );
264 };
265 
266 #endif
267