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
planet_generic.h
Go to the documentation of this file.
1 #ifndef __PLANETGENERIC_H
2 #define __PLANETGENERIC_H
3 
4 #include "unit_generic.h"
5 #include "ai/order.h"
6 #include "configxml.h"
7 #include "gfxlib_struct.h"
8 #include "images.h"
9 
10 class Atmosphere;
11 class PlanetaryTransform;
12 class ContinuousTerrain;
13 
14 class PlanetaryOrbit : public Order
15 {
16 private:
17  double velocity;
18  double theta;
19  double inittheta;
20 
21  QVector x_size;
22  QVector y_size;
23  QVector focus;
24 #define ORBIT_PRIORITY 8
25 #define NUM_ORBIT_AVERAGE (SIM_QUEUE_SIZE/ORBIT_PRIORITY)
26  QVector orbiting_average[NUM_ORBIT_AVERAGE];
27  float orbiting_last_simatom;
28  int current_orbit_frame;
29  bool orbit_list_filled;
30 protected:
32  std::vector< int >lights;
33 
34 public: PlanetaryOrbit( Unit *p,
35  double velocity,
36  double initpos,
37  const QVector &x_axis,
38  const QVector &y_axis,
39  const QVector &Centre,
40  Unit *target = NULL );
42  void Execute();
43 };
44 
45 class Planet : public Unit
46 {
47 protected:
48  PlanetaryTransform *terraintrans;
53  bool inside;
54  bool atmospheric; //then users can go inside!
55  float radius;
56  float gravity;
58  std::vector< int >lights;
59 protected:
61  Planet();
63  Planet( QVector x,
64  QVector y,
65  float vely,
66  const Vector &rotvel,
67  float pos,
68  float gravity,
69  float radius,
70  const string &filename,
71  const string &technique,
72  const string &unitname,
73  const vector< string > &dest,
74  const QVector &orbitcent,
75  Unit *parent,
76  int faction,
77  string fullname,
78  bool inside_out = false,
79  unsigned int lights_num = 0 );
80  void InitPlanet( QVector x,
81  QVector y,
82  float vely,
83  const Vector &rotvel,
84  float pos,
85  float gravity,
86  float radius,
87  const string &filename,
88  const string &technique,
89  const string &unitname,
90  const vector< string > &dest,
91  const QVector &orbitcent,
92  Unit *parent,
93  int faction,
94  string fullname,
95  bool inside_out,
96  unsigned int lights_num );
97 
98  friend class UnitFactory;
99  Planet( std::vector< Mesh* >m, bool b, int i ) : Unit( m, b, i ) {}
100 public:
102  virtual ~Planet();
103  virtual Vector AddSpaceElevator( const std::string &name, const std::string &faction, char direction );
104  virtual void AddFog( const vector< AtmosphericFogMesh > &meshes, bool optical_illusion ) {}
105  virtual void AddAtmosphere( const std::string &texture,
106  float radius,
107  BLENDFUNC blendSrc,
108  BLENDFUNC blendDst,
109  bool inside_out ) {}
110  virtual void AddRing( const std::string &texture,
111  float iradius,
112  float oradius,
113  const QVector &r,
114  const QVector &s,
115  int slices,
116  int numwrapx,
117  int numwrapy,
118  BLENDFUNC blendSrc,
119  BLENDFUNC blendDst ) {}
120  virtual void AddCity( const std::string &texture,
121  float radius,
122  int numwrapx,
123  int numwrapy,
124  BLENDFUNC blendSrc,
125  BLENDFUNC blendDst,
126  bool inside_out = false,
127  bool reverse_normals = true ) {}
128  virtual void DisableLights() {}
129  virtual void EnableLights() {}
130  void AddSatellite( Unit *orbiter );
131  void endElement();
132  string getCargoUnitName() const
133  {
134  return getFullname();
135  }
136  string getHumanReadablePlanetType() const;
138  QVector y,
139  float vely,
140  const Vector &rotvel,
141  float pos,
142  float gravity,
143  float radius,
144  const string &filename,
145  const string &technique,
146  const string &unitname,
147  BLENDFUNC blendsrc,
148  BLENDFUNC blenddst,
149  const vector< string > &dest,
150  int level,
151  const GFXMaterial &ourmat,
152  const std::vector< GFXLightLocal > &ligh,
153  bool isunit,
154  int faction,
155  string fullname,
156  bool inside_out );
157  Planet * GetTopPlanet( int level );
158  virtual enum clsptr isUnit() const
159  {
160  return PLANETPTR;
161  }
162  virtual void Draw( const Transformation &quat = identity_transformation, const Matrix &m = identity_matrix ) {}
163  virtual void DrawTerrain() {}
164  static void ProcessTerrains() {}
165  virtual void Kill( bool erasefromsave = false );
166 
167  virtual PlanetaryTransform * setTerrain( ContinuousTerrain*, float ratiox, int numwraps, float scaleatmos )
168  {
169  return NULL;
170  }
171  virtual ContinuousTerrain * getTerrain( PlanetaryTransform* &t )
172  {
173  return NULL;
174  }
175  virtual void setAtmosphere( Atmosphere* ) {}
177  {
178  return NULL;
179  }
180  virtual void reactToCollision( Unit *smaller,
181  const QVector &biglocation,
182  const Vector &bignormal,
183  const QVector &smalllocation,
184  const Vector &smallnormal,
185  float dist )
186  {
187  this->Unit::reactToCollision( smaller, biglocation, bignormal, smalllocation, smallnormal, dist );
188  }
189 
191  {
192 public: PlanetIterator( Planet *p )
193  {
194  localCollection.append( p );
195  pos = localCollection.createIterator();
196  }
198  void preinsert( Unit *unit )
199  {
200  abort();
201  }
202  void postinsert( Unit *unit )
203  {
204  abort();
205  }
206  void remove()
207  {
208  abort();
209  }
210  inline Unit * current()
211  {
212  if ( pos.notDone() )
213  return *pos;
214  return NULL;
215  }
216  void advance()
217  {
218  if (current() != NULL) {
219  Unit *cur = *pos;
220  if (cur->isUnit() == PLANETPTR)
221  for (un_iter tmp( ( (Planet*) cur )->satellites.createIterator() ); tmp.notDone(); ++tmp)
222  localCollection.append( (*tmp) );
223  ++pos;
224  }
225  }
227  {
228  advance();
229  return *this;
230  }
231  inline Unit* operator*()
232  {
233  return current();
234  }
235 private:
236  inline un_iter operator++( int )
237  {
238  abort();
239  }
240  UnitCollection localCollection;
241  un_iter pos;
242  };
244  {
245  return PlanetIterator( this );
246  }
248  {
249  return hasLights() || atmospheric;
250  }
251 
252  bool hasLights()
253  {
254  return !lights.empty();
255  }
256  const std::vector< int >& activeLights()
257  {
258  return lights;
259  }
260 
262  friend class PlanetaryOrbit;
263 
264 private:
266  Planet( const Planet& );
268  Planet& operator=( const Planet& );
269 };
270 
271 #endif
272